def depthFunc(self,taskPrefix,dependencies,bamFile,outFile) : outputPath=outFile outputFilename=os.path.basename(outputPath) tmpDir=os.path.join(outputPath+".tmpdir") makeTmpDirCmd = getMkdirCmd() + [tmpDir] dirTask=self.addTask(preJoin(taskPrefix,"makeTmpDir"), makeTmpDirCmd, dependencies=dependencies, isForceLocal=True) tmpFiles = [] scatterTasks = set() def getChromosomeGroups(params) : """ Iterate through chromosomes/contigs and group small contigs together. This functions as a generator yielding successive contig groups. """ minSize=200000 group = [] headSize = 0 chromCount = len(params.chromSizes) assert(len(params.chromOrder) == chromCount) for chromIndex in range(chromCount) : chromLabel = params.chromOrder[chromIndex] if chromLabel in params.chromIsSkipped : continue chromSize = params.chromSizes[chromLabel] if headSize+chromSize <= minSize : group.append((chromIndex,chromLabel)) headSize += chromSize else : if len(group) != 0 : yield(group) group = [(chromIndex,chromLabel)] headSize = chromSize if len(group) != 0 : yield(group) for chromGroup in getChromosomeGroups(self.params) : assert(len(chromGroup) > 0) cid = getRobustChromId(chromGroup[0][0], chromGroup[0][1]) if len(chromGroup) > 1 : cid += "_to_"+getRobustChromId(chromGroup[-1][0], chromGroup[-1][1]) tmpFiles.append(os.path.join(tmpDir,outputFilename+"_"+cid)) cmd = [self.params.getChromDepthBin,"--ref", self.params.referenceFasta, "--align-file", bamFile, "--output", tmpFiles[-1]] for (chromIndex,chromLabel) in chromGroup : cmd.extend(["--chrom",chromLabel]) scatterTasks.add(self.addTask(preJoin(taskPrefix,"estimateChromDepth_"+cid),cmd,dependencies=dirTask,memMb=self.params.estimateMemMb)) assert(len(tmpFiles) != 0) catCmd = [self.params.catScript,"--output",outputPath]+tmpFiles catTask = self.addTask(preJoin(taskPrefix,"catChromDepth"),catCmd,dependencies=scatterTasks, isForceLocal=True) nextStepWait = set() nextStepWait.add(catTask) return nextStepWait
def depthFunc(self,taskPrefix,dependencies,bamFile,outFile) : outputPath=outFile outputFilename=os.path.basename(outputPath) tmpDir=os.path.join(outputPath+".tmpdir") makeTmpDirCmd = getMkdirCmd() + [tmpDir] dirTask=self.addTask(preJoin(taskPrefix,"makeTmpDir"), makeTmpDirCmd, dependencies=dependencies, isForceLocal=True) tmpFiles = [] scatterTasks = set() def getChromosomeGroups(params) : """ Iterate chromosomes/contigs and 'clump' small contigs together """ minSize=200000 group = [] headSize = 0 chromCount = len(params.chromSizes) assert(len(params.chromOrder) == chromCount) for chromIndex in range(chromCount) : chromLabel = params.chromOrder[chromIndex] chromSize = params.chromSizes[chromLabel] if headSize+chromSize <= minSize : group.append((chromIndex,chromLabel)) headSize += chromSize else : if len(group) != 0 : yield(group) group = [(chromIndex,chromLabel)] headSize = chromSize if len(group) != 0 : yield(group) for chromGroup in getChromosomeGroups(self.params) : assert(len(chromGroup) > 0) cid = getRobustChromId(chromGroup[0][0], chromGroup[0][1]) if len(chromGroup) > 1 : cid += "_to_"+getRobustChromId(chromGroup[-1][0], chromGroup[-1][1]) tmpFiles.append(os.path.join(tmpDir,outputFilename+"_"+cid)) cmd = [self.params.mantaGetChromDepthBin,"--align-file",bamFile,"--output",tmpFiles[-1]] for (chromIndex,chromLabel) in chromGroup : cmd.extend(["--chrom",chromLabel]) scatterTasks.add(self.addTask(preJoin(taskPrefix,"estimateChromDepth_"+cid),cmd,dependencies=dirTask)) catCmd = [self.params.mantaCat,"--output",outputPath]+tmpFiles catTask = self.addTask(preJoin(taskPrefix,"catChromDepth"),catCmd,dependencies=scatterTasks, isForceLocal=True) nextStepWait = set() nextStepWait.add(catTask) return nextStepWait
def depthFunc(self,taskPrefix,dependencies,bamFile,outFile) : outputPath=outFile outputFilename=os.path.basename(outputPath) tmpDir=os.path.join(outputPath+".tmpdir") dirTask=self.addTask(preJoin(taskPrefix,"makeTmpDir"), "mkdir -p "+tmpDir, dependencies=dependencies, isForceLocal=True) tmpFiles = [] scatterTasks = set() for (chromIndex, chromLabel) in enumerate(self.params.chromOrder) : cid = getRobustChromId(chromIndex, chromLabel) tmpFiles.append(os.path.join(tmpDir,outputFilename+"_"+cid)) cmd = [self.params.mantaGetChromDepthBin,"--align-file",bamFile,"--chrom",chromLabel,"--output",tmpFiles[-1]] scatterTasks.add(self.addTask(preJoin(taskPrefix,"estimateChromDepth_"+cid),cmd,dependencies=dirTask)) catCmd = "cat " + " ".join(["'%s'" % (x) for x in tmpFiles]) + " > '%s'" % (outputPath) catTask = self.addTask(preJoin(taskPrefix,"catChromDepth"),catCmd,dependencies=scatterTasks, isForceLocal=True) nextStepWait = set() nextStepWait.add(catTask) return nextStepWait