Module: RGFATools::Multiplication

Included in:
Defined in:


Methods which edit the graph components without traversal

Constant Summary collapse

[:off, :auto, :equal, :E, :B]

Instance Method Summary collapse

Instance Method Details

#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. To call the original method use #multiply_without_rgfatools.

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 to factor, 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


  • factor (Integer)

    multiplication factor; if 0, delete the segment; if 1; do nothing; if > 1; number of copies to create

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

    segment name or instance

  • copy_names (:lowcase, :upcase, :number, :copy, Array<String>) (defaults to: :lowcase)

    (Defaults to: :lowcase) Array of names for the copies of the segment, or a symbol, which defines a system to compute the names from the name of the original segment. See “Automatic computation of the copy names”.

  • conserve_components (Boolean) (defaults to: true)

    (Defaults to: true) If factor == 0 (i.e. deletion), delete segment only if #cut_segment?(segment) is false (see RGFA API).

  • distribute (defaults to: :auto)

    (Defaults to: :auto) Determines if and for which end of the segment, links are distributed among the copies. See “Links distribution policy”.

  • origin_tag (Symbol) (defaults to: :or)

    (Defaults to: :or) Name of the custom tag to use for storing origin information.


# File 'lib/rgfatools/multiplication.rb', line 80

def multiply_with_rgfatools(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

#multiply_without_rgfatools(segment, factor, copy_names: :lowcase, conserve_components: true) ⇒ RGFA

Original multiply method of RGFA. See the RGFA API documentation for detail.


# File 'lib/rgfatools/multiplication.rb', line 9