X-Git-Url: http://woldlab.caltech.edu/gitweb/?p=erange.git;a=blobdiff_plain;f=cistematic%2Fprograms%2FcisSampler.py;fp=cistematic%2Fprograms%2FcisSampler.py;h=059032fdc7705039692eab700ebe049cbc2a84e5;hp=0000000000000000000000000000000000000000;hb=bc30aca13e5ec397c92e67002fbf7a103130b828;hpb=0d3e3112fd04c2e6b44a25cacef1d591658ad181 diff --git a/cistematic/programs/cisSampler.py b/cistematic/programs/cisSampler.py new file mode 100644 index 0000000..059032f --- /dev/null +++ b/cistematic/programs/cisSampler.py @@ -0,0 +1,198 @@ +########################################################################### +# # +# 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. # +########################################################################### +# +# covariance.py +from cistematic.programs import Program +import time +import cistematic.programs.gibbs as Gibbs +from cistematic.core.motif import Motif + + +class CisSampler(Program): + + + def getSettings(self): + return (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON, self.iterations,self.bfile, self.percID,self.MarkovSize,self.findBest) + + + def setSettings(self, settings): + self.motifs = [] + (self.model, self.nmotifs, self.minwidth, self.maxwidth, self.bON, self.iterations, self.bfile,self.percID,self.MarkovSize,self.findBest) = settings + + + def setGenExpOptions(self, optionArray): + self.setModel("zoops") + self.setNumMotifs("10") + self.setMaxWidth("15") + self.setIterations("1000") + self.setMinWidth("6") + self.setBON(True) + self.bfile = "None" + self.setPercID("85") + self.setMarkovSize("2") + self.setFindBest("100") + for option in optionArray: + (optionTag, optionValue) = option.split(":") + if optionTag == "Markov size": + self.setMarkovSize(optionValue) + + if optionTag == "percentID": + self.setPercID(optionValue) + + if optionTag == "founderPercentID": + self.setFounderPID(optionValue) + + if optionTag == "model": + self.setModel(optionValue) + + if optionTag == "nmotifs": + self.setNumMotifs(optionValue) + + if optionTag == "width": + self.setMinWidth(optionValue) + self.setMaxWidth(optionValue) + + if optionTag == "minWidth": + self.setMinWidth(optionValue) + + if optionTag == "maxWidth": + self.setMaxWidth(optionValue) + + if optionTag == "reverse": + self.setBON(optionValue) + + if optionTag == "iterations": + self.setIterations(optionValue) + + if optionTag == "background": + self.setBackground(optionValue) + + if optionTag == "founder": + self.setFounder(True) + + #if no background file is provided the default setting + #is to use the input sequences as a background + print self.bfile + + + def setMarkovSize(self,val): + self.MarkovSize = int(str(val)) + + + def setFindBest(self,val): + self.findBest = int(str(val)) + + + def setFounderPID(self,val): + self.founderPercID = int(str(val)) + + + def setFounder(self, boolVal): + if boolVal: + self.Founder = True + else: + self.Founder = False + + + def setPercID(self, percVal): + self.percID = int(str(percVal)) + + + def setModel(self, modelType): + if modelType in ["oops", "zoops", "tcm"]: + self.model = str(modelType) + else: + self.model = "zoops"; + + + def setIterations(self, number): + self.iterations = int(str(number)) + + + def setNumMotifs(self, motifNum): + self.nmotifs = int(str(motifNum)) + + + def setBON(self, B_val): + if str(B_val) == "False": + self.bON = False + else: + self.bON = True + + + def getSequences(self, infile): + seqFiles = open(infile, "r") + Lines = seqFiles.readlines() + seqFiles.close() + self.sequences = [] + for line in Lines: + if line[0] != ">": + self.sequences.append(line[:-1]) + + + def setMinWidth(self, width): + self.minwidth = int(str(width)) + + + def setMaxWidth(self, width): + self.maxwidth = int(str(width)) + + + ##willlikley satr to use this but not yet + # set background frequency file + def setBackground(self, backFile): + self.bfile = str(backFile) + + + def run(self): + print self.nmotifs + startTime = time.time() + if self.bfile == "None": + self.bfile = Gibbs.Markov(self.sequences, self.bON,self.MarkovSize) + print "geting consensus score" + self.contents = Gibbs.MotifFinder(self.sequences, self.minwidth, self.maxwidth, self.nmotifs, + self.MarkovSize, self.bON, self.bfile, False, self.percID, + self.iterations, self.findBest) + stopTime = time.time() + print self.contents + print "right here!\n \n\n" + print "\nThis run took %.3f - %.3f = %.3f seconds and produced %d motifs" % (startTime, stopTime, stopTime - startTime, len(self.contents)) + + + def getMotifs(self): + self.motifs = [] + try: + for motif in range(len(self.contents)): + info = "" + self.motifs.append(Motif("%s-cisSampler-%s" % (self.tagID, str(motif + 1)), "", self.contents[motif], [], 0.0, info)) + except: + print "error returning motifs" + pass + + return self.motifs \ No newline at end of file