List<Individual> individualsToCreate = new ArrayList<>(); for (Individual individual : family.getMembers()) { individualMap.put(individual.getId(), individual); if (individual.getUid() <= 0) { individualsToCreate.add(individual); if (entry.getValue().getFather() != null && StringUtils.isNotEmpty(entry.getValue().getFather().getId())) { entry.getValue().setFather(individualMap.get(entry.getValue().getFather().getId())); if (entry.getValue().getMother() != null && StringUtils.isNotEmpty(entry.getValue().getMother().getId())) { entry.getValue().setMother(individualMap.get(entry.getValue().getMother().getId()));
Set<String> individualIds = new HashSet<>(); for (Individual individual : family.getMembers()) { memberMap.put(individual.getId(), individual); individualIds.add(individual.getId()); if (individual.getFather() != null && StringUtils.isNotEmpty(individual.getFather().getId())) { individualIds.add(individual.getFather().getId()); if (individual.getMother() != null && StringUtils.isNotEmpty(individual.getMother().getId())) { individualIds.add(individual.getMother().getId()); for (Individual individual : individualQueryResult.getResult()) { memberMap.put(individual.getId(), individual);
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()); }
public static Pedigree getPedigreeFromFamily(Family family) { List<Individual> members = family.getMembers(); Map<String, Member> individualMap = new HashMap<>(); // Parse all the individuals for (Individual member : members) { Member individual = new Member( member.getId(), member.getName(), null, null, member.getMultiples(), Member.Sex.getEnum(member.getSex().toString()), member.getLifeStatus(), Member.AffectionStatus.getEnum(member.getAffectationStatus().toString()), member.getPhenotypes(), member.getAttributes()); individualMap.put(individual.getId(), individual); } // Fill parent information for (Individual member : members) { if (member.getFather() != null && StringUtils.isNotEmpty(member.getFather().getId())) { individualMap.get(member.getId()).setFather(individualMap.get(member.getFather().getId())); } if (member.getMother() != null && StringUtils.isNotEmpty(member.getMother().getId())) { individualMap.get(member.getId()).setMother(individualMap.get(member.getMother().getId())); } } List<Member> individuals = new ArrayList<>(individualMap.values()); return new Pedigree(family.getId(), individuals, family.getPhenotypes(), family.getAttributes()); }
private void validateMultiples(Family family) throws CatalogException { if (family.getMembers() == null || family.getMembers().isEmpty()) { return; } Map<String, List<String>> multiples = new HashMap<>(); // Look for all the multiples for (Individual individual : family.getMembers()) { if (individual.getMultiples() != null && individual.getMultiples().getSiblings() != null && !individual.getMultiples().getSiblings().isEmpty()) { multiples.put(individual.getId(), individual.getMultiples().getSiblings()); } } if (multiples.size() > 0) { // Check if they are all cross-referenced for (Map.Entry<String, List<String>> entry : multiples.entrySet()) { for (String sibling : entry.getValue()) { if (!multiples.containsKey(sibling)) { throw new CatalogException("Missing sibling " + sibling + " of member " + entry.getKey()); } if (!multiples.get(sibling).contains(entry.getKey())) { throw new CatalogException("Incomplete sibling information. Sibling " + sibling + " does not contain " + entry.getKey() + " as its sibling"); } } } } }
void processDeNovo(ClinicalAnalysis clinicalAnalysis, Pedigree pedigree, Phenotype phenotype, Query query, Map<String, ReportedVariant> reportedVariantMap, Panel diseasePanel) throws CatalogException, StorageEngineException, IOException { VariantQueryResult<Variant> variantQueryResult; Map<String, List<String>> probandGenotype = new HashMap<>(); probandGenotype.put(clinicalAnalysis.getProband().getId(), Arrays.asList(ModeOfInheritance.toGenotypeString(ModeOfInheritance.GENOTYPE_0_0))); putGenotypesNegated(probandGenotype, query); variantQueryResult = variantStorageManager.get(query, QueryOptions.empty(), token); List<Variant> deNovoVariantList = ModeOfInheritance.deNovoVariants(pedigree.getProband(), variantQueryResult.getResult().iterator()); // TODO: We need to create another ReportedModeOfInheritance for de novo!!?? generateReportedVariants(deNovoVariantList, phenotype, diseasePanel, ClinicalProperty.ModeOfInheritance.DE_NOVO, reportedVariantMap); }
private void fillIndividuals(String studyId, List<org.opencb.biodata.models.metadata.Individual> individuals) throws CatalogException { Map<String, org.opencb.biodata.models.metadata.Individual> individualMap = individuals .stream() .collect(Collectors.toMap(org.opencb.biodata.models.metadata.Individual::getId, i -> i)); Query query = new Query(IndividualDBAdaptor.QueryParams.ID.key(), new ArrayList<>(individualMap.keySet())); List<Individual> catalogIndividuals = catalogManager.getIndividualManager().get(studyId, query, INDIVIDUAL_QUERY_OPTIONS, sessionId) .getResult(); for (Individual catalogIndividual : catalogIndividuals) { org.opencb.biodata.models.metadata.Individual individual = individualMap.get(catalogIndividual.getName()); individual.setSex(catalogIndividual.getSex().name()); // individual.setFamily(catalogIndividual.getFamily()); individual.setPhenotype(catalogIndividual.getAffectationStatus().toString()); if (catalogIndividual.getMother() != null) { individual.setMother(catalogIndividual.getMother().getId()); } if (catalogIndividual.getFather() != null) { individual.setFather(catalogIndividual.getFather().getId()); } } }
void processCompoundHeterozygous(ClinicalAnalysis clinicalAnalysis, Pedigree pedigree, Phenotype phenotype, Query query, Map<String, ReportedVariant> reportedVariantMap, Panel diseasePanel) throws Exception { VariantQueryResult<Variant> variantQueryResult; Map<String, List<String>> probandGenotype; // Calculate compound heterozygous probandGenotype = new HashMap<>(); probandGenotype.put(clinicalAnalysis.getProband().getId(), Arrays.asList(ModeOfInheritance.toGenotypeString(ModeOfInheritance.GENOTYPE_0_1))); putGenotypes(probandGenotype, query); for (GenePanel gene : diseasePanel.getDiseasePanel().getGenes()) { query.put(VariantQueryParam.ANNOT_XREF.key(), gene); variantQueryResult = variantStorageManager.get(query, QueryOptions.empty(), token); List<Variant> compoundHetVariantList = ModeOfInheritance.compoundHeterozygosity(pedigree, variantQueryResult.getResult().iterator()); // TODO: We need to create another ReportedModeOfInheritance for compound heterozygous!!?? generateReportedVariants(compoundHetVariantList, phenotype, diseasePanel, ClinicalProperty.ModeOfInheritance.COMPOUND_HETEROZYGOUS, reportedVariantMap); } }
MyResource<Individual> resource = catalogManager.getIndividualManager().getUid(proband.getId(), study.getFqn(), sessionId); proband.setUid(resource.getResource().getUid());
@Test public void includeMemberIdOnly() throws CatalogException { createDummyFamily("family"); QueryOptions options = new QueryOptions(QueryOptions.INCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key() + "." + IndividualDBAdaptor.QueryParams.ID.key()); QueryResult<Family> family = familyManager.get(STUDY, "family", options, sessionIdUser); for (Individual individual : family.first().getMembers()) { assertTrue(StringUtils.isNotEmpty(individual.getId())); assertTrue(StringUtils.isEmpty(individual.getName())); assertTrue(StringUtils.isEmpty(individual.getCreationDate())); } }
@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 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); }
private void validateFamilyAndProband(ClinicalAnalysis clinicalAnalysis, Study study, String sessionId) throws CatalogException { if (clinicalAnalysis.getFamily() != null && StringUtils.isNotEmpty(clinicalAnalysis.getFamily().getId())) { MyResource<Family> familyResource = catalogManager.getFamilyManager().getUid(clinicalAnalysis.getFamily().getId(), study.getFqn(), sessionId); clinicalAnalysis.setFamily(familyResource.getResource()); // Check the proband is an actual member of the family Query query = new Query() .append(FamilyDBAdaptor.QueryParams.UID.key(), familyResource.getResource().getUid()) .append(FamilyDBAdaptor.QueryParams.MEMBER_UID.key(), clinicalAnalysis.getProband().getUid()); QueryResult<Family> count = catalogManager.getFamilyManager().count(study.getFqn(), query, sessionId); if (count.getNumTotalResults() == 0) { throw new CatalogException("The member " + clinicalAnalysis.getProband().getId() + " does not belong to the family " + clinicalAnalysis.getFamily().getId()); } } }
assertEquals(1, familyQueryResult.getNumResults()); assertEquals(1, familyQueryResult.first().getMembers().size()); assertEquals("child2", familyQueryResult.first().getMembers().get(0).getId()); assertEquals(1, familyQueryResult.getNumResults()); assertEquals(2, familyQueryResult.first().getMembers().size()); assertEquals("child2", familyQueryResult.first().getMembers().get(0).getId()); assertEquals("child3", familyQueryResult.first().getMembers().get(1).getId()); assertEquals(null, familyQueryResult.first().getName()); assertEquals(2, familyQueryResult.first().getMembers().size()); assertEquals(null, familyQueryResult.first().getMembers().get(0).getId()); assertEquals(null, familyQueryResult.first().getMembers().get(1).getId()); assertEquals("child2", familyQueryResult.first().getMembers().get(0).getName()); assertEquals("child3", familyQueryResult.first().getMembers().get(1).getName());
@Test public void testAnnotateIndividualUnique() throws CatalogException { String individualId = catalogManager.getIndividualManager().create(studyFqn, new Individual().setId("INDIVIDUAL_1"), new QueryOptions(), sessionIdUser).first().getId();
@Test public void createClinicalAnalysisTest() throws CatalogException { QueryResult<ClinicalAnalysis> dummyEnvironment = createDummyEnvironment(true); assertEquals(1, dummyEnvironment.getNumResults()); assertEquals(0, dummyEnvironment.first().getInterpretations().size()); assertEquals("family", dummyEnvironment.first().getFamily().getId()); assertEquals(5, dummyEnvironment.first().getFamily().getMembers().size()); assertNotNull(dummyEnvironment.first().getProband()); assertEquals("child1", dummyEnvironment.first().getProband().getId()); assertEquals(1, dummyEnvironment.first().getProband().getSamples().size()); assertEquals("sample2", dummyEnvironment.first().getProband().getSamples().get(0).getId()); assertEquals(catalogManager.getSampleManager().getUid("sample2", STUDY, sessionIdUser).getResource().getUid(), dummyEnvironment.first().getProband().getSamples().get(0).getUid()); }
@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) )); }
@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()); }
@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()); }