1 ###########################################################################
3 # C O P Y R I G H T N O T I C E #
4 # Copyright (c) 2003-13 by: #
5 # * California Institute of Technology #
7 # All Rights Reserved. #
9 # Permission is hereby granted, free of charge, to any person #
10 # obtaining a copy of this software and associated documentation files #
11 # (the "Software"), to deal in the Software without restriction, #
12 # including without limitation the rights to use, copy, modify, merge, #
13 # publish, distribute, sublicense, and/or sell copies of the Software, #
14 # and to permit persons to whom the Software is furnished to do so, #
15 # subject to the following conditions: #
17 # The above copyright notice and this permission notice shall be #
18 # included in all copies or substantial portions of the Software. #
20 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, #
21 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF #
22 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND #
23 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS #
24 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN #
25 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN #
26 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE #
28 ###########################################################################
30 # data for Saccharomyces cerevisiae
32 from cistematic.genomes import Genome
33 from os import environ
35 if environ.get("CISTEMATIC_ROOT"):
36 cisRoot = environ.get("CISTEMATIC_ROOT")
38 cisRoot = "/proj/genome"
40 geneDB = "%s/S_cerevisiae/scerevisiae.genedb" % cisRoot
43 def buildScerevisiaeDB(db=geneDB):
44 genePath = "%s/download/SGD_features.tab" % cisRoot
45 goDefPath = "%s/download/GO.terms_and_ids" % cisRoot
46 goPath = "%s/download/gene_association.sgd" % cisRoot
48 print "Creating database %s" % db
51 print "Adding gene entries"
52 loadGeneEntries(db, genePath)
54 print "Adding gene annotations"
55 loadGeneAnnotations(db, genePath)
57 print "Adding gene ontology"
58 loadGeneOntology(db, goPath, goDefPath)
60 for chromID in ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16"]:
61 print "Loading chromosome %s" % chromID
62 chromPath = "%s/download/chr%s.fsa" % (cisRoot, chromID)
63 loadChromosome(db, chromID, chromPath, "/S_cerevisiae/chr%s.bin" % chromID)
65 print "Creating Indices"
68 print "Finished creating database %s" % db
72 scGenome = Genome("scerevisiae", version="SGD1", dbFile=db)
73 scGenome.createGeneDB(db)
76 def loadGeneEntries(db, gFile):
79 scGenome = Genome("scerevisiae", dbFile=db)
80 geneFile = open(gFile, "r")
82 field = line.split("\t")
86 orfName = field[3].strip()
88 chrom = field[8].strip()
92 start = int(field[9].strip()) - 1
93 stop = int(field[10].strip()) - 1
100 start = int(field[10].strip()) - 1
101 stop = int(field[9].strip()) - 1
106 geneID = ("scerevisiae", orfName)
108 geneEntries.append((geneID, chrom, start, stop, sense, "chromosomal_feature", gidVersion))
109 geneFeatures.append((geneID, gidVersion, chrom, start, stop, sense, "CDS"))
111 print "loading %d gene entries" % len(geneEntries)
112 scGenome.addGeneEntryBatch(geneEntries)
113 print "loading %d gene features" % len(geneFeatures)
114 scGenome.addFeatureEntryBatch(geneFeatures)
117 def loadGeneAnnotations(db, annotPath):
119 annotFile = open(annotPath, "r")
120 lines = annotFile.readlines()
122 scGenome = Genome("scerevisiae", dbFile=db)
124 field = line.split("\t")
125 if field[1] != "ORF":
129 orfName = field[6].strip()
130 description = field[15].strip()
131 geneAnnotations.append((("scerevisiae", orfName), string.replace(description, "'", "p")))
135 print "Adding %d annotations" % len(geneAnnotations)
136 scGenome.addAnnotationBatch(geneAnnotations)
139 def loadGeneOntology(db, goPath, goDefPath):
140 scGenome = Genome("scerevisiae", version="SGD1", dbFile=db)
141 goDefFile = open(goDefPath, "r")
142 goFile = open(goPath, "r")
143 goDefEntries = goDefFile.readlines()
145 for goDefEntry in goDefEntries:
146 if goDefEntry[0] != "!":
147 cols = goDefEntry.split("\t")
148 goDefs[cols[0]] = (cols[1], cols[2].strip())
150 goEntries = goFile.readlines()
152 for line in goEntries:
156 fields = line.split("\t")
157 genes = fields[10].split("|")
161 objNameArray = fields[10].split("|")
162 objName = objNameArray[0]
165 GOterm = string.replace(goDefs[GOID][0], "'", "p")
167 print "Could not translate %s" % (GOID)
171 goArray.append((("scerevisiae", gID), GOID[3:], objType, objName, isNot, GOterm, evidence, fields[1]))
173 scGenome.addGoInfoBatch(goArray)
176 def loadChromosome(db, chromID, chromPath, chromOut):
178 scGenome = Genome("scerevisiae", dbFile=db)
179 inFile = open(chromPath, "r")
180 line = inFile.readline()
182 seqArray.append(line.strip())
184 seq = string.join(seqArray, "")
187 print "Problems reading sequence from file"
189 print "writing to file %s" % chromOut
190 outFile = open("%s%s" % (cisRoot, chromOut), "w")
194 print "calling scGenome()"
195 scGenome.addChromosomeEntry(chromID, chromOut, "file")
198 def createDBindices(db):
199 scGenome = Genome("scerevisiae", version="SGD1", dbFile=db)
200 scGenome.createIndices()