Class: Bio::Velvet::Graph::Node

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/bio-velvet/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#log

Instance Attribute Details

#coveragesObject

Returns the value of attribute coverages.



379
380
381
# File 'lib/bio-velvet/graph.rb', line 379

def coverages
  @coverages
end

#ends_of_kmers_of_nodeObject

Returns the value of attribute ends_of_kmers_of_node.



379
380
381
# File 'lib/bio-velvet/graph.rb', line 379

def ends_of_kmers_of_node
  @ends_of_kmers_of_node
end

#ends_of_kmers_of_twin_nodeObject

Returns the value of attribute ends_of_kmers_of_twin_node.



379
380
381
# File 'lib/bio-velvet/graph.rb', line 379

def ends_of_kmers_of_twin_node
  @ends_of_kmers_of_twin_node
end

#lengthObject

Number of nucleotides in this node if a contig was made from this contig alone



390
391
392
# File 'lib/bio-velvet/graph.rb', line 390

def length
  @length
end

#node_idObject

Returns the value of attribute node_id.



379
380
381
# File 'lib/bio-velvet/graph.rb', line 379

def node_id
  @node_id
end

#number_of_short_readsObject

For read tracking



382
383
384
# File 'lib/bio-velvet/graph.rb', line 382

def number_of_short_reads
  @number_of_short_reads
end

#parent_graphObject

Graph to which this node belongs



387
388
389
# File 'lib/bio-velvet/graph.rb', line 387

def parent_graph
  @parent_graph
end

#short_readsObject

For read tracking - an array of NodedRead objects



384
385
386
# File 'lib/bio-velvet/graph.rb', line 384

def short_reads
  @short_reads
end

Instance Method Details

#corresponding_contig_lengthObject

The common length of [ends_of_kmers_of_node and :ends_of_kmers_of_twin_node] is equal to the length of the corresponding contig minus k − 1.

This method returns that corresponding contig’s length



424
425
426
# File 'lib/bio-velvet/graph.rb', line 424

def corresponding_contig_length
  @ends_of_kmers_of_node.length+@parent_graph.hash_length-1
end

#coverageObject

Return the sum of all coverage columns, divided by the length of the node, or nil if this node has no coverage



459
460
461
462
463
464
465
466
467
468
# File 'lib/bio-velvet/graph.rb', line 459

def coverage
  return nil if length == 0

  coverage = 0
  coverages.each_with_index do |cov, i|
    # Only take the 0th, 2nd, 4th, etc, don't want the O_cov things
    coverage += cov if i.modulo(2) == 0
  end
  return coverage.to_f / length
end

#inspectObject



453
454
455
# File 'lib/bio-velvet/graph.rb', line 453

def inspect
  to_s
end

#length_aloneObject

Number of nucleotides in this node if this contig length is being added to another node’s length (nodes overlap)



416
417
418
# File 'lib/bio-velvet/graph.rb', line 416

def length_alone
  @ends_of_kmers_of_node.length
end

#reverse_sequenceObject

The reverse complement of this node’s sequence



439
440
441
# File 'lib/bio-velvet/graph.rb', line 439

def reverse_sequence
  revcom(sequence)
end

#sequenceObject

The sequence of this node, should a contig be made solely out of this node. The kmer length is that kmer length that was used to create the assembly.

If this node has a sequence that is 2 or more less than the hash length, then the sequence of this node requires information outside of this object, and gathering that information is not implemented here.



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'lib/bio-velvet/graph.rb', line 398

def sequence
  if !sequence?
    raise NotImplementedException, "Attempted to get the sequence of a velvet node that is too short, such that the sequence info is not fully present in the node object"
  end
  kmer_length = @parent_graph.hash_length

   # Sequence is the reverse complement of the ends_of_kmers_of_twin_node,
   # Then the ends_of_kmers_of_node after removing the first kmer_length - 1
   # nucleotides
   length_to_get_from_fwd = corresponding_contig_length - @ends_of_kmers_of_twin_node.length
   fwd_length = @ends_of_kmers_of_node.length
   raise "Programming error" if length_to_get_from_fwd > fwd_length
   revcom(@ends_of_kmers_of_twin_node)+
     @ends_of_kmers_of_node[-length_to_get_from_fwd...fwd_length]
end

#sequence?Boolean

Is it possible to extract the sequence of this node? I.e. is it long enough?

Returns:

  • (Boolean)


429
430
431
432
433
434
435
436
# File 'lib/bio-velvet/graph.rb', line 429

def sequence?
  kmer_length = @parent_graph.hash_length
  if kmer_length -1 > @ends_of_kmers_of_node.length
    return false
  else
    return true
  end
end

#to_sObject



443
444
445
446
447
448
449
450
451
# File 'lib/bio-velvet/graph.rb', line 443

def to_s
  fwd = @ends_of_kmers_of_node
  rev = @ends_of_kmers_of_twin_node
  if @ends_of_kmers_of_node.length > 10
    fwd = @ends_of_kmers_of_node[0...10]+'..'
    rev = @ends_of_kmers_of_twin_node[0...10]+'..'
  end
  "Node from #{@parent_graph.class}: #{@node_id}: #{fwd} / #{rev}"
end