def _initParts(self): gm = ['Alignment._initParts()'] if len(self.parts): for p in self.parts: del(p) self.parts = [] if self.equates: eqSymb = self.equates.keys() eqSymb.sort() eqSymb = string.join(eqSymb, '') else: eqSymb = '' if len(self.sequences) and self.length and self.symbols and self.dim: pass else: gm.append("Can't allocate part.") if not len(self.sequences): gm.append("-no sequences.") elif not self.length: gm.append("-the sequences have no length") elif not self.symbols: gm.append("-no symbols") elif not self.dim: gm.append("-dim not set") raise P4Error(gm) # its all one part if not self.nexusSets or not self.nexusSets.charPartition: aPart = Part() aPart.alignment = self aPart.name = 'all' aPart.lowName = 'all' aPart.dataType = self.dataType aPart.dim = self.dim aPart.symbols = self.symbols aPart.equates = self.equates aPart.nTax = len(self.sequences) aPart.nChar = self.length assert aPart.nChar if 0: print gm[0] print " symbols=%s" % self.symbols aPart.cPart = pf.newPart(len(self.sequences), self.length, eqSymb, self.symbols) if not aPart or not aPart.cPart: gm.append("Failed to get memory for part.") raise P4Error(gm) # Make the equates table verbose = 0 equatesTable = [] if verbose: print "equates is %s" % self.equates print "eqSymb is %s" % eqSymb # the keys print "symbols is %s" % self.symbols for i in range(len(eqSymb)): if verbose: print "%3s: " % eqSymb[i], e = self.equates[eqSymb[i]] if verbose: print "%8s : " % e, for s in self.symbols: if s in e: if verbose: print "%1i" % 1, equatesTable.append('1') else: if verbose: print "%1i" % 0, equatesTable.append('0') if verbose: print '' equatesTable = string.join(equatesTable, '') if verbose: print "\n\nequatesTable:" print equatesTable pf.pokeEquatesTable(aPart.cPart, equatesTable) sList = [] for s in self.sequences: sList.append(s.sequence) if 0: print gm[0] print "sList = %s" % sList print "joined = %s" % string.join(sList, '') pf.pokeSequences(aPart.cPart, string.join(sList, '')) # print "about to makePatterns ..." pf.makePatterns(aPart.cPart) # print "about to setInvar" pf.setGlobalInvarSitesVec(aPart.cPart) # pf.dumpPart(aPart.cPart) self.parts.append(aPart) elif self.nexusSets.charPartition: for cpp in self.nexusSets.charPartition.subsets: # print "Doing subset '%s', mask: %s" % (cpp.name, cpp.mask) # print "About to subsetUsingMask (self length is %i)" % # self.length b = self.subsetUsingMask(cpp.mask) # This very method, but now there are no charPartitions in b. b._initParts() b.parts[0].name = cpp.name b.parts[0].lowName = string.lower(cpp.name) self.parts.append(b.parts[0]) b.parts = [] # so we don't try free-ing it twice