Module: RGFATools::SuperfluousLinks

Included in:
RGFATools
Defined in:
lib/rgfatools/superfluous_links.rb

Overview

Methods which edit the graph components without traversal

Instance Method Summary collapse

Instance Method Details

Remove superfluous links in the presence of mandatory links in the entire graph

Parameters:

  • conserve_components (Boolean) (defaults to: true)

    (Defaults to: true) delete links only if #cut_link?(link) is false (see RGFA API).

Returns:



42
43
44
45
46
# File 'lib/rgfatools/superfluous_links.rb', line 42

def enforce_all_mandatory_links(conserve_components: true)
  segment_names.each {|sn| enforce_segment_mandatory_links(sn,
                             conserve_components: conserve_components)}
  self
end

Remove superfluous links in the presence of mandatory links for a single segment

Parameters:

  • segment (String, RGFA::Line::Segment)

    segment name or instance

  • conserve_components (Boolean) (defaults to: true)

    (Defaults to: true) delete links only if #cut_link?(link) is false (see RGFA API).

Returns:



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/rgfatools/superfluous_links.rb', line 13

def enforce_segment_mandatory_links(segment, conserve_components: true)
  sn = segment_and_segment_name(segment)[1]
  se = {}
  l = {}
  [:B, :E].each do |et|
    se[et] = [sn, et]
    l[et] = links_of(se[et])
  end
  cs = connectivity_symbols(l[:B].size, l[:E].size)
  if cs == [1, 1]
    oe = {}
    [:B, :E].each {|et| oe[et] = l[et][0].other_end(se[et])}
    return if oe[:B] == oe[:E]
    [:B, :E].each {|et| delete_other_links(oe[et], se[et],
                                  conserve_components: conserve_components)}
  else
    i = cs.index(1)
    return if i.nil?
    et = [:B, :E][i]
    oe = l[et][0].other_end(se[et])
    delete_other_links(oe, se[et], conserve_components: conserve_components)
  end
  self
end

Remove links of segment to itself

Parameters:

Returns:



51
52
53
54
55
# File 'lib/rgfatools/superfluous_links.rb', line 51

def remove_self_link(segment)
  segment_name = segment.kind_of?(RGFA::Line) ? segment.name : segment
  unconnect_segments(segment_name, segment_name)
  self
end

Remove all links of segments to themselves

Returns:



59
60
61
62
# File 'lib/rgfatools/superfluous_links.rb', line 59

def remove_self_links
  segment_names.each {|sn| remove_self_link(sn)}
  self
end