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.



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

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)



351
352
353
# File 'lib/assembly/contig_printer.rb', line 351

def deletion_length
  @deletion_length
end

#positionObject

0-based position on the contig



345
346
347
# File 'lib/assembly/contig_printer.rb', line 345

def position
  @position
end

#reference_nameObject

Returns the value of attribute reference_name.



342
343
344
# File 'lib/assembly/contig_printer.rb', line 342

def reference_name
  @reference_name
end

#sequenceObject

sequence (or nil if variant is a deletion)



348
349
350
# File 'lib/assembly/contig_printer.rb', line 348

def sequence
  @sequence
end

#typeObject

See constants in this class



354
355
356
# File 'lib/assembly/contig_printer.rb', line 354

def type
  @type
end

Instance Method Details

#base_numberObject



366
367
368
# File 'lib/assembly/contig_printer.rb', line 366

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)



384
385
386
387
388
# File 'lib/assembly/contig_printer.rb', line 384

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

#to_shorthandObject



370
371
372
373
374
375
376
377
378
379
380
# File 'lib/assembly/contig_printer.rb', line 370

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



417
418
419
# File 'lib/assembly/contig_printer.rb', line 417

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

#vcf_array(reference_sequence) ⇒ Object

CHROM POS ID REF ALT QUAL FILTER INFO



391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
# File 'lib/assembly/contig_printer.rb', line 391

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