Class: Demultiplexer

Inherits:
Object
  • Object
show all
Defined in:
lib/demultiplexer.rb,
lib/demultiplexer/version.rb

Overview

Adding VERSION constant to class.

Constant Summary collapse

DEFAULT =
{ verbose:        false,
  mismatches_max: 0,
  revcomp_index1: false,
  revcomp_index2: false,
  scores_min:     16,
  scores_mean:    16
}
VERSION =
'0.1.2'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fastq_files, options) ⇒ Demultiplexer

Internal: Constructor method for Demultiplexer object.

fastq_files - Array with paths to FASTQ files. options - Options Hash.

:verbose        - Verbose flag (default: false).
:mismatches_max - Integer value indicating max mismatches
                  (default: 0).
:samples_file   - String with path to samples file.
:revcomp_index1 - Flag indicating that index1 should be
                  reverse-complemented (default: false).
:revcomp_index2 - Flag indicating that index2 should be
                  reverse-complemented (default: false).
:output_dir     - String with output directory (optional).
:scores_min     - An Integer representing the Phred score
                  minimum, such that a reads is dropped if a
                  single position in the index contain a
                  score below this value (default: 16).
:scores_mean=>  - An Integer representing the mean Phread
                  score, such that a read is dropped if the
                  mean quality score is below this value
                  (default: 16).

Returns Demultiplexer object



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/demultiplexer.rb', line 104

def initialize(fastq_files, options)
  @options      = options
  @samples      = SampleReader.read(options[:samples_file],
                                    options[:revcomp_index1],
                                    options[:revcomp_index2])
  @undetermined = @samples.size
  @index_hash   = IndexBuilder.build(@samples, options[:mismatches_max])
  @data_io      = DataIO.new(@samples, fastq_files, options[:compress],
                             options[:output_dir])
  @status       = Status.new(@samples)
end

Instance Attribute Details

#statusObject (readonly)

Returns the value of attribute status.



40
41
42
# File 'lib/demultiplexer.rb', line 40

def status
  @status
end

Class Method Details

.run(fastq_files, options) ⇒ Object

Public: Class method to run demultiplexing of MiSeq sequences.

fastq_files - Array with paths to FASTQ files. options - Options Hash.

:verbose        - Verbose flag (default: false).
:mismatches_max - Integer value indicating max mismatches
                  (default: 0).
:samples_file   - String with path to samples file.
:revcomp_index1 - Flag indicating that index1 should be
                  reverse-complemented (default: false).
:revcomp_index2 - Flag indicating that index2 should be
                  reverse-complemented (default: false).
:output_dir     - String with output directory (optional).
:scores_min     - An Integer representing the Phred score
                  minimum, such that a reads is dropped if a
                  single position in the index contain a
                  score below this value (default: 16).
:scores_mean=>  - An Integer representing the mean Phread
                  score, such that a read is dropped if the
                  mean quality score is below this value
                  (default: 16).

Examples

Demultiplexer.run(['I1.fq', 'I2.fq', 'R1.fq', 'R2.fq'], \
  samples_file: 'samples.txt')
# => <Demultiplexer>

Returns Demultiplexer object



71
72
73
74
75
76
77
78
79
# File 'lib/demultiplexer.rb', line 71

def self.run(fastq_files, options)
  options       = DEFAULT.merge(options)
  log_file      = File.join(options[:output_dir], 'Demultiplex.log')
  demultiplexer = new(fastq_files, options)
  Screen.clear if options[:verbose]
  demultiplexer.demultiplex
  puts demultiplexer.status if options[:verbose]
  demultiplexer.status.save(log_file)
end

Instance Method Details

#demultiplexObject

Internal: Method to demultiplex reads according the index. This is done by simultaniously read-opening all input files (forward and reverse index files and forward and reverse read files) and read one entry from each. Such four entries we call a set of entries. If the quality scores from either index1 or index2 fails the criteria for mean and min required quality the set is skipped. In the combined indexes are found in the search index, then the reads are writting to files according to the sample information in the search index. If the combined indexes are not found, then the reads have their names appended with the index sequences and the reads are written to the Undertermined files.

Returns nothing.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/demultiplexer.rb', line 128

def demultiplex
  @data_io.open_input_files do |ios_in|
    @data_io.open_output_files do |ios_out|
      ios_in.each do |index1, index2, read1, read2|
        @status.count += 2
        puts(@status) if @options[:verbose] &&
                         (@status.count % 1_000) == 0

        next unless index_qual_ok?(index1, index2)

        match_index(ios_out, index1, index2, read1, read2)

        # break if @status.count == 100_000
      end
    end
  end
end