Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@arq5x
Last active December 15, 2015 09:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arq5x/5236411 to your computer and use it in GitHub Desktop.
Save arq5x/5236411 to your computer and use it in GitHub Desktop.
Example script using the Gemini query API for custom analysis.
#!/usr/bin/env python
import sys
from gemini import GeminiQuery
db = sys.argv[1]
# create a GeminiQery instance for the requested database
gq = GeminiQuery(db)
# issue a basic query and iterate over the results.
query = "select chrom, start, end, gts.NA20814 from variants limit 5"
gq.run(query)
for row in gq:
print row, row['chrom'], row['gts.NA20814']
# issue a query with filters placed on genotype data.
query = "select chrom, start, end, gts.NA20814 from variants limit 50"
gt_filter = "gt_types.NA20814 == HET"
gq.run(query, gt_filter)
for row in gq:
print row, row['chrom'], row['gts.NA20814']
# grab dict mapping sample to genotype array indices
smp2idx = gq.sample_to_idx
query = "select chrom, start, end, gts.NA20814 from variants"
gt_filter = "gt_types.NA20814 == HET"
gq.run(query, gt_filter)
# print a header listing the selected columns
print gq.header
for row in gq:
# access a NUMPY array of the sample genotypes.
gts = row['gts']
# use the sample to index dictionary to access sample genotypes
idx = smp2idx['NA20814']
print row, gts[idx]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment