Skip to content

Commit

Permalink
Merge pull request #33 from biolink/27-mart-extensions
Browse files Browse the repository at this point in the history
[#27] merge routes
  • Loading branch information
jnguyenx committed Mar 17, 2017
2 parents 1fbaed9 + 5f98de5 commit 8581971
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
5 changes: 4 additions & 1 deletion biogolr/golr_associations.py
Expand Up @@ -224,6 +224,7 @@ def translate_docs_compact(ds, field_mapping=None, slim=None, map_identifiers=No
map_doc(d, field_mapping)

subject = d[M.SUBJECT]
subject_label = d[M.SUBJECT_LABEL]

# TODO: use a more robust method; we need equivalence as separate field in solr
if map_identifiers is not None:
Expand All @@ -243,6 +244,7 @@ def translate_docs_compact(ds, field_mapping=None, slim=None, map_identifiers=No
k = (subject,rel)
if k not in amap:
amap[k] = {'subject':subject,
'subject_label':subject_label,
'relation':rel,
'objects': []}
if slim is not None and len(slim)>0:
Expand Down Expand Up @@ -381,6 +383,7 @@ def search_associations(subject_category=None,
facet_limit = 0
select_fields = [
M.SUBJECT,
M.SUBJECT_LABEL,
M.RELATION,
M.OBJECT]

Expand Down Expand Up @@ -501,7 +504,7 @@ def search_associations(subject_category=None,
logging.info("PARAMS="+str(params))
results = solr.search(**params)
n_docs = len(results.docs)
logging.info("Num_docs: {}".format(n_docs))
logging.info("Docs found: {}".format(results.hits))

if iterate:
docs = results.docs
Expand Down
32 changes: 10 additions & 22 deletions biolink/api/mart/endpoints/mart.py
Expand Up @@ -62,6 +62,11 @@ def get(self, object_category, taxon):
NOTE: this route has a limiter on it, you may be restricted in the number of downloads per hour. Use carefully.
"""

# TODO temporary workaround
if taxon == "NCBITaxon:9606":
taxon = None

assocs = bulk_fetch(subject_category='case',
object_category=object_category,
taxon=taxon,
Expand All @@ -82,30 +87,13 @@ def get(self, object_category, taxon):
NOTE: this route has a limiter on it, you may be restricted in the number of downloads per hour. Use carefully.
"""

# TODO temporary workaround
if taxon == "NCBITaxon:9606":
taxon = None

assocs = bulk_fetch(subject_category='disease',
object_category=object_category,
taxon=taxon,
iterate=True)
return assocs

@ns.route('/labels/<subject_category>/<objet_category>/<taxon>')
@api.doc(params={'subject_category': 'CATEGORY of the subject entity, e.g. gene, phenotype, disease'})
@api.doc(params={'objet_category': 'CATEGORY of the object entity, e.g. phenotype, disease'})
@api.doc(params={'taxon': 'taxon of gene, must be of form NCBITaxon:9606'})
class MartLabelsResource(Resource):
def get(self, subject_category, objet_category, taxon):
"""
Bulk download of labels.
Retrieves the labels of the subjects.
"""
myArgs = {
"subject_category": subject_category,
"object_category": objet_category,
"subject_taxon": taxon,
"rows": MAX_ROWS,
"facet_on": "off",
"select_fields": ["subject", "subject_label"],
"iterate": True
}
return search_associations(**myArgs)

0 comments on commit 8581971

Please sign in to comment.