public RegionCoverage coverage(Region region, AlignmentFilters<SAMRecord> filters, AlignmentOptions options)
            throws AlignmentCoverageException {
        // Check region size is smaller than MAX_REGION_COVERAGE
        if (region.size() > MAX_REGION_COVERAGE) {
            throw new AlignmentCoverageException("Region size is bigger than MAX_REGION_COVERAGE [" + MAX_REGION_COVERAGE +"]");
        }

        RegionCoverage regionCoverage = new RegionCoverage(region);
        if (options == null) {
            options = new AlignmentOptions();
        }
        SamRecordRegionCoverageCalculator calculator = new SamRecordRegionCoverageCalculator(options.getMinBaseQuality());
        try (BamIterator<SAMRecord> iterator = iterator(region, filters, options)) {
            while (iterator.hasNext()) {
                SAMRecord next = iterator.next();
                if (!next.getReadUnmappedFlag()) {
                    calculator.update(next, regionCoverage);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return regionCoverage;
    }
public RegionCoverage coverage ( Region region , AlignmentFilters < SAMRecord > filters , AlignmentOptions options ) throws AlignmentCoverageException { if ( region . size ( ) > MAX_REGION_COVERAGE ) { throw new AlignmentCoverageException ( "Region size is bigger than MAX_REGION_COVERAGE [" + MAX_REGION_COVERAGE + "]" ) ; } RegionCoverage regionCoverage = new RegionCoverage ( region ) ; if ( options == null ) { options = new AlignmentOptions ( ) ; } SamRecordRegionCoverageCalculator calculator = new SamRecordRegionCoverageCalculator ( options . getMinBaseQuality ( ) ) ; try ( BamIterator < SAMRecord > iterator = iterator ( region , filters , options ) ) { while ( iterator . hasNext ( ) ) { SAMRecord next = iterator . next ( ) ; if ( ! next . getReadUnmappedFlag ( ) ) { calculator . update ( next , regionCoverage ) ; } } } catch ( Exception e ) { e . printStackTrace ( ) ; } return regionCoverage ; }
This method get some filters and calculate the coverage from the BAM file with the reads filtered.
@param region Region to calculate coverage from
@param filters Filters to be applied to reads
@param options Other possible options
@return The coverage for each position of the region (windowSize == 1)