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 ###########################################################################
31 from cistematic.programs import Program
33 from cistematic.core.motif import Motif
37 """ Multiple Alignment using Fast Fourier Transform. Uses fftnsi as described in:
38 K. Katoh, K. Misawa, K. Kuma and T. Miyata (2002)
39 Nucleic Acids Research 30: 3059-3066.
41 mafftPath = "%s/mafft/" % Program.programRoot
46 def getSettings(self):
50 def setSettings(self, settings):
52 self.argDict = settings
55 def buildCommand(self):
56 cmd = self.mafftPath + "fftnsi "
57 for arg in self.argDict.keys():
58 cmd = cmd + " --" + arg + " %s" % str(self.argDict[arg])
59 cmd += " --quiet " + self.inputFilePath
60 print "cmd is %s" % (cmd)
65 def setGapOpening(self, op):
66 """ Gap opening penalty. Default is 1.58
68 self.argDict["op"] = op
71 def setOffset(self, ep):
72 """ Offset - like a gap expansion penalty. Default is 0.120
74 self.argDict["ep"] = ep
77 def setScoringMatrix(self, bl):
78 """ set Blossum scoring matrix. Choices are 30, 45, 62, and 80.
80 self.argDict["bl"] = bl
83 def setMaxiterate(self, maxi):
84 """ maximum number of iterations in progressive method.
86 self.argDict["maxiterate"] = maxi
89 def setRetree(self, tnum):
90 """ number of tree building in progressive method.
92 self.argDict["retree"] = tnum
96 startTime = time.time()
97 self.contents = os.popen(Mafft.buildCommand(self)).readlines()
98 stopTime = time.time()
100 print "\nThis run took %.3f - %.3f = %.3f seconds" % (startTime, stopTime, stopTime - startTime)
103 def getAlignment(self):
104 """ take the results stored in self.contents and return a dictionary for inclusion into the genepool.
109 for line in self.contents:
111 if len(dictKey) > 0 and len(sequence) > 0:
112 alignedDict[dictKey] = sequence
116 sequence += line[:-1]
118 if len(dictKey) > 0 and len(sequence) > 0:
119 alignedDict[dictKey] = sequence