erange 4.0a dev release with integrated cistematic
[erange.git] / cistematic / experiments / phyloFoot.py
diff --git a/cistematic/experiments/phyloFoot.py b/cistematic/experiments/phyloFoot.py
new file mode 100644 (file)
index 0000000..c88e641
--- /dev/null
@@ -0,0 +1,105 @@
+###########################################################################
+#                                                                         #
+# C O P Y R I G H T   N O T I C E                                         #
+#  Copyright (c) 2003-10 by:                                              #
+#    * California Institute of Technology                                 #
+#                                                                         #
+#    All Rights Reserved.                                                 #
+#                                                                         #
+# Permission is hereby granted, free of charge, to any person             #
+# obtaining a copy of this software and associated documentation files    #
+# (the "Software"), to deal in the Software without restriction,          #
+# including without limitation the rights to use, copy, modify, merge,    #
+# publish, distribute, sublicense, and/or sell copies of the Software,    #
+# and to permit persons to whom the Software is furnished to do so,       #
+# subject to the following conditions:                                    #
+#                                                                         #
+# The above copyright notice and this permission notice shall be          #
+# included in all copies or substantial portions of the Software.         #
+#                                                                         #
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,         #
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF      #
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND                   #
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS     #
+# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN      #
+# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN       #
+# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE        #
+# SOFTWARE.                                                               #
+###########################################################################
+#
+#  a simple use of the experiment class
+from experiment import Experiment
+from analyzeMotifs import AnalyzeMotifs
+from conservation import Conservation
+from draw import Draw
+from cistematic.core.homology import homologyDB
+
+class PhyloFoot(Experiment, AnalyzeMotifs, Conservation, Draw):
+    experimentType = "phyloFoot"
+    startingGenome = "scerevisiae"
+    targetGenomes = []
+    refGenes = []
+    phyloMap = {}
+    useConservation = True
+
+
+    def initialize(self, sGenome="", rGenes=[], tGenomes=[], analysisDB="", conservationDB="", maskNonConserved=True):
+        wholeDataset = []
+        try:
+            self.createAnalysis(dbName=analysisDB)
+            if self.consDBName == "":
+                self.createConservation(dbName=conservationDB)
+        except:
+            pass
+
+        if sGenome == "":
+            sGenome = self.startingGenome
+        else:
+            self.startingGenome = sGenome
+
+        if len(rGenes) == 0:
+            rGenes = self.refGenes
+        else:
+            self.refGenes = rGenes
+
+        if len(tGenomes) == 0:
+            tGenomes = self.targetGenomes
+        else:
+            self.targetGenomes = tGenomes
+
+        self.useConservation = maskNonConserved
+        try:
+            for gene in rGenes:
+                wholeDataset.append((sGenome, [gene]))
+                hGenes = self.returnHomologs((sGenome, gene))
+                self.phyloMap[(sGenome, gene)] = hGenes
+                for oneGene in hGenes:
+                    wholeDataset.append((oneGene[0], [oneGene[1]]))
+        except:
+            self.mlog("could not load from homology for (%s,%s,%s)" % (sGenome, str(rGenes), str(tGenomes)))
+
+        Experiment.initialize(self, wholeDataset)
+        
+
+    def run(self):
+        for gene in self.refGenes:
+            dset = self.phyloMap[(self.startingGenome, gene)]
+            dset.append((self.startingGenome, gene))
+            datasetID = self.setSettingsID("dataset-%s-%s" % (self.startingGenome, gene), dset)
+            if self.useConservation:
+                fastaFile = self.createDataFile(datasetID, geneDict= self.maskNonConservedSequence(datasetID))
+            else:
+                fastaFile = self.createDataFile(datasetID)
+
+            for (prog, settingsID) in self.programs:
+                prog.inputFile(fastaFile)
+                runID = self.setRun(prog.name(), datasetID, settingsID)
+                tag = str(runID)
+                prog.setTagID(tag)
+                if True:
+                    prog.run()
+                    theMotifs = prog.getMotifs()
+                    for mot in theMotifs:
+                        self.appendResults(mot)
+                else:
+                    self.mlog("problem with run %s" % tag)
\ No newline at end of file