def mpileup( opts )
raise SAMException.new(), "No BAMFile provided" unless @sam and @binary
raise SAMException.new(), "No FastA provided" unless @fasta_path
long_opts = {
:region => :r,
:illumina_quals => :six,
:count_anomalous => :A,
:no_baq => :B,
:adjust_mapq => :C,
:max_per_bam_depth => :d,
:extended_baq => :E,
:exclude_reads_file => :G,
:list_of_positions => :l,
:mapping_quality_cap => :M,
:ignore_rg => :R,
:min_mapping_quality => :q,
:min_base_quality => :Q
}
opts.each_pair do |k,v|
if long_opts[k]
opts[long_opts[k]] = v
opts.delete(k)
end
end
[:g, :u, :e, :h, :I, :L, :o, :p].each {|x| opts.delete(x) }
strptrs = []
strptrs << FFI::MemoryPointer.from_string("mpileup")
opts.each do |k,v|
next unless opts[k]
k = '6' if k == :six
k = '-' + k.to_s
strptrs << FFI::MemoryPointer.from_string(k)
strptrs << FFI::MemoryPointer.from_string(v.to_s) unless ["-R", "-B", "-E", "-6", "-A"].include?(k)
end
strptrs << FFI::MemoryPointer.from_string('-f')
strptrs << FFI::MemoryPointer.from_string(@fasta_path)
strptrs << FFI::MemoryPointer.from_string(@sam)
strptrs << nil
argv = FFI::MemoryPointer.new(:pointer, strptrs.length)
strptrs.each_with_index do |p, i|
argv[i].put_pointer(0, p)
end
old_stdout = STDOUT.clone
read_pipe, write_pipe = IO.pipe()
STDOUT.reopen(write_pipe)
Bio::DB::SAM::Tools.bam_mpileup(strptrs.length - 1,argv)
if fork
write_pipe.close
STDOUT.reopen(old_stdout)
begin
while line = read_pipe.readline
yield Pileup.new(line)
end
rescue EOFError
read_pipe.close
Process.wait
end
end
end