entry.getValue().setFather(individualMap.get(entry.getValue().getFather().getId()));
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 createFamilyDuo() throws CatalogException { Family family = new Family() .setId("test") .setPhenotypes(Arrays.asList(new Phenotype("E00", "blabla", "blabla"))) .setMembers(Arrays.asList(new Individual().setId("proband").setSex(IndividualProperty.Sex.MALE), new Individual().setFather(new Individual().setId("proband")).setId("child") .setSex(IndividualProperty.Sex.FEMALE))); QueryResult<Family> familyQueryResult = familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); assertEquals(2, familyQueryResult.first().getMembers().size()); }
.setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child2", "child3"))) Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child2")))
@Test public void createFamilyMissingMember() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Collections.singletonList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relChild1, relChild2), "", 3, Collections.emptyList(), Collections.emptyMap()); thrown.expect(CatalogException.class); thrown.expectMessage("not present in the members list"); familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); }
@Test public void createFamilyRepeatedMember() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relMother, relChild1, relChild2, relChild1), "", -1, Collections.emptyList(), Collections.emptyMap ()); QueryResult<Family> familyQueryResult = familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); assertEquals(4, familyQueryResult.first().getMembers().size()); }
@Test public void createFamilyPhenotypeNotPassed() throws CatalogException { Phenotype phenotype1 = new Phenotype("dis1", "Phenotype 1", "HPO"); Phenotype phenotype2 = new Phenotype("dis2", "Phenotype 2", "HPO"); Individual father = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual mother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relMother = new Individual().setId("mother").setPhenotypes(Arrays.asList(new Phenotype("dis2", "dis2", "OT"))); Individual relChild1 = new Individual().setId("child1") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis3", "dis3", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family("Martinez-Martinez", "Martinez-Martinez", Arrays.asList(phenotype1, phenotype2), null, Arrays.asList(relFather, relMother, relChild1, relChild2), "", 4, Collections.emptyList(), Collections.emptyMap()); thrown.expect(CatalogException.class); thrown.expectMessage("not present in any member of the family"); familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); }
.setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child2", "child3"))) Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child20")))
individual.setFather(fatherResource.getResource());
.setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child2", "child3"))) Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1")))
.setFather(father) .setMother(mother) .setSamples(Arrays.asList( Individual relChild2 = new Individual().setId("child2") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child3"))) Individual relChild3 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))) .setFather(father) .setMother(mother) .setMultiples(new Multiples("multiples", Arrays.asList("child1", "child2")))
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 updateFamilyMissingMember() throws CatalogException, JsonProcessingException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Individual father = new Individual().setId("father"); Individual mother = new Individual().setId("mother2"); // We create a new father and mother with the same information to mimic the behaviour of the webservices. Otherwise, we would be // ingesting references to exactly the same object and this test would not work exactly the same way. Individual relFather = new Individual().setId("father").setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"))); Individual relChild1 = new Individual().setId("child3") .setPhenotypes(Arrays.asList(new Phenotype("dis1", "dis1", "OT"), new Phenotype("dis2", "dis2", "OT"))) .setFather(father) .setMother(mother) .setParentalConsanguinity(true); Family family = new Family(); family.setMembers(Arrays.asList(relChild1, relFather)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.MEMBERS.key(), params.get(FamilyDBAdaptor.QueryParams.MEMBERS.key())); thrown.expect(CatalogException.class); thrown.expectMessage("not present in the members list"); familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); }