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

Inherits:
Object
  • Object
show all
Defined in:
lib/bio-velvet_underground/graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph, node_struct) ⇒ Node

Returns a new instance of Node.



82
83
84
85
# File 'lib/bio-velvet_underground/graph.rb', line 82

def initialize(graph, node_struct)
  @graph = graph
  @internal_node_struct = node_struct
end

Instance Attribute Details

#internal_node_structObject

Returns the value of attribute internal_node_struct.



80
81
82
# File 'lib/bio-velvet_underground/graph.rb', line 80

def internal_node_struct
  @internal_node_struct
end

Instance Method Details

#coveragesObject



95
96
97
98
99
100
# File 'lib/bio-velvet_underground/graph.rb', line 95

def coverages
  [
    @internal_node_struct[:virtualCoverage1],
    @internal_node_struct[:virtualCoverage2],
    ]
end

#ends_of_kmers_of_nodeObject



102
103
104
105
106
107
108
109
110
111
# File 'lib/bio-velvet_underground/graph.rb', line 102

def ends_of_kmers_of_node
  return @ends_of_kmers_of_node unless @ends_of_kmers_of_node.nil?
  seq = []
  key = %w(A C G T)
  0.upto(length_alone-1) do |i|
    n = Bio::Velvet::Underground.getNucleotideInNode(@internal_node_struct, i)
    seq.push key[n]
  end
  @ends_of_kmers_of_node = seq.join
end

#ends_of_kmers_of_twin_nodeObject



113
114
115
# File 'lib/bio-velvet_underground/graph.rb', line 113

def ends_of_kmers_of_twin_node
  twin.ends_of_kmers_of_node
end

#fwd_short_readsObject



127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/bio-velvet_underground/graph.rb', line 127

def fwd_short_reads
  return @short_reads unless @short_reads.nil?
  array_start_pointer = Bio::Velvet::Underground.getNodeReads @internal_node_struct, @graph.internal_graph_struct
  num_short_reads = Bio::Velvet::Underground.getNodeReadCount @internal_node_struct, @graph.internal_graph_struct
  struct_size = Bio::Velvet::Underground::ShortReadMarker.size #calculate once for performance

  # Return a hash of read_id => short_read object
  @short_reads = Bio::Velvet::Graph::NodedReadArray.new
  0.step(num_short_reads-1, 1).each do |i|
    # Use the fact that FFI pointers can do pointer arithmetic
    pointer = array_start_pointer+(i*struct_size)
    @short_reads.push(NodedRead.new(Bio::Velvet::Underground::ShortReadMarker.new(pointer), true))
  end
  return @short_reads
end

#length_aloneObject



91
92
93
# File 'lib/bio-velvet_underground/graph.rb', line 91

def length_alone
  @length_alone ||= @internal_node_struct[:length]
end

#node_idObject



87
88
89
# File 'lib/bio-velvet_underground/graph.rb', line 87

def node_id
  @node_id ||= @internal_node_struct[:ID]
end

#rev_short_readsObject



143
144
145
# File 'lib/bio-velvet_underground/graph.rb', line 143

def rev_short_reads
  twin.fwd_short_reads
end

#short_readsObject



147
148
149
150
151
152
153
154
155
# File 'lib/bio-velvet_underground/graph.rb', line 147

def short_reads
  return @reads unless @reads.nil?
  @reads = fwd_short_reads
  rev_short_reads.each do |read|
    read.direction = false
    @reads.push read
  end
  return @reads
end

#twinObject



117
118
119
120
121
122
123
124
125
# File 'lib/bio-velvet_underground/graph.rb', line 117

def twin
  return @twin unless @twin.nil?

  twin_pointer = Bio::Velvet::Underground.getTwinNode(@internal_node_struct)
  @twin = Bio::Velvet::Underground::Graph::Node.new(
    @graph,
    Bio::Velvet::Underground::NodeStruct.new(twin_pointer)
    )
end