class Bio::Velvet::Graph::Node

Attributes

coverages[RW]
ends_of_kmers_of_node[RW]
ends_of_kmers_of_twin_node[RW]
length[RW]

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

node_id[RW]
number_of_short_reads[RW]

For read tracking

parent_graph[RW]

Graph to which this node belongs

short_reads[RW]

For read tracking - an array of NodedRead objects

Public Instance Methods

corresponding_contig_length() click to toggle source

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

# File lib/bio-velvet/graph.rb, line 434
def corresponding_contig_length
  @ends_of_kmers_of_node.length+@parent_graph.hash_length-1
end
coverage() click to toggle source

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

# File lib/bio-velvet/graph.rb, line 469
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
inspect() click to toggle source
# File lib/bio-velvet/graph.rb, line 463
def inspect
  to_s
end
length_alone() click to toggle source

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

# File lib/bio-velvet/graph.rb, line 426
def length_alone
  @ends_of_kmers_of_node.length
end
reverse_sequence() click to toggle source

The reverse complement of this node’s sequence

# File lib/bio-velvet/graph.rb, line 449
def reverse_sequence
  revcom(sequence)
end
sequence() click to toggle source

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.

# File lib/bio-velvet/graph.rb, line 408
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?() click to toggle source

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

# File lib/bio-velvet/graph.rb, line 439
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_s() click to toggle source
# File lib/bio-velvet/graph.rb, line 453
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

Private Instance Methods

revcom(seq) click to toggle source
# File lib/bio-velvet/graph.rb, line 481
def revcom(seq)
  Bio::Sequence::NA.new(seq).reverse_complement.to_s.upcase
end