Skip to content

Instantly share code, notes, and snippets.

@rjpbonnal
Created April 26, 2011 14:47
Show Gist options
  • Save rjpbonnal/942392 to your computer and use it in GitHub Desktop.
Save rjpbonnal/942392 to your computer and use it in GitHub Desktop.
binding with ffi bam_merge_core
# @abstract Merge multiple sorted BAM.
# @param is_by_qname whether to sort by query name
# @param out output BAM file name
# @param headers name of SAM file from which to copy '@' header lines,
# or NULL to copy them from the first file to be merged
# @param n number of files to be merged
# @param fn names of files to be merged
#
# @discussion Padding information may NOT correctly maintained. This
# function is NOT thread safe.
# int bam_merge_core(int by_qname, const char *out, const char *headers, int n, char * const *fn,
# int flag, const char *reg)
attach_function :bam_merge_core, [:int, :string, :string, :int, :pointer, :int, :string], :int
def self.bam_merge(bam_output_file_name, bam_array_input_file_names)
is_by_qname = 0
headers = 0
flag = 0
reg = 0
ary = bam_array_input_file_names.map do |filename|
FFI::MemoryPointer.from_string(filename)
end
fns=FFI::MemoryPointer.new :pointer, ary.size
fns.put_array_of_pointer 0, ary
bam_merge_core(is_by_qname, bam_output_file_name, headers, bam_array_input_file_names.size, fns, flag, reg)
end
# @abstract Merge multiple sorted BAM.
# @param is_by_qname whether to sort by query name
# @param out output BAM file name
# @param headers name of SAM file from which to copy '@' header lines,
# or NULL to copy them from the first file to be merged
# @param n number of files to be merged
# @param fn names of files to be merged
#
# @discussion Padding information may NOT correctly maintained. This
# function is NOT thread safe.
# int bam_merge_core(int by_qname, const char *out, const char *headers, int n, char * const *fn,
# int flag, const char *reg)
attach_function :bam_merge_core, [:int, :string, :string, :int, :pointer, :int, :string], :int
def self.bam_merge(bam_output_file_name, bam_array_input_file_names)
is_by_qname = 0
headers = 0
flag = 0
reg = 0
ary = bam_array_input_file_names.map do |filename|
FFI::MemoryPointer.from_string(filename)
end
fns=FFI::MemoryPointer.new :pointer, ary.size
fns.put_array_of_pointer 0, ary
bam_merge_core(is_by_qname, bam_output_file_name, headers, bam_array_input_file_names.size, fns, flag, reg)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment