def test_from_pedigree_missing_value_in_domain(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_incomplete_domain.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() with pytest.raises(AssertionError) as excinfo: PersonSetCollection.from_families( config.status, quads_f1_families, ) assert "Domain for 'status' does not have the value 'frozenset({'affected'})'!" in str( excinfo.value )
def test_from_pedigree_nonexistent_domain(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_nonexistent_domain.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() with pytest.raises(AssertionError) as excinfo: PersonSetCollection.from_families( config.invalid, quads_f1_families, ) assert "Domain for 'invalid' does not have the value 'frozenset({None})'!" in \ str(excinfo.value)
def build_families_report(families): status_collection_config = { "id": "status", "name": "Affected status", "domain": [{ "id": "affected", "name": "affected", "values": ["affected"], "color": "#e35252" }, { "id": "unaffected", "name": "unaffected", "values": ["unaffected"], "color": "#ffffff" }], "default": { "id": "unspecified", "name": "unspecified", "color": "#aaaaaa" }, "sources": [{ "from": "pedigree", "column": "status" }] } status_collection_config = FrozenBox(status_collection_config) status_collection = PersonSetCollection.from_families( status_collection_config, families) return FamiliesReport(families, [status_collection])
def phenotype_person_sets(variants_impl): vvars = variants_impl("variants_impala")("backends/a") families = vvars.families person_sets_config = FrozenBox({ "id": "phenotype", "sources": [{ "from": "pedigree", "source": "status", }], "default": { "id": "unknown", "name": "Unknown", "color": "#aaaaaa", }, "domain": [{ "id": "autism", "name": "Autism", "values": ["affected"], "color": "#ff0000" }, { "id": "unaffected", "name": "Unaffected", "values": ["unaffected"], "color": "#0000ff", }] }) person_sets = PersonSetCollection.from_families(person_sets_config, families) assert person_sets is not None return person_sets
def test_get_person_color(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() status_collection = PersonSetCollection.from_families( config.status, quads_f1_families ) assert ( PersonSetCollection.get_person_color( quads_f1_families.persons["prb1"], status_collection ) == "#aabbcc" )
def test_phenotype_person_set_continuous( fixture_dirname, fixtures_gpf_instance ): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_phenotype.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() quads_f1_pheno = fixtures_gpf_instance.get_phenotype_data("quads_f1") with pytest.raises(AssertionError) as excinfo: PersonSetCollection.from_families( config.pheno_cont, quads_f1_families, quads_f1_pheno ) assert "Continuous measures not allowed in person sets! (instrument1.continuous)" in \ str(excinfo.value) # TODO Add unit test for default values in person sets (normal and phenotype)
def _build_person_set_collections(self): person_set_collections = dict() collections_json = self.rest_client.get_all_person_set_collections( self._remote_study_id) for coll_json in collections_json: psc = PersonSetCollection.from_json(coll_json, self._families) person_set_collections[psc.id] = psc self._person_set_collections = person_set_collections
def test_collection_merging_ordering(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets.toml") ) config_ext = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_extended_roles.toml") ) filename = fixture_dirname("studies/quads_f1/data/quads_f1.ped") print(filename) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() role_collection = PersonSetCollection.from_families( config.role, quads_f1_families ) role_collection_extended = PersonSetCollection.from_families( config_ext.role, quads_f1_families ) merged_role_collections = PersonSetCollection.merge( [role_collection, role_collection_extended], quads_f1_families, "role", "Merged Roles Collection" ) assert list(merged_role_collections.person_sets.keys()) == [ "0_new_role_first", "dad", "mom", "prb", "sib", "unknown", "z_new_role_last", ]
def get_family_pedigree(family, person_set_collection): return [( p.family_id, p.person_id, p.mom_id if p.mom_id else "0", p.dad_id if p.dad_id else "0", p.sex.short(), str(p.role), PersonSetCollection.get_person_color(p, person_set_collection), p.layout, p.generated, "", "", ) for p in family.persons.values()]
def test_produce_sets(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("sample_person_sets.toml") ) people_sets = PersonSetCollection._produce_sets(config.status) assert people_sets == { "affected": PersonSet( "affected", "Affected", {"affected_val"}, "#aabbcc", dict() ), "unaffected": PersonSet( "unaffected", "Unaffected", {"unaffected_val"}, "#ffffff", dict() ), "unknown": PersonSet( "unknown", "Unknown", {"DEFAULT"}, "#aaaaaa", dict() ), }
def test_from_pedigree(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() status_collection = PersonSetCollection.from_families( config.status, quads_f1_families ) result_person_ids = set( status_collection.person_sets["affected"].persons.keys() ) assert result_person_ids == { 'prb2', 'sib2_3', 'sib2', 'prb1', 'sib1' }
def _build_person_set_collection(self, person_set_collection_id): assert person_set_collection_id in \ self.config.person_set_collections.selected_person_set_collections collections = list() for study in self.studies: collections.append( study.get_person_set_collection(person_set_collection_id)) sample_collection = self.studies[0].get_person_set_collection( person_set_collection_id) self.person_set_collections[person_set_collection_id] = \ PersonSetCollection.merge( collections, self.families, person_set_collection_id, sample_collection.name )
def test_multiple_column_person_set(fixture_dirname): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_multiple_columns.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() status_sex_collection = PersonSetCollection.from_families( config.status_sex, quads_f1_families ) affected_male = set( status_sex_collection.person_sets["affected_male"].persons.keys() ) affected_female = set( status_sex_collection.person_sets["affected_female"].persons.keys() ) assert affected_male == {'prb1', 'prb2'} assert affected_female == {'sib1', 'sib2', 'sib2_3'}
def test_phenotype_person_set_categorical( fixture_dirname, fixtures_gpf_instance ): config = get_person_set_collections_config( fixture_dirname("quads_f1_person_sets_phenotype.toml") ) quads_f1_families = FamiliesLoader( fixture_dirname("studies/quads_f1/data/quads_f1.ped") ).load() quads_f1_pheno = fixtures_gpf_instance.get_phenotype_data("quads_f1") pheno_categorical_collection = PersonSetCollection.from_families( config.pheno_cat, quads_f1_families, quads_f1_pheno ) option1 = set( pheno_categorical_collection.person_sets["option1"].persons.keys() ) option2 = set( pheno_categorical_collection.person_sets["option2"].persons.keys() ) assert option1 == {"mom1"} assert option2 == {"prb1"}
def _build_person_set_collection(self, person_set_collection_id): collection_config = getattr(self.config.person_set_collections, person_set_collection_id) self.person_set_collections[person_set_collection_id] = \ PersonSetCollection.from_families(collection_config, self.families)