public Map<String, List<String>> calculateFamilyGenotypes(String studyStr, String familyId, ClinicalProperty.ModeOfInheritance moi, String disease, boolean incompletePenetrance, String token) throws CatalogException { QueryResult<Family> familyQueryResult = get(studyStr, familyId, QueryOptions.empty(), token); Pedigree pedigree = getPedigreeFromFamily(familyQueryResult.first());
@Test public void createEmptyFamily() throws CatalogException { Family family = new Family("xxx", "xxx", null, null, null, "", -1, Collections.emptyList(), Collections.emptyMap()); QueryResult<Family> familyQueryResult = familyManager.create(STUDY, family, QueryOptions.empty(), sessionIdUser); assertEquals(1, familyQueryResult.getNumResults()); }
public List<QueryResult<FamilyAclEntry>> getAcls(String studyStr, List<String> familyList, String member, boolean silent, String sessionId) throws CatalogException { List<QueryResult<FamilyAclEntry>> familyAclList = new ArrayList<>(familyList.size()); for (String family : familyList) { try { MyResource<Family> resource = getUid(family, studyStr, sessionId); QueryResult<FamilyAclEntry> allFamilyAcls; if (StringUtils.isNotEmpty(member)) { allFamilyAcls = authorizationManager.getFamilyAcl(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser(), member); } else { allFamilyAcls = authorizationManager.getAllFamilyAcls(resource.getStudy().getUid(), resource.getResource().getUid(), resource.getUser()); } allFamilyAcls.setId(family); familyAclList.add(allFamilyAcls); } catch (CatalogException e) { if (silent) { familyAclList.add(new QueryResult<>(family, 0, 0, 0, "", e.toString(), new ArrayList<>(0))); } else { throw e; } } } return familyAclList; }
MyResources<Family> resource = getUids(familyList, studyStr, sessionId); authorizationManager.checkCanAssignOrSeePermissions(resource.getStudy().getUid(), resource.getUser()); checkMembers(resource.getStudy().getUid(), members);
public QueryResult<Family> create(String studyStr, Family family, QueryOptions options, String sessionId) throws CatalogException { String userId = catalogManager.getUserManager().getUserId(sessionId); Study study = catalogManager.getStudyManager().resolveId(studyStr, userId); authorizationManager.checkStudyPermission(study.getUid(), userId, StudyAclEntry.StudyPermissions.WRITE_FAMILIES); ParamUtils.checkObj(family, "family"); ParamUtils.checkAlias(family.getId(), "id"); family.setName(ParamUtils.defaultObject(family.getName(), family.getId())); family.setMembers(ParamUtils.defaultObject(family.getMembers(), Collections.emptyList())); family.setPhenotypes(ParamUtils.defaultObject(family.getPhenotypes(), Collections.emptyList())); family.setDisorders(ParamUtils.defaultObject(family.getDisorders(), Collections.emptyList())); family.setCreationDate(TimeUtils.getTime()); family.setDescription(ParamUtils.defaultString(family.getDescription(), "")); family.setStatus(new Family.FamilyStatus()); family.setAnnotationSets(ParamUtils.defaultObject(family.getAnnotationSets(), Collections.emptyList())); family.setRelease(catalogManager.getStudyManager().getCurrentRelease(study, userId)); family.setVersion(1); family.setAttributes(ParamUtils.defaultObject(family.getAttributes(), Collections.emptyMap())); List<VariableSet> variableSetList = validateNewAnnotationSetsAndExtractVariableSets(study.getUid(), family.getAnnotationSets()); autoCompleteFamilyMembers(family, study, sessionId); validateFamily(family); validateMultiples(family); validatePhenotypes(family); validateDisorders(family); createMissingMembers(family, study, sessionId); options = ParamUtils.defaultObject(options, QueryOptions::new); family.setUuid(UUIDUtils.generateOpenCGAUUID(UUIDUtils.Entity.FAMILY)); QueryResult<Family> queryResult = familyDBAdaptor.insert(study.getUid(), family, variableSetList, options); auditManager.recordCreation(AuditRecord.Resource.family, queryResult.first().getId(), userId, queryResult.first(), null, null); return queryResult; }
options = ParamUtils.defaultObject(options, QueryOptions::new); MyResource resource = getUid(entryStr, studyStr, sessionId); long familyId = resource.getResource().getUid(); } else { autoCompleteFamilyMembers(family, resource.getStudy(), sessionId); validateFamily(family); validateMultiples(family); validatePhenotypes(family); validateDisorders(family); List<VariableSet> variableSetList = checkUpdateAnnotationsAndExtractVariableSets(resource, parameters, options, familyDBAdaptor);
public QueryResult<Family> updateAnnotationSet(String studyStr, String familyStr, List<AnnotationSet> annotationSetList, ParamUtils.UpdateAction action, QueryOptions options, String token) throws CatalogException { ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, annotationSetList); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATION_SETS, action)); return update(studyStr, familyStr, params, options, token); }
QueryResult<Family> familyQueryResult = catalogManager.getFamilyManager().get(study.getFqn(), family.getId(), new QueryOptions(), sessionId); if (familyQueryResult.getNumResults() == 0) {
familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); fail("Expected authorization exception. user2 should not be able to see the study"); } catch (CatalogAuthorizationException ignored) { familyManager.updateAcl(STUDY, Collections.singletonList("Martinez-Martinez"), "user2", new AclParams("VIEW", AclParams.Action.SET), sessionIdUser); QueryResult<Family> familyQueryResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyQueryResult.getNumResults()); assertEquals(0, familyQueryResult.first().getMembers().size()); familyQueryResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyQueryResult.getNumResults()); assertEquals(1, familyQueryResult.first().getMembers().size()); familyQueryResult = familyManager.get(STUDY, "Martinez-Martinez", QueryOptions.empty(), token); assertEquals(1, familyQueryResult.getNumResults()); assertEquals(2, familyQueryResult.first().getMembers().size()); assertEquals("child3", familyQueryResult.first().getMembers().get(1).getId()); familyQueryResult = familyManager.get(STUDY, "Martinez-Martinez", new QueryOptions(QueryOptions.EXCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key()), token); assertEquals(1, familyQueryResult.getNumResults()); assertEquals(null, familyQueryResult.first().getMembers()); familyQueryResult = familyManager.get(STUDY, "Martinez-Martinez", new QueryOptions(QueryOptions.INCLUDE, FamilyDBAdaptor.QueryParams.MEMBERS.key() + "." + IndividualDBAdaptor.QueryParams.NAME.key()),
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()); } } }
Pedigree pedigree = FamilyManager.getPedigreeFromFamily(clinicalAnalysis.getFamily()); OntologyTerm disease = clinicalAnalysis.getDisorder(); Phenotype phenotype = new Phenotype(disease.getId(), disease.getName(), disease.getSource(), Phenotype.Status.UNKNOWN);
public QueryResult<Family> addAnnotationSet(String studyStr, String familyStr, AnnotationSet annotationSet, QueryOptions options, String token) throws CatalogException { return addAnnotationSets(studyStr, familyStr, Collections.singletonList(annotationSet), options, token); }
cohortManager = new CohortManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory, configuration); familyManager = new FamilyManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory, configuration); panelManager = new PanelManager(authorizationManager, auditManager, this, catalogDBAdaptorFactory, catalogIOManagerFactory,
public QueryResult<Family> updateAnnotations(String studyStr, String familyStr, String annotationSetId, Map<String, Object> annotations, ParamUtils.CompleteUpdateAction action, QueryOptions options, String token) throws CatalogException { if (annotations == null || annotations.isEmpty()) { return new QueryResult<>(familyStr, -1, -1, -1, "Nothing to do: The map of annotations is empty", "", Collections.emptyList()); } ObjectMap params = new ObjectMap(AnnotationSetManager.ANNOTATIONS, new AnnotationSet(annotationSetId, "", annotations)); options = ParamUtils.defaultObject(options, QueryOptions::new); options.put(Constants.ACTIONS, new ObjectMap(AnnotationSetManager.ANNOTATIONS, action)); return update(studyStr, familyStr, params, options, token); }
@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())); } }
throw VariantQueryException.missingStudyFor("family", familyId, null); Family family = catalogManager.getFamilyManager().get(defaultStudyStr, familyId, null, sessionId).first(); Pedigree pedigree = FamilyManager.getPedigreeFromFamily(family);
@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()); }
@Test public void updateFamilyMissingPhenotype() throws JsonProcessingException, CatalogException { QueryResult<Family> originalFamily = createDummyFamily("Martinez-Martinez"); Phenotype phenotype1 = new Phenotype("dis1", "New name", "New source"); Family family = new Family(); family.setPhenotypes(Arrays.asList(phenotype1)); ObjectMapper jsonObjectMapper = catalogManagerResource.generateNewObjectMapper(); ObjectMap params = new ObjectMap(jsonObjectMapper.writeValueAsString(family)); params = new ObjectMap(FamilyDBAdaptor.QueryParams.PHENOTYPES.key(), params.get(FamilyDBAdaptor.QueryParams.PHENOTYPES.key())); thrown.expect(CatalogException.class); thrown.expectMessage("not present in any member of the family"); familyManager.update(STUDY, originalFamily.first().getName(), params, QueryOptions.empty(), sessionIdUser); }
@Test public void updateSubjectsAndFamilyTest() throws CatalogException { createDummyEnvironment(false); ObjectMap params = new ObjectMap() .append(ClinicalAnalysisDBAdaptor.QueryParams.PROBAND.key(), new Individual().setId("child1").setSamples(Arrays.asList(new Sample().setId("sample2")))) .append(ClinicalAnalysisDBAdaptor.QueryParams.FAMILY.key(), new Family().setId("family")); QueryResult<ClinicalAnalysis> updateResult = catalogManager.getClinicalAnalysisManager().update(STUDY, "analysis", params, QueryOptions.empty(), sessionIdUser); assertEquals(1, updateResult.getNumResults()); assertEquals(0, updateResult.first().getInterpretations().size()); assertEquals(catalogManager.getFamilyManager().getUid("family", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getFamily().getUid()); assertEquals(catalogManager.getIndividualManager().getUid("child1", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getUid()); assertEquals(1, updateResult.first().getProband().getSamples().size()); assertEquals(catalogManager.getSampleManager().getUid("sample2", STUDY, sessionIdUser).getResource().getUid(), updateResult.first().getProband().getSamples().get(0).getUid()); }
@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()); }