def RunPhyldogAnalysis(phyldogDir, ogs, speciesToUse, nParallel): qRunSingley = True Setup(phyldogDir, ogs, speciesToUse, qRunSingley) start = time.time() if qRunSingley: nOGs = len(ogs) cmds = [["mpirun -np 2 phyldog param=%s%s" % (phyldogDir, "GeneralOptions_OG%07d.opt" % i)] for i in xrange(nOGs)] util.RunParallelCommands(nParallel, cmds, True) else: subprocess.call("mpirun -np %d phyldog param=GeneralOptions.opt" % nParallel, shell=True, cwd=phyldogDir, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stop = time.time() print("%f seconds" % (stop-start)) return ProcessSpeciesTree(phyldogDir)
def DoTrees(self, ogs, idDict, nProcesses, qStopAfterSeqs, qStopAfterAlignments, nSwitchToMafft=500): # 0 resultsDirsFullPath = [] for fn in [ self.GetFastaFilename, self.GetAlignmentFilename, self.GetTreeFilename ]: for qIDs in [True, False]: d = os.path.split(fn(0, not qIDs))[0] if not os.path.exists(d): os.mkdir(d) if not qIDs: resultsDirsFullPath.append(d) if qStopAfterSeqs: break if qStopAfterAlignments and fn == self.GetAlignmentFilename: break # 1. fastaWriter = FastaWriter(self.ogsWorkingDir) self.WriteFastaFiles(fastaWriter, ogs, idDict) if qStopAfterSeqs: return resultsDirsFullPath # 2 if qStopAfterAlignments: util.PrintUnderline("Inferring multiple sequence alignments") else: util.PrintUnderline( "Inferring multiple sequence alignments and gene trees") # 3 alignCommands = self.GetAlignmentCommands(ogs, nSwitchToMafft) if qStopAfterAlignments: util.RunParallelCommands(nProcesses, alignCommands, qShell=True) return resultsDirsFullPath[:2] alignmentFilesToUse = [ self.GetAlignmentFilename(i) for i, _ in enumerate(alignCommands) ] treeCommands = self.GetTreeCommands(alignmentFilesToUse, ogs) commandsSet = [] for i in xrange(len(treeCommands)): commandsSet.append([alignCommands[i], treeCommands[i]]) for i in xrange(len(treeCommands), len(alignCommands)): commandsSet.append([alignCommands[i]]) util.RunParallelOrderedCommandLists(nProcesses, commandsSet) # Convert ids to accessions for i, alignFN in enumerate(alignmentFilesToUse): with open(alignFN, 'rb') as infile, open(self.GetAlignmentFilename(i, True), 'wb') as outfile: for line in infile: if line.startswith(">"): outfile.write(">" + idDict[line[1:].rstrip()] + "\n") else: outfile.write(line) if os.path.exists(self.GetTreeFilename(i)): util.RenameTreeTaxa(self.GetTreeFilename(i), self.GetTreeFilename(i, True), idDict, qFixNegatives=True) return resultsDirsFullPath[:2]