first pass cleanup of cistematic/genomes; change bamPreprocessing
[erange.git] / cistematic / genomes / cfamiliaris.py
index 75c31d1c9fa21e84708e5f1c3891cb09d1f589ac..12eda3008a9b31d8b13f25d263b6812198065dc9 100644 (file)
@@ -1,7 +1,7 @@
 ###########################################################################
 #                                                                         #
 # C O P Y R I G H T   N O T I C E                                         #
-#  Copyright (c) 2003-10 by:                                              #
+#  Copyright (c) 2003-13 by:                                              #
 #    * California Institute of Technology                                 #
 #                                                                         #
 #    All Rights Reserved.                                                 #
@@ -33,36 +33,48 @@ from cistematic.genomes import Genome
 from os import environ
 
 if environ.get("CISTEMATIC_ROOT"):
-    cisRoot = environ.get("CISTEMATIC_ROOT") 
+    cisRoot = environ.get("CISTEMATIC_ROOT")
 else:
     cisRoot = "/proj/genome"
 
 geneDB = "%s/C_familiaris/cfamiliaris.genedb" % cisRoot
 
 
-def loadChromosome(db, chromID, chromPath, chromOut):
-    seqArray = []
-    cfGenome = Genome("cfamiliaris", dbFile=db)
-    inFile = open(chromPath, "r")
-    line = inFile.readline()
-    for line in inFile:
-        seqArray.append(line.strip())
+def buildDogDB(db=geneDB):
+    genePath = "%s/download/seq_gene.md" % cisRoot
+    print "Creating database %s" % db
+    createDBFile(db)
 
-    seq = string.join(seqArray, "")
-    seqLen = len(seq)
-    if seqLen < 1:
-        print "Problems reading sequence from file"
+    print "Adding gene entries"
+    loadGeneEntries(db, genePath)
 
-    print "writing to file %s" % chromOut
-    outFile = open("%s%s" % (cisRoot, chromOut), "w")
-    outFile.write(seq)
-    outFile.close()
-    cfGenome.addChromosomeEntry(chromID, chromOut, "file")
+    print "Adding gene features"
+    loadGeneFeatures(db, genePath)
+
+    chromList = ["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", "X", "Un"
+    ]
+    for chromID in chromList:
+        print "Loading chromosome %s" % chromID
+        chromPath = "%s/download/chr%s.fa" % (cisRoot, chromID)
+        loadChromosome(db, chromID, chromPath, "/C_familiaris/chromo%s.bin" % chromID)
+
+    print "Creating Indices"
+    createDBindices(db)
+
+    print "Finished creating database %s" % db
+
+
+def createDBFile(db):
+    cfGenome = Genome("cfamiliaris",  dbFile=db)
+    cfGenome.createGeneDB(db)
 
 
 def loadGeneEntries(db, gFile):
-    """ FIXME - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
-    """
+    #TODO: - NEED TO DEAL WITH ALTERNATIVE SPLICING ENTRIES
+
     geneEntries = []
     alreadySeen = []
     cfGenome = Genome("cfamiliaris", dbFile=db)
@@ -177,7 +189,7 @@ def loadGeneOntology(db, goPath, goDefPath):
                 synonyms = idb.geneIDSynonyms(gID)
                 if len(synonyms) >0:
                     for entry in synonyms:
-                        gene_name += ","   
+                        gene_name += ","
                         gene_name += entry
                 else:
                     gene_name = " "
@@ -191,74 +203,26 @@ def loadGeneOntology(db, goPath, goDefPath):
     cfGenome.addGoInfoBatch(goArray)
 
 
-def createDBFile(db):
-    cfGenome = Genome("cfamiliaris",  dbFile=db)
-    cfGenome.createGeneDB(db)
-
-
-def createDBindices(db):
+def loadChromosome(db, chromID, chromPath, chromOut):
+    seqArray = []
     cfGenome = Genome("cfamiliaris", dbFile=db)
