Skip to content

Instantly share code, notes, and snippets.

@kevinxin90
Created September 23, 2020 15:25
Show Gist options
  • Save kevinxin90/0f97190ec785e7c37e6b3ed79622c48c to your computer and use it in GitHub Desktop.
Save kevinxin90/0f97190ec785e7c37e6b3ed79622c48c to your computer and use it in GitHub Desktop.
Demo of how to use NGD scores providing by Text Mining Co-occurrence API

How to retrieve NGD scores using Text Mining co-occurrence API

install and import requests library

!pip install requests
import requests

Query for only one pair of association

Get NGD score between PR:000010229 and UBERON:0000043

doc = requests.post("https://biothings.ncats.io/text_mining_co_occurrence_kp/query",
    json={
        "q": [["PR:000010229", "UBERON:0000043"]],
        "scopes": [["subject.PR", "object.PR"], ["subject.UBERON", "object.UBERON"],],
        "fields": "association.ngd",
        "dotfield": True,
    }).json()
doc
[{'query': ['PR:000010229', 'UBERON:0000043'],
  '_id': 'NCBIGene:8720-UBERON:0000043-0.6896383897934035',
  '_score': 16.28219,
  'association.ngd': 0.6896383897934035}]

Query for a list of pairs of association

Get NGD score for a list of Disease-Chemical associations

Result is represented as a list of dictionaries.

The query field represents your input, e.g. ['MONOD:0015338', 'CHEBI:31522']

The association.ngd field represents the ngd score.

doc = requests.post("https://biothings.ncats.io/text_mining_co_occurrence_kp/query",
    json={
        "q": [["MONDO:0015338", "CHEBI:31522"], ["MONDO:0021669", "CHEBI:31522"], ["MONDO:0004993", "CHEBI:30674"]],
        "scopes": [["subject.MONDO", "object.MONDO"], ["subject.CHEBI", "object.CHEBI"]],
        "fields": "association.ngd",
        "dotfield": True,
    }).json()
doc
[{'query': ['MONDO:0015338', 'CHEBI:31522'],
  '_id': 'CHEBI:31522-MONDO:0015338-0.6780940282884421',
  '_score': 17.552275,
  'association.ngd': 0.6780940282884421},
 {'query': ['MONDO:0021669', 'CHEBI:31522'],
  '_id': 'CHEBI:31522-MONDO:0021669-0.681381466532217',
  '_score': 16.74813,
  'association.ngd': 0.681381466532217},
 {'query': ['MONDO:0004993', 'CHEBI:30674'],
  '_id': 'CHEBI:30674-MONDO:0004993-0.7395095443131897',
  '_score': 18.456928,
  'association.ngd': 0.7395095443131897}]

What will happen if a pair of association is not found

It will be labeled as notfound

doc = requests.post("https://biothings.ncats.io/text_mining_co_occurrence_kp/query",
    json={
        "q": [["MONDO:001533", "CHEBI:31522"], ["MONDO:0021669", "CHEBI:31522"], ["MONDO:0004993", "CHEBI:30674"]],
        "scopes": [["subject.MONDO", "object.MONDO"], ["subject.CHEBI", "object.CHEBI"]],
        "fields": "association.ngd",
        "dotfield": True,
    }).json()
doc
[{'query': ['MONDO:001533', 'CHEBI:31522'], 'notfound': True},
 {'query': ['MONDO:0021669', 'CHEBI:31522'],
  '_id': 'CHEBI:31522-MONDO:0021669-0.681381466532217',
  '_score': 16.74813,
  'association.ngd': 0.681381466532217},
 {'query': ['MONDO:0004993', 'CHEBI:30674'],
  '_id': 'CHEBI:30674-MONDO:0004993-0.7395095443131897',
  '_score': 18.456928,
  'association.ngd': 0.7395095443131897}]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment