Instantly share code, notes, and snippets.

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
# 0. install jq from if not already present
# 1. make this script executable
# chmod u+x
# 2. then run it on a gene list with one gene ID per line
./ 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$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