Last active
March 24, 2017 10:56
-
-
Save danielecook/7088662 to your computer and use it in GitHub Desktop.
Quick function for fetching the gene coordinates when given the gene name. Can sepcify build.
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
# Note: Requires mysqldb; install using: | |
# pip install MySQL-python | |
from MySQLdb.constants import FIELD_TYPE | |
import _mysql | |
db = None | |
def fetch_gene_coordinates(gene_name,build): | |
global db # db is global to prevent reconnecting. | |
if db is None: | |
print 'connect' | |
conv= { FIELD_TYPE.LONG: int } | |
db = _mysql.connect(host='genome-mysql.cse.ucsc.edu',user='genome',passwd='',db=build,conv=conv) | |
db.query("""SELECT * FROM kgXref INNER JOIN knownGene ON kgXref.kgID=knownGene.name WHERE kgXref.geneSymbol = '%s'""" % gene_name) | |
r = db.use_result().fetch_row(how=1,maxrows=0) | |
print r | |
if len(r)>1: | |
pass | |
else: | |
return r[0]['txStart'], r[0]['txEnd'], r[0]['chrom'],r[0]['strand'] | |
print fetch_gene_coordinates('klf1','mm9') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment