def get_object_genotype(id, **args): obj = scigraph.bioobject(id, 'Genotype') obj.phenotype_associations = search_associations(subject=id, object_category='phenotype', **args)['associations'] obj.disease_associations = search_associations(subject=id, object_category='disease', **args)['associations'] obj.gene_associations = search_associations(subject=id, object_category='gene', **args)['associations'] return(obj)
def get(self, id): """ Returns associations to GO terms for a gene """ args = core_parser_with_rel.parse_args() if args['relationship_type'] == ACTS_UPSTREAM_OF_OR_WITHIN: return search_associations(subject_category='gene', object_category='function', fq={'regulates_closure': id}, invert_subject_object=True, **args) elif args['relationship_type'] == INVOLVED_IN_REGULATION_OF: # Temporary fix until https://github.com/geneontology/amigo/pull/469 # and https://github.com/owlcollab/owltools/issues/241 are resolved return search_associations(subject_category='gene', object_category='function', fq={ 'regulates_closure': id, '-isa_partof_closure': id }, invert_subject_object=True, **args) elif args['relationship_type'] == INVOLVED_IN: return search_associations(subject_category='gene', object_category='function', subject=id, invert_subject_object=True, **core_parser.parse_args())
def get_object_gene(id, **args): obj = scigraph.bioobject(id, 'Gene') obj.phenotype_associations = search_associations(subject=id, object_category='phenotype', **args)['associations'] obj.homology_associations = search_associations(subject=id, rel=homol_rel, object_category='gene', **args)['associations'] obj.disease_associations = search_associations(subject=id, object_category='disease', **args)['associations'] obj.genotype_associations = search_associations(subject=id, invert_subject_object=True, object_category='genotype', **args)['associations'] return(obj)
def get_association_counts(bioentity_id, bioentity_type=None): """ For a given CURIE, get the number of associations by each category. """ count_map = {} subject_associations = search_associations( fq={'subject_closure': bioentity_id}, facet_pivot_fields=['{!stats=piv1}object_category', 'relation'], stats=True, stats_field=[ '{!tag=piv1 calcdistinct=true distinctValues=false}object' ]) object_associations = search_associations( fq={'object_closure': bioentity_id}, facet_pivot_fields=['{!stats=piv1}subject_category', 'relation'], stats=True, stats_field=[ '{!tag=piv1 calcdistinct=true distinctValues=false}subject' ]) subject_facet_pivot = subject_associations['facet_pivot'][ 'object_category,relation'] object_facet_pivot = object_associations['facet_pivot'][ 'subject_category,relation'] parse_facet_pivot(subject_facet_pivot, count_map) parse_facet_pivot(object_facet_pivot, count_map) if bioentity_type == 'gene': if CATEGORY_NAME_MAP['gene'] in count_map: count_map.pop(CATEGORY_NAME_MAP['gene']) # get counts for all ortholog associations ortholog_associations = search_associations( fq={'subject_ortholog_closure': bioentity_id}, facet_pivot_fields=['{!stats=piv1}object_category', 'relation'], stats=True, stats_field=[ '{!tag=piv1 calcdistinct=true distinctValues=false}object' ]) ortholog_pivot_counts = ortholog_associations['facet_pivot'][ 'object_category,relation'] for category in ortholog_pivot_counts: type = category['value'] if type == 'gene': if 'pivot' in category: for relation in category['pivot']: if relation['value'] == INTERACTS_WITH: # Ortholog-Interactions count_map[CATEGORY_NAME_MAP[ 'ortholog-interaction']] = relation['stats'][ 'stats_fields']['object']['countDistinct'] else: key = 'ortholog-{}'.format(type) count_map[CATEGORY_NAME_MAP[key]] = category['stats'][ 'stats_fields']['object']['countDistinct'] return count_map
def get(self, id): """ Returns associations for an entity regardless of the type """ return search_associations(subject=id, user_agent=USER_AGENT, **core_parser.parse_args())
def get(self, object): """ Returns list of matching associations pointing to a given object (target) """ args = parser.parse_args() return search_associations(object=object, **args)
def test_disease_assocs(): payload = search_associations(subject=HUMAN_SHH, object_category='disease' ) print(str(payload)) assocs = payload['associations'] assert len(assocs) > 0
def get(self): """ Generalized search over complete corpus of associations """ args = parser.parse_args() return search_associations(user_agent=USER_AGENT, **args)
def get(self): """ Generalized search over complete corpus of associations """ args = parser.parse_args() return search_associations(**args)
def get(self, id): """ Returns associations to GO terms for a gene """ return search_associations( subject_category='gene', object_category='function', subject=id, invert_subject_object=True, **core_parser.parse_args())
def get(self, subject): """ Returns list of matching associations starting from a given subject (source) """ args = parser.parse_args() return search_associations(subject=subject, **args)
def get(self, id): """ Returns interactions for a gene """ return search_associations( subject_category='gene', object_category='gene', relation='RO:0002434', subject=id, **core_parser.parse_args())
def get_counts(entities=None, object_category=None, min_count=1, **kwargs): """ given a set of entities (genes, diseases, etc), finds the number of entities associated with each descriptor in a given category. The result is a tuple (cmap, results), where cmap is a dict of TERM:COUNT """ if entities is None: entities = [] results = search_associations( subjects=entities, subject_direct=True, rows=0, facet_fields=[M.IS_DEFINED_BY, M.SUBJECT_TAXON, M.SUBJECT_CATEGORY], object_category=object_category, facet_mincount=3, # TODO facet_limit=-1, json_facet={ 'categories': { 'limit': -1, 'type': 'terms', 'field': M.OBJECT_CLOSURE, 'facet': { 'uniq_subject': "unique(subject)" } } }, **kwargs) buckets = results['facets']['categories']['buckets'] cmap = {} for bucket in buckets: if bucket['uniq_subject'] >= min_count: cmap[bucket['val']] = bucket['uniq_subject'] return (cmap, results)
def get(self, subject_category='gene', object_category='gene'): """ Returns list of matching associations """ args = parser.parse_args() return search_associations(subject_category, object_category, **args)
def test_disease2gene(): payload = search_associations(subject=LSD, subject_category='disease', object_category='gene') assocs = payload['associations'] for a in assocs: print(str(a)) assert len(assocs) > 0
def get(self, id): """ Returns expression events for a gene """ return search_associations( subject_category='gene', object_category='anatomical entity', object=id, **core_parser.parse_args())
def test_species_facet(): payload = search_associations(subject_category='gene', object_category='phenotype', facet_fields=['subject_taxon', 'subject_taxon_label'], rows=0) fcs = payload['facet_counts'] print(str(fcs)) assert 'H**o sapiens' in fcs['subject_taxon_label'].keys()
def get(self, id): """ Returns the association with a given identifier. An association connects, at a minimum, two things, designated subject and object, via some relationship. Associations also include evidence, provenance etc. """ return search_associations(id=id, user_agent=USER_AGENT)
def get(self, subject_category): """ Returns list of matching associations for a given subject category. """ args = self.parser.parse_args() return search_associations(subject_category=subject_category, user_agent=USER_AGENT, **args)
def get(self, id): """ Returns genes associated with a disease """ args = core_parser.parse_args() return search_associations( subject_category='disease', object_category='gene', subject=id, invert_subject_object=True, **core_parser.parse_args())
def test_go_assocs(): """ Test basic association search functionality """ payload = search_associations(subject=TWIST_ZFIN, object_category='function') assocs = payload['associations'] assert len(assocs) > 0
def get(self, id): """ Returns phenotypes associated with a genotype """ return search_associations( subject_category='genotype', object_category='phenotype', subject=id, **core_parser.parse_args())
def get(self, id): """ Return diseases associated with orthologs of a gene """ return search_associations(fq={'subject_ortholog_closure': id}, object_category='disease', **core_parser.parse_args())
def get(self, id): """ Returns associations between a lit entity and a genotype """ return search_associations(subject_category='literature', object_category='genotype', subject=id, **core_parser.parse_args())
def get(self, id): """ Returns genes associated with a variant """ # TODO: invert return search_associations( subject_category='variant', object_category='gene', subject=id, **core_parser.parse_args())
def test_func_objects(): results = search_associations(subject=TWIST_ZFIN, fetch_objects=True, rows=0, object_category='function') objs = results['objects'] print(objs) assert DVPF in objs assert len(objs) > 1
def test_pheno_objects(): results = search_associations(subject=TWIST_ZFIN, fetch_objects=True, rows=0, object_category='phenotype') objs = results['objects'] print(str(objs)) assert len(objs) > 1 assert 'ZP:0007631' in objs
def test_pheno_assocs(): payload = search_associations(subject=TWIST_ZFIN, object_category='phenotype') assocs = payload['associations'] assert len(assocs) > 0 for a in assocs: print(str(a)) assocs = [a for a in assocs if a['subject']['id'] == TWIST_ZFIN] assert len(assocs) > 0
def get(self, id): """ Returns genes associated with a pathway """ args = core_parser.parse_args() return search_associations( subject_category='gene', object_category='pathway', object=id, **core_parser.parse_args())
def get(self, id): """ Returns diseases associated with a genotype """ # TODO: invert return search_associations( subject_category='genotype', object_category='disease', subject=id, **core_parser.parse_args())