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 Equus Caballus
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/E_caballus/ecaballus.genedb" % cisRoot
43 def loadChromosome(db, chromID, chromPath, chromOut):
45 ecGenome = Genome("ecaballus", dbFile=db)
46 inFile = open(chromPath, "r")
47 line = inFile.readline()
49 seqArray.append(line.strip())
51 seq = string.join(seqArray, "")
54 print "Problems reading sequence from file"
56 print "writing to file %s" % chromOut
57 outFile = open("%s%s" % (cisRoot, chromOut), "w")
60 ecGenome.addChromosomeEntry(chromID, chromOut, "file")
63 def loadGeneEntries(db, gFile):
64 """ FIXME - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
68 ecGenome = Genome("ecaballus", dbFile=db)
69 geneFile = open(gFile, "r")
72 cols = line.split("\t")
73 if cols[11].strip() != "GENE":
76 name = cols[10].split(":")
78 if gid == "" or gid in alreadySeen:
81 alreadySeen.append(gid)
82 start = int(cols[2]) - 1
83 stop = int(cols[3]) - 1
85 chrom = cols[1].strip()
91 geneID = ("ecaballus", gid)
93 geneEntries.append((geneID, chrom, start, stop, sense, "gene", gidVersion))
95 print "Adding %d gene entries" % len(geneEntries)
96 ecGenome.addGeneEntryBatch(geneEntries)
99 def loadGeneFeatures(db, gFile):
100 """ Load gene features such as CDS, UTR, and PSEUDO from the gene file.
103 ecGenome = Genome("ecaballus", dbFile=db)
104 featureFile = open(gFile, "r")
105 featureFile.readline()
106 for line in featureFile:
107 cols = line.split("\t")
108 if cols[11].strip() not in ["CDS", "UTR", "PSEUDO"]:
112 name = cols[10].split(":")
117 start = int(cols[2]) - 1
118 stop = int(cols[3]) - 1
120 chrom = cols[1].strip()
126 geneID = ("ecaballus", gid)
128 featureEntries.append((geneID, gidVersion, chrom, start, stop, sense, fType))
130 print "Adding %d feature entries" % len(featureEntries)
131 ecGenome.addFeatureEntryBatch(featureEntries)
134 def createDBFile(db):
135 ecGenome = Genome("ecaballus", dbFile=db)
136 ecGenome.createGeneDB(db)
139 def createDBindices(db):
140 ecGenome = Genome("ecaballus", dbFile=db)
141 ecGenome.createIndices()
144 def buildHorseDB(db=geneDB):
145 genePath = "%s/download/seq_gene.md" % cisRoot
146 chromos = {"1": "%s/download/chr1.fa" % cisRoot,
147 "2": "%s/download/chr2.fa" % cisRoot,
148 "3": "%s/download/chr3.fa" % cisRoot,
149 "4": "%s/download/chr4.fa" % cisRoot,
150 "5": "%s/download/chr5.fa" % cisRoot,
151 "6": "%s/download/chr6.fa" % cisRoot,
152 "7": "%s/download/chr7.fa" % cisRoot,
153 "8": "%s/download/chr8.fa" % cisRoot,
154 "9": "%s/download/chr9.fa" % cisRoot,
155 "10": "%s/download/chr10.fa" % cisRoot,
156 "11": "%s/download/chr11.fa" % cisRoot,
157 "12": "%s/download/chr12.fa" % cisRoot,
158 "13": "%s/download/chr13.fa" % cisRoot,
159 "14": "%s/download/chr14.fa" % cisRoot,
160 "15": "%s/download/chr15.fa" % cisRoot,
161 "16": "%s/download/chr16.fa" % cisRoot,
162 "17": "%s/download/chr17.fa" % cisRoot,
163 "18": "%s/download/chr18.fa" % cisRoot,
164 "19": "%s/download/chr19.fa" % cisRoot,
165 "20": "%s/download/chr20.fa" % cisRoot,
166 "21": "%s/download/chr21.fa" % cisRoot,
167 "22": "%s/download/chr22.fa" % cisRoot,
168 "23": "%s/download/chr23.fa" % cisRoot,
169 "24": "%s/download/chr24.fa" % cisRoot,
170 "25": "%s/download/chr25.fa" % cisRoot,
171 "26": "%s/download/chr26.fa" % cisRoot,
172 "27": "%s/download/chr27.fa" % cisRoot,
173 "28": "%s/download/chr28.fa" % cisRoot,
174 "29": "%s/download/chr29.fa" % cisRoot,
175 "30": "%s/download/chr30.fa" % cisRoot,
176 "31": "%s/download/chr31.fa" % cisRoot,
177 "M": "%s/download/chrM.fa" % cisRoot,
178 "X": "%s/download/chrX.fa" % cisRoot,
179 "Un": "%s/download/chrUn.fa" % cisRoot
182 print "Creating database %s" % db
185 print "Adding gene entries"
186 loadGeneEntries(db, genePath)
188 print "Adding gene features"
189 loadGeneFeatures(db, genePath)
191 for chromID in chromos.keys():
192 print "Loading chromosome %s" % chromID
193 loadChromosome(db, chromID, chromos[chromID], "/E_caballus/chromo%s.bin" % chromID)
195 print "Creating Indices"
198 print "Finished creating database %s" % db