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.



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

def coverages
  @coverages
end

#ends_of_kmers_of_nodeObject

Returns the value of attribute ends_of_kmers_of_node.



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

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.



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

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



400
401
402
# File 'lib/bio-velvet/graph.rb', line 400

def length
  @length
end

#node_idObject

Returns the value of attribute node_id.



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

def node_id
  @node_id
end

#number_of_short_readsObject

For read tracking



392
393
394
# File 'lib/bio-velvet/graph.rb', line 392

def number_of_short_reads
  @number_of_short_reads
end

#parent_graphObject

Graph to which this node belongs



397
398
399
# File 'lib/bio-velvet/graph.rb', line 397

def parent_graph
  @parent_graph
end

#short_readsObject

For read tracking - an array of NodedRead objects



394
395
396
# File 'lib/bio-velvet/graph.rb', line 394

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



434
435
436
# File 'lib/bio-velvet/graph.rb', line 434

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



469
470
471
472
473
474
475
476
477
478
# 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

#inspectObject



463
464
465
# File 'lib/bio-velvet/graph.rb', line 463

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)



426
427
428
# File 'lib/bio-velvet/graph.rb', line 426

def length_alone
  @ends_of_kmers_of_node.length
end

#reverse_sequenceObject

The reverse complement of this node’s sequence



449
450
451
# File 'lib/bio-velvet/graph.rb', line 449

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.



408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# 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?Boolean

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

Returns:

  • (Boolean)


439
440
441
442
443
444
445
446
# 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_sObject



453
454
455
456
457
458
459
460
461
# 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