Skip to content

Commit

Permalink
Make the VCF option in CollectSamErrorMetrics optional. (#1476)
Browse files Browse the repository at this point in the history
* Make the VCF option in CollectSamErrorMetrics optional

* Some additional checks for no-VCF. One of the tests requires an index that was in the vcf testdata folder but not sam.

---------

Co-authored-by: Can Kockan <kockan@broadinstitute.org>
  • Loading branch information
nh13 and kockan authored Feb 15, 2024
1 parent 6d33c94 commit 6f2c61a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public class CollectSamErrorMetrics extends CommandLineProgram {
public ReadBaseStratification.Stratifier STRATIFIER_VALUE;

@Argument(shortName = "V", doc = "VCF of known variation for sample. program will skip over polymorphic sites in this VCF and " +
"avoid collecting data on these loci.")
"avoid collecting data on these loci.", optional = true)
public String VCF;

@Argument(shortName = "L", doc = "Region(s) to limit analysis to. Supported formats are VCF or interval_list. Will *intersect* inputs if multiple are given. " +
Expand Down Expand Up @@ -206,7 +206,7 @@ public class CollectSamErrorMetrics extends CommandLineProgram {
@Argument(
fullName = "INTERVAL_ITERATOR",
doc = "Iterate through the file assuming it consists of a pre-created subset interval of the full genome. " +
"This enables fast processing of files with reads at disperate parts of the genome. " +
"This enables fast processing of files with reads at disparate parts of the genome. " +
"Requires that the provided VCF file is indexed. ",
optional = true
)
Expand Down Expand Up @@ -305,16 +305,18 @@ protected String[] customCommandLineValidation() {
* Otherwise, will initialize the {@link #vcfIterator}.
*/
private void initializeVcfDataSource() throws IOException {
if ( INTERVAL_ITERATOR ) {
vcfFileReader = new VCFFileReader(IOUtil.getPath(VCF), false);
if (VCF == null) {
vcfIterator = new PeekableIterator<>(Collections.emptyIterator());
}
else if (INTERVAL_ITERATOR) {
vcfFileReader = new VCFFileReader(IOUtil.getPath(VCF), true);
// Make sure we can query our file for interval mode:
if (!vcfFileReader.isQueryable()) {
throw new PicardException("Cannot query VCF File! VCF Files must be queryable! Please index input VCF and re-run.");
}
}
else {
vcfIterator = new PeekableIterator<>(
VCF == null ? Collections.emptyIterator() : new VCFFileReader(IOUtil.getPath(VCF), false).iterator());
vcfIterator = new PeekableIterator<>(new VCFFileReader(IOUtil.getPath(VCF), true).iterator());
}
}

Expand Down Expand Up @@ -366,7 +368,9 @@ private void closeVcfDataSource() {
vcfFileReader.close();
}
else {
vcfIterator.close();
if(vcfIterator != null) {
vcfIterator.close();
}
}
}

Expand Down Expand Up @@ -414,7 +418,9 @@ private int processData() {
}
finally {
// Close our data source:
closeVcfDataSource();
if(VCF != null) {
closeVcfDataSource();
}
}

return 0;
Expand Down Expand Up @@ -501,7 +507,9 @@ protected int doWork() {
// Make sure we can read our files:
try {
IOUtil.assertFileIsReadable(IOUtil.getPath(INPUT));
IOUtil.assertFileIsReadable(IOUtil.getPath(VCF));
if (VCF != null) {
IOUtil.assertFileIsReadable(IOUtil.getPath(VCF));
}
IOUtil.assertFileIsReadable(REFERENCE_SEQUENCE);
IOUtil.assertFilesAreReadable(INTERVALS);
}
Expand Down
Binary file not shown.

0 comments on commit 6f2c61a

Please sign in to comment.