demultiplexer 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Rakefile +6 -3
- data/bin/demultiplexer +67 -59
- data/demultiplexer.gemspec +12 -12
- data/lib/data_io.rb +132 -96
- data/lib/demultiplexer/version.rb +2 -1
- data/lib/demultiplexer.rb +34 -37
- data/lib/index_builder.rb +29 -33
- data/lib/sample_reader.rb +45 -23
- data/lib/status.rb +48 -21
- data/test/helper.rb +5 -0
- data/test/test_data_io.rb +158 -2
- data/test/test_demultiplexer.rb +206 -2
- data/test/test_index_builder.rb +57 -2
- data/test/test_sample_reader.rb +75 -2
- data/test/test_status.rb +56 -2
- metadata +3 -6
- data/test/test_screen.rb +0 -7
data/test/test_data_io.rb
CHANGED
@@ -1,7 +1,163 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
|
3
3
|
|
4
4
|
require 'test/helper'
|
5
5
|
|
6
|
-
|
6
|
+
# Class for testing the DataIO class.
|
7
|
+
class TestDataIO < Test::Unit::TestCase
|
8
|
+
SAMPLES = <<-DATA.gsub(/^\s+\|/, '')
|
9
|
+
|#ID\tIndex1\tIndex2
|
10
|
+
|sample1\tAT\tCG
|
11
|
+
DATA
|
12
|
+
|
13
|
+
FASTQ_INDEX1 = <<-DATA.gsub(/^\s+\|/, '')
|
14
|
+
|@index1
|
15
|
+
|at
|
16
|
+
|+
|
17
|
+
|II
|
18
|
+
DATA
|
19
|
+
|
20
|
+
FASTQ_INDEX2 = <<-DATA.gsub(/^\s+\|/, '')
|
21
|
+
|@index2
|
22
|
+
|ct
|
23
|
+
|+
|
24
|
+
|II
|
25
|
+
DATA
|
26
|
+
|
27
|
+
FASTQ_READ1 = <<-DATA.gsub(/^\s+\|/, '')
|
28
|
+
|@read1
|
29
|
+
|A
|
30
|
+
|+
|
31
|
+
|I
|
32
|
+
DATA
|
33
|
+
|
34
|
+
FASTQ_READ2 = <<-DATA.gsub(/^\s+\|/, '')
|
35
|
+
|@read2
|
36
|
+
|G
|
37
|
+
|+
|
38
|
+
|I
|
39
|
+
DATA
|
40
|
+
|
41
|
+
def setup
|
42
|
+
@tmp_input = Dir.mktmpdir('data_io_input')
|
43
|
+
@tmp_output = Dir.mktmpdir('data_io_input')
|
44
|
+
|
45
|
+
file_samples = File.join(@tmp_input, 'samples.txt')
|
46
|
+
file_index1 = File.join(@tmp_input, 'x_S1_L001_I1_001x.fq')
|
47
|
+
file_index2 = File.join(@tmp_input, 'x_S1_L001_I2_001x.fq')
|
48
|
+
file_read1 = File.join(@tmp_input, 'x_S1_L001_R1_001x.fq')
|
49
|
+
file_read2 = File.join(@tmp_input, 'x_S1_L001_R2_001x.fq')
|
50
|
+
|
51
|
+
File.open(file_samples, 'w') { |ios| ios.puts SAMPLES }
|
52
|
+
File.open(file_index1, 'w') { |ios| ios.puts FASTQ_INDEX1 }
|
53
|
+
File.open(file_index2, 'w') { |ios| ios.puts FASTQ_INDEX2 }
|
54
|
+
File.open(file_read1, 'w') { |ios| ios.puts FASTQ_READ1 }
|
55
|
+
File.open(file_read2, 'w') { |ios| ios.puts FASTQ_READ2 }
|
56
|
+
|
57
|
+
@samples = SampleReader.read(file_samples, false, false)
|
58
|
+
@fastq_files = [file_index1, file_index2, file_read1, file_read2]
|
59
|
+
end
|
60
|
+
|
61
|
+
def teardown
|
62
|
+
FileUtils.rm_rf(@tmp_input)
|
63
|
+
FileUtils.rm_rf(@tmp_output)
|
64
|
+
end
|
65
|
+
|
66
|
+
test 'DataIO#new with FASTQ files not matching _R1_ fails' do
|
67
|
+
fastq_files = %w(x_S1_L001_R2_001x)
|
68
|
+
|
69
|
+
assert_raise(DataIOError) do
|
70
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
test 'DataIO#new with FASTQ files not matching _R2_ fails' do
|
75
|
+
fastq_files = %w(x_S1_L001_R1_001x)
|
76
|
+
|
77
|
+
assert_raise(DataIOError) do
|
78
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
test 'DataIO#new with multiple FASTQ files matching _R1_ fails' do
|
83
|
+
fastq_files = %w(_R1_ _R1_ x_S1_L001_R2_001x)
|
84
|
+
|
85
|
+
assert_raise(DataIOError) do
|
86
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
test 'DataIO#new with multiple FASTQ files matching _R2_ fails' do
|
91
|
+
fastq_files = %w(_R2_ _R2_ x_S1_L001_R1_001x)
|
92
|
+
|
93
|
+
assert_raise(DataIOError) do
|
94
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
test 'DataIO#new with badly formatted SLR R1 string fails' do
|
99
|
+
fastq_files = %w(x_S1_XXXX_R1_001x x_S1_L001_R2_001x)
|
100
|
+
|
101
|
+
assert_raise(DataIOError) do
|
102
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'DataIO#new with badly formatted SLR R2 string fails' do
|
107
|
+
fastq_files = %w(x_S1_XXXX_R2_001x x_S1_L001_R1_001x)
|
108
|
+
|
109
|
+
assert_raise(DataIOError) do
|
110
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'DataIO#new with bad number of input files fails' do
|
115
|
+
fastq_files = %w(x_S1_L001_R1_001x
|
116
|
+
x_S1_L001_R2_001x)
|
117
|
+
|
118
|
+
assert_raise(DataIOError) do
|
119
|
+
DataIO.new(@samples, fastq_files, false, @tmp_output)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
test '#open_input_files returns readable file handles' do
|
124
|
+
data_io = DataIO.new(@samples, @fastq_files, false, @tmp_output)
|
125
|
+
|
126
|
+
data_io.open_input_files do |ios|
|
127
|
+
ios.each do |index1, index2, read1, read2|
|
128
|
+
assert_equal('at', index1.seq)
|
129
|
+
assert_equal('ct', index2.seq)
|
130
|
+
assert_equal('A', read1.seq)
|
131
|
+
assert_equal('G', read2.seq)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
test '#open_output_files returns writable file handles' do
|
137
|
+
data_io = DataIO.new(@samples, @fastq_files, false, @tmp_output)
|
138
|
+
|
139
|
+
data_io.open_output_files do |ios|
|
140
|
+
ios[0].first.puts 'foo 0'
|
141
|
+
ios[0].last.puts 'bar 0'
|
142
|
+
ios[1].first.puts 'foo 1'
|
143
|
+
ios[1].last.puts 'bar 1'
|
144
|
+
end
|
145
|
+
|
146
|
+
files = Dir["#{@tmp_output}/*"]
|
147
|
+
|
148
|
+
expected_names = ['sample1_S1_L001_R1_001.fastq',
|
149
|
+
'sample1_S1_L001_R2_001.fastq',
|
150
|
+
'Undetermined_S1_L001_R1_001.fastq',
|
151
|
+
'Undetermined_S1_L001_R2_001.fastq']
|
152
|
+
|
153
|
+
result_names = files.map { |file| File.basename(file) }
|
154
|
+
|
155
|
+
assert_equal(expected_names, result_names)
|
156
|
+
|
157
|
+
expected_content = files.each_with_object([]) { |e, a| a << File.read(e) }
|
158
|
+
|
159
|
+
result_content = ["foo 0\n", "bar 0\n", "foo 1\n", "bar 1\n"]
|
160
|
+
|
161
|
+
assert_equal(expected_content, result_content)
|
162
|
+
end
|
7
163
|
end
|
data/test/test_demultiplexer.rb
CHANGED
@@ -1,7 +1,211 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
|
3
3
|
|
4
4
|
require 'test/helper'
|
5
5
|
|
6
|
-
|
6
|
+
# Class for testing Demultiplexer.
|
7
|
+
class TestDemultiplexer < Test::Unit::TestCase
|
8
|
+
SAMPLES = <<-DATA.gsub(/^\s+\|/, '')
|
9
|
+
|#ID\tIndex1\tIndex2
|
10
|
+
|sample1\taT\tCg
|
11
|
+
DATA
|
12
|
+
|
13
|
+
FASTQ_INDEX1 = <<-DATA.gsub(/^\s+\|/, '')
|
14
|
+
|@index1
|
15
|
+
|Aa
|
16
|
+
|+
|
17
|
+
|II
|
18
|
+
DATA
|
19
|
+
|
20
|
+
FASTQ_INDEX2 = <<-DATA.gsub(/^\s+\|/, '')
|
21
|
+
|@index2
|
22
|
+
|cC
|
23
|
+
|+
|
24
|
+
|II
|
25
|
+
DATA
|
26
|
+
|
27
|
+
FASTQ_READ1 = <<-DATA.gsub(/^\s+\|/, '')
|
28
|
+
|@read1
|
29
|
+
|A
|
30
|
+
|+
|
31
|
+
|I
|
32
|
+
DATA
|
33
|
+
|
34
|
+
FASTQ_READ2 = <<-DATA.gsub(/^\s+\|/, '')
|
35
|
+
|@read2
|
36
|
+
|G
|
37
|
+
|+
|
38
|
+
|I
|
39
|
+
DATA
|
40
|
+
|
41
|
+
STATUS1 = <<-YAML.gsub(/^\s+\|/, '')
|
42
|
+
|---
|
43
|
+
|:count: 2
|
44
|
+
|:match: 0
|
45
|
+
|:undetermined: 2
|
46
|
+
|:undetermined_percent: 100.0
|
47
|
+
|:index1_bad_mean: 0
|
48
|
+
|:index2_bad_mean: 0
|
49
|
+
|:index1_bad_min: 0
|
50
|
+
|:index2_bad_min: 0
|
51
|
+
|:sample_ids:
|
52
|
+
|- sample1
|
53
|
+
|:index1:
|
54
|
+
|- AT
|
55
|
+
|:index2:
|
56
|
+
|- CG
|
57
|
+
|:time_elapsed: '00:00:00'
|
58
|
+
YAML
|
59
|
+
|
60
|
+
STATUS2 = <<-YAML.gsub(/^\s+\|/, '')
|
61
|
+
|---
|
62
|
+
|:count: 2
|
63
|
+
|:match: 2
|
64
|
+
|:undetermined: 0
|
65
|
+
|:undetermined_percent: 0.0
|
66
|
+
|:index1_bad_mean: 0
|
67
|
+
|:index2_bad_mean: 0
|
68
|
+
|:index1_bad_min: 0
|
69
|
+
|:index2_bad_min: 0
|
70
|
+
|:sample_ids:
|
71
|
+
|- sample1
|
72
|
+
|:index1:
|
73
|
+
|- AT
|
74
|
+
|:index2:
|
75
|
+
|- CG
|
76
|
+
|:time_elapsed: '00:00:00'
|
77
|
+
YAML
|
78
|
+
|
79
|
+
def setup
|
80
|
+
@tmp_input = Dir.mktmpdir('data_io_input')
|
81
|
+
@tmp_output = Dir.mktmpdir('data_io_input')
|
82
|
+
|
83
|
+
@file_samples = File.join(@tmp_input, 'samples.txt')
|
84
|
+
file_index1 = File.join(@tmp_input, 'x_S1_L001_I1_001x.fq')
|
85
|
+
file_index2 = File.join(@tmp_input, 'x_S1_L001_I2_001x.fq')
|
86
|
+
file_read1 = File.join(@tmp_input, 'x_S1_L001_R1_001x.fq')
|
87
|
+
file_read2 = File.join(@tmp_input, 'x_S1_L001_R2_001x.fq')
|
88
|
+
|
89
|
+
File.open(@file_samples, 'w') { |ios| ios.puts SAMPLES }
|
90
|
+
File.open(file_index1, 'w') { |ios| ios.puts FASTQ_INDEX1 }
|
91
|
+
File.open(file_index2, 'w') { |ios| ios.puts FASTQ_INDEX2 }
|
92
|
+
File.open(file_read1, 'w') { |ios| ios.puts FASTQ_READ1 }
|
93
|
+
File.open(file_read2, 'w') { |ios| ios.puts FASTQ_READ2 }
|
94
|
+
|
95
|
+
@fastq_files = [file_index1, file_index2, file_read1, file_read2]
|
96
|
+
end
|
97
|
+
|
98
|
+
def teardown
|
99
|
+
FileUtils.rm_rf(@tmp_input)
|
100
|
+
FileUtils.rm_rf(@tmp_output)
|
101
|
+
end
|
102
|
+
|
103
|
+
test '#run produces the correct output files' do
|
104
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
105
|
+
output_dir: @tmp_output)
|
106
|
+
|
107
|
+
result = Dir["#{@tmp_output}/*"].map { |file| File.basename file }
|
108
|
+
|
109
|
+
expected = ['Demultiplex.log',
|
110
|
+
'sample1_S1_L001_R1_001.fastq',
|
111
|
+
'sample1_S1_L001_R2_001.fastq',
|
112
|
+
'Undetermined_S1_L001_R1_001.fastq',
|
113
|
+
'Undetermined_S1_L001_R2_001.fastq']
|
114
|
+
|
115
|
+
assert_equal(expected, result)
|
116
|
+
end
|
117
|
+
|
118
|
+
test '#run produces OK log file with mismatches_max: 0' do
|
119
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
120
|
+
mismatches_max: 0, output_dir: @tmp_output)
|
121
|
+
|
122
|
+
result = File.read(File.join(@tmp_output, 'Demultiplex.log'))
|
123
|
+
|
124
|
+
assert_equal(STATUS1, result)
|
125
|
+
end
|
126
|
+
|
127
|
+
test '#run produces OK R1 file with mismatches_max: 0' do
|
128
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
129
|
+
mismatches_max: 0, output_dir: @tmp_output)
|
130
|
+
|
131
|
+
result = File.read(File.join(@tmp_output, 'sample1_S1_L001_R1_001.fastq'))
|
132
|
+
|
133
|
+
assert_equal('', result)
|
134
|
+
end
|
135
|
+
|
136
|
+
test '#run produces OK R2 file with mismatches_max: 0' do
|
137
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
138
|
+
mismatches_max: 0, output_dir: @tmp_output)
|
139
|
+
|
140
|
+
result = File.read(File.join(@tmp_output, 'sample1_S1_L001_R2_001.fastq'))
|
141
|
+
|
142
|
+
assert_equal('', result)
|
143
|
+
end
|
144
|
+
|
145
|
+
test '#run produces OK Undetermined R1 file with mismatches_max: 0' do
|
146
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
147
|
+
mismatches_max: 0, output_dir: @tmp_output)
|
148
|
+
|
149
|
+
file = File.join(@tmp_output, 'Undetermined_S1_L001_R1_001.fastq')
|
150
|
+
result = File.read(file)
|
151
|
+
|
152
|
+
assert_equal("@read1 Aa\nA\n+\nI\n", result)
|
153
|
+
end
|
154
|
+
|
155
|
+
test '#run produces OK Undetermined R2 file with mismatches_max: 0' do
|
156
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
157
|
+
mismatches_max: 0, output_dir: @tmp_output)
|
158
|
+
|
159
|
+
file = File.join(@tmp_output, 'Undetermined_S1_L001_R2_001.fastq')
|
160
|
+
result = File.read(file)
|
161
|
+
|
162
|
+
assert_equal("@read2 cC\nG\n+\nI\n", result)
|
163
|
+
end
|
164
|
+
|
165
|
+
test '#run produces OK log with mismatches_max: 1' do
|
166
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
167
|
+
mismatches_max: 1, output_dir: @tmp_output)
|
168
|
+
|
169
|
+
result = File.read(File.join(@tmp_output, 'Demultiplex.log'))
|
170
|
+
|
171
|
+
assert_equal(STATUS2, result)
|
172
|
+
end
|
173
|
+
|
174
|
+
test '#run produces OK R1 file with mismatches_max: 1' do
|
175
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
176
|
+
mismatches_max: 1, output_dir: @tmp_output)
|
177
|
+
|
178
|
+
result = File.read(File.join(@tmp_output, 'sample1_S1_L001_R1_001.fastq'))
|
179
|
+
|
180
|
+
assert_equal("@read1\nA\n+\nI\n", result)
|
181
|
+
end
|
182
|
+
|
183
|
+
test '#run produces OK R2 file with mismatches_max: 1' do
|
184
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
185
|
+
mismatches_max: 1, output_dir: @tmp_output)
|
186
|
+
|
187
|
+
result = File.read(File.join(@tmp_output, 'sample1_S1_L001_R2_001.fastq'))
|
188
|
+
|
189
|
+
assert_equal("@read2\nG\n+\nI\n", result)
|
190
|
+
end
|
191
|
+
|
192
|
+
test '#run produces OK Undetermined R1 file with mismatches_max: 1' do
|
193
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
194
|
+
mismatches_max: 1, output_dir: @tmp_output)
|
195
|
+
|
196
|
+
file = File.join(@tmp_output, 'Undetermined_S1_L001_R1_001.fastq')
|
197
|
+
result = File.read(file)
|
198
|
+
|
199
|
+
assert_equal('', result)
|
200
|
+
end
|
201
|
+
|
202
|
+
test '#run produces OK Undetermined R2 file with mismatches_max: 1' do
|
203
|
+
Demultiplexer.run(@fastq_files, samples_file: @file_samples,
|
204
|
+
mismatches_max: 1, output_dir: @tmp_output)
|
205
|
+
|
206
|
+
file = File.join(@tmp_output, 'Undetermined_S1_L001_R2_001.fastq')
|
207
|
+
result = File.read(file)
|
208
|
+
|
209
|
+
assert_equal('', result)
|
210
|
+
end
|
7
211
|
end
|
data/test/test_index_builder.rb
CHANGED
@@ -1,7 +1,62 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
|
3
3
|
|
4
4
|
require 'test/helper'
|
5
5
|
|
6
|
-
|
6
|
+
# Class for testing IndexBuilder.
|
7
|
+
class TestIndexBuilder < Test::Unit::TestCase
|
8
|
+
DATA1 = <<-DATA.gsub(/^\s+\|/, '')
|
9
|
+
|#ID\tIndex1\tIndex2
|
10
|
+
|A\tAT\tCG
|
11
|
+
DATA
|
12
|
+
|
13
|
+
DATA2 = <<-DATA.gsub(/^\s+\|/, '')
|
14
|
+
|#ID\tIndex1\tIndex2
|
15
|
+
|A\tAT\tCG
|
16
|
+
|B\tAA\tCC
|
17
|
+
DATA
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@file1 = Tempfile.new('sample_reader')
|
21
|
+
@file2 = Tempfile.new('sample_reader')
|
22
|
+
|
23
|
+
File.open(@file1, 'w') { |ios| ios.puts DATA1 }
|
24
|
+
File.open(@file2, 'w') { |ios| ios.puts DATA2 }
|
25
|
+
|
26
|
+
@samples1 = SampleReader.read(@file1, false, false)
|
27
|
+
@samples2 = SampleReader.read(@file2, false, false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def teardown
|
31
|
+
@file1.close
|
32
|
+
@file1.unlink
|
33
|
+
@file2.close
|
34
|
+
@file2.unlink
|
35
|
+
end
|
36
|
+
|
37
|
+
test 'IndexBuilder#build with mismatches_max 0 returns correctly' do
|
38
|
+
ghash = IndexBuilder.build(@samples1, 0)
|
39
|
+
size = 0
|
40
|
+
|
41
|
+
ghash.each { |_| size += 1 }
|
42
|
+
|
43
|
+
assert_equal(1, size)
|
44
|
+
assert_equal(0, ghash['ATCG'.hash])
|
45
|
+
end
|
46
|
+
|
47
|
+
test 'IndexBuilder#build with mismatches_max 1 returns correctly' do
|
48
|
+
ghash = IndexBuilder.build(@samples1, 1)
|
49
|
+
size = 0
|
50
|
+
keys = %w(AT AA AC AG AT TT CT GT).product(%w(CA CT CC CG AG TG CG GG)).
|
51
|
+
each_with_object([]) { |(a, b), m| m << a + b }.uniq
|
52
|
+
|
53
|
+
ghash.each { |_| size += 1 }
|
54
|
+
|
55
|
+
assert_equal(keys.size, size)
|
56
|
+
keys.each { |key| assert_equal(0, ghash[key.hash]) }
|
57
|
+
end
|
58
|
+
|
59
|
+
test 'IndexBuilder#build with non-unique index combo fails' do
|
60
|
+
assert_raise(IndexBuilderError) { IndexBuilder.build(@samples2, 1) }
|
61
|
+
end
|
7
62
|
end
|
data/test/test_sample_reader.rb
CHANGED
@@ -1,7 +1,80 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
|
3
3
|
|
4
4
|
require 'test/helper'
|
5
5
|
|
6
|
-
|
6
|
+
# Class for testing SampleReader.
|
7
|
+
class TestSampleReader < Test::Unit::TestCase
|
8
|
+
DATA1 = <<-DATA.gsub(/^\s+\|/, '')
|
9
|
+
|#ID\tIndex1\tIndex2
|
10
|
+
|A\tATCG\tTCCG
|
11
|
+
|B\tATCG\tTCCC
|
12
|
+
DATA
|
13
|
+
|
14
|
+
DATA2 = <<-DATA.gsub(/^\s+\|/, '')
|
15
|
+
|#ID\tIndex1\tIndex2
|
16
|
+
|A\tATCG\tTCCG
|
17
|
+
|A\tATCG\tTCCC
|
18
|
+
DATA
|
19
|
+
|
20
|
+
DATA3 = <<-DATA.gsub(/^\s+\|/, '')
|
21
|
+
|#ID\tIndex1\tIndex2
|
22
|
+
|A\tATCG\tTCCG
|
23
|
+
|B\tATCG\tTCCG
|
24
|
+
DATA
|
25
|
+
|
26
|
+
def setup
|
27
|
+
@file1 = Tempfile.new('sample_reader')
|
28
|
+
@file2 = Tempfile.new('sample_reader')
|
29
|
+
@file3 = Tempfile.new('sample_reader')
|
30
|
+
|
31
|
+
File.open(@file1, 'w') { |ios| ios.puts DATA1 }
|
32
|
+
File.open(@file2, 'w') { |ios| ios.puts DATA2 }
|
33
|
+
File.open(@file3, 'w') { |ios| ios.puts DATA3 }
|
34
|
+
end
|
35
|
+
|
36
|
+
def teardown
|
37
|
+
@file1.close
|
38
|
+
@file1.unlink
|
39
|
+
@file2.close
|
40
|
+
@file2.unlink
|
41
|
+
@file3.close
|
42
|
+
@file3.unlink
|
43
|
+
end
|
44
|
+
|
45
|
+
test 'SampleReader#read returns correctly' do
|
46
|
+
data = SampleReader.read(@file1, false, false)
|
47
|
+
|
48
|
+
assert_equal(["A\tATCG\tTCCG", "B\tATCG\tTCCC"], data.map(&:to_s))
|
49
|
+
end
|
50
|
+
|
51
|
+
test 'SampleReader#read with index1 reverse_complemented returns correctly' do
|
52
|
+
data = SampleReader.read(@file1, true, false)
|
53
|
+
|
54
|
+
assert_equal(["A\tCGAT\tTCCG", "B\tCGAT\tTCCC"], data.map(&:to_s))
|
55
|
+
end
|
56
|
+
|
57
|
+
test 'SampleReader#read with index2 reverse_complemented returns correctly' do
|
58
|
+
data = SampleReader.read(@file1, false, true)
|
59
|
+
|
60
|
+
assert_equal(["A\tATCG\tCGGA", "B\tATCG\tGGGA"], data.map(&:to_s))
|
61
|
+
end
|
62
|
+
|
63
|
+
test 'SampleReader#read with both reverse_complemented returns correctly' do
|
64
|
+
data = SampleReader.read(@file1, true, true)
|
65
|
+
|
66
|
+
assert_equal(["A\tCGAT\tCGGA", "B\tCGAT\tGGGA"], data.map(&:to_s))
|
67
|
+
end
|
68
|
+
|
69
|
+
test 'SampleReader#read with non-unique sample IDs fails' do
|
70
|
+
assert_raise(SampleReaderError) do
|
71
|
+
capture_stderr { SampleReader.read(@file2, true, true) }
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
test 'SampleReader#read with non-unique index combination fails' do
|
76
|
+
assert_raise(SampleReaderError) do
|
77
|
+
capture_stderr { SampleReader.read(@file3, true, true) }
|
78
|
+
end
|
79
|
+
end
|
7
80
|
end
|
data/test/test_status.rb
CHANGED
@@ -1,7 +1,61 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..')
|
3
3
|
|
4
4
|
require 'test/helper'
|
5
5
|
|
6
|
-
|
6
|
+
# Class for testing the Status class.
|
7
|
+
class TestStatus < Test::Unit::TestCase
|
8
|
+
SAMPLES = <<-DATA.gsub(/^\s+\|/, '')
|
9
|
+
|#ID\tIndex1\tIndex2
|
10
|
+
|A\tATCG\tTCCG
|
11
|
+
|B\tATCG\tTCCC
|
12
|
+
DATA
|
13
|
+
|
14
|
+
EXPECTED = <<-YAML.gsub(/^\s+\|/, '')
|
15
|
+
|---
|
16
|
+
|:count: 0
|
17
|
+
|:match: 0
|
18
|
+
|:undetermined: 0
|
19
|
+
|:undetermined_percent: 0.0
|
20
|
+
|:index1_bad_mean: 0
|
21
|
+
|:index2_bad_mean: 0
|
22
|
+
|:index1_bad_min: 0
|
23
|
+
|:index2_bad_min: 0
|
24
|
+
|:sample_ids:
|
25
|
+
|- A
|
26
|
+
|- B
|
27
|
+
|:index1:
|
28
|
+
|- ATCG
|
29
|
+
|:index2:
|
30
|
+
|- TCCC
|
31
|
+
|- TCCG
|
32
|
+
|:time_elapsed: '00:00:00'
|
33
|
+
YAML
|
34
|
+
|
35
|
+
def setup
|
36
|
+
@file_samples = Tempfile.new('samples')
|
37
|
+
@file_status = Tempfile.new('status')
|
38
|
+
|
39
|
+
File.open(@file_samples, 'w') { |ios| ios.puts SAMPLES }
|
40
|
+
|
41
|
+
@samples = SampleReader.read(@file_samples, false, false)
|
42
|
+
@status = Status.new(@samples)
|
43
|
+
end
|
44
|
+
|
45
|
+
def teardown
|
46
|
+
@file_samples.close
|
47
|
+
@file_samples.unlink
|
48
|
+
@file_status.close
|
49
|
+
@file_status.unlink
|
50
|
+
end
|
51
|
+
|
52
|
+
test 'Status#to_s returns correctly' do
|
53
|
+
assert_equal(EXPECTED, @status.to_s)
|
54
|
+
end
|
55
|
+
|
56
|
+
test 'Status#save does so correctly' do
|
57
|
+
@status.save(@file_status)
|
58
|
+
|
59
|
+
assert_equal(EXPECTED, File.read(@file_status))
|
60
|
+
end
|
7
61
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: demultiplexer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin A. Hansen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: biopieces
|
@@ -90,7 +90,6 @@ files:
|
|
90
90
|
- test/test_demultiplexer.rb
|
91
91
|
- test/test_index_builder.rb
|
92
92
|
- test/test_sample_reader.rb
|
93
|
-
- test/test_screen.rb
|
94
93
|
- test/test_status.rb
|
95
94
|
homepage: http://github.com/maasha/demultiplexer
|
96
95
|
licenses:
|
@@ -112,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
111
|
version: '0'
|
113
112
|
requirements: []
|
114
113
|
rubyforge_project: demultiplexer
|
115
|
-
rubygems_version: 2.
|
114
|
+
rubygems_version: 2.2.2
|
116
115
|
signing_key:
|
117
116
|
specification_version: 4
|
118
117
|
summary: Demultiplexer
|
@@ -122,6 +121,4 @@ test_files:
|
|
122
121
|
- test/test_demultiplexer.rb
|
123
122
|
- test/test_index_builder.rb
|
124
123
|
- test/test_sample_reader.rb
|
125
|
-
- test/test_screen.rb
|
126
124
|
- test/test_status.rb
|
127
|
-
has_rdoc:
|