Skip to content

Examples

Constantine Rafikov edited this page Aug 23, 2023 · 6 revisions

Basic examples

Task:

Get a list of genes associated with a disease "Lipodystrophy, familial partial", output their HGNCs

JavaScript

fetch('https://open-genes.com/api/gene/search?byDiseases=43', {})
  .then(response => response.json())
  .then(data => {
    data.items.forEach(gene => {
      console.log(gene.symbol);
    });
  });

Python

import requests

result = requests.get("https://open-genes.com/api/gene/search?byDiseases=43").json()
for item in result['items']:
    print(item['gene']['symbol'])

R

install.packages("httr")
library(httr)

endpoint <- "https://open-genes.com/api/gene/search"
params <- list(
  byDiseases = 43
)

res <- GET(url = endpoint, query = params)
res_json <- content(res, "parsed")

for (i in 1:length(res_json$items)) {
  print(res_json$items[[i]]$gene$symbol)
}

Bash (using CURL and JQ)

curl -X GET "https://open-genes.com/api/gene/search?byDiseases=43" | jq '.items[].symbol'

Note that JQ command-line tool for JSON processing is not a part of Bash.

On Linux you can install JQ using your package manager, such as apt-get or yum.
For example, on Ubuntu you can run the following command to install JQ:

sudo apt-get install jq

On Mac, you can install JQ using Homebrew. To install JQ using Homebrew, run the following command:

brew install jq
Clone this wiki locally