lib/transrate/assembly.rb
# Calls *block* with two arguments, the contig and an array
# of integer per-base coverage counts.
#
# @param bam [Bio::Db::Sam] a bam alignment of reads against this assembly
# @param block [Block] the block to call
Calls *block* with two arguments, the contig and an array
of integer per-base coverage counts.
Calls * block * with two arguments the contig and an array of integer per - base coverage counts .
def each_with_coverage(bam, &block)
      covfile = Samtools.coverage bam
      assembly_enum = assembly.each
      contig = assembly_enum.next
      contig.coverage = Array.new(contig.length, 0)
      name_i, pos_i, cov_i = 0, 1, 3
      File.open(covfile).each_line do |line|
        cols = line.chomp.split("\t")
        unless (cols && cols.length > 4)
          break
        end
        name, pos, cov = cols[name_i], cols[pos_i].to_i, cols[cov_i].to_i
        unless contig.name == name
          while contig.name != name
            block.call(contig, contig.coverage)
            contig = assembly_enum.next
            contig.coverage = Array.new(contig.length, 0)
          end
        end
        contig.coverage[pos - 1] = cov
      end
      block.call(contig, contig.coverage)
    end
def each_with_coverage ( bam , & block ) covfile = Samtools . coverage bam assembly_enum = assembly . each contig = assembly_enum . next contig . coverage = Array . new ( contig . length , 0 ) name_i , pos_i , cov_i = 0 , 1 , 3 File . open ( covfile ) . each_line do | line | cols = line . chomp . split ( "\t" ) unless ( cols && cols . length > 4 ) break end name , pos , cov = cols [ name_i ] , cols [ pos_i ] . to_i , cols [ cov_i ] . to_i unless contig . name == name while contig . name != name block . call ( contig , contig . coverage ) contig = assembly_enum . next contig . coverage = Array . new ( contig . length , 0 ) end end contig . coverage [ pos - 1 ] = cov end block . call ( contig , contig . coverage ) end
Calls *block* with two arguments, the contig and an array
of integer per-base coverage counts.
Calls * block * with two arguments the contig and an array of integer per - base coverage counts .
# generate coverage with samtools # get an assembly enumerator # precreate an array of the correct size to contain # coverage. this is necessary because samtools mpileup # doesn't print a result line for bases with 0 coverage # the columns we need # parse the coverage file # last line # extract the columns # yield the final contig
bam
a bam alignment of reads against this assembly
a bam alignment of reads against this assembly
block
the block to call
the block to call