cannin / enhance_nlp_interaction_network_gsoc2020

3 stars 4 forks source link

MeSH to INDRA #19

Open cannin opened 4 years ago

cannin commented 4 years ago

I think this task is separate from others.

Do we have a function where I can pass in a string (this will be a PubMed query) and it returns INDRA statements? If not, can you create one? It should have a parameter that limits the number of articles to send to INDRA set to 10 as default. The INDRA statements should be merged into one collection.

PritiShaw commented 4 years ago

I did not find a direct method, but I found following methods which when used together can solve the purpose

  1. indra.literature.pubmed_client.get_ids, to get PMIDS from the search term
  2. indra.sources.indra_db_rest.api.get_statements_for_paper, to get statements from each PMID
import os
os.environ["INDRA_DB_REST_URL"] = "INDRA API"
from indra.literature import pubmed_client
from indra.sources import indra_db_rest

def get_stmts_from_term(search_term, maximum_articles = 10):
  pmid_list = pubmed_client.get_ids(search_term.strip(), retmax = maximum_articles)
  search_pmid_list = [('pmid',pmid) for pmid in pmid_list]
  stmts = []
  if search_pmid_list:
    stmts = indra_db_rest.get_statements_for_paper(search_pmid_list).statements
  return stmts

# Main
search_term = input("Please Enter Search Query: ")
get_stmts_from_term(search_term)

Binder

Can you please check if this addresses the requirement. Should I make a PR to INDRA adding this function? or should I make a gist of the function and attach link here?

Thanks