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 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 buildChickenDB(db=geneDB):
45 genePath = "%s/download/seq_gene.md" % cisRoot
46 goDefPath = "%s/download/GO.terms_and_ids" % cisRoot # ftp://ftp.geneontology.org/pub/go/doc/GO.terms_and_ids
47 goPath = "%s/download/gene2go" % cisRoot # ftp://ftp.ncbi.nih.gov/gene/DATA/gene2go.gz
49 print "Creating database %s" % db
52 print "Adding gene entries"
53 loadGeneEntries(db, genePath)
55 #print "Adding gene annotations"
56 #loadGeneAnnotations(db, annotPath)
58 print "Adding gene features"
59 loadGeneFeatures(db, genePath)
61 chromList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10",
62 "11", "12", "13", "14", "15", "16", "17", "18", "19", "20",
63 "21", "22", "23", "24", "25", "26", "27", "28",
64 "32", "W", "Z", "M", "E22C19W28_E50C23", "E64",
65 "1_random", "2_random", "4_random", "5_random", "6_random",
66 "7_random", "8_random", "10_random", "11_random", "12_random",
67 "13_random", "16_random", "17_random", "18_random", "20_random",
68 "22_random", "25_random", "28_random", "Un_random", "W_random",
69 "E64_random", "Z_random", "E22C19W28_E50C23_random"
71 for chromID in chromList:
72 print "Loading chromosome %s" % chromID
73 chromPath = "%s/download/chr%s.fa" % (cisRoot, chromID)
74 loadChromosome(db, chromID, chromPath, "/G_gallus/chromo%s.bin" % chromID)
76 print "Adding gene ontology"
77 loadGeneOntology(db, goPath, goDefPath)
79 print "Creating Indices"
82 print "Finished creating database %s" % db
86 ggGenome = Genome("ggallus", dbFile=db)
87 ggGenome.createGeneDB(db)
90 def loadGeneEntries(db, gFile):
91 #TODO: - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
95 ggGenome = Genome("ggallus", dbFile=db)
96 geneFile = open(gFile, "r")
102 cols = line.split("\t")
103 if cols[11].strip() != "GENE":
106 name = cols[10].split(":")
108 if gid == "" or gid in alreadySeen:
111 alreadySeen.append(gid)
112 start = int(cols[2]) - 1
113 stop = int(cols[3]) - 1
115 chrom = cols[1].strip()
121 geneID = ("ggallus", gid)
123 geneEntries.append((geneID, chrom, start, stop, sense, "gene", gidVersion))
125 print "Adding %d gene entries" % len(geneEntries)
126 ggGenome.addGeneEntryBatch(geneEntries)
129 def loadGeneFeatures(db, gFile):
130 """ Load gene features such as CDS, UTR, and PSEUDO from the gene file.
133 ggGenome = Genome("ggallus", dbFile=db)
134 featureFile = open(gFile, "r")
135 featureFile.readline()
136 for line in featureFile:
140 cols = line.split("\t")
141 if cols[11].strip() not in ["CDS", "UTR", "PSEUDO"]:
145 name = cols[10].split(":")
150 start = int(cols[2]) - 1
151 stop = int(cols[3]) - 1
153 chrom = cols[1].strip()
159 geneID = ("ggallus", gid)
161 featureEntries.append((geneID, gidVersion, chrom, start, stop, sense, fType))
163 print "Adding %d feature entries" % len(featureEntries)
164 ggGenome.addFeatureEntryBatch(featureEntries)
167 def loadChromosome(db, chromID, chromPath, chromOut):
169 ggGenome = Genome("ggallus", dbFile=db)
170 inFile = open(chromPath, "r")
171 line = inFile.readline()
173 seqArray.append(line.strip())
175 seq = string.join(seqArray, "")
178 print "Problems reading sequence from file"
180 print "writing to file %s" % chromOut
181 outFile = open("%s%s" % (cisRoot, chromOut), "w")
184 ggGenome.addChromosomeEntry(chromID, chromOut, "file")
187 def loadGeneOntology(db, goPath, goDefPath):
188 ggGenome = Genome("ggallus", dbFile=db)
189 goDefFile = open(goDefPath, "r")
190 goFile = open(goPath, "r")
194 for goDefEntry in goDefFile:
195 if goDefEntry[0] != "!":
196 cols = goDefEntry.split("\t")
197 goDefs[cols[0]] = (cols[1], cols[2].strip())
199 goEntries = goFile.readlines()
201 for entry in goEntries:
203 fields = entry.split("\t")
204 if fields[0] != "9031":
207 locID = fields[1].strip()
208 gID = ("ggallus", locID)
212 synonyms = idb.geneIDSynonyms(gID)
214 gene_name = string.join(synonyms, ",")
216 goArray.append((gID, fields[2], "", gene_name, "", string.replace(goDefs[fields[2]][0], "'", "p"), goDefs[fields[2]][1], ""))
218 print "locus ID %s could not be added" % locID
221 print "adding %d go entries" % len(goArray)
222 ggGenome.addGoInfoBatch(goArray)
225 def createDBindices(db):
226 ggGenome = Genome("ggallus", dbFile=db)
227 ggGenome.createIndices()