class Status

Class containing methods to records demultiplexing status.

Attributes

count[RW]
index1_bad_mean[RW]
index1_bad_min[RW]
index2_bad_mean[RW]
index2_bad_min[RW]
match[RW]
undetermined[RW]

Public Class Methods

new(samples) click to toggle source

Internal: Constructor method to initialize a Status object, which contains the following instance variables initialized to 0:

@count           - Number or reads.
@match           - Number of reads found in index.
@undetermined    - Number of reads not found in index.
@index1_bad_mean - Number of reads dropped due to bad mean in index1.
@index2_bad_mean - Number of reads dropped due to bad mean in index2.
@index1_bad_min  - Number of reads dropped due to bad min in index1.
@index2_bad_min  - Number of reads dropped due to bad min in index2.

samples - Array of Sample objects.

Examples

Status.new(samples)
# => <Status>

Returns a Status object.

# File lib/status.rb, line 47
def initialize(samples)
  @samples         = samples
  @count           = 0
  @match           = 0
  @undetermined    = 0
  @index1_bad_mean = 0
  @index2_bad_mean = 0
  @index1_bad_min  = 0
  @index2_bad_min  = 0
  @time_start      = Time.now
end

Public Instance Methods

save(file) click to toggle source

Internal: Method to save stats to the log file ‘Demultiplex.log’ in the output directory.

Returns nothing.

# File lib/status.rb, line 83
def save(file)
  File.open(file, 'w') do |ios|
    ios.puts self
  end
end
to_s() click to toggle source

Internal: Method to format a String from a Status object. This is done by adding the relevant instance variables to a Hash and return this as an YAML String.

Returns a YAML String.

# File lib/status.rb, line 64
def to_s
  { count:                @count,
    match:                @match,
    undetermined:         @undetermined,
    undetermined_percent: undetermined_percent,
    index1_bad_mean:      @index1_bad_mean,
    index2_bad_mean:      @index2_bad_mean,
    index1_bad_min:       @index1_bad_min,
    index2_bad_min:       @index2_bad_min,
    sample_ids:           @samples.map(&:id),
    index1:               uniq_index1,
    index2:               uniq_index2,
    time_elapsed:         time_elapsed }.to_yaml
end

Private Instance Methods

time_elapsed() click to toggle source

Internal: Method that calculates the elapsed time and formats a nice Time String.

Returns String with elapsed time.

# File lib/status.rb, line 104
def time_elapsed
  time_elapsed = Time.now - @time_start
  (Time.mktime(0) + time_elapsed).strftime('%H:%M:%S')
end
undetermined_percent() click to toggle source

Internal: Method that calculate the percentage of undetermined reads.

Returns a Float with the percentage of undetermined reads.

# File lib/status.rb, line 94
def undetermined_percent
  return 0.0 if @count == 0

  (100 * @undetermined / @count.to_f).round(1)
end
uniq_index1() click to toggle source

Internal: Method that iterates over @samples and compiles a sorted Array with all unique index1 sequences.

Returns Array with uniq index1 sequences.

# File lib/status.rb, line 113
def uniq_index1
  @samples.each_with_object(SortedSet.new) do |e, a|
    a << e.index1
  end.to_a
end
uniq_index2() click to toggle source

Internal: Method that iterates over @samples and compiles a sorted Array with all unique index2 sequences.

Returns Array with uniq index2 sequences.

# File lib/status.rb, line 123
def uniq_index2
  @samples.each_with_object(SortedSet.new) do |e, a|
    a << e.index2
  end.to_a
end