Class: Bio::BWA
- Inherits:
-
Object
- Object
- Bio::BWA
- Extended by:
- FFI::Library
- Defined in:
- lib/bio/bwa.rb,
lib/bio/bwa/library.rb
Overview
Defined Under Namespace
Classes: Library
Class Method Summary (collapse)
-
+ (Object) build_args_for_BWA(args)
Internal method to build argument list for BWA C functions.
-
+ (Object) build_parameters(function_name, valid_params, params, last_params)
Internal method to produce a correct parameter list for BWA functions.
-
+ (Object) bwt2sa(params = {})
Generate SA file from BWT and Occ files.
-
+ (Object) bwtupdate(params = {})
Convert a BWT file to the new BWT format.
-
+ (Object) call_BWA_function(args)
Internal method to call the BWA C functions.
-
+ (Object) change_arg_name(hash, key, new_key)
Internal method used to change parameters name from Ruby to BWA functions.
-
+ (Object) check_mandatory(mandatory_params, params)
Internal method to check if mandatory params have been set.
-
+ (Object) fa2pac(params = {})
Convert a Fasta to Packed format.
-
+ (Object) long_read_alignment(params = {})
Run the alignment for long query sequences.
-
+ (Object) make_index(params = {})
Generate the BWT index for a Fasta database.
-
+ (Object) pac2bwt(params = {})
Convert a Packed file format to Burrows-Wheeler Transform format.
-
+ (Object) pac_rev(params = {})
Generate reverse Packed format.
-
+ (Object) sai_to_sam_paired(params = {})
Convert the SAI alignment output into SAM format (paired ends).
-
+ (Object) sai_to_sam_single(params = {})
Convert the SAI alignment output into SAM format (single end).
-
+ (Object) short_read_alignment(params = {})
Run the alignment for short query sequences.
-
+ (Object) simple_SW(params = {})
Run the alignment between multiple short sequences and ONE long sequence.
Class Method Details
+ (Object) build_args_for_BWA(args)
this method should not be called directly
Internal method to build argument list for BWA C functions
263 264 265 266 267 268 269 270 271 272 |
# File 'lib/bio/bwa.rb', line 263 def self.build_args_for_BWA(args) cmd_args = args.map do |arg| FFI::MemoryPointer.from_string(arg.to_s) # convert every parameters into a string and then into a memory pointer end exec_args = FFI::MemoryPointer.new(:pointer, cmd_args.length) # creating a pointer to an array of pointers cmd_args.each_with_index do |arg, i| exec_args[i].put_pointer(0, arg) # filling in the array of pointers end return exec_args end |
+ (Object) build_parameters(function_name, valid_params, params, last_params)
this method should not be called directly
Internal method to produce a correct parameter list for BWA functions
276 277 278 279 280 281 282 283 284 285 286 287 |
# File 'lib/bio/bwa.rb', line 276 def self.build_parameters(function_name,valid_params,params,last_params) args = [function_name] params.each_key do |k| raise ArgumentError, "Unknown parameter '#{k}'" unless valid_params.include?(k.to_s) unless last_params.include?(k) then # the last_params are required after the options for BWA functions args << "-#{k}" args << params[k] unless params[k] == true # skipping boolean values. just include the param name end end last_params.each {|p| args << params[p]} # now adding the last_params so the parameter list is in the correct order return args end |
+ (Object) bwt2sa(params = {})
Generate SA file from BWT and Occ files
60 61 62 63 64 65 66 |
# File 'lib/bio/bwa.rb', line 60 def self.bwt2sa(params={}) valid_params = %q(file_in file_out i) last_params = [:file_in,:file_out] check_mandatory(last_params, params) args = build_parameters("bwt2sa",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) bwtupdate(params = {})
this method overwrite existing BWT file
Convert a BWT file to the new BWT format
36 37 38 39 40 41 42 |
# File 'lib/bio/bwa.rb', line 36 def self.bwtupdate(params={}) valid_params = %w(file_in) last_params = [:file_in] check_mandatory(last_params, params) args = build_parameters("bwtupdate",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) call_BWA_function(args)
this method should not be called directly
Internal method to call the BWA C functions
256 257 258 259 |
# File 'lib/bio/bwa.rb', line 256 def self.call_BWA_function(args) c_args = build_args_for_BWA(args) self.send("bwa_#{args[0]}".to_sym,args.size,c_args) # call the C function and pass the arguments size and parameters list (same as int argc, char *argv[]) end |
+ (Object) change_arg_name(hash, key, new_key)
this method should not be called directly
Internal method used to change parameters name from Ruby to BWA functions
297 298 299 300 301 |
# File 'lib/bio/bwa.rb', line 297 def self.change_arg_name(hash,key,new_key) hash[new_key] = hash[key] hash.delete(key) return hash end |
+ (Object) check_mandatory(mandatory_params, params)
this method should not be called directly
Internal method to check if mandatory params have been set
291 292 293 |
# File 'lib/bio/bwa.rb', line 291 def self.check_mandatory(mandatory_params, params) mandatory_params.each {|mp| raise ArgumentError,"You must provide parameter '#{mp}'" unless params.include?(mp)} end |
+ (Object) fa2pac(params = {})
Convert a Fasta to Packed format
11 12 13 14 15 16 17 18 |
# File 'lib/bio/bwa.rb', line 11 def self.fa2pac(params={}) valid_params = %q(file_in prefix) last_params = [:file_in, :prefix] mandatory_params = [:file_in] check_mandatory(mandatory_params, params) args = build_parameters("fa2pac",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) long_read_alignment(params = {})
Boolean arguments must be set to ‘true’
Run the alignment for long query sequences
203 204 205 206 207 208 209 210 211 |
# File 'lib/bio/bwa.rb', line 203 def self.long_read_alignment(params = {}) valid_params = %w(q r a b t T w d z m y s c N H f prefix file_in) mandatory_params = [:prefix, :file_in, :file_out] last_params = [:prefix,:file_in] check_mandatory(mandatory_params, params) params = change_arg_name(params,:file_out,:f) if params[:file_out] args = build_parameters("bwtsw2",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) make_index(params = {})
Boolean values must be set to ‘true’
Generate the BWT index for a Fasta database
75 76 77 78 79 80 81 82 83 |
# File 'lib/bio/bwa.rb', line 75 def self.make_index(params = {}) valid_params = %w(file_in p a c) mandatory_params = [:file_in] last_params = [:file_in] check_mandatory(mandatory_params, params) params = change_arg_name(params,:prefix,:p) if params[:prefix] args = build_parameters("index",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) pac2bwt(params = {})
Convert a Packed file format to Burrows-Wheeler Transform format
24 25 26 27 28 29 30 |
# File 'lib/bio/bwa.rb', line 24 def self.pac2bwt(params={}) valid_params = %q(file_in file_out) last_params = [:file_in,:file_out] check_mandatory(last_params, params) args = build_parameters("pac2bwt",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) pac_rev(params = {})
Generate reverse Packed format
48 49 50 51 52 53 54 |
# File 'lib/bio/bwa.rb', line 48 def self.pac_rev(params={}) valid_params = %w(file_in file_out) last_params = [:file_in,:file_out] check_mandatory(last_params, params) args = build_parameters("pac_rev",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) sai_to_sam_paired(params = {})
Boolean values must be set to ‘true’
Convert the SAI alignment output into SAM format (paired ends)
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/bio/bwa.rb', line 162 def self.sai_to_sam_paired(params = {}) valid_params = %w(a o s P n N c f A r prefix first_sai second_sai first_fastq second_fastq) mandatory_params = [:prefix, :sai, :fastq] last_params = [:prefix, :first_sai, :second_sai, :first_fastq, :second_fastq] check_mandatory(mandatory_params, params) params = change_arg_name(params,:file_out,:f) if params[:file_out] if params[:sai] raise ArgumentError,"you must provide an array with two SAI files!" unless params[:sai].is_a?(Array) and params[:sai].size == 2 params[:first_sai] = params[:sai][0] params[:second_sai] = params[:sai][1] params.delete(:sai) end if params[:fastq] raise ArgumentError,"you must provide an array with two FastQ files!" unless params[:fastq].is_a?(Array) and params[:fastq].size == 2 params[:first_fastq] = params[:fastq][0] params[:second_fastq] = params[:fastq][1] params.delete(:fastq) end args = build_parameters("sai2sam_pe",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) sai_to_sam_single(params = {})
Convert the SAI alignment output into SAM format (single end)
136 137 138 139 140 141 142 143 144 |
# File 'lib/bio/bwa.rb', line 136 def self.sai_to_sam_single(params = {}) valid_params = %w(n r fastq sai prefix f) mandatory_params = [:prefix,:sai,:fastq] last_params = [:prefix,:sai,:fastq] check_mandatory(mandatory_params, params) params = change_arg_name(params,:file_out,:f) if params[:file_out] args = build_parameters("sai2sam_se",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) short_read_alignment(params = {})
Boolean values must be set to ‘true’
Run the alignment for short query sequences
114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/bio/bwa.rb', line 114 def self.short_read_alignment(params={}) args = ["aln"] valid_params = %w(n o e i d l k c L R m t N M O E q f b single first second I B prefix file_in) mandatory_params = [:prefix,:file_in,:file_out] last_params = [:prefix,:file_in] check_mandatory(mandatory_params, params) params = change_arg_name(params,:file_out,:f) if params[:file_out] params = change_arg_name(params,:single,"0") if params[:single] params = change_arg_name(params,:first,"1") if params[:first] params = change_arg_name(params,:second,"2") if params[:second] args = build_parameters("aln",valid_params,params,last_params) call_BWA_function(args) end |
+ (Object) simple_SW(params = {})
Boolean values must be set to ‘true’
Run the alignment between multiple short sequences and ONE long sequence
224 225 226 227 228 229 230 231 232 233 234 235 236 |
# File 'lib/bio/bwa.rb', line 224 def self.simple_SW(params = {}) args = ["stdsw"] valid_params = %w(g T f r p file_out long_seq short_seq) mandatory_params = [:long_seq,:short_seq] last_params = mandatory_params check_mandatory(mandatory_params, params) file_out = params[:file_out] params.delete(:file_out) args = build_parameters("stdsw",valid_params,params,last_params) $stdout.reopen(file_out,"w") if file_out call_BWA_function(args) $stdout.reopen("/dev/tty","w") if file_out end |