Module: RGFA::Links

Included in:
RGFA
Defined in:
lib/rgfa/links.rb

Overview

Methods for the RGFA class, which allow to handle links in the graph.

Instance Method Summary collapse

Instance Method Details

Deletes a link and all paths depending on it

Parameters:

Returns:



43
44
45
46
47
48
# File 'lib/rgfa/links.rb', line 43

def delete_link(l)
  @links.delete(l)
  segment(l.from).links[:from][l.from_orient].delete(l)
  segment(l.to).links[:to][l.to_orient].delete(l)
  l.paths.each {|pt, orient| delete_path(pt)}
end

Remove all links of a segment end end except that to the other specified segment end.

Parameters:

  • segment_end (RGFA::SegmentEnd)

    the segment end

  • other_end (RGFA::SegmentEnd)

    the other segment end

  • conserve_components (Boolean) (defaults to: false)

    (defaults to: false) Do not remove links if removing them breaks the graph into unconnected components.

Returns:



58
59
60
61
62
63
64
65
66
67
# File 'lib/rgfa/links.rb', line 58

def delete_other_links(segment_end, other_end, conserve_components: false)
  other_end = other_end.to_segment_end
  links_of(segment_end).each do |l|
    if l.other_end(segment_end) != other_end
      if !conserve_components or !cut_link?(l)
        delete_link(l)
      end
    end
  end
end

Searches a link between segment_end1 and segment_end2

Parameters:

Returns:



122
123
124
125
126
127
128
129
# File 'lib/rgfa/links.rb', line 122

def link(segment_end1, segment_end2)
  segment_end1 = segment_end1.to_segment_end
  segment_end2 = segment_end2.to_segment_end
  links_of(segment_end1).each do |l|
    return l if l.other_end(segment_end1) == segment_end2
  end
  return nil
end

#link!(segment_end1, segment_end2) ⇒ RGFA::Line::Link

Searches a link between segment_end1 and segment_end2

Parameters:

Returns:

Raises:



133
134
135
136
137
138
139
140
# File 'lib/rgfa/links.rb', line 133

def link!(segment_end1, segment_end2)
  l = link(segment_end1, segment_end2)
  raise RGFA::LineMissingError,
    "No link was found: "+
        "#{segment_end1.to_s} -- "+
        "#{segment_end2.to_s}" if l.nil?
  l
end

Search the link from a segment S1 in a given orientation to another segment S2 in a given, or the equivalent link from S2 to S1 with inverted orientations.

Parameters:

  • oriented_segment1 (RGFA::OrientedSegment)

    a segment with orientation

  • oriented_segment2 (RGFA::OrientedSegment)

    a segment with orientation

  • cigar (RGFA::CIGAR) (defaults to: [])

    shall match if not empty/undef

  • equivalent (Boolean) (defaults to: true)

    return also equivalent links.

Returns:



210
211
212
213
214
215
216
217
218
219
# File 'lib/rgfa/links.rb', line 210

def link_from_to(oriented_segment1, oriented_segment2,
                 cigar = [], equivalent = true)
  oriented_segment1 = oriented_segment1.to_oriented_segment
  oriented_segment2 = oriented_segment2.to_oriented_segment
  links_from(oriented_segment1, equivalent).select do |l|
    return l if l.compatible?(oriented_segment1, oriented_segment2,
                              cigar, equivalent)
  end
  return nil
end

Search the link from a segment S1 in a given orientation to another segment S2 in a given, or the equivalent link from S2 to S1 with inverted orientations.

Parameters:

  • oriented_segment1 (RGFA::OrientedSegment)

    a segment with orientation

  • oriented_segment2 (RGFA::OrientedSegment)

    a segment with orientation

  • cigar (RGFA::CIGAR) (defaults to: [])

    shall match if not empty/undef

  • equivalent (Boolean) (defaults to: true)

    return also equivalent links.

Returns:

Raises:



231
232
233
234
235
236
237
238
239
240
# File 'lib/rgfa/links.rb', line 231

def link_from_to!(oriented_segment1, oriented_segment2,
                  cigar = [], equivalent = true)
  l = link_from_to(oriented_segment1, oriented_segment2,
                   cigar, equivalent)
  raise RGFA::LineMissingError,
    "No link was found: "+
        "#{oriented_segment1.join(":")} -> "+
        "#{oriented_segment2.join(":")}" if l.nil?
  l
end

All links of the graph

Returns:



71
72
73
# File 'lib/rgfa/links.rb', line 71

def links
  @links
end

Searches all links between segment_end1 and segment_end2

Parameters:

Returns:



109
110
111
112
113
114
115
# File 'lib/rgfa/links.rb', line 109

def links_between(segment_end1, segment_end2)
  segment_end1 = segment_end1.to_segment_end
  segment_end2 = segment_end2.to_segment_end
  links_of(segment_end1).select do |l|
    l.other_end(segment_end1) == segment_end2
  end
end
Note:

to add or remove links, use the appropriate methods; adding or removing links from the returned array will not work

Find links from the segment in the specified orientation (or the equivalent links, i.e. to the segment in opposite orientation).

Parameters:

  • oriented_segment (RGFA::OrientedSegment)

    a segment with orientation

  • equivalent (Boolean) (defaults to: true)

    return also equivalent links.

Returns:



150
151
152
153
154
155
156
157
158
159
# File 'lib/rgfa/links.rb', line 150

def links_from(oriented_segment, equivalent = true)
  oriented_segment = oriented_segment.to_oriented_segment
  s = segment!(oriented_segment.segment)
  retval = s.links[:from][oriented_segment.orient]
  if equivalent
    retval + s.links[:to][oriented_segment.orient_inverted]
  else
    retval
  end
end
Note:

to add or remove links, use the appropriate methods; adding or removing links from the returned array will not work

Search all links from a segment S1 in a given orientation to another segment S2 in a given, or the equivalent links from S2 to S1 with inverted orientations.

Parameters:

  • oriented_segment1 (RGFA::OrientedSegment)

    a segment with orientation

  • oriented_segment2 (RGFA::OrientedSegment)

    a segment with orientation

  • cigar (RGFA::CIGAR) (defaults to: [])

    shall match if not empty/undef

  • equivalent (Boolean) (defaults to: true)

    return also equivalent links.

Returns:



191
192
193
194
195
196
197
198
# File 'lib/rgfa/links.rb', line 191

def links_from_to(oriented_segment1, oriented_segment2,
                  cigar = [], equivalent = true)
  oriented_segment1 = oriented_segment1.to_oriented_segment
  oriented_segment2 = oriented_segment2.to_oriented_segment
  links_from(oriented_segment1, equivalent).select do |l|
    l.compatible?(oriented_segment1, oriented_segment2, cigar, equivalent)
  end
end
Note:

to add or remove links, use the appropriate methods; adding or removing links from the returned array will not work

Finds links of the specified end of segment.

Parameters:

Returns:



86
87
88
89
90
91
# File 'lib/rgfa/links.rb', line 86

def links_of(segment_end)
  segment_end = segment_end.to_segment_end
  s = segment!(segment_end.segment)
  o = segment_end.end_type == :E ? [:+,:-] : [:-,:+]
  s.links[:from][o[0]] + s.links[:to][o[1]]
end
Note:

to add or remove links, use the appropriate methods; adding or removing links from the returned array will not work

Find links to the segment in the specified orientation (or the equivalent links, i.e. from the segment in opposite orientation).

Parameters:

  • oriented_segment (RGFA::OrientedSegment)

    a segment with orientation

  • equivalent (Boolean) (defaults to: true)

    return also equivalent links.

Returns:



169
170
171
172
173
174
175
176
177
178
# File 'lib/rgfa/links.rb', line 169

def links_to(oriented_segment, equivalent = true)
  oriented_segment = oriented_segment.to_oriented_segment
  s = segment!(oriented_segment.segment)
  retval = s.links[:to][oriented_segment.orient]
  if equivalent
    retval + s.links[:from][oriented_segment.orient_inverted]
  else
    retval
  end
end

#neighbours(segment_end) ⇒ Array<RGFA::SegmentEnd>

Finds segment ends connected to the specified segment end.

Parameters:

Returns:



99
100
101
# File 'lib/rgfa/links.rb', line 99

def neighbours(segment_end)
  links_of(segment_end).map {|l| l.other_end(segment_end) }
end