Skip to content

Instantly share code, notes, and snippets.

@ScottPDickinson
Created September 8, 2016 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottPDickinson/40534d396b97d7281094fab32baca92a to your computer and use it in GitHub Desktop.
Save ScottPDickinson/40534d396b97d7281094fab32baca92a to your computer and use it in GitHub Desktop.
Getting SNP list from PredictDB database
import sqlite3
def get_snp_list(db_file, out_file):
'''
Queries a PredictDB sqlite database and creates a tab-delimited file with fields
rsid number, ref_allele, eff_allele.
db_file: path to the database file
out_file: name of the output file
'''
conn = sqlite3.connect(db_file)
with open(out_file, 'w') as snp_file:
snp_file.write('\t'.join(['rsid', 'ref_allele', 'eff_allele']) + '\n')
for row in conn.execute("SELECT DISTINCT rsid, ref_allele, eff_allele FROM weights"):
snp_file.write('\t'.join(row) + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment