Module: RGFATools::CopyNumber

Included in:
RGFATools
Defined in:
lib/rgfatools/copy_number.rb

Overview

Methods which edit the graph components without traversal

Instance Method Summary collapse

Instance Method Details

#apply_copy_number(segment, count_tag: :cn, distribute: :auto, copy_names_suffix: :lowcase, origin_tag: :or, conserve_components: true) ⇒ RGFA

Applies the computed copy number to a segment

Parameters:

  • copy_names_suffix (:lowcase, :upcase, :number, :copy) (defaults to: :lowcase)

    (Defaults to: :lowcase) Symbol representing a system to compute the names from the name of the original segment. See “Automatic computation of the copy names” in #multiply_extended.

  • count_tag (Symbol) (defaults to: :cn)

    tag to use for storing the copy number (default: cn)

  • distribute (Symbol) (defaults to: :auto)

    distribution policy, see #multiply_extended

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

    tag to use for storing the origin (default: or)

  • conserve_components (Boolean) (defaults to: true)

    when factor is 0, do not remove segments if doing so increases the number of components in the graph (default: true)

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

    segment or segment name

Returns:



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/rgfatools/copy_number.rb', line 97

def apply_copy_number(segment, count_tag: :cn,
                      distribute: :auto,
                      copy_names_suffix: :lowcase, origin_tag: :or,
                      conserve_components: true)
  s, sn = segment_and_segment_name(segment)
  factor = s.get!(count_tag)
  multiply_extended(sn, factor,
           distribute: distribute,
           copy_names: copy_names_suffix,
           conserve_components: conserve_components,
           origin_tag: origin_tag)
  self
end

#apply_copy_numbers(count_tag: :cn, distribute: :auto, copy_names_suffix: :lowcase, origin_tag: :or, conserve_components: true) ⇒ RGFA

Applies the computed copy number to all segments

Parameters:

  • copy_names_suffix (:lowcase, :upcase, :number, :copy) (defaults to: :lowcase)

    (Defaults to: :lowcase) Symbol representing a system to compute the names from the name of the original segment. See “Automatic computation of the copy names” in #multiply_extended.

  • count_tag (Symbol) (defaults to: :cn)

    tag to use for storing the copy number (default: cn)

  • distribute (Symbol) (defaults to: :auto)

    distribution policy, see #multiply_extended

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

    tag to use for storing the origin (default: or)

  • conserve_components (Boolean) (defaults to: true)

    when factor is 0, do not remove segments if doing so increases the number of components in the graph (default: true)

Returns:



113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/rgfatools/copy_number.rb', line 113

def apply_copy_numbers(count_tag: :cn, distribute: :auto,
                       copy_names_suffix: :lowcase, origin_tag: :or,
                       conserve_components: true)
  segments.sort_by{|s|s.get!(count_tag)}.each do |s|
    multiply_extended(s.name, s.get(count_tag),
             distribute: distribute,
             copy_names: copy_names_suffix,
             conserve_components: conserve_components,
             origin_tag: origin_tag)
  end
  self
end

#compute_copy_numbers(single_copy_coverage, mincov: single_copy_coverage * 0.25, count_tag: , cn_tag: :cn, unit_length: ) ⇒ RGFA

Returns self.

Parameters:

  • mincov (Integer) (defaults to: single_copy_coverage * 0.25)

    (defaults to: 1/4 of single_copy_coverage) the minimum coverage, cn for segments under this value is set to 0

  • single_copy_coverage (Integer)

    the coverage that shall be considered to be single copy

  • cn_tag (Symbol) (defaults to: :cn)

    (defaults to: :cn) the tag to use for storing the copy number

  • count_tag (Symbol) (defaults to: )

    (defaults to: :RC or the value set by #set_default_count_tag) the count tag to use for coverage computation

  • unit_length (Integer) (defaults to: )

    (defaults to: 1 or the value set by #set_count_unit_length) the unit length to use for coverage computation

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/rgfatools/copy_number.rb', line 62

def compute_copy_numbers(single_copy_coverage,
                         mincov: single_copy_coverage * 0.25,
                         count_tag: @default[:count_tag],
                         cn_tag: :cn,
                         unit_length: @default[:unit_length])
  segments.each do |s|
    cov = s.coverage!(count_tag: count_tag, unit_length: unit_length).to_f
    if cov < mincov
      cn = 0
    elsif cov < single_copy_coverage
      cn = 1
    else
      cn = (cov / single_copy_coverage).round
    end
    s.set(cn_tag, cn)
  end
  self
end

#delete_low_coverage_segments(mincov, count_tag: , unit_length: ) ⇒ RGFA

Delete segments which have a coverage under a specified value.

Parameters:

  • mincov (Integer)

    the minimum coverage

  • count_tag (Symbol) (defaults to: )

    (defaults to: :RC or the value set by #set_default_count_tag) the count tag to use for coverage computation

  • unit_length (Integer) (defaults to: )

    (defaults to: 1 or the value set by #set_count_unit_length) the unit length to use for coverage computation

Returns:



40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rgfatools/copy_number.rb', line 40

def delete_low_coverage_segments(mincov,
                                 count_tag: @default[:count_tag],
                                 unit_length: @default[:unit_length])
  segments.map do |s|
    cov = s.coverage(count_tag: count_tag,
                     unit_length: unit_length)
    cov < mincov ? s.name : nil
  end.compact.each do |sn|
    delete_segment(sn)
  end
  self
end

#set_count_unit_length(unit_length) ⇒ RGFA

Sets the unit length (k-mer size, average read lenght or average fragment length) to use for coverage computation (defaults to: 1).

Parameters:

  • unit_length (Integer)

    the unit length to use

Returns:



22
23
24
25
# File 'lib/rgfatools/copy_number.rb', line 22

def set_count_unit_length(unit_length)
  @default[:unit_length] = unit_length
  return self
end

#set_default_count_tag(tag) ⇒ RGFA

Sets the count tag to use as default by coverage computations (defaults to: :RC).

Parameters:

  • tag (Symbol)

    the tag to use

Returns:



11
12
13
14
# File 'lib/rgfatools/copy_number.rb', line 11

def set_default_count_tag(tag)
  @default[:count_tag] = tag
  return self
end