Module: RGFA::LinearPaths
- Included in:
- RGFA
- Defined in:
- lib/rgfa/linear_paths.rb
Overview
Methods for the RGFA class, which allow to find and merge linear paths.
Instance Method Summary collapse
-
#linear_path(s, exclude = Set.new) ⇒ Array<RGFA::SegmentEnd>
Find a path without branches.
-
#linear_paths ⇒ Array<Array<RGFA::SegmentEnd>>
Find all unbranched paths in the graph.
-
#merge_linear_path(segpath, **options) ⇒ RGFA
Merge a linear path, i.e.
-
#merge_linear_paths(**options) ⇒ RGFA
Merge all linear paths in the graph, i.e.
Instance Method Details
#linear_path(s, exclude = Set.new) ⇒ Array<RGFA::SegmentEnd>
Find a path without branches.
The path must include segment
and excludes segments in exclude
. Any segment used in the returned path will be added to exclude
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/rgfa/linear_paths.rb', line 21 def linear_path(s, exclude = Set.new) s = s.to_sym cs = connectivity(s) segpath = RGFA::SegmentEndsPath.new() [:B, :E].each_with_index do |et, i| if cs[i] == 1 exclude << s segpath.pop segpath += traverse_linear_path(RGFA::SegmentEnd.new([s, et]), exclude) end end return (segpath.size < 2) ? nil : segpath end |
#linear_paths ⇒ Array<Array<RGFA::SegmentEnd>>
Find all unbranched paths in the graph.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rgfa/linear_paths.rb', line 38 def linear_paths exclude = Set.new retval = [] segnames = segment_names progress_log_init(:linear_paths, "segments", segnames.size, "Detect linear paths (#{segnames.size} segments)") if @progress segnames.each do |sn| progress_log(:linear_paths) if @progress next if exclude.include?(sn) retval << linear_path(sn, exclude) end progress_log_end(:linear_paths) return retval.compact end |
#merge_linear_path(segpath, **options) ⇒ RGFA
Merge a linear path, i.e. a path of segments without extra-branches Limitations: all containments und paths involving merged segments are deleted.
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/rgfa/linear_paths.rb', line 72 def merge_linear_path(segpath, **) return if segpath.size < 2 segpath.map!{|se|se.to_segment_end} if segpath[1..-2].any? {|sn,et| connectivity(sn) != [1,1]} raise ArgumentError, "The specified path is not linear" end merged, first_reversed, last_reversed = create_merged_segment(segpath, ) self << merged link_merged(merged.name, segpath.first.to_segment_end.invert_end_type, first_reversed) link_merged(merged.name, segpath.last, last_reversed) segpath.each do |sn_et| delete_segment(sn_et.segment) progress_log(:merge_linear_paths, 0.05) if @progress end self end |
#merge_linear_paths(**options) ⇒ RGFA
Merge all linear paths in the graph, i.e. paths of segments without extra-branches Limitations: all containments und paths involving merged segments are deleted.
97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rgfa/linear_paths.rb', line 97 def merge_linear_paths(**) paths = linear_paths psize = paths.flatten.size / 2 progress_log_init(:merge_linear_paths, "segments", psize, "Merge #{paths.size} linear paths (#{psize} segments)") if @progress paths.each do |path| merge_linear_path(path, **) end progress_log_end(:merge_linear_paths) self end |