-    cfGenome.createIndices()
-
-
-def buildDogDB(db=geneDB):
-    genePath = "%s/download/seq_gene.md" % cisRoot
-    chromos = {"1": "%s/download/chr1.fa" % cisRoot,
-               "2": "%s/download/chr2.fa" % cisRoot,
-               "3": "%s/download/chr3.fa" % cisRoot,
-               "4": "%s/download/chr4.fa" % cisRoot,
-               "5": "%s/download/chr5.fa" % cisRoot,
-               "6": "%s/download/chr6.fa" % cisRoot,
-               "7": "%s/download/chr7.fa" % cisRoot,
-               "8": "%s/download/chr8.fa" % cisRoot,
-               "9": "%s/download/chr9.fa" % cisRoot,
-               "10": "%s/download/chr10.fa" % cisRoot,
-               "11": "%s/download/chr11.fa" % cisRoot,
-               "12": "%s/download/chr12.fa" % cisRoot,
-               "13": "%s/download/chr13.fa" % cisRoot,
-               "14": "%s/download/chr14.fa" % cisRoot,
-               "15": "%s/download/chr15.fa" % cisRoot,
-               "16": "%s/download/chr16.fa" % cisRoot,
-               "17": "%s/download/chr17.fa" % cisRoot,
-               "18": "%s/download/chr18.fa" % cisRoot,
-               "19": "%s/download/chr19.fa" % cisRoot,
-               "20": "%s/download/chr20.fa" % cisRoot,
-               "21": "%s/download/chr21.fa" % cisRoot,
-               "22": "%s/download/chr22.fa" % cisRoot,
-               '23': "%s/download/chr23.fa" % cisRoot,
-               "24": "%s/download/chr24.fa" % cisRoot,
-               "25": "%s/download/chr25.fa" % cisRoot,
-               "26": "%s/download/chr26.fa" % cisRoot,
-               "27": "%s/download/chr27.fa" % cisRoot,
-               "28": "%s/download/chr28.fa" % cisRoot,
-               "29": "%s/download/chr29.fa" % cisRoot,
-               "30": "%s/download/chr30.fa" % cisRoot,
-               "31": "%s/download/chr31.fa" % cisRoot,
-               "32": "%s/download/chr32.fa" % cisRoot,
-               "33": "%s/download/chr33.fa" % cisRoot,
-               "34": "%s/download/chr34.fa" % cisRoot,
-               "35": "%s/download/chr35.fa" % cisRoot,
-               "36": "%s/download/chr36.fa" % cisRoot,
-               "37": "%s/download/chr37.fa" % cisRoot,
-               "38": "%s/download/chr38.fa" % cisRoot,
-               "X": "%s/download/chrX.fa" % cisRoot,
-               "Un": "%s/download/chrUn.fa" % cisRoot
-    }
-
-    print "Creating database %s" % db
-    createDBFile(db)
-
-    print "Adding gene entries"
-    loadGeneEntries(db, genePath)
+    inFile = open(chromPath, "r")
+    line = inFile.readline()
+    for line in inFile:
+        seqArray.append(line.strip())
 
-    print "Adding gene features"
-    loadGeneFeatures(db, genePath)
+    seq = string.join(seqArray, "")
+    seqLen = len(seq)
+    if seqLen < 1:
+        print "Problems reading sequence from file"
 
-    for chromID in chromos.keys():
-        print "Loading chromosome %s" % chromID
-        loadChromosome(db, chromID, chromos[chromID], "/C_familiaris/chromo%s.bin" % chromID)
+    print "writing to file %s" % chromOut
+    outFile = open("%s%s" % (cisRoot, chromOut), "w")
+    outFile.write(seq)
+    outFile.close()
+    cfGenome.addChromosomeEntry(chromID, chromOut, "file")
 
-    print "Creating Indices"
-    createDBindices(db)
 
-    print "Finished creating database %s" % db
\ No newline at end of file
+def createDBindices(db):
+    cfGenome = Genome("cfamiliaris", dbFile=db)
+    cfGenome.createIndices()