def getHalTreeMutations(halPath, args, rootName=None): root = rootName if root is None: root = getHalRootName(halPath) for child in getHalChildrenNames(halPath, root): getHalBranchMutations(halPath, child, args) getHalTreeMutations(halPath, args, child)
def computeTreePhyloP(args): visitQueue = [args.root] bigwigCmds = [] while len(visitQueue) > 0: genome = visitQueue.pop() bedFlags = "" # Generate a bed file of all regions of # genome that dont align to parent bedInsertsFile = outFileName(args, genome, "bed", "inserts", True) if genome != args.root: runShellCommand( "halAlignedExtract %s %s --alignedFile %s --complement" % ( args.hal, genome, bedInsertsFile)) bedFlags = "--refBed %s" % bedInsertsFile # Run halPhyloP on the inserts wigFile = outFileName(args, genome, "wig", "phyloP", False) cmd = "halPhyloPMP.py %s %s %s %s --numProc %d %s" % ( args.hal, genome, args.mod, bedFlags, args.numProc, wigFile) if args.subtree is not None: cmd += " --subtree %s" % args.subtree if args.prec is not None: cmd += " --prec %d" % args.prec runShellCommand(cmd) runShellCommand("rm -f %s" % bedInsertsFile) # Lift down from the parent, appending to the wig file computed above if genome != args.root: parent = getHalParentName(args.hal, genome) parentWig = outFileName(args, parent, "wig", "phyloP", False) if os.path.isfile(parentWig): runShellCommand("halWiggleLiftover %s %s %s %s %s --append" % ( args.hal, parent, parentWig, genome, wigFile)) # Convert to bigwig if desired and delete wig file if args.bigWig is True and os.path.isfile(wigFile): sizesFile = outFileName(args, genome, "sizes", "chr", True) bwFile = outFileName(args, genome, "bw", "phyloP", False) bwCmd = "halStats %s --chromSizes %s > %s && " % (args.hal, genome, sizesFile) bwCmd += "wigToBigWig %s %s %s && " % (wigFile, sizesFile, bwFile) bwCmd += "rm -f %s &&" % wigFile bwCmd += "rm -f %s" % sizesFile bigwigCmds.append(bwCmd) # Recurse on children. children = getHalChildrenNames(args.hal, genome) for child in children: visitQueue.append(child) #parallel bigwig conversion runParallelShellCommands(bigwigCmds, args.numProc)