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:

  • count_tag (Symbol)

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

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

    (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”.

Returns:


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

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(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:

  • count_tag (Symbol)

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

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

    (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”.

Returns:


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

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(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: @default[:count_tag], cn_tag: :cn, unit_length: @default[:unit_length]) ⇒ RGFA

Returns self

Parameters:

  • mincov (Integer)

    (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) the tag to use for storing the copy number

  • count_tag (Symbol)

    (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: 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: @default[:count_tag], unit_length: @default[:unit_length]) ⇒ RGFA

Delete segments which have a coverage under a specified value.

Parameters:

  • mincov (Integer)

    the minimum coverage

  • count_tag (Symbol)

    (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: 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