Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow option to define relationship type in /goterm/<id>/genes/ endpoint #146

Merged
merged 2 commits into from
Mar 5, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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