1 ###########################################################################
3 # C O P Y R I G H T N O T I C E #
4 # Copyright (c) 2003-10 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 Gallus gallus
32 from cistematic.genomes import Genome
33 from cistematic.core.geneinfo import geneinfoDB
34 from os import environ
36 if environ.get("CISTEMATIC_ROOT"):
37 cisRoot = environ.get("CISTEMATIC_ROOT")
39 cisRoot = "/proj/genome"
41 geneDB = "%s/G_gallus/ggallus.genedb" % cisRoot
44 def loadChromosome(db, chromID, chromPath, chromOut):
46 ggGenome = Genome("ggallus", dbFile=db)
47 inFile = open(chromPath, "r")
48 line = inFile.readline()
50 seqArray.append(line.strip())
52 seq = string.join(seqArray, "")
55 print "Problems reading sequence from file"
57 print "writing to file %s" % chromOut
58 outFile = open("%s%s" % (cisRoot, chromOut), "w")
61 ggGenome.addChromosomeEntry(chromID, chromOut, "file")
64 def loadGeneEntries(db, gFile):
65 """ FIXME - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
69 ggGenome = Genome("ggallus", dbFile=db)
70 geneFile = open(gFile, "r")
76 cols = line.split("\t")
77 if cols[11].strip() != "GENE":
80 name = cols[10].split(":")
82 if gid == "" or gid in alreadySeen:
85 alreadySeen.append(gid)
86 start = int(cols[2]) - 1
87 stop = int(cols[3]) - 1
89 chrom = cols[1].strip()
95 geneID = ("ggallus", gid)
97 geneEntries.append((geneID, chrom, start, stop, sense, "gene", gidVersion))
99 print "Adding %d gene entries" % len(geneEntries)
100 ggGenome.addGeneEntryBatch(geneEntries)
103 def loadGeneFeatures(db, gFile):
104 """ Load gene features such as CDS, UTR, and PSEUDO from the gene file.
107 ggGenome = Genome("ggallus", dbFile=db)
108 featureFile = open(gFile, "r")
109 featureFile.readline()
110 for line in featureFile:
114 cols = line.split("\t")
115 if cols[11].strip() not in ["CDS", "UTR", "PSEUDO"]:
119 name = cols[10].split(":")
124 start = int(cols[2]) - 1
125 stop = int(cols[3]) - 1
127 chrom = cols[1].strip()
133 geneID = ("ggallus", gid)
135 featureEntries.append((geneID, gidVersion, chrom, start, stop, sense, fType))
137 print "Adding %d feature entries" % len(featureEntries)
138 ggGenome.addFeatureEntryBatch(featureEntries)
141 def loadGeneOntology(db, goPath, goDefPath):
142 ggGenome = Genome("ggallus", dbFile=db)
143 goDefFile = open(goDefPath, "r")
144 goFile = open(goPath, "r")
148 for goDefEntry in goDefFile:
149 if goDefEntry[0] != "!":
150 cols = goDefEntry.split("\t")
151 goDefs[cols[0]] = (cols[1], cols[2].strip())
153 goEntries = goFile.readlines()
155 for entry in goEntries:
157 fields = entry.split("\t")
158 if fields[0] != "9031":
161 locID = fields[1].strip()
162 gID = ("ggallus", locID)
166 synonyms = idb.geneIDSynonyms(gID)
168 gene_name = string.join(synonyms, ",")
170 goArray.append((gID, fields[2], "", gene_name, "", string.replace(goDefs[fields[2]][0], "'", "p"), goDefs[fields[2]][1], ""))
172 print "locus ID %s could not be added" % locID
175 print "adding %d go entries" % len(goArray)
176 ggGenome.addGoInfoBatch(goArray)
179 def createDBFile(db):
180 ggGenome = Genome("ggallus", dbFile=db)
181 ggGenome.createGeneDB(db)
184 def createDBindices(db):
185 ggGenome = Genome("ggallus", dbFile=db)
186 ggGenome.createIndices()
189 def buildChickenDB(db=geneDB):
190 genePath = "%s/download/seq_gene.md" % cisRoot
191 goDefPath = "%s/download/GO.terms_and_ids" % cisRoot # ftp://ftp.geneontology.org/pub/go/doc/GO.terms_and_ids
192 goPath = "%s/download/gene2go" % cisRoot # ftp://ftp.ncbi.nih.gov/gene/DATA/gene2go.gz
193 chromos = {"1": "%s/download/chr1.fa" % cisRoot,
194 "2": "%s/download/chr2.fa" % cisRoot,
195 "3": "%s/download/chr3.fa" % cisRoot,
196 "4": "%s/download/chr4.fa" % cisRoot,
197 "5": "%s/download/chr5.fa" % cisRoot,
198 "6": "%s/download/chr6.fa" % cisRoot,
199 "7": "%s/download/chr7.fa" % cisRoot,
200 "8": "%s/download/chr8.fa" % cisRoot,
201 "9": "%s/download/chr9.fa" % cisRoot,
202 "10": "%s/download/chr10.fa" % cisRoot,
203 "11": "%s/download/chr11.fa" % cisRoot,
204 "12": "%s/download/chr12.fa" % cisRoot,
205 "13": "%s/download/chr13.fa" % cisRoot,
206 "14": "%s/download/chr14.fa" % cisRoot,
207 "15": "%s/download/chr15.fa" % cisRoot,
208 "16": "%s/download/chr16.fa" % cisRoot,
209 "17": "%s/download/chr17.fa" % cisRoot,
210 "18": "%s/download/chr18.fa" % cisRoot,
211 "19": "%s/download/chr19.fa" % cisRoot,
212 "20": "%s/download/chr20.fa" % cisRoot,
213 "21": "%s/download/chr21.fa" % cisRoot,
214 "22": "%s/download/chr22.fa" % cisRoot,
215 "23": "%s/download/chr23.fa" % cisRoot,
216 "24": "%s/download/chr24.fa" % cisRoot,
217 "25": "%s/download/chr25.fa" % cisRoot,
218 "26": "%s/download/chr26.fa" % cisRoot,
219 "27": "%s/download/chr27.fa" % cisRoot,
220 "28": "%s/download/chr28.fa" % cisRoot,
221 "32": "%s/download/chr32.fa" % cisRoot,
222 "W": "%s/download/chrW.fa" % cisRoot,
223 "Z": "%s/download/chrZ.fa" % cisRoot,
224 "M": "%s/download/chrM.fa" % cisRoot,
225 "E22C19W28_E50C23": "%s/download/chrE22C19W28_E50C23.fa" % cisRoot,
226 "E64": "%s/download/chrE64.fa" % cisRoot,
227 "1_random": "%s/download/chr1_random.fa" % cisRoot,
228 "2_random": "%s/download/chr2_random.fa" % cisRoot,
229 "4_random": "%s/download/chr4_random.fa" % cisRoot,
230 "5_random": "%s/download/chr5_random.fa" % cisRoot,
231 "6_random": "%s/download/chr6_random.fa" % cisRoot,
232 "7_random": "%s/download/chr7_random.fa" % cisRoot,
233 "8_random": "%s/download/chr8_random.fa" % cisRoot,
234 "10_random": "%s/download/chr10_random.fa" % cisRoot,
235 "11_random": "%s/download/chr11_random.fa" % cisRoot,
236 "12_random": "%s/download/chr12_random.fa" % cisRoot,
237 "13_random": "%s/download/chr13_random.fa" % cisRoot,
238 "16_random": "%s/download/chr16_random.fa" % cisRoot,
239 "17_random": "%s/download/chr17_random.fa" % cisRoot,
240 "18_random": "%s/download/chr18_random.fa" % cisRoot,
241 "20_random": "%s/download/chr20_random.fa" % cisRoot,
242 "22_random": "%s/download/chr22_random.fa" % cisRoot,
243 "25_random": "%s/download/chr25_random.fa" % cisRoot,
244 "28_random": "%s/download/chr28_random.fa" % cisRoot,
245 "Un_random": "%s/download/chrUn_random.fa" % cisRoot,
246 "W_random": "%s/download/chrW_random.fa" % cisRoot,
247 "E64_random": "%s/download/chrE64_random.fa" % cisRoot,
248 "Z_random": "%s/download/chrZ_random.fa" % cisRoot,
249 "E22C19W28_E50C23_random": "%s/download/chrE22C19W28_E50C23_random.fa" % cisRoot
252 print "Creating database %s" % db
255 print "Adding gene entries"
256 loadGeneEntries(db, genePath)
258 #print "Adding gene annotations"
259 #loadGeneAnnotations(db, annotPath)
261 print "Adding gene features"
262 loadGeneFeatures(db, genePath)
264 for chromID in chromos.keys():
265 print "Loading chromosome %s" % chromID
266 loadChromosome(db, chromID, chromos[chromID], "/G_gallus/chromo%s.bin" % chromID)
268 print "Adding gene ontology"
269 loadGeneOntology(db, goPath, goDefPath)
271 print "Creating Indices"
274 print "Finished creating database %s" % db