Skip to content

Commit df51b26

Browse files
Merge pull request #20459 from jmchilton/auto_pairing_fix
[25.0] Fix bug with handling compressed file names while auto-pairing.
2 parents 0bf37ec + 5194738 commit df51b26

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
- doc: Simple _R1 _R2 fastqs split.
2+
inputs:
3+
- input_R1.fastq
4+
- input_R2.fastq
5+
paired:
6+
input:
7+
forward: input_R1.fastq
8+
reverse: input_R2.fastq
9+
10+
- doc: Compressed _R1 _R2 fastqs split.
11+
inputs:
12+
- input_R1.fastq.gz
13+
- input_R2.fastq.gz
14+
paired:
15+
input:
16+
forward: input_R1.fastq.gz
17+
reverse: input_R2.fastq.gz
18+
19+
- doc: Joining common prefixes on _R1 _R2.
20+
inputs:
21+
- input541_R1.fastq
22+
- input541_R2.fastq
23+
- input521_R1.fastq
24+
- input521_R2.fastq
25+
paired:
26+
input541:
27+
forward: input541_R1.fastq
28+
reverse: input541_R2.fastq
29+
input521:
30+
forward: input521_R1.fastq
31+
reverse: input521_R2.fastq
32+
33+
- doc: Simple .1.fastq/.2.fastq split.
34+
inputs:
35+
- input.1.fastq
36+
- input.2.fastq
37+
paired:
38+
input:
39+
forward: input.1.fastq
40+
reverse: input.2.fastq
41+
42+
- doc: Simple .1.fastq.gz/.2.fastq.gz split.
43+
inputs:
44+
- input.1.fastq.gz
45+
- input.2.fastq.gz
46+
paired:
47+
input:
48+
forward: input.1.fastq.gz
49+
reverse: input.2.fastq.gz
50+
51+
- doc: Simple _1/_2 split.
52+
inputs:
53+
- input_1.fastq
54+
- input_2.fastq
55+
paired:
56+
input:
57+
forward: input_1.fastq
58+
reverse: input_2.fastq
59+
60+
- doc: Simple _1/_2 split on compressed files (.gz)
61+
inputs:
62+
- input_1.fastq.gz
63+
- input_2.fastq.gz
64+
paired:
65+
input:
66+
forward: input_1.fastq.gz
67+
reverse: input_2.fastq.gz
68+
69+
- doc: Simple _1/_2 split on compressed files (.bz2)
70+
inputs:
71+
- input_1.fastq.bz2
72+
- input_2.fastq.bz2
73+
paired:
74+
input:
75+
forward: input_1.fastq.bz2
76+
reverse: input_2.fastq.bz2

client/src/components/Collections/pairing.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import AUTO_PAIRING_SPECIFICATION from "./auto_pairing_spec.yml";
12
import {
23
autoDetectPairs,
34
autoPairWithCommonFilters,
@@ -117,3 +118,32 @@ describe("splitIntoPairedAndUnpaired", () => {
117118
expect(summary.pairs).toHaveLength(0);
118119
});
119120
});
121+
122+
interface ExpectedPair {
123+
name: string;
124+
forward: string;
125+
reverse: string;
126+
}
127+
128+
interface AutoPairingTest {
129+
doc?: string;
130+
inputs: string[];
131+
paired: Record<string, ExpectedPair>;
132+
}
133+
134+
describe("fulfills auto pairing specification ", () => {
135+
test("the specification", () => {
136+
const tests = AUTO_PAIRING_SPECIFICATION;
137+
tests.forEach((test: AutoPairingTest) => {
138+
const inputs = test.inputs.map((name) => mockDataset(name));
139+
const summary = autoPairWithCommonFilters(inputs, true);
140+
for (const name in test.paired) {
141+
const expectedPair = test.paired[name] as ExpectedPair;
142+
const pair = summary.pairs?.find((p) => p.name === name);
143+
expect(pair).toBeDefined();
144+
expect(pair?.forward.name).toEqual(expectedPair.forward);
145+
expect(pair?.reverse.name).toEqual(expectedPair.reverse);
146+
}
147+
});
148+
});
149+
});

client/src/components/Collections/pairing.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,13 @@ export function _guessNameForPair(
7070
if (willRemoveExtensions) {
7171
const lastDotIndex = lcs.lastIndexOf(".");
7272
if (lastDotIndex > 0) {
73-
const extension = lcs.slice(lastDotIndex, lcs.length);
73+
let extension = lcs.slice(lastDotIndex, lcs.length);
74+
if ([".gz", ".bz", ".bzip", ".bz2"].indexOf(extension) !== -1) {
75+
const secondLastDotIndex = lcs.lastIndexOf(".", lastDotIndex - 1);
76+
if (secondLastDotIndex > 0) {
77+
extension = lcs.slice(secondLastDotIndex, lcs.length);
78+
}
79+
}
7480
lcs = lcs.replace(extension, "");
7581
fwdName = fwdName.replace(extension, "");
7682
revName = revName.replace(extension, "");

0 commit comments

Comments
 (0)