1
1
package org .broadinstitute .hellbender .tools ;
2
2
3
+ import htsjdk .beta .io .IOPathUtils ;
4
+ import htsjdk .beta .io .bundle .Bundle ;
5
+ import htsjdk .beta .io .bundle .BundleJSON ;
6
+ import htsjdk .beta .plugin .registry .HaploidReferenceResolver ;
3
7
import htsjdk .samtools .SAMFileHeader ;
4
8
import htsjdk .samtools .SAMRecord ;
5
9
import htsjdk .samtools .SamReader ;
9
13
import org .broadinstitute .hellbender .GATKBaseTest ;
10
14
import org .broadinstitute .hellbender .cmdline .ReadFilterArgumentDefinitions ;
11
15
import org .broadinstitute .hellbender .cmdline .StandardArgumentDefinitions ;
16
+ import org .broadinstitute .hellbender .engine .GATKPath ;
12
17
import org .broadinstitute .hellbender .engine .ReadsDataSource ;
13
18
import org .broadinstitute .hellbender .engine .ReadsPathDataSource ;
14
19
import org .broadinstitute .hellbender .engine .filters .ReadLengthReadFilter ;
19
24
import org .broadinstitute .hellbender .testutils .SamAssertionUtils ;
20
25
import org .broadinstitute .hellbender .utils .Utils ;
21
26
import org .broadinstitute .hellbender .utils .gcs .BucketUtils ;
27
+ import org .broadinstitute .hellbender .utils .io .IOUtils ;
22
28
import org .broadinstitute .hellbender .utils .read .GATKRead ;
23
29
import org .testng .Assert ;
24
30
import org .testng .annotations .DataProvider ;
@@ -37,14 +43,20 @@ public void doFileToFile(String fileIn, String extOut, String reference, boolean
37
43
String samFile = fileIn ;
38
44
final File outFile = GATKBaseTest .createTempFile (samFile + "." , extOut );
39
45
final File ORIG_BAM = new File (TEST_DATA_DIR , samFile );
40
- final File refFile ;
46
+ final GATKPath refFile ;
41
47
42
48
final ArrayList <String > args = new ArrayList <>();
43
49
args .add ("--input" ); args .add (ORIG_BAM .getAbsolutePath ());
44
50
args .add ("--output" ); args .add (outFile .getAbsolutePath ());
45
51
if (reference != null ) {
46
- refFile = new File (TEST_DATA_DIR , reference );
47
- args .add ("-R" ); args .add (refFile .getAbsolutePath ());
52
+ if (reference .endsWith (BundleJSON .BUNDLE_EXTENSION )) {
53
+ // the test json files are temporary files, not files in TEST_DATA_DIR
54
+ refFile = new GATKPath (reference );
55
+ args .add ("-R" ); args .add (reference );
56
+ } else {
57
+ refFile = new GATKPath (new File (TEST_DATA_DIR , reference ).getAbsolutePath ());
58
+ args .add ("-R" ); args .add (refFile .toString ());
59
+ }
48
60
}
49
61
else {
50
62
refFile = null ;
@@ -55,13 +67,33 @@ public void doFileToFile(String fileIn, String extOut, String reference, boolean
55
67
}
56
68
runCommandLine (args );
57
69
58
- SamAssertionUtils .assertSamsEqual (outFile , ORIG_BAM , refFile );
70
+ SamAssertionUtils .assertSamsEqual (outFile , ORIG_BAM , refFile == null ? null : refFile . toPath (). toFile () );
59
71
60
72
if (testMD5 ) {
61
73
checkMD5asExpected (outFile );
62
74
}
63
75
}
64
76
77
+ public void doFileToFileUsingReferenceBundle (String fileIn , String extOut , String reference , boolean testMD5 ) throws Exception {
78
+ final String referenceToUse ;
79
+ if (reference != null ) {
80
+ // create the bundle, using inference to find the sibling files, then write the bundle out to a temp file
81
+ final Bundle referenceBundle = HaploidReferenceResolver .referenceBundleFromFastaPath (
82
+ new GATKPath (new File (TEST_DATA_DIR , reference ).toPath ().toString ()),
83
+ GATKPath ::new );
84
+ final GATKPath tempBundlePath = new GATKPath (
85
+ IOUtils .createTempFile ("printReadsRefBundle" , ".json" ).getAbsolutePath ()
86
+ );
87
+ IOPathUtils .writeStringToPath (tempBundlePath , BundleJSON .toJSON (referenceBundle ));
88
+ referenceToUse = tempBundlePath .toString ();
89
+ } else {
90
+ referenceToUse = reference ;
91
+ }
92
+
93
+ // no run the regular test, but using the reference bundle
94
+ doFileToFile (fileIn , extOut , referenceToUse , testMD5 );
95
+ }
96
+
65
97
private void checkMD5asExpected (final File outFile ) throws IOException {
66
98
final File md5File = new File (outFile .getAbsolutePath () + ".md5" );
67
99
if (md5File .exists ()) {
@@ -74,8 +106,8 @@ private void checkMD5asExpected(final File outFile) throws IOException {
74
106
}
75
107
76
108
@ Test (dataProvider ="testingData" )
77
- public void testFileToFile (String fileIn , String extOut , String reference ) throws Exception {
78
- doFileToFile (fileIn , extOut , reference , false );
109
+ public void testFileToFileWithReferenceBundle (String fileIn , String extOut , String reference ) throws Exception {
110
+ doFileToFileUsingReferenceBundle (fileIn , extOut , reference , false );
79
111
}
80
112
81
113
@ DataProvider (name ="testingData" )
@@ -120,6 +152,18 @@ public Object[][] testingData() {
120
152
};
121
153
}
122
154
155
+ @ Test (dataProvider ="testingData" )
156
+ public void testFileToFileUsingReferenceBundle (String fileIn , String extOut , String reference ) throws Exception {
157
+ if (reference != null ) {
158
+ doFileToFileUsingReferenceBundle (fileIn , extOut , reference , false );
159
+ }
160
+ }
161
+
162
+ @ Test (dataProvider ="testingData" )
163
+ public void testFileToFile (String fileIn , String extOut , String reference ) throws Exception {
164
+ doFileToFile (fileIn , extOut , reference , false );
165
+ }
166
+
123
167
@ Test
124
168
public void testReadThatConsumesNoReferenceBases () throws IOException {
125
169
final File zeroRefBasesReadBam = new File (TEST_DATA_DIR , "read_consumes_zero_ref_bases.bam" );
0 commit comments