-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconvert_adaptive.nf.test
More file actions
207 lines (170 loc) · 6.83 KB
/
convert_adaptive.nf.test
File metadata and controls
207 lines (170 loc) · 6.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
nextflow_process {
name "Test CONVERT_ADAPTIVE"
script "modules/local/airr_convert/convert_adaptive.nf"
process "CONVERT_ADAPTIVE"
// Note: Test fixtures in tests/fixtures/data/ contain small subsets of
// Adaptive Biotechnologies format TCR data for testing conversion to AIRR format
test("Should convert valid Adaptive format to AIRR") {
tag "basic"
when {
process {
"""
input[0] = [
[sample: 'Patient01_Base'],
file("${projectDir}/tests/fixtures/data/PD1_Patient01_Base.tsv")
]
input[1] = file("${projectDir}/assets/airr/airr_rearrangement_schema.json")
input[2] = file("${projectDir}/assets/airr/imgt_adaptive_lookup.tsv")
"""
}
}
then {
assert process.success
assert process.out.adaptive_convert
with(process.out.adaptive_convert) {
assert size() == 1
// Check the tuple structure [sample_meta, file]
def (meta, airr_file) = get(0)
assert meta.sample == 'Patient01_Base'
// Check output file exists and has correct name
def file_path = path(airr_file)
assert file_path.exists()
assert file_path.getFileName().toString() == 'Patient01_Base_airr.tsv'
// Verify AIRR format structure
def lines = file_path.readLines()
assert lines.size() > 1 // Header + data rows
// Check for AIRR standard columns
def header = lines[0]
assert header.contains("sequence_id")
assert header.contains("sequence")
assert header.contains("junction")
assert header.contains("junction_aa")
assert header.contains("v_call")
assert header.contains("d_call")
assert header.contains("j_call")
assert header.contains("productive")
assert header.contains("duplicate_count")
}
}
}
test("Should convert multiple samples from minimal-example") {
tag "integration"
when {
process {
"""
input[0] = [
[sample: 'Patient02_Base'],
file("${projectDir}/tests/test_data/minimal-example/PD1_Patient02_Base.tsv")
]
input[1] = file("${projectDir}/assets/airr/airr_rearrangement_schema.json")
input[2] = file("${projectDir}/assets/airr/imgt_adaptive_lookup.tsv")
"""
}
}
then {
assert process.success
assert process.out.adaptive_convert
with(process.out.adaptive_convert) {
def (meta, airr_file) = get(0)
assert meta.sample == 'Patient02_Base'
def file_path = path(airr_file)
assert file_path.exists()
// Verify substantial data was converted
def lines = file_path.readLines()
assert lines.size() > 10 // Should have many rows from full dataset
}
}
}
test("Should preserve sample metadata through conversion") {
tag "metadata"
when {
process {
"""
input[0] = [
[
sample: 'Patient03_Base',
subject_id: 'Patient03',
timepoint: 'Base',
origin: 'tumor'
],
file("${projectDir}/tests/fixtures/data/PD1_Patient03_Base.tsv")
]
input[1] = file("${projectDir}/assets/airr/airr_rearrangement_schema.json")
input[2] = file("${projectDir}/assets/airr/imgt_adaptive_lookup.tsv")
"""
}
}
then {
assert process.success
assert process.out.adaptive_convert
with(process.out.adaptive_convert) {
def (meta, airr_file) = get(0)
// Verify all metadata is preserved
assert meta.sample == 'Patient03_Base'
assert meta.subject_id == 'Patient03'
assert meta.timepoint == 'Base'
assert meta.origin == 'tumor'
assert path(airr_file).exists()
}
}
}
test("Should handle malformed Adaptive data gracefully") {
tag "error-handling"
when {
process {
"""
input[0] = [
[sample: 'MalformedSample'],
file("${projectDir}/tests/fixtures/data/malformed_adaptive.tsv")
]
input[1] = file("${projectDir}/assets/airr/airr_rearrangement_schema.json")
input[2] = file("${projectDir}/assets/airr/imgt_adaptive_lookup.tsv")
"""
}
}
then {
// Should fail due to missing required columns
assert process.failed
}
}
test("Should convert V, D, J gene calls correctly") {
tag "gene-conversion"
when {
process {
"""
input[0] = [
[sample: 'Patient01_Base'],
file("${projectDir}/tests/fixtures/data/PD1_Patient01_Base.tsv")
]
input[1] = file("${projectDir}/assets/airr/airr_rearrangement_schema.json")
input[2] = file("${projectDir}/assets/airr/imgt_adaptive_lookup.tsv")
"""
}
}
then {
assert process.success
assert process.out.adaptive_convert
with(process.out.adaptive_convert) {
def (meta, airr_file) = get(0)
def file_path = path(airr_file)
def lines = file_path.readLines()
// Check that gene calls are present in output
def header = lines[0].split('\t')
def v_idx = header.findIndexOf { it == 'v_call' }
def d_idx = header.findIndexOf { it == 'd_call' }
def j_idx = header.findIndexOf { it == 'j_call' }
assert v_idx >= 0
assert d_idx >= 0
assert j_idx >= 0
// Check first data row has gene calls
if (lines.size() > 1) {
def first_row = lines[1].split('\t')
// Should have IMGT format gene calls (e.g., TRBV30-01*01)
if (first_row.size() > v_idx && first_row[v_idx]) {
assert first_row[v_idx].contains('TRB') || first_row[v_idx].isEmpty()
}
}
}
}
}
}