Skip to content

Instantly share code, notes, and snippets.

@ravila4
Last active February 23, 2021 23:40
Show Gist options
  • Save ravila4/59631c03b9d6efcfae68b3dc757d12b9 to your computer and use it in GitHub Desktop.
Save ravila4/59631c03b9d6efcfae68b3dc757d12b9 to your computer and use it in GitHub Desktop.
A demo of converting API responses to CSV format with JQ.
#!/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