public String getStudyFQN() { return study != null ? study.getFqn() : null; }
int getCurrentRelease(Study study, String userId) throws CatalogException { return catalogManager.getProjectManager().resolveId(StringUtils.split(study.getFqn(), ":")[0], userId).getCurrentRelease(); }
public void fillGaps(String studyStr, List<String> samples, ObjectMap config, String sessionId) throws CatalogException, IllegalAccessException, InstantiationException, ClassNotFoundException, StorageEngineException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); DataStore dataStore = getDataStore(study.getFqn(), sessionId); VariantStorageEngine variantStorageEngine = storageEngineFactory.getVariantStorageEngine(dataStore.getStorageEngine(), dataStore.getDbName()); if (samples == null || samples.size() < 2) { throw new IllegalArgumentException("Fill gaps operation requires at least two samples!"); } variantStorageEngine.fillGaps(study.getFqn(), samples, config); }
private static DataStore getDataStore(CatalogManager catalogManager, Study study, File.Bioformat bioformat, String sessionId) throws CatalogException { DataStore dataStore; if (study.getDataStores() != null && study.getDataStores().containsKey(bioformat)) { dataStore = study.getDataStores().get(bioformat); } else { String projectId = catalogManager.getStudyManager().getProjectFqn(study.getFqn()); dataStore = getDataStoreByProjectId(catalogManager, projectId, bioformat, sessionId); } return dataStore; }
private void fixQueryObject(Study study, Query query, String sessionId) throws CatalogException { // The individuals introduced could be either ids or names. As so, we should use the smart resolutor to do this. if (StringUtils.isNotEmpty(query.getString(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()))) { MyResources<Individual> resource = catalogManager.getIndividualManager().getUids( query.getAsStringList(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()), study.getFqn(), sessionId); query.put(SampleDBAdaptor.QueryParams.INDIVIDUAL_UID.key(), resource.getResourceList().stream().map(Individual::getUid) .collect(Collectors.toList())); query.remove(SampleDBAdaptor.QueryParams.INDIVIDUAL.key()); } }
public void fillMissing(String studyStr, boolean overwrite, ObjectMap config, String sessionId) throws CatalogException, IllegalAccessException, InstantiationException, ClassNotFoundException, StorageEngineException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); DataStore dataStore = getDataStore(study.getFqn(), sessionId); VariantStorageEngine variantStorageEngine = storageEngineFactory.getVariantStorageEngine(dataStore.getStorageEngine(), dataStore.getDbName()); variantStorageEngine.fillMissing(study.getFqn(), config, overwrite); }
private void fixQueryObject(Study study, Query query, String sessionId) throws CatalogException { if (query.containsKey(CohortDBAdaptor.QueryParams.SAMPLES.key())) { // First look for the sample ids. MyResources<Sample> samples = catalogManager.getSampleManager() .getUids(query.getAsStringList(CohortDBAdaptor.QueryParams.SAMPLES.key()), study.getFqn(), sessionId); query.remove(CohortDBAdaptor.QueryParams.SAMPLES.key()); query.append(CohortDBAdaptor.QueryParams.SAMPLE_UIDS.key(), samples.getResourceList().stream().map(Sample::getUid) .collect(Collectors.toList())); } }
@Test public void testGetMetadataFromVcfWithAlreadyExistingSamplesUnsorted() throws CatalogException, FileNotFoundException { //Create samples in a different order than the file order catalogManager.getSampleManager().create(study.getFqn(), expectedSampleNames.get(2), "", "", null, false, null, new HashMap<>(), Collections.emptyMap(), new QueryOptions(), sessionIdUser); catalogManager.getSampleManager().create(study.getFqn(), expectedSampleNames.get(0), "", "", null, false, null, new HashMap<>(), Collections.emptyMap(), new QueryOptions(), sessionIdUser); catalogManager.getSampleManager().create(study.getFqn(), expectedSampleNames.get(3), "", "", null, false, null, new HashMap<>(), Collections.emptyMap(), new QueryOptions(), sessionIdUser); catalogManager.getSampleManager().create(study.getFqn(), expectedSampleNames.get(1), "", "", null, false, null, new HashMap<>(), Collections.emptyMap(), new QueryOptions(), sessionIdUser); testGetMetadataFromVcf(); }
private String updateDefaultCohortStatus(Study study, String status, String sessionId) throws CatalogException { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); Cohort defaultCohort = catalogManager.getCohortManager().get(study.getFqn(), query, new QueryOptions(), sessionId).first(); String prevStatus = defaultCohort.getStatus().getName(); catalogManager.getCohortManager().setStatus(study.getFqn(), defaultCohort.getId(), status, null, sessionId); return prevStatus; }
@Test public void testGetMetadataFromVcfWithAlreadyExistingSamples() throws CatalogException, FileNotFoundException { //Create the samples in the same order than in the file for (String sampleName : expectedSampleNames) { catalogManager.getSampleManager().create(study.getFqn(), sampleName, "", "", null, false, null, new HashMap<>(), Collections .emptyMap(), new QueryOptions(), sessionIdUser); } testGetMetadataFromVcf(); }
public Map<String, Object> facet(String projectStr, String fileFields, String sampleFields, String individualFields, String cohortFields, String familyFields, boolean defaultStats, String sessionId) throws CatalogException, IOException { String userId = catalogManager.getUserManager().getUserId(sessionId); Project project = resolveId(projectStr, userId); Query query = new Query(StudyDBAdaptor.QueryParams.PROJECT_UID.key(), project.getUid()); QueryResult<Study> studyQueryResult = catalogManager.getStudyManager().get(query, new QueryOptions(QueryOptions.INCLUDE, Arrays.asList(StudyDBAdaptor.QueryParams.FQN.key(), StudyDBAdaptor.QueryParams.ID.key())), sessionId); Map<String, Object> result = new HashMap<>(); for (Study study : studyQueryResult.getResult()) { result.put(study.getId(), catalogManager.getStudyManager().facet(study.getFqn(), fileFields, sampleFields, individualFields, cohortFields, familyFields, defaultStats, sessionId)); } return result; }
public QueryResult<PermissionRule> createPermissionRule(String studyStr, Study.Entity entry, PermissionRule permissionRule, String sessionId) throws CatalogException { ParamUtils.checkObj(entry, "entry"); ParamUtils.checkObj(permissionRule, "permission rule"); String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = resolveId(studyStr, userId); authorizationManager.checkCanUpdatePermissionRules(study.getUid(), userId); validatePermissionRules(study.getUid(), entry, permissionRule); studyDBAdaptor.createPermissionRule(study.getUid(), entry, permissionRule); return new QueryResult<>(study.getFqn(), -1, 1, 1, "", "", Collections.singletonList(permissionRule)); }
private void checkInterpretationPermissions(String study, long interpretationId, String token) throws CatalogException, ClinicalVariantException { // Get user ID from token and study numeric ID String userId = catalogManager.getUserManager().getUserId(token); String studyId = catalogManager.getStudyManager().resolveId(study, userId).getFqn(); // This checks that the user has permission to this interpretation Query query = new Query(ClinicalAnalysisDBAdaptor.QueryParams.INTERPRETATIONS_ID.key(), interpretationId); QueryResult<ClinicalAnalysis> clinicalAnalysisQueryResult = catalogManager.getClinicalAnalysisManager() .get(studyId, query, QueryOptions.empty(), token); if (clinicalAnalysisQueryResult.getResult().isEmpty()) { throw new ClinicalVariantException("Either the interpretation ID (" + interpretationId + ") does not exist or the user does" + " not have access permissions"); } }
@Test public void testScanStudyURI() throws IOException, CatalogException { CatalogManagerTest.createDebugFile(directory.resolve("file1.txt").toString()); FileScanner fileScanner = new FileScanner(catalogManager); List<File> files = fileScanner.scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); assertEquals(1, files.size()); URI studyUri = study.getUri(); CatalogManagerTest.createDebugFile(studyUri.resolve("data/test/folder/").resolve("file2.txt").getPath()); File root = catalogManager.getFileManager().get(study.getFqn(), new Query("name", "."), null, sessionIdUser).first(); files = fileScanner.scan(root, studyUri, FileScanner.FileScannerPolicy.REPLACE, true, true, sessionIdUser); assertEquals(1, files.size()); files.forEach((f) -> assertTrue(f.getSize() > 0)); files.forEach((f) -> assertEquals(f.getStatus().getName(), File.FileStatus.READY)); files.forEach((f) -> assertTrue(StringUtils.isNotEmpty(f.getChecksum()))); }
@Test public void testGetMetadataFromVcfWithSomeExistingSamples() throws CatalogException, FileNotFoundException { catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(2)), new QueryOptions(), sessionIdUser); catalogManager.getSampleManager().create(study.getFqn(), new Sample().setId(expectedSampleNames.get(0)), new QueryOptions(), sessionIdUser); testGetMetadataFromVcf(); }
public File getFile(long id) throws CatalogException { return catalogManager.getFileManager().get(String.valueOf(study.getFqn()), new Query(FileDBAdaptor.QueryParams.UID.key(), id) .append(FileDBAdaptor.QueryParams.STATUS_NAME.key(), Status.DELETED + "," + File.FileStatus.TRASHED + "," + Status.READY) , null, sessionIdUser) .first(); }
@Test public void testDeleteExisting() throws IOException, CatalogException { QueryResult<File> queryResult = catalogManager.getFileManager().upload(study.getFqn(), CatalogManagerTest.createDebugFile().toURI(), new File().setPath(folder.getPath() + "file1.txt"), false, false, sessionIdUser); File file = queryResult.first(); CatalogManagerTest.createDebugFile(directory.resolve("file1.txt").toString()); List<File> files = new FileScanner(catalogManager).scan(folder, directory.toUri(), FileScanner.FileScannerPolicy.DELETE, false, true, sessionIdUser); files.forEach((File f) -> assertFalse(f.getAttributes().containsKey("checksum"))); assertEquals(File.FileStatus.DELETED, getFile(file.getUid()).getStatus().getName()); }
@Test public void testGetMetadataFromBam() throws CatalogException, FileNotFoundException { File file = catalogManager.getFileManager().upload(study.getFqn(), bamFileUri, new File().setPath(folder.getPath() + BAM_FILE_NAME), false, false, sessionIdUser).first(); assertTrue(file.getSize() > 0); file = FileMetadataReader.get(catalogManager). setMetadataInformation(file, null, null, sessionIdUser, false); assertEquals(File.FileStatus.READY, file.getStatus().getName()); // assertEquals(File.Format.GZIP, file.getFormat()); assertEquals(File.Bioformat.ALIGNMENT, file.getBioformat()); assertNotNull(file.getAttributes().get("alignmentHeader")); assertEquals(1, file.getSamples().size()); assertEquals("HG00096", catalogManager.getSampleManager().get(study.getFqn(), file.getSamples().get(0).getId(), null, sessionIdUser).first().getId()); }
@Test public void testDeleteIndexedFile() throws Exception { QueryOptions queryOptions = new QueryOptions(VariantStorageEngine.Options.ANNOTATE.key(), false) .append(VariantStorageEngine.Options.CALCULATE_STATS.key(), false); File inputFile = getFile(0); indexFile(inputFile, queryOptions, outputId); Study study = catalogManager.getFileManager().getStudy(inputFile, sessionId); WriteResult result = catalogManager.getFileManager().delete( study.getFqn(), new Query(FileDBAdaptor.QueryParams.PATH.key(), inputFile.getPath()) , null, sessionId); assertEquals(0, result.getNumModified()); assertTrue(result.getFailed().get(0).getMessage().contains("index status")); }