Class: SampleReader
- Inherits:
-
Object
- Object
- SampleReader
- Defined in:
- lib/sample_reader.rb
Overview
Class containing methods for reading and checking sample information.
Defined Under Namespace
Classes: Sample
Class Method Summary collapse
-
.read(file, revcomp1, revcomp2) ⇒ Object
Internal: Class method that reads sample information from a samples file, which consists of ASCII text in three tab separated columns: The first column is the sample_id, the second column is index1 and the third column is index2.
Instance Method Summary collapse
-
#initialize(revcomp1, revcomp2) ⇒ SampleReader
constructor
Internal: Constructor method for SampleReader object.
-
#samples_parse(file) ⇒ Object
Internal: Method that reads sample information from a samples file, which consists of ASCII text in three tab separated columns: The first column is the sample_id, the second column is index1 and the third column is index2.
Constructor Details
#initialize(revcomp1, revcomp2) ⇒ SampleReader
Internal: Constructor method for SampleReader object. The given revcomp1 and revcomp2 flags are stored as instance variables.
revcomp1 - Flag indicating that index1 should be reverse-complemented. revcomp2 - Flag indicating that index2 should be reverse-complemented.
Examples
SampleReader.new(false, false)
# => <SampleReader>
Returns SampleReader object.
68 69 70 71 |
# File 'lib/sample_reader.rb', line 68 def initialize(revcomp1, revcomp2) @revcomp1 = revcomp1 @revcomp2 = revcomp2 end |
Class Method Details
.read(file, revcomp1, revcomp2) ⇒ Object
Internal: Class method that reads sample information from a samples file, which consists of ASCII text in three tab separated columns: The first column is the sample_id, the second column is index1 and the third column is index2.
If revcomp1 or revcomp2 is set then index1 and index2 are reverse-complemented accordingly.
file - String with path to sample file. revcomp1 - Flag indicating that index1 should be reverse-complemented. revcomp2 - Flag indicating that index2 should be reverse-complemented.
Examples
SampleReader.read("samples.txt", false, false)
# => [<Sample>, <Sample>, <Sample> ...]
Returns an Array of Sample objects.
51 52 53 54 |
# File 'lib/sample_reader.rb', line 51 def self.read(file, revcomp1, revcomp2) sample_reader = new(revcomp1, revcomp2) sample_reader.samples_parse(file) end |
Instance Method Details
#samples_parse(file) ⇒ Object
Internal: Method that reads sample information from a samples file, which consists of ASCII text in three tab separated columns: The first column is the sample_id, the second column is index1 and the third column is index2.
file - String with path to sample file.
Examples
samples_parse("samples.txt")
# => [<Sample>, <Sample>, <Sample> ...]
Returns an Array of Sample objects.
85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/sample_reader.rb', line 85 def samples_parse(file) samples = samples_read(file) samples_reverse_complement(samples) errors = [] errors.push(*samples_check_index_combo(samples)) errors.push(*samples_check_uniq_id(samples)) unless errors.empty? warn errors fail SampleReaderError, 'errors found in sample file.' end samples end |