module RGFA::RGL
Conversion to RGL
graphs
Public Class Methods
included(base)
click to toggle source
# File lib/rgfa/rgl.rb, line 83 def self.included(base) base.extend(ClassMethods) end
Public Instance Methods
to_rgl(oriented: true)
click to toggle source
Creates an RGL
graph.
@param oriented [Boolean] (defaults to: true
) may the graph
contain links of segments in different orientation?
@return [RGL::ImplicitGraph] an rgl implicit directed graph
# File lib/rgfa/rgl.rb, line 16 def to_rgl(oriented: true) if oriented to_rgl_oriented else to_rgl_unoriented end end
to_rgl_oriented()
click to toggle source
Creates an RGL
graph, including links orientations.
@return [RGL::ImplicitGraph] an rgl implicit directed graph;
where vertices are [RGFA::Segment, orientation] pairs (instances of the RGFA::OrientedSegment subclass of Array)
# File lib/rgfa/rgl.rb, line 29 def to_rgl_oriented RGL::ImplicitGraph.new do |g| g.vertex_iterator do |block| self.each_segment do |segment| [:+, :-].each do |orient| block.call([segment, orient].to_oriented_segment) end end end g.adjacent_iterator do |oriented_segment, block| s = segment(oriented_segment.segment) o = oriented_segment.orient s.links[:from][o].each do |l| os = [segment(l.to), l.to_orient].to_oriented_segment block.call(os) end o = oriented_segment.invert_orient s.links[:to][o].each do |l| os = [segment(l.from), l.from_orient].to_oriented_segment block.call(os.invert_orient) end end g.directed = true end end
to_rgl_unoriented()
click to toggle source
Creates an RGL
graph, assuming that all links orientations are “+”.
@raise [RGFA::RGL::ValueError] if the graph contains any link where
from_orient or to_orient is :-
@return [RGL::ImplicitGraph] an rgl implicit directed graph;
where vertices are RGFA::Segment objects
# File lib/rgfa/rgl.rb, line 62 def to_rgl_unoriented RGL::ImplicitGraph.new do |g| g.vertex_iterator {|block| self.each_segment {|s| block.call(s)}} g.adjacent_iterator do |s, bl| s = segment(s) s.links[:from][:+].each do |l| if l.to_orient == :- raise RGFA::RGL::ValueError, "Graph contains links with segments in reverse orientations" end bl.call(segment(l.to)) end if s.links[:from][:-].size > 0 raise RGFA::RGL::ValueError, "Graph contains links with segments in reverse orientations" end end g.directed = true end end