All Downloads are FREE. Search and download functionalities are using the official Maven repository.

htsjdk.samtools.SAMFileSpanImpl Maven / Gradle / Ivy

There is a newer version: v1-0.8
Show newest version
package htsjdk.samtools;

import java.util.List;

/**
 * Dealing with visibility constraints of classes in HTSJDK we need to use.
 * Allows construction of SAMFileSpan objects and exposes a method
 * to calculate approximate size of span in bytes.
 */
public class SAMFileSpanImpl extends BAMFileSpan {
	private static final long serialVersionUID = 1L;
	private long cachedSize = -1;
	
	public SAMFileSpanImpl() {
		super();
	}
	
	public SAMFileSpanImpl(final List chunks) {
		super(chunks);
	}
	
	private static final double AVERAGE_BAM_COMPRESSION_RATIO = 0.39;
	
	public long approximateSizeInBytes() {
	  if (cachedSize < 0) {
    	  cachedSize = 0;
    	  for (Chunk chunk : getChunks()) {
    	    final long chunkSpan = Math.round(((chunk.getChunkEnd()>>16)-(chunk.getChunkStart()>>16))/AVERAGE_BAM_COMPRESSION_RATIO);
            final int offsetSpan = (int)((chunk.getChunkEnd()&0xFFFF)-(chunk.getChunkStart()&0xFFFF));
            cachedSize += chunkSpan + offsetSpan;
    	  }
	  }
      return cachedSize;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy