private List<String> createCohortsIfNeeded(String studyId, Set<String> cohortNames, String sessionId) throws CatalogException { List<String> cohorts = new ArrayList<>(); // Silent query, so it does not fail for missing cohorts Set<String> catalogCohorts = catalogManager.getCohortManager().get(studyId, new ArrayList<>(cohortNames), new Query(), new QueryOptions(QueryOptions.INCLUDE, "name,id"), true, sessionId) .stream() .map(QueryResult::first) .filter(Objects::nonNull) .map(Cohort::getId) .collect(Collectors.toSet()); for (String cohortName : cohortNames) { if (!catalogCohorts.contains(cohortName)) { QueryResult<Cohort> cohort = catalogManager.getCohortManager().create(studyId, cohortName, Study.Type.COLLECTION, "", Collections.emptyList(), null, null, sessionId); logger.info("Creating cohort {}", cohortName); cohorts.add(cohort.first().getId()); } else { logger.debug("cohort {} was already created", cohortName); cohorts.add(cohortName); } } return cohorts; }
@Override public QueryResult<Cohort> update(String studyStr, String entryStr, ObjectMap parameters, QueryOptions options, String sessionId) throws CatalogException { return update(studyStr, entryStr, parameters, false, options, sessionId); }
MyResources<Cohort> resource = getUids(cohortList, studyStr, sessionId); members = Collections.emptyList(); checkMembers(resource.getStudy().getUid(), members); authorizationManager.checkNotAssigningPermissionsToAdminsGroup(members);
private Cohort createDefaultCohortIfNeeded(Study study, String sessionId) throws CatalogException { Query query = new Query(CohortDBAdaptor.QueryParams.ID.key(), StudyEntry.DEFAULT_COHORT); Cohort cohort = catalogManager.getCohortManager().get(study.getFqn(), query, null, sessionId).first(); if (cohort == null) { try { return createDefaultCohort(study, sessionId); } catch (CatalogDBException e) { if (e.getMessage().contains("already exists")) { cohort = catalogManager.getCohortManager().get(study.getFqn(), query, null, sessionId).first(); if (cohort == null) { throw e; } else { // Do not fail when concurrent cohort creation. return cohort; } } else { throw e; } } } else { return cohort; } }
.collect(Collectors.toSet()); Cohort defaultCohort = catalogManager.getCohortManager() .get(studyConfiguration.getStudyName(), cohortName, null, sessionId).first(); List<String> cohortFromCatalog = defaultCohort .getSamples() catalogManager.getCohortManager().setStatus(studyConfiguration.getStudyName(), cohortName, status, null, sessionId); catalogManager.getCohortManager().update(studyConfiguration.getStudyName(), cohortName, new ObjectMap(CohortDBAdaptor.QueryParams.SAMPLES.key(), cohortFromStorage), true, null, sessionId); try (DBIterator<Cohort> iterator = catalogManager.getCohortManager().iterator(studyConfiguration.getStudyName(), query, new QueryOptions(), sessionId)) { logger.debug("Cohort \"{}\" change status from {} to {}", cohort.getId(), cohort.getStats(), Cohort.CohortStatus.READY); catalogManager.getCohortManager().setStatus(studyConfiguration.getStudyName(), cohort.getId(), Cohort.CohortStatus.READY, "Update status from Storage", sessionId); .map(studyConfiguration.getCohortIds().inverse()::get) .collect(Collectors.toList())); try (DBIterator<Cohort> iterator = catalogManager.getCohortManager().iterator(studyConfiguration.getStudyName(), query, new QueryOptions(), sessionId)) { logger.debug("Cohort \"{}\" change status from {} to {}", cohort.getId(), cohort.getStats(), Cohort.CohortStatus.INVALID);
@Test public void testDeleteCohort() throws CatalogException, IOException { String studyId = "user@1000G:phase1"; Sample sampleId1 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first(); Sample sampleId2 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_2"), new QueryOptions(), sessionIdUser).first(); Sample sampleId3 = catalogManager.getSampleManager().create(studyId, new Sample().setId("SAMPLE_3"), new QueryOptions(), sessionIdUser).first(); Cohort myCohort = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), null, sessionIdUser).first(); assertEquals("MyCohort", myCohort.getId()); assertEquals(3, myCohort.getSamples().size()); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId1.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId2.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId3.getUid())); WriteResult deleteResult = catalogManager.getCohortManager().delete(studyId, new Query(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()), null, sessionIdUser); assertEquals(1, deleteResult.getNumModified()); Query query = new Query() .append(CohortDBAdaptor.QueryParams.UID.key(), myCohort.getUid()) .append(CohortDBAdaptor.QueryParams.STATUS_NAME.key(), "!=" + Cohort.CohortStatus.READY); Cohort cohort = catalogManager.getCohortManager().get(studyId, query, null, sessionIdUser).first(); assertEquals(Status.DELETED, cohort.getStatus().getName()); }
@Deprecated public QueryResult<Cohort> create(long studyId, String name, Study.Type type, String description, List<Sample> samples, List<AnnotationSet> annotationSetList, Map<String, Object> attributes, String sessionId) throws CatalogException { return create(String.valueOf(studyId), name, type, description, samples, annotationSetList, attributes, sessionId); }
assertEquals(Cohort.CohortStatus.NONE, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getStatus().getName()); assertEquals(Cohort.CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getStatus().getName()); cohorts.put("coh0", catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); checkCalculatedStats(cohorts); catalogManager.getCohortManager().update(studyId, coh[0], new ObjectMap("description", "NewDescription"), new QueryOptions(), sessionId); assertEquals(Cohort.CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getStatus().getName()); List<String> newCohort = catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getSamples().stream() .map(Sample::getId) .skip(10).limit(100) .collect(Collectors.toList()); catalogManager.getCohortManager().update(studyId, coh[0], new ObjectMap("samples", newCohort), new QueryOptions(), sessionId); assertEquals(Cohort.CohortStatus.INVALID, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getStatus().getName()); assertEquals(Cohort.CohortStatus.READY, catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first().getStatus().getName()); cohorts.put("coh0", catalogManager.getCohortManager().get(studyId, coh[0], null, sessionId).first()); checkCalculatedStats(cohorts);
description = "Cohort data imported from " + source; Cohort cohort = catalogManager.getCohortManager().create(studyConfiguration.getStudyName(), cohortName, Study .Type.COLLECTION, description, newSampleList, null, Collections.emptyMap(), sessionId).first(); newCohortIds.put(cohortName, (int) cohort.getUid()); newCohorts.put((int) cohort.getUid(), newSampleList.stream().map(Sample::getUid).map(Long::intValue) .collect(Collectors.toSet())); catalogManager.getCohortManager().setStatus(studyStr, cohort.getId(), Cohort.CohortStatus.READY, "", sessionId);
@Test public void testUpdateCohort() throws CatalogException { Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first(); Sample sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_2"), new QueryOptions(), sessionIdUser).first(); Sample sampleId3 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_3"), new QueryOptions(), sessionIdUser).first(); Sample sampleId4 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_4"), new QueryOptions(), sessionIdUser).first(); Sample sampleId5 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_5"), new QueryOptions(), sessionIdUser).first(); Cohort myCohort = catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3)), null, sessionIdUser).first(); assertEquals("MyCohort", myCohort.getId()); assertEquals(3, myCohort.getSamples().size()); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId1.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId2.getUid())); assertTrue(myCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId3.getUid())); Cohort myModifiedCohort = catalogManager.getCohortManager().update(studyFqn, myCohort.getId(), new ObjectMap("samples", Arrays.asList(sampleId1.getId(), sampleId3.getId(), sampleId4.getId(), sampleId5.getId())) .append(CohortDBAdaptor.QueryParams.ID.key(), "myModifiedCohort"), new QueryOptions(), sessionIdUser).first(); assertEquals("myModifiedCohort", myModifiedCohort.getId()); assertEquals(4, myModifiedCohort.getSamples().size()); assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId1.getUid())); assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId3.getUid())); assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId4.getUid())); assertTrue(myModifiedCohort.getSamples().stream().map(Sample::getUid).collect(Collectors.toList()).contains(sampleId5.getUid())); }
public static File create(String resourceName, boolean indexed) throws IOException, CatalogException { File file; URI uri = getResourceUri(resourceName); file = fileMetadataReader.create(studyId, uri, "data/vcfs/", "", true, null, sessionId).first(); catalogFileUtils.upload(uri, file, null, sessionId, false, false, true, false, Long.MAX_VALUE); if (indexed) { FileIndex fileIndex = new FileIndex("user", "today", new FileIndex.IndexStatus(FileIndex.IndexStatus.READY), 1234, Collections.emptyMap()); catalogManager.getFileManager().setFileIndex(studyId, file.getPath(), fileIndex, sessionId); indexedFiles.add((int) file.getUid()); List<String> samples = catalogManager.getCohortManager().getSamples(studyId, cohortId, null, sessionId).getResult().stream().map(Sample::getId).collect(Collectors.toList()); samples.addAll(file.getSamples().stream().map(Sample::getId).collect(Collectors.toList())); catalogManager.getCohortManager().update(studyId, cohortId, new ObjectMap(CohortDBAdaptor.QueryParams.SAMPLES.key(), samples), true, null, sessionId); } return catalogManager.getFileManager().get(studyId, file.getId(), null, sessionId).first(); }
catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort1").setSamples(Arrays.asList(sample1, sample2, sample3)), QueryOptions.empty(), sessionIdAdmin); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort2").setSamples(Arrays.asList(sample1, sample2)), QueryOptions.empty(), sessionIdAdmin); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("cohort3").setSamples(Arrays.asList(sample2, sample3)), QueryOptions.empty(), sessionIdAdmin); catalogManager.getCohortManager().updateAcl(studyFqn, Collections.singletonList("cohort1"), "@study_deny,user3", new AclParams("VIEW,VIEW_ANNOTATIONS", AclParams.Action.ADD), sessionIdAdmin); catalogManager.getCohortManager().updateAcl(studyFqn, Collections.singletonList("cohort2"), "@study_allow", new AclParams("", AclParams.Action.SET), sessionIdAdmin);
catalogManager.getCohortManager().unsafeUpdate(study, cohort, cohortUpdateParams, false, QueryOptions.empty(), userId); WriteResult delete = catalogManager.getCohortManager().delete(studyStr, cohortQuery, new ObjectMap(), sessionId); if (delete.getWarning() != null || delete.getError() != null) { logger.warn("Cohort {} could not be deleted after extracting the sample {}. WriteResult: {}",
List<Long> samples = catalogManager.getCohortManager().getSamples(studyId, cohortId, null, sessionId) .getResult() .stream() catalogManager.getCohortManager().setStatus(studyId, cohortId, Cohort.CohortStatus.CALCULATING, "", sessionId);
@Test public void testDeleteCohortWithStats() throws Exception { QueryOptions queryOptions = new QueryOptions(VariantStorageEngine.Options.ANNOTATE.key(), false) .append(VariantStorageEngine.Options.CALCULATE_STATS.key(), true); File transformedFile = transformFile(getFile(0), queryOptions); loadFile(transformedFile, queryOptions, outputId); WriteResult result = catalogManager.getCohortManager().delete(studyFqn, new Query(CohortDBAdaptor.QueryParams.ID.key(), "ALL"), null, sessionId); assertEquals(0, result.getNumModified()); assertTrue(result.getFailed().get(0).getMessage().contains("ALL cannot be deleted")); }
protected void updateCohorts(String studyId, List<String> cohortIds, String sessionId, String status, String message) throws CatalogException { for (String cohortId : cohortIds) { catalogManager.getCohortManager().setStatus(studyId, cohortId, status, message, sessionId); } }
@Override protected List<String> validate(String defaultStudyStr, List<String> values, Integer release, VariantQueryParam param, String sessionId) throws CatalogException { if (release == null) { AbstractManager.MyResources<Cohort> uids = catalogManager.getCohortManager().getUids(values, defaultStudyStr, sessionId); return uids.getResourceList().stream().map(Cohort::getId).collect(Collectors.toList()); } else { return validate(defaultStudyStr, values, release, param, catalogManager.getCohortManager(), Cohort::getId, Cohort::getRelease, null, sessionId); } } }
individualManager = new IndividualManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory, configuration); cohortManager = new CohortManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory, configuration); familyManager = new FamilyManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory,
cohortIds = new ArrayList<>(cohorts.size()); for (String cohort : cohorts) { String cohortId = catalogManager.getCohortManager().get(study.getFqn(), cohort, new QueryOptions(QueryOptions.INCLUDE, CohortDBAdaptor.QueryParams.ID.key()), sessionId).first().getId(); cohortIds.add(cohortId);