@Deprecated public QueryResult<Individual> create(long studyId, String name, String family, long fatherId, long motherId, IndividualProperty.Sex sex, String ethnicity, String populationName, String populationSubpopulation, String populationDescription, String dateOfBirth, IndividualProperty.KaryotypicSex karyotypicSex, IndividualProperty.LifeStatus lifeStatus, IndividualProperty.AffectationStatus affectationStatus, QueryOptions options, String sessionId) throws CatalogException { Individual individual = new Individual(name, name, null, null, null, null, sex, karyotypicSex, ethnicity, new Individual.Population(populationName, populationSubpopulation, populationDescription), dateOfBirth, -1, 1, null, null, lifeStatus, affectationStatus, null, null, null, false, null, null); return create(String.valueOf(studyId), individual, options, sessionId); }
private void createMissingIndividual(Individual individual, Map<String, Individual> individualMap, Study study, String sessionId) throws CatalogException { if (individual == null || individual.getUid() > 0) { return; } if (individual.getFather() != null && StringUtils.isNotEmpty(individual.getFather().getId())) { createMissingIndividual(individual.getFather(), individualMap, study, sessionId); individual.setFather(individualMap.get(individual.getFather().getId())); } if (individual.getMother() != null && StringUtils.isNotEmpty(individual.getMother().getId())) { createMissingIndividual(individual.getMother(), individualMap, study, sessionId); individual.setMother(individualMap.get(individual.getMother().getId())); } QueryResult<Individual> individualQueryResult = catalogManager.getIndividualManager().create(study.getFqn(), individual, QueryOptions.empty(), sessionId); if (individualQueryResult.getNumResults() == 0) { throw new CatalogException("Unexpected error when trying to create individual " + individual.getId()); } individualMap.put(individual.getId(), individualQueryResult.first()); }
@Test public void testGetIndividualWithSamples() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); individualManager.create(studyFqn, new Individual().setId("individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"), new Sample().setId("sample3"))), QueryOptions.empty(), sessionIdUser); individualManager.create(studyFqn, new Individual().setId("individual2") .setSamples(Arrays.asList(new Sample().setId("sample4"), new Sample().setId("sample5"), new Sample().setId("sample6"))), QueryOptions.empty(), sessionIdUser);
individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual1", "individual1", IndividualProperty.Sex.MALE, null, null, 0, Collections.emptyList(), Collections.emptyMap()), null, sessionId).first()); individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual2", "individual2", IndividualProperty.Sex.FEMALE, null, null, 0, Collections.emptyList(), Collections.emptyMap()), null, sessionId).first()); individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual3", "individual3", IndividualProperty.Sex.MALE, null, null, 0, Collections.emptyList(), Collections.emptyMap()).setFather(individuals.get(0)).setMother(individuals.get(1)).setPhenotypes(Collections.singletonList(phenotype)), null, sessionId).first()); individuals.add(catalog.getIndividualManager().create("s1", new Individual("individual4", "individual4", IndividualProperty.Sex.FEMALE, null, null, 0, Collections.emptyList(), Collections.emptyMap()).setFather(individuals.get(0)).setMother(individuals.get(1)), null, sessionId).first()); catalog.getFamilyManager().create("s1", new Family("f1", "f1", Collections.singletonList(phenotype), null, individuals, null, 3, null, null), null, sessionId);
@Test public void testAnnotateIndividualUnique() throws CatalogException { String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1"), new QueryOptions(), sessionIdUser).first().getId();
sample.getIndividual().setSamples(Collections.singletonList(queryResult.first())); try { catalogManager.getIndividualManager().create(studyStr, sample.getIndividual(), QueryOptions.empty(), sessionId); } catch (CatalogException e) {
@Test public void testCreateSampleWithIndividual() throws CatalogException { String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); String sampleId1 = catalogManager.getSampleManager().create(studyFqn, new Sample() .setId("SAMPLE_1") .setIndividual(new Individual().setId(individualId)), new QueryOptions(), sessionIdUser).first().getId(); QueryResult<Individual> individualQueryResult = catalogManager.getIndividualManager().get(studyFqn, individualId, QueryOptions.empty(), sessionIdUser); assertEquals(sampleId1, individualQueryResult.first().getSamples().get(0).getId()); // Create sample linking to individual based on the individual name String sampleId2 = catalogManager.getSampleManager().create(studyFqn, new Sample() .setId("SAMPLE_2") .setIndividual(new Individual().setId("Individual1")), new QueryOptions(), sessionIdUser).first().getId(); individualQueryResult = catalogManager.getIndividualManager().get(studyFqn, individualId, QueryOptions.empty(), sessionIdUser); assertEquals(2, individualQueryResult.first().getSamples().size()); assertTrue(individualQueryResult.first().getSamples().stream().map(Sample::getId).collect(Collectors.toSet()).containsAll( Arrays.asList(sampleId1, sampleId2) )); }
VariableSet variableSet = study.getVariableSets().get(0); String individualId1 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN) .setAffectationStatus(IndividualProperty.AffectationStatus.UNKNOWN), new QueryOptions(), sessionIdUser) .first().getId(); String individualId2 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_2") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN) .setAffectationStatus(IndividualProperty.AffectationStatus.UNKNOWN), new QueryOptions(), sessionIdUser) .first().getId(); String individualId3 = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_3") .setKaryotypicSex(IndividualProperty.KaryotypicSex.UNKNOWN).setLifeStatus(IndividualProperty.LifeStatus.UNKNOWN) .setAffectationStatus(IndividualProperty.AffectationStatus.UNKNOWN), new QueryOptions(), sessionIdUser)
@Test public void testUpdateIndividuaParents() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); individualManager.create(studyFqn, new Individual().setId("child"), QueryOptions.empty(), sessionIdUser); individualManager.create(studyFqn, new Individual().setId("father"), QueryOptions.empty(), sessionIdUser); individualManager.create(studyFqn, new Individual().setId("mother"), QueryOptions.empty(), sessionIdUser); QueryResult<Individual> individualQueryResult = individualManager.update(studyFqn, "child", new ObjectMap() .append(IndividualDBAdaptor.QueryParams.FATHER.key(), new ObjectMap(IndividualDBAdaptor.QueryParams.ID.key(), "father")) .append(IndividualDBAdaptor.QueryParams.MOTHER.key(), new ObjectMap(IndividualDBAdaptor.QueryParams.ID.key(), "mother")), QueryOptions.empty(), sessionIdUser); assertEquals("mother", individualQueryResult.first().getMother().getId()); assertEquals(1, individualQueryResult.first().getMother().getVersion()); assertEquals("father", individualQueryResult.first().getFather().getId()); assertEquals(1, individualQueryResult.first().getFather().getVersion()); }
.setSex(IndividualProperty.Sex.UNKNOWN); ind.setAnnotationSets(Collections.singletonList(annotationSet)); ind = catalogManager.getIndividualManager().create(studyFqn, ind, QueryOptions.empty(), sessionIdUser).first();
@Test public void testModifySample() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() .create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); Sample sample = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), individualId), new QueryOptions("lazy", false), sessionIdUser).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); }
@Test public void searchSamplesByIndividual() throws CatalogException { catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1") .setSamples(Arrays.asList(new Sample().setId("sample1"), new Sample().setId("sample2"))), new QueryOptions(), sessionIdUser); QueryResult<Sample> sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual1"), QueryOptions.empty(), sessionIdUser); assertEquals(2, sampleQueryResult.getNumResults()); sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual1") .append(SampleDBAdaptor.QueryParams.ID.key(), "sample1"), QueryOptions.empty(), sessionIdUser); assertEquals(1, sampleQueryResult.getNumResults()); catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual2"), new QueryOptions(), sessionIdUser); sampleQueryResult = catalogManager.getSampleManager().search(studyFqn, new Query().append(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), "Individual2"), QueryOptions.empty(), sessionIdUser); assertEquals(0, sampleQueryResult.getNumResults()); }
@Test public void testUpdateIndividualInfo() throws CatalogException { IndividualManager individualManager = catalogManager.getIndividualManager(); QueryResult<Individual> individualQueryResult = individualManager.create(studyFqn, new Individual().setId("Test") .setDateOfBirth("19870214"), QueryOptions.empty(), sessionIdUser); assertEquals(1, individualQueryResult.getNumResults()); assertEquals("Test", individualQueryResult.first().getId()); assertEquals("19870214", individualQueryResult.first().getDateOfBirth()); QueryResult<Individual> update = individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key() , null), QueryOptions.empty(), sessionIdUser); assertEquals("", update.first().getDateOfBirth()); update = individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key(), "19870214"), QueryOptions.empty(), sessionIdUser); assertEquals("19870214", update.first().getDateOfBirth()); update = individualManager.update(studyFqn, String.valueOf(individualQueryResult.first().getId()), new ObjectMap(IndividualDBAdaptor.QueryParams.ATTRIBUTES.key(), Collections.singletonMap("key", "value")), QueryOptions.empty(), sessionIdUser); assertEquals("value", update.first().getAttributes().get("key")); update = individualManager.update(studyFqn, String.valueOf(individualQueryResult.first().getId()), new ObjectMap(IndividualDBAdaptor.QueryParams.ATTRIBUTES.key(), Collections.singletonMap("key2", "value2")), QueryOptions.empty(), sessionIdUser); assertEquals("value", update.first().getAttributes().get("key")); // Keep "key" assertEquals("value2", update.first().getAttributes().get("key2")); // add new "key2" // Wrong date of birth format thrown.expect(CatalogException.class); thrown.expectMessage("Invalid date of birth format"); individualManager.update(studyFqn, individualQueryResult.first().getId(), new ObjectMap(IndividualDBAdaptor.QueryParams.DATE_OF_BIRTH.key(), "198421"), QueryOptions.empty(), sessionIdUser); }
@Test public void testGetSampleAndIndividualWithPermissionsChecked() throws CatalogException { String sampleId1 = catalogManager.getSampleManager() .create(studyFqn, new Sample().setId("SAMPLE_1"), new QueryOptions(), sessionIdUser).first().getId(); String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("Individual1"), new QueryOptions(), sessionIdUser).first().getId(); Sample sample = catalogManager.getSampleManager() .update(studyFqn, sampleId1, new ObjectMap(SampleDBAdaptor.QueryParams.INDIVIDUAL.key(), individualId), new QueryOptions("lazy", false), sessionIdUser).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("SAMPLE_1"), "user2", new Sample.SampleAclParams(SampleAclEntry.SamplePermissions.VIEW.name(), AclParams.Action.SET, null, null, null), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(null, sample.getAttributes().get("individual")); assertEquals(sampleId1, sample.getId()); catalogManager.getSampleManager().updateAcl(studyFqn, Collections.singletonList("SAMPLE_1"), "user2", new Sample.SampleAclParams(SampleAclEntry.SamplePermissions.VIEW.name(), AclParams.Action.SET, null, null, null, true), sessionIdUser); sample = catalogManager.getSampleManager().get(studyFqn, "SAMPLE_1", new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); sample = catalogManager.getSampleManager().get(studyFqn, new Query("individual", "Individual1"), new QueryOptions("lazy", false), sessionIdUser2).first(); assertEquals(individualId, ((Individual) sample.getAttributes().get("individual")).getId()); assertEquals(sampleId1, sample.getId()); }