1
1
package org .broadinstitute .hellbender .tools .walkers ;
2
2
3
3
import htsjdk .samtools .SAMSequenceRecord ;
4
- import java .nio .file .Path ;
5
- import java .nio .file .Paths ;
6
4
import org .broadinstitute .hellbender .CommandLineProgramTest ;
7
5
import org .broadinstitute .hellbender .engine .ReferenceDataSource ;
8
6
import org .broadinstitute .hellbender .utils .GenomeLocParser ;
12
10
import org .testng .annotations .Test ;
13
11
14
12
import java .io .File ;
13
+ import java .nio .file .Path ;
14
+ import java .nio .file .Paths ;
15
15
import java .util .List ;
16
16
import java .util .stream .Collectors ;
17
17
import java .util .stream .IntStream ;
@@ -26,6 +26,7 @@ public class SplitIntervalsIntegrationTest extends CommandLineProgramTest {
26
26
private static final Path REFERENCE = Paths .get (b37_reference_20_21 );
27
27
private static final GenomeLocParser GLP = new GenomeLocParser (ReferenceDataSource .of (REFERENCE ).getSequenceDictionary ());
28
28
29
+
29
30
@ Test
30
31
public void testOneInterval () {
31
32
final int scatterCount = 5 ;
@@ -37,8 +38,25 @@ public void testOneInterval() {
37
38
"-O" , outputDir .getAbsolutePath ()
38
39
};
39
40
runCommandLine (args );
40
- verifyScatteredFilesExist (scatterCount , outputDir );
41
- checkIntervalSizes (scatterCount , outputDir , 1000000 );
41
+ verifyScatteredFilesExist (scatterCount , outputDir , SplitIntervals .DEFAULT_EXTENSION );
42
+ checkIntervalSizes (scatterCount , outputDir , 1000000 , SplitIntervals .DEFAULT_EXTENSION );
43
+ }
44
+
45
+ @ Test
46
+ public void testOneIntervalAlternateExtension () {
47
+ final int scatterCount = 5 ;
48
+ final File outputDir = createTempDir ("output" );
49
+ final String extension = "-scattered.with.a.wierd.extension" ;
50
+ final String [] args = {
51
+ "-L" , "20:1000000-2000000" ,
52
+ "-R" , REFERENCE .toAbsolutePath ().toString (),
53
+ "-" + SplitIntervals .SCATTER_COUNT_SHORT_NAME , Integer .toString (scatterCount ),
54
+ "-O" , outputDir .getAbsolutePath (),
55
+ "--extension" , extension
56
+ };
57
+ runCommandLine (args );
58
+ verifyScatteredFilesExist (scatterCount , outputDir , extension );
59
+ checkIntervalSizes (scatterCount , outputDir , 1000000 , extension );
42
60
}
43
61
44
62
@ Test
@@ -52,8 +70,8 @@ public void testSingleScatter() {
52
70
"-O" , outputDir .getAbsolutePath ()
53
71
};
54
72
runCommandLine (args );
55
- verifyScatteredFilesExist (scatterCount , outputDir );
56
- checkIntervalSizes (scatterCount , outputDir , 1000000 );
73
+ verifyScatteredFilesExist (scatterCount , outputDir , SplitIntervals . DEFAULT_EXTENSION );
74
+ checkIntervalSizes (scatterCount , outputDir , 1000000 , SplitIntervals . DEFAULT_EXTENSION );
57
75
58
76
}
59
77
@@ -69,8 +87,8 @@ public void testTwoIntervals() {
69
87
"-O" , outputDir .getAbsolutePath ()
70
88
};
71
89
runCommandLine (args );
72
- verifyScatteredFilesExist (scatterCount , outputDir );
73
- checkIntervalSizes (scatterCount , outputDir , 2000000 );
90
+ verifyScatteredFilesExist (scatterCount , outputDir , SplitIntervals . DEFAULT_EXTENSION );
91
+ checkIntervalSizes (scatterCount , outputDir , 2000000 , SplitIntervals . DEFAULT_EXTENSION );
74
92
75
93
}
76
94
@@ -84,28 +102,28 @@ public void testNoIntervals() {
84
102
"-O" , outputDir .getAbsolutePath ()
85
103
};
86
104
runCommandLine (args );
87
- verifyScatteredFilesExist (scatterCount , outputDir );
105
+ verifyScatteredFilesExist (scatterCount , outputDir , SplitIntervals . DEFAULT_EXTENSION );
88
106
final int totalLengthInRef = GLP .getSequenceDictionary ().getSequences ().stream ().mapToInt (SAMSequenceRecord ::getSequenceLength ).sum ();
89
- checkIntervalSizes (scatterCount , outputDir , totalLengthInRef );
107
+ checkIntervalSizes (scatterCount , outputDir , totalLengthInRef , SplitIntervals . DEFAULT_EXTENSION );
90
108
91
109
}
92
110
93
- private static Stream <File > getScatteredFiles (final int scatterCount , final File outputDir ) {
94
- return IntStream .range (0 , scatterCount ).mapToObj (n -> new File (outputDir , "000" + n + "-scattered.intervals" ));
111
+ private static Stream <File > getScatteredFiles (final int scatterCount , final File outputDir , String extension ) {
112
+ return IntStream .range (0 , scatterCount ).mapToObj (n -> new File (outputDir , "000" + n + extension ));
95
113
}
96
114
97
- private static void verifyScatteredFilesExist (final int scatterCount , final File outputDir ) {
98
- getScatteredFiles (scatterCount , outputDir ).forEach (f -> Assert .assertTrue (f .exists ()));
99
- Assert .assertFalse (new File (outputDir , "000" + scatterCount + "-scattered.intervals" ).exists ());
115
+ private static void verifyScatteredFilesExist (final int scatterCount , final File outputDir , String extension ) {
116
+ getScatteredFiles (scatterCount , outputDir , extension ).forEach (f -> Assert .assertTrue (f .exists ()));
117
+ Assert .assertFalse (new File (outputDir , "000" + scatterCount + extension ).exists ());
100
118
}
101
119
102
120
private static List <SimpleInterval > readIntervals (final File intervalsFile ) {
103
121
return IntervalUtils .intervalFileToList (GLP , intervalsFile .getAbsolutePath ()).stream ().map (SimpleInterval ::new ).collect (Collectors .toList ());
104
122
}
105
123
106
- private static void checkIntervalSizes (final int scatterCount , final File outputDir , final int expectedTotalLength ) {
124
+ private static void checkIntervalSizes (final int scatterCount , final File outputDir , final int expectedTotalLength , String extension ) {
107
125
final int splitLength = expectedTotalLength / scatterCount ;
108
- getScatteredFiles (scatterCount , outputDir ).forEach (f -> Assert .assertEquals (readIntervals (f ).stream ().mapToInt (SimpleInterval ::size ).sum (), splitLength , 100 ));
126
+ getScatteredFiles (scatterCount , outputDir , extension ).forEach (f -> Assert .assertEquals (readIntervals (f ).stream ().mapToInt (SimpleInterval ::size ).sum (), splitLength , 100 ));
109
127
}
110
128
111
129
}
0 commit comments