Module: RGFATools::Multiplication
- Included in:
- RGFATools
- Defined in:
- lib/rgfatools/multiplication.rb
Overview
Methods which edit the graph components without traversal
Constant Summary collapse
- LINKS_DISTRIBUTION_POLICY =
Allowed values for the links_distribution_policy option
[:off, :auto, :equal, :E, :B]
Instance Method Summary collapse
-
#multiply_extended(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) ⇒ RGFA
Create multiple copies of a segment.
-
#multiply(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) ⇒ RGFA
Create multiple copies of a segment.
Instance Method Details
#multiply_extended(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) ⇒ RGFA
Create multiple copies of a segment.
Complements the multiply method of gfatools with additional functionality. To always run the additional functionality when multiply is called, use RGFA#enable_extensions.
Automatic computation of the copy names:
-
First, itis checked if the name of the original segment ends with a relevant string, i.e. a lower case letter (for
:lowcase
), an upper case letter (for:upcase
), a digit (for:number
), or the string “_copy” plus one or more optional digits (for:copy
). -
If so, it is assumed, it was already a copy, and it is not altered.
-
If not, then
a
(for:lowcase
),A
(for:upcase
),1
(for:number
),_copy
(for:copy
) is appended to the string. -
Then, in all cases, next (*) is called on the string, until a valid, non-existant name is found for each of the segment copies
-
(*) = except for
:copy
, where for the first copy no digit is present, but for the following is, i.e. the segment names will be:copy
,:copy2
,:copy3
, etc. -
Can be overridden, by providing an array of copy names.
Links distribution policy
Depending on the value of the option distribute
, an end is eventually selected for distribution of the links.
-
:off
: no distribution performed -
:E
: links of the E end are distributed -
:B
: links of the B end are distributed -
:equal
: select an end for which the number of links is equal tofactor
, if any; if both, then the E end is selected -
:auto
: automatically select E or B, trying to maximize the number of links which can be deleted
105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/rgfatools/multiplication.rb', line 105 def multiply_extended(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) s, sn = segment_and_segment_name(segment) s.set(origin_tag, sn) if !s.get(origin_tag) copy_names = compute_copy_names(copy_names, sn, factor) multiply_without_rgfatools(sn, factor, copy_names: copy_names, conserve_components: conserve_components) distribute_links(distribute, sn, copy_names, factor) return self end |
#multiply(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) ⇒ RGFA
Create multiple copies of a segment.
Complements the multiply method of gfatools with additional functionality. These extensions are used only after #enable_extensions is called on the RGFA object. After that, you may still call the original method using #multiply_without_rgfatools.
For more information on the additional functionality, see #multiply_extended.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rgfatools/multiplication.rb', line 21 def multiply_with_rgfatools(segment, factor, copy_names: :lowcase, distribute: :auto, conserve_components: true, origin_tag: :or) if !@extensions_enabled return multiply_without_rgfatools(segment, factor, copy_names: copy_names, conserve_components: conserve_components) else multiply_extended(segment, factor, copy_names: copy_names, distribute: distribute, conserve_components: conserve_components, origin_tag: origin_tag) end end |