Class: Bio::AssemblyGraphAlgorithms::ContigPrinter::Variant
- Inherits:
-
Object
- Object
- Bio::AssemblyGraphAlgorithms::ContigPrinter::Variant
- Defined in:
- lib/assembly/contig_printer.rb
Constant Summary collapse
- INSERT =
Types:
:insert- DELETION =
:deletion- SWAP =
n bases swapped for another n bases
:swap
Instance Attribute Summary collapse
-
#deletion_length ⇒ Object
length of deletion (or nil if not a deletion).
-
#position ⇒ Object
0-based position on the contig.
-
#reference_name ⇒ Object
Returns the value of attribute reference_name.
-
#sequence ⇒ Object
sequence (or nil if variant is a deletion).
-
#type ⇒ Object
See constants in this class.
Instance Method Summary collapse
- #base_number ⇒ Object
-
#initialize(position = nil, sequence_or_deletion_length = nil, type = nil) ⇒ Variant
constructor
A new instance of Variant.
-
#reverse! ⇒ Object
The reference sequence has been reverse complemented.
- #to_shorthand ⇒ Object
- #vcf(reference_sequence) ⇒ Object
-
#vcf_array(reference_sequence) ⇒ Object
CHROM POS ID REF ALT QUAL FILTER INFO.
Constructor Details
#initialize(position = nil, sequence_or_deletion_length = nil, type = nil) ⇒ Variant
Returns a new instance of Variant.
346 347 348 349 350 351 352 353 354 |
# File 'lib/assembly/contig_printer.rb', line 346 def initialize(position=nil, sequence_or_deletion_length=nil, type=nil) @position = position @type = type if type == DELETION @deletion_length = sequence_or_deletion_length else @sequence = sequence_or_deletion_length end end |
Instance Attribute Details
#deletion_length ⇒ Object
length of deletion (or nil if not a deletion)
341 342 343 |
# File 'lib/assembly/contig_printer.rb', line 341 def deletion_length @deletion_length end |
#position ⇒ Object
0-based position on the contig
335 336 337 |
# File 'lib/assembly/contig_printer.rb', line 335 def position @position end |
#reference_name ⇒ Object
Returns the value of attribute reference_name.
332 333 334 |
# File 'lib/assembly/contig_printer.rb', line 332 def reference_name @reference_name end |
#sequence ⇒ Object
sequence (or nil if variant is a deletion)
338 339 340 |
# File 'lib/assembly/contig_printer.rb', line 338 def sequence @sequence end |
#type ⇒ Object
See constants in this class
344 345 346 |
# File 'lib/assembly/contig_printer.rb', line 344 def type @type end |
Instance Method Details
#base_number ⇒ Object
356 357 358 |
# File 'lib/assembly/contig_printer.rb', line 356 def base_number @position+1 end |
#reverse! ⇒ Object
The reference sequence has been reverse complemented. Fix this variant so it makes sense again (position aside)
374 375 376 377 378 |
# File 'lib/assembly/contig_printer.rb', line 374 def reverse! if type == SWAP or type == INSERT @sequence = Bio::Sequence::NA.new(@sequence).reverse_complement.to_s.upcase end end |
#to_shorthand ⇒ Object
360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/assembly/contig_printer.rb', line 360 def to_shorthand if type == DELETION "#{base_number}D:#{deletion_length}" elsif type == SWAP "#{base_number}S:#{sequence.upcase}" elsif type == INSERT "#{base_number}I:#{sequence.upcase}" else raise end end |
#vcf(reference_sequence) ⇒ Object
407 408 409 |
# File 'lib/assembly/contig_printer.rb', line 407 def vcf(reference_sequence) vcf_array(reference_sequence).join("\t") end |
#vcf_array(reference_sequence) ⇒ Object
CHROM POS ID REF ALT QUAL FILTER INFO
381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/assembly/contig_printer.rb', line 381 def vcf_array(reference_sequence) bits = [ @reference_name, @position+1, '.', ] case type when SWAP then bits.push reference_sequence[@position...(@position+@sequence.length) ] bits.push @sequence when INSERT then bits.push '.' bits.push @sequence when DELETION then bits.push reference_sequence[@position...(@position+@deletion_length) ] bits.push '.' else raise end bits.push '20' bits.push 'PASS' bits.push 'finishm' return bits end |