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
-
#delete_link(l) ⇒ RGFA
Deletes a link and all paths depending on it.
-
#delete_other_links(segment_end, other_end, conserve_components: false) ⇒ RGFA
Remove all links of a segment end end except that to the other specified segment end.
-
#link(segment_end1, segment_end2) ⇒ RGFA::Line::Link?
Searches a link between
segment_end1
andsegment_end2
. -
#link!(segment_end1, segment_end2) ⇒ RGFA::Line::Link
Searches a link between
segment_end1
andsegment_end2
. -
#link_from_to(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ RGFA::Line::Link?
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.
-
#link_from_to!(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ RGFA::Line::Link
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.
-
#links ⇒ Array<RGFA::Line::Link>
All links of the graph.
-
#links_between(segment_end1, segment_end2) ⇒ Array<RGFA::Line::Link>
Searches all links between
segment_end1
andsegment_end2
. -
#links_from(oriented_segment, equivalent = true) ⇒ Array<RGFA::Line::Link>
Find links from the segment in the specified orientation (or the equivalent links, i.e. to the segment in opposite orientation).
-
#links_from_to(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ Array<RGFA::Line::Link>
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.
-
#links_of(segment_end) ⇒ Array<RGFA::Line::Link>
Finds links of the specified end of segment.
-
#links_to(oriented_segment, equivalent = true) ⇒ Array<RGFA::Line::Link>
Find links to the segment in the specified orientation (or the equivalent links, i.e. from the segment in opposite orientation).
-
#neighbours(segment_end) ⇒ Array<RGFA::SegmentEnd>
Finds segment ends connected to the specified segment end.
Instance Method Details
#delete_link(l) ⇒ RGFA
Deletes a link and all paths depending on it
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 |
#delete_other_links(segment_end, other_end, conserve_components: false) ⇒ RGFA
Remove all links of a segment end end except that to the other specified segment end.
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 |
#link(segment_end1, segment_end2) ⇒ RGFA::Line::Link?
Searches a link between segment_end1
and segment_end2
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
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 |
#link_from_to(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ RGFA::Line::Link?
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.
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 |
#link_from_to!(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ RGFA::Line::Link
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.
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 |
#links ⇒ Array<RGFA::Line::Link>
All links of the graph
71 72 73 |
# File 'lib/rgfa/links.rb', line 71 def links @links end |
#links_between(segment_end1, segment_end2) ⇒ Array<RGFA::Line::Link>
Searches all links between segment_end1
and segment_end2
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 |
#links_from(oriented_segment, equivalent = true) ⇒ Array<RGFA::Line::Link>
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).
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 |
#links_from_to(oriented_segment1, oriented_segment2, cigar = [], equivalent = true) ⇒ Array<RGFA::Line::Link>
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.
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 |
#links_of(segment_end) ⇒ Array<RGFA::Line::Link>
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.
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 |
#links_to(oriented_segment, equivalent = true) ⇒ Array<RGFA::Line::Link>
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).
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.
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 |