diff --git a/biolink/api/bio/endpoints/bioentity.py b/biolink/api/bio/endpoints/bioentity.py index 206ad827..84d961a7 100644 --- a/biolink/api/bio/endpoints/bioentity.py +++ b/biolink/api/bio/endpoints/bioentity.py @@ -29,6 +29,14 @@ or a specific publication or other supporting ibject, e.g. ZFIN:ZDB-PUB-060503-2. """) +INVOLVED_IN = 'involved_in' +INVOLVED_IN_REGULATION_OF = 'involved_in_regulation_of' +ACTS_UPSTREAM_OF_OR_WITHIN = 'acts_upstream_of_or_within' + +core_parser_with_rel = core_parser.copy() +core_parser_with_rel.add_argument('relationship_type', required=False, default='involved_in', help="relationship type ('{}', '{}' or '{}')".format(INVOLVED_IN, INVOLVED_IN_REGULATION_OF, ACTS_UPSTREAM_OF_OR_WITHIN)) + + scigraph = SciGraph('https://scigraph-data.monarchinitiative.org/scigraph/') homol_rel = HomologyTypes.Homolog.value @@ -459,15 +467,29 @@ def get(self, id): @ns.route('/goterm//genes/') class GotermGeneAssociations(Resource): - @api.expect(core_parser) + @api.expect(core_parser_with_rel) @api.marshal_with(association_results) 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()) + 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()) @ns.route('/pathway/') @api.doc(params={'id': 'CURIE any pathway element. May be a GO ID or a pathway database ID'}) @@ -806,4 +828,3 @@ def get(self, id): """ obj = scigraph.bioobject(id) return obj -