public QueryResult<Cohort> create(String studyId, String name, Study.Type type, String description, List<Sample> samples, List<AnnotationSet> annotationSetList, Map<String, Object> attributes, String sessionId) throws CatalogException { Cohort cohort = new Cohort(name, type, "", description, samples, annotationSetList, -1, attributes); return create(studyId, cohort, QueryOptions.empty(), sessionId); }
threads.add(new Thread(() -> { try { dbAdaptorFactory.getCatalogCohortDBAdaptor().insert(studyId, new Cohort(cohortName, Study.Type.COLLECTION, "", "", Collections.emptyList(), 1, null), null); } catch (CatalogException ignore) {
public static List<Cohort> createCohorts(String sessionId, String studyId, String tagmapPath, CatalogManager catalogManager, Logger logger) throws IOException, CatalogException { List<Cohort> queryResults = new ArrayList<>(); Properties tagmap = new Properties(); tagmap.load(new FileInputStream(tagmapPath)); Map<String, Cohort> cohorts = catalogManager.getCohortManager().get(studyId, new Query(), null, sessionId) .getResult().stream().collect(Collectors.toMap(Cohort::getId, c->c)); Set<String> catalogCohorts = cohorts.keySet(); for (String cohortName : VariantAggregatedStatsCalculator.getCohorts(tagmap)) { if (!catalogCohorts.contains(cohortName)) { QueryResult<Cohort> cohort = catalogManager.getCohortManager().create(studyId, new Cohort() .setId(cohortName) .setName(cohortName) .setSamples(Collections.emptyList()) .setType(Study.Type.COLLECTION), null, sessionId); queryResults.add(cohort.first()); } else { logger.warn("cohort {} was already created", cohortName); queryResults.add(cohorts.get(cohortName)); } } return queryResults; }
/** * Sample methods * *************************** */ /* * Cohort methods * */ @Test public void testCreateCohort() 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(); Cohort myCohort = catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort") .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())); }
@Test public void testCreateCohortAlreadyExisting() throws CatalogException { Sample sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first(); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY) .setSamples(Collections.singletonList(sampleId1)), null, sessionIdUser).first(); thrown.expect(CatalogDBException.class); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY) .setSamples(Collections.singletonList(sampleId1)), null, sessionIdUser).first(); }
@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())); }
@Test @Ignore // TODO: This should be tested in the sample manager, not here !!! public void deleteSampleFail3Test() throws Exception { long studyId = user3.getProjects().get(0).getStudies().get(0).getUid(); Sample hg0097 = new Sample("HG0097", "1000g", new Individual(), "A description", 1); QueryResult<Sample> createResult = dbAdaptorFactory.getCatalogSampleDBAdaptor().insert(studyId, hg0097, null); dbAdaptorFactory.getCatalogCohortDBAdaptor().insert(studyId, new Cohort("Cohort", Study.Type.COLLECTION, "", "", Collections.singletonList(createResult.first()), 1, null), null); thrown.expect(CatalogDBException.class); dbAdaptorFactory.getCatalogSampleDBAdaptor().delete(createResult.first().getUid()); }
@Test public void testCreateCohortFail() throws CatalogException { thrown.expect(CatalogException.class); List<Sample> sampleList = Arrays.asList(new Sample().setUid(23L), new Sample().setUid(4L), new Sample().setUid(5L)); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("MyCohort").setType(Study.Type.FAMILY).setSamples(sampleList), null, sessionIdUser); }
@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()); }
@Test public void CohortToSolrTest() { Study study = new Study().setFqn("user@project:study").setAttributes(new HashMap<>()); Cohort cohort = new Cohort("id", Study.Type.CASE_SET, TimeUtils.getTime(), "test", Arrays.asList(new Sample().setId("1"), new Sample().setId("2")), 2, null) .setAttributes(new HashMap<>());
catalog.getCohortManager().create("s1", new Cohort().setId("c1").setSamples(Collections.emptyList()), null, sessionId); createSample("sample3", "individual3"); createSample("sample4", "individual4"); catalog.getCohortManager().create("s1", new Cohort().setId("c2").setSamples(Collections.emptyList()), null, sessionId); catalog.getCohortManager().create("s1", new Cohort().setId(StudyEntry.DEFAULT_COHORT).setSamples(samples), null, sessionId);
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);
smp6 = catalogManager.getSampleManager().create(studyFqn, new Sample().setId("smp6"), QueryOptions.empty(), ownerSessionId).first(); catalogManager.getCohortManager().create(studyFqn, new Cohort().setId("all").setSamples(Arrays.asList(smp1, smp2, smp3)), QueryOptions.empty(), ownerSessionId);
sessionIdUser).first(); Cohort myCohort1 = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort1").setType(Study.Type.FAMILY).setSamples(Arrays.asList(sampleId1,sampleId2, sampleId3)), null, sessionIdUser).first(); Cohort myCohort2 = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort2").setType(Study.Type.FAMILY) .setSamples(Arrays.asList(sampleId1, sampleId2, sampleId3, sampleId4)), null, sessionIdUser).first(); Cohort myCohort3 = catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort3") .setType(Study.Type.CASE_CONTROL).setSamples(Arrays.asList(sampleId3, sampleId4)), null, sessionIdUser).first(); catalogManager.getCohortManager().create(studyId, new Cohort().setId("MyCohort4").setType(Study.Type.TRIO) .setSamples(Arrays.asList(sampleId5, sampleId3)), null, sessionIdUser).first();