Class: DataIO
- Inherits:
-
Object
- Object
- DataIO
- Defined in:
- lib/data_io.rb
Overview
Class containing methods for reading and write FASTQ data files.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Internal: Getter method that returns a tuple of file handles from key - Sample index Integer key used for lookup.
-
#each ⇒ Object
Internal: Method that reads a Seq entry from each of the file handles in the @input_file_ios Array.
-
#initialize(samples, fastq_files, compress, output_dir) ⇒ DataIO
constructor
Internal: Constructor method for DataIO objects.
-
#open_input_files ⇒ Object
Internal: Method that opens the @input_files for reading.
-
#open_output_files ⇒ Object
Internal: Method that opens the output files for writing.
Constructor Details
#initialize(samples, fastq_files, compress, output_dir) ⇒ DataIO
Internal: Constructor method for DataIO objects.
samples - Array with Sample objects consisting id, index1 and index2 fastq_files - Array of Strings with FASTQ file names of multiplexed data. compress - Symbol indicating if output data should be compressed with
either gzip or bzip2.
output_dir - String with path of output directory.
Returns DataIO object.
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/data_io.rb', line 38 def initialize(samples, fastq_files, compress, output_dir) @samples = samples @compress = compress @output_dir = output_dir @suffix1 = extract_suffix(fastq_files, '_R1_') @suffix2 = extract_suffix(fastq_files, '_R2_') @input_files = identify_input_files(fastq_files) @undetermined = @samples.size @output_file_ios = nil end |
Instance Method Details
#[](key) ⇒ Object
Internal: Getter method that returns a tuple of file handles from key - Sample index Integer key used for lookup.
Returns Array with a tuple of IO objects.
107 108 109 |
# File 'lib/data_io.rb', line 107 def [](key) @output_file_ios[key] end |
#each ⇒ Object
Internal: Method that reads a Seq entry from each of the file handles in the @input_file_ios Array. Iteration stops when no more Seq entries are found.
Yields an Array with 4 Seq objects.
Returns nothing
89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/data_io.rb', line 89 def each loop do entries = @input_file_ios.each_with_object([]) do |e, a| a << e.next_entry end break if entries.compact.size != 4 yield entries end end |
#open_input_files ⇒ Object
Internal: Method that opens the @input_files for reading.
input_files - Array with input file paths.
Returns an Array with IO objects (file handles).
54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/data_io.rb', line 54 def open_input_files @input_file_ios = [] @input_files.each do |input_file| @input_file_ios << BioPieces::Fastq.open(input_file) end yield self ensure close_input_files end |
#open_output_files ⇒ Object
Internal: Method that opens the output files for writing.
Yields a Hash with an incrementing index as keys, and a tuple of file handles as values.
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/data_io.rb', line 70 def open_output_files @output_file_ios = {} comp = @compress @output_file_ios.merge!(open_output_files_samples(comp)) @output_file_ios.merge!(open_output_files_undet(comp)) yield self ensure close_output_files end |