Class: Bio::AssemblyGraphAlgorithms::ContigPrinter::Variant

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(position = nil, sequence_or_deletion_length = nil, type = nil) ⇒ Variant

Returns a new instance of Variant.



329
330
331
332
333
334
335
336
337
# File 'lib/assembly/contig_printer.rb', line 329

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_lengthObject

length of deletion (or nil if not a deletion)



324
325
326
# File 'lib/assembly/contig_printer.rb', line 324

def deletion_length
  @deletion_length
end

#positionObject

0-based position on the contig



318
319
320
# File 'lib/assembly/contig_printer.rb', line 318

def position
  @position
end

#reference_nameObject

Returns the value of attribute reference_name.



315
316
317
# File 'lib/assembly/contig_printer.rb', line 315

def reference_name
  @reference_name
end

#sequenceObject

sequence (or nil if variant is a deletion)



321
322
323
# File 'lib/assembly/contig_printer.rb', line 321

def sequence
  @sequence
end

#typeObject

See constants in this class



327
328
329
# File 'lib/assembly/contig_printer.rb', line 327

def type
  @type
end

Instance Method Details

#base_numberObject



339
340
341
# File 'lib/assembly/contig_printer.rb', line 339

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)



357
358
359
360
361
# File 'lib/assembly/contig_printer.rb', line 357

def reverse!
  if type == SWAP or type == INSERT
    @sequence = Bio::Sequence::NA.new(@sequence).reverse_complement.to_s.upcase
  end
end

#to_shorthandObject



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/assembly/contig_printer.rb', line 343

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



390
391
392
# File 'lib/assembly/contig_printer.rb', line 390

def vcf(reference_sequence)
  vcf_array(reference_sequence).join("\t")
end

#vcf_array(reference_sequence) ⇒ Object

CHROM POS ID REF ALT QUAL FILTER INFO



364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
# File 'lib/assembly/contig_printer.rb', line 364

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