Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Map human gene symbols to ensembl gene ids, using the ensembl REST api, curl and jq
#!/usr/bin/env bash
# USAGE:
# 0. install jq from https://stedolan.github.io/jq/ if not already present
# 1. make this script executable
# chmod u+x gene2ensembl.sh
# 2. then run it on a gene list with one gene ID per line
./gene2ensembl.sh genesymbollist.txt > ensembl_list.txt
# NOTE: this command does not run in parallel on purpose
# so that ordering of the gene IDs remains constant
while read gene; do
curl -X GET http://rest.ensembl.org/xrefs/symbol/homo_sapiens/$gene?content-type=application/json 2>/dev/null | jq -r '.[0].id'
done < "${1:-/dev/stdin}"
#The substitution ${1:-...} takes $1 if defined otherwise the file name
# of the standard input of the own process is used.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment