def alignment(self): """Make self into an alignment, and return it. If all the sequences are the same length and type, then self, a sequenceList, could be an Alignment. This method generates an Alignment instance, runs the Alignment method checkLengthsAndTypes(), and returns the Alignment. If you feed p4 a fasta sequence, it makes SequenceList object, and runs this method on it. If it works then p4 puts the Alignment object in var.alignments, and if not it puts the SequenceList object in var.sequenceLists. It is possible that p4 might think that some short sequences are DNA when they are really protein. In that case it will fail to make an alignment, because it will fail the types check. So what you can do is something like this:: sl = var.sequenceLists[0] for s in sl.sequences: s.dataType = 'protein' a = sl.alignment() """ from alignment import Alignment a = Alignment() a.fName = self.fName import copy a.sequences = copy.deepcopy(self.sequences) # self will be deleted a.fName = self.fName a.checkLengthsAndTypes() return a
def calcUnconstrainedLogLikelihood1(self): """Calculate likelihood under the multinomial model. This calculates the unconstrained (multinomial) log like without regard to character partitions. The result is placed in the data variable unconstrainedLogLikelihood. If there is more than one partition, it makes a new temporary alignment and puts all the sequences in one part in that alignment. So it ultimately only works on one data partition. If there is more than one alignment, there is possibly more than one datatype, and so this method will refuse to do it. Note that the unconstrained log like of the combined data is not the sum of the unconstrained log likes of the separate partitions. See also calcUnconstrainedLogLikelihood2 """ if len(self.alignments) > 1: gm = ["Data.calcUnconstrainedLogLikelihood()"] gm.append("This method is not implemented for more than one alignment.") raise P4Error(gm) if self.nParts == 1: # no problem self.unconstrainedLogLikelihood = pf.getUnconstrainedLogLike(self.parts[0].cPart) else: a = self.alignments[0] import copy newAlig = Alignment() newAlig.dataType = a.dataType newAlig.symbols = a.symbols newAlig.dim = a.dim newAlig.equates = a.equates newAlig.taxNames = a.taxNames for s in a.sequences: newAlig.sequences.append(copy.deepcopy(s)) newAlig.checkLengthsAndTypes() newAlig._initParts() # newAlig.dump() self.unconstrainedLogLikelihood = pf.getUnconstrainedLogLike(newAlig.parts[0].cPart) del (newAlig)