Last active
February 23, 2021 23:40
-
-
Save ravila4/59631c03b9d6efcfae68b3dc757d12b9 to your computer and use it in GitHub Desktop.
A demo of converting API responses to CSV format with JQ.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Genesets aggregated by taxid | |
aggs=`curl -s "https://mygeneset.info/v1/query?q=*&facets=taxid&facet_size=100"` | |
taxids=`echo $aggs | jq -r '.facets.taxid.terms | map(.term) | @csv'` | |
counts=`echo $aggs | jq -r '.facets.taxid.terms | map(.count) | @csv'` | |
# Query scientific name for each taxid | |
resp=`curl -s -X POST -d "q=${taxids}" "http://t.biothings.io/v1/query"` | |
species=`echo $resp | jq -r 'map(.scientific_name) | @csv'` | |
echo "${taxids} | |
${species} | |
${counts}" | rs -c, -C, -T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment