Last active
December 15, 2015 09:09
-
-
Save arq5x/5236411 to your computer and use it in GitHub Desktop.
Example script using the Gemini query API for custom analysis.
This file contains 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
#!/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