Skip to content

Commit

Permalink
Merge pull request #146 from deepakunni3/issue-138
Browse files Browse the repository at this point in the history
allow option to define relationship_type in /goterm/<id>/genes/ endpoint
  • Loading branch information
deepakunni3 authored Mar 5, 2018
2 parents 308ea24 + 47aa6fd commit 5c07dd4
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions biolink/api/bio/endpoints/bioentity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -459,15 +467,29 @@ def get(self, id):
@ns.route('/goterm/<id>/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/<id>')
@api.doc(params={'id': 'CURIE any pathway element. May be a GO ID or a pathway database ID'})
Expand Down Expand Up @@ -806,4 +828,3 @@ def get(self, id):
"""
obj = scigraph.bioobject(id)
return obj

0 comments on commit 5c07dd4

Please sign in to comment.