3 from splicegraph
import *
6 spliceCalcs
={'HUMAN_SPLICE_03':
7 TableGroup(db
='HUMAN_SPLICE_03',suffix
='JUN03',clusters
='cluster_JUN03',
8 exons
='exon_formJUN03',splices
='splice_verification_JUN03',
9 genomic
='genomic_cluster_JUN03',mrna
='mrna_seqJUN03',
10 protein
='protein_seqJUN03'),
12 TableGroup(db
='HUMAN_SPLICE',suffix
='jan02',clusters
='cluster_jan02',
13 exons
='HUMAN_ISOFORMS.exon_form_4',splices
='splice_verification_jan02',
14 genomic
='genomic_cluster_jan02',mrna
='HUMAN_ISOFORMS.mrna_seq_4',
15 protein
='HUMAN_ISOFORMS.protein_seq_4'),
17 TableGroup(db
='MOUSE_SPLICE',suffix
='jan02',clusters
='cluster_jan02',
18 exons
='MOUSE_ISOFORMS.exon_form_2',splices
='splice_verification_jan02',
19 genomic
='genomic_cluster_jan02',mrna
='MOUSE_ISOFORMS.mrna_seq_2',
20 protein
='MOUSE_ISOFORMS.protein_seq_2'),
22 TableGroup(db
='MOUSE_SPLICE_03',suffix
='JUN03',clusters
='cluster_JUN03',
23 exons
='exon_formJUN03',splices
='splice_verification_JUN03',
24 genomic
='genomic_cluster_JUN03',mrna
='mrna_seqJUN03',
25 protein
='protein_seqJUN03')
29 def getUserCursor(db
):
30 'get a cursor as the current user'
31 db
=MySQLdb
.connect(db
=db
,read_default_file
=os
.environ
['HOME']+'/.my.cnf',compress
=True)
35 def getSpliceGraphFromDB(dbgroup
,loadAll
=False):
36 """load data from MySQL using the designated database table group.
37 If loadAll true, then load the entire splice graph into memory."""
38 cursor
=getUserCursor(dbgroup
.db
)
40 print >>sys
.stderr
,'Reading database schema...'
42 tables
=describeDBTables(dbgroup
.db
,cursor
,idDict
)
43 if hasattr(dbgroup
,'suffix'):
44 tables
=suffixSubset(tables
,dbgroup
.suffix
) # SET OF TABLES ENDING IN JUN03
45 idDict
=indexIDs(tables
) # CREATE AN INDEX OF THEIR PRIMARY KEYS
46 for t
in dbgroup
.values():
47 if t
is not None and '.' in t
and t
not in tables
: # THIS TABLE COMES FROM ANOTHER DATABASE...
48 tables
[t
]=SQLTable(t
,cursor
) # SO GET IT FROM OTHER DATABASE
50 # LOAD DATA & BUILD THE SPLICE GRAPH
51 return loadSpliceGraph(tables
,dbgroup
.clusters
,dbgroup
.exons
,dbgroup
.splices
,
52 dbgroup
.genomic
,dbgroup
.mrna
,dbgroup
.protein
,loadAll
)
55 def localCopy(localFile
,cpCommand
):
56 'if not already present on local file location, run cpCommand'
57 if not os
.access(localFile
,os
.R_OK
):
58 cmd
=cpCommand
% localFile
59 print 'copying data:',cmd
60 exit_code
=os
.system(cmd
)
62 raise OSError((exit_code
,'command failed: %s' % cmd
))