use of htsjdk.samtools.filter.ReadNameFilter in project gatk by broadinstitute.
the class FilterReads method doWork.
@Override
protected Object doWork() {
try {
IOUtil.assertFileIsReadable(INPUT);
IOUtil.assertFileIsWritable(OUTPUT);
if (WRITE_READS_FILES)
writeReadsFile(INPUT);
switch(FILTER) {
case includeAligned:
filterReads(new FilteringSamIterator(SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT).iterator(), new AlignedFilter(true), true));
break;
case excludeAligned:
filterReads(new FilteringSamIterator(SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT).iterator(), new AlignedFilter(false), true));
break;
case includeReadList:
filterReads(new FilteringSamIterator(SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT).iterator(), new ReadNameFilter(READ_LIST_FILE, true)));
break;
case excludeReadList:
filterReads(new FilteringSamIterator(SamReaderFactory.makeDefault().referenceSequence(REFERENCE_SEQUENCE).open(INPUT).iterator(), new ReadNameFilter(READ_LIST_FILE, false)));
break;
default:
throw new UnsupportedOperationException(FILTER.name() + " has not been implemented!");
}
IOUtil.assertFileIsReadable(OUTPUT);
if (WRITE_READS_FILES)
writeReadsFile(OUTPUT);
} catch (IOException e) {
if (OUTPUT.exists() && !OUTPUT.delete()) {
throw new UserException("Failed to delete existing output: " + OUTPUT.getAbsolutePath());
} else {
throw new UserException("Failed to filter " + INPUT.getName());
}
}
return null;
}
Aggregations