parameters: (self, bamList, outputPath, taskPrefix="", dependencies=None)
return_statement: return _getDepthShared(self, taskPrefix, dependencies, bamList, outputPath, depthFunc)
docstring: estimate chrom depth directly from BAM/CRAM file
docstring_summary: estimate chrom depth directly from BAM/CRAM file
docstring_tokens: estimate chrom depth directly from BAM / CRAM file
function: def getDepthFromAlignments(self, bamList, outputPath, taskPrefix="", dependencies=None) :
      """
      estimate chrom depth directly from BAM/CRAM file
      """
  
      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))
  
          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
  
      return _getDepthShared(self, taskPrefix, dependencies, bamList, outputPath, depthFunc)
function_tokens: def getDepthFromAlignments ( self , bamList , outputPath , taskPrefix = "" , dependencies = None ) : 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 ) ) 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 return _getDepthShared ( self , taskPrefix , dependencies , bamList , outputPath , depthFunc )