Search in sources :

Example 1 with AlignedFilter

use of htsjdk.samtools.filter.AlignedFilter 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;
}
Also used : AlignedFilter(htsjdk.samtools.filter.AlignedFilter) FilteringSamIterator(htsjdk.samtools.filter.FilteringSamIterator) ReadNameFilter(htsjdk.samtools.filter.ReadNameFilter) IOException(java.io.IOException) UserException(org.broadinstitute.hellbender.exceptions.UserException)

Aggregations

AlignedFilter (htsjdk.samtools.filter.AlignedFilter)1 FilteringSamIterator (htsjdk.samtools.filter.FilteringSamIterator)1 ReadNameFilter (htsjdk.samtools.filter.ReadNameFilter)1 IOException (java.io.IOException)1 UserException (org.broadinstitute.hellbender.exceptions.UserException)1