-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGO_parseRelationships.py
More file actions
42 lines (26 loc) · 1.1 KB
/
GO_parseRelationships.py
File metadata and controls
42 lines (26 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Parse all relationships between terms for go from GO XML
import Config
import sys, string
import MySQLdb
import Database
import gzip
from xml.etree import ElementTree
with Database.db as cursor :
cursor.execute( "TRUNCATE TABLE " + Config.DB_NAME + ".go_relationships" )
Database.db.commit( )
with gzip.open( Config.GO_DEFINITIONS, 'r' ) as file :
ontology = ElementTree.parse( file ).getroot( )
insertCount = 0
for element in ontology.findall( 'term' ) :
goFullID = element.find( 'id' ).text.strip( )
goShortID = goFullID[3:]
for goISA in element.findall( 'is_a' ) :
goISA_id = goISA.text
goISA_short = goISA_id[3:]
cursor.execute( "INSERT INTO " + Config.DB_NAME + ".go_relationships VALUES ( '0',%s, %s,'active' )", [goShortID, goISA_short] )
insertCount = insertCount + 1
if 0 == (insertCount % Config.DB_COMMIT_COUNT ) :
Database.db.commit( )
cursor.execute( "INSERT INTO " + Config.DB_STATS + ".update_tracker VALUES ( '0', 'GO_parseRelationships', NOW( ) )" )
Database.db.commit( )
sys.exit( )