本文整理汇总了Java中htsjdk.samtools.seekablestream.SeekableStream类的典型用法代码示例。如果您正苦于以下问题:Java SeekableStream类的具体用法?Java SeekableStream怎么用?Java SeekableStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SeekableStream类属于htsjdk.samtools.seekablestream包,在下文中一共展示了SeekableStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initStream
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
public void initStream(final File plusFile) {
if(plusFile.exists()) {
try {
final ISeekableStreamFactory ssf = SeekableStreamFactory.getInstance();
final SeekableStream seekableStream =
ssf.getBufferedStream(ssf.getStreamFor(plusFile.getAbsolutePath()));
BlockCompressedInputStream is = new BlockCompressedInputStream(seekableStream);
writeIndex(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new IllegalArgumentException("plus file in location:" + path +" is needed to write a plus index.");
}
}
示例2: initStream
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
public void initStream() {
File inputFile = new File(path);
if(inputFile.exists() && inputFile.getName().toLowerCase().endsWith(IntervalIndex.PLUS_EXTENSION)) {
try {
final ISeekableStreamFactory ssf = SeekableStreamFactory.getInstance();
final SeekableStream seekableStream =
ssf.getBufferedStream(ssf.getStreamFor(inputFile.getAbsolutePath()));
BlockCompressedInputStream is = new BlockCompressedInputStream(seekableStream);
writeIndex(is);
is.close();
} catch (IOException e) {
e.printStackTrace();
}
} else {
throw new IllegalArgumentException("plus file is needed to write a plus index.");
}
}
示例3: readBytes
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
/**
* Read the bytes between file position posStart and posEnd
*/
private byte[] readBytes(long posStart, long posEnd) throws IOException {
SeekableStream ss = null;
try {
ss = SeekableStreamFactory.getInstance().getStreamFor(path);
int nBytes = (int) (posEnd - posStart);
byte[] bytes = new byte[nBytes];
ss.seek(posStart);
ss.readFully(bytes);
return bytes;
} finally {
if (ss != null) {
ss.close();
}
}
}
示例4: createStream
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
private InputStream createStream(final FileInputStream fileStream) throws IOException {
// if this looks like a block compressed file and it in fact is, we will use it
// otherwise we will use the file as is
if (!AbstractFeatureReader.hasBlockCompressedExtension(inputFile)) {
return fileStream;
}
// make a buffered stream to test that this is in fact a valid block compressed file
final int bufferSize = Math.max(Defaults.BUFFER_SIZE,
BlockCompressedStreamConstants.MAX_COMPRESSED_BLOCK_SIZE);
final BufferedInputStream bufferedStream = new BufferedInputStream(fileStream, bufferSize);
if (!BlockCompressedInputStream.isValidFile(bufferedStream)) {
throw new TribbleException.MalformedFeatureFile(
"Input file is not in valid block compressed format.", inputFile.getAbsolutePath());
}
final ISeekableStreamFactory ssf = SeekableStreamFactory.getInstance();
// if we got here, the file is valid, make a SeekableStream for the BlockCompressedInputStream
// to read from
final SeekableStream seekableStream =
ssf.getBufferedStream(ssf.getStreamFor(inputFile.getAbsolutePath()));
return new BlockCompressedInputStream(seekableStream);
}
示例5: loadIndex
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
/**
* A method that seeks and downloads the index for the set BAM URI.
* Seeks an index file with the same name in the BAM directory
* in case there's no custom index URI specified
*
* @param bamURI an http address of the required file.
* @return A SeekableStream optional on index file URI
*/
Optional<SeekableStream> loadIndex(AmazonS3URI bamURI) throws IOException {
LOG.info("Trying to set index file for " + bamURI.toString());
Optional<AmazonS3URI> index = providedIndexURI()
.map(Optional::of)
.orElseGet(() -> nearbyIndexURI(bamURI));
if (!index.isPresent()) {
LOG.info("Index wasn't provided for " + bamURI.toString());
return Optional.empty();
}
LOG.info("Start download index: " + index.get());
AmazonS3URI indexURI = index.get();
S3InputStreamFactory streamFactory = new S3InputStreamFactory(client);
InputStream stream = streamFactory.loadFully(indexURI);
long fileSize = client.getFileSize(indexURI);
byte[] buffer = IOUtils.toByteArray(stream);
if (fileSize != buffer.length) {
throw new IOException("Failed to fully download index " + indexURI);
}
LOG.info("Finished download index: " + index.get());
return Optional.of(new SeekableMemoryStream(buffer, indexURI.toString()));
}
示例6: open
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
/**
* A method that creates a SamReader object that's passed on to the HTSJDK.
* Each time someone tries to open a SamReader on an URL,
* HTSJDK checks if there's a custom reader factory and if it's there, this method is called.
*
* @param url target file URL
* @return A SamReader object on a specified file URL
*/
@Override
public SamReader open(URL url) {
PerformanceMonitor.start();
AmazonS3URI amazonURI = new AmazonS3URI(url.toString());
S3Client client = new S3Client();
S3InputStreamFactory streamFactory = new S3InputStreamFactory(client);
//download index file if is possible, and then start download .bam file
final Optional<SeekableStream> indexStream;
try {
IndexLoader loader = new IndexLoader(client);
indexStream = loader.loadIndex(amazonURI);
} catch (IOException e) {
throw new RuntimeIOException(e.getMessage() + " failed to download index", e);
}
SeekableStream stream = new S3SeekableStream(amazonURI, client, streamFactory);
SamReaderFactory factory = SamReaderFactory.makeDefault();
SamInputResource inputResource = SamInputResource.of(stream);
indexStream.ifPresent(inputResource::index);
return factory.open(inputResource);
}
示例7: streamShouldSkipSmallSeek
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
@Test
public void streamShouldSkipSmallSeek() throws IOException {
final int seekPosition = 100;
SeekableStream fakeSeekable = new S3SeekableStream(S3DataLoaderMocker.FAKE_URI,
client,
factory);
assertEquals(0, fakeSeekable.position());
fakeSeekable.seek(seekPosition);
assertEquals(seekPosition, fakeSeekable.position());
final int READ_COUNT = 12;
for (int i = 0; i < READ_COUNT; i++) {
assertEquals(seekPosition + i, fakeSeekable.read());
}
assertEquals(seekPosition + READ_COUNT, fakeSeekable.position());
fakeSeekable.close();
}
示例8: streamShouldSeek
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
@Test
public void streamShouldSeek() throws IOException {
System.setProperty("samjdk.s3plugin.number_of_connections", "2");
Configuration.init();
final int seekPosition = Configuration.getMaxDownloadPartSize() * 2;
SeekableStream fakeSeekable = new S3SeekableStream(S3DataLoaderMocker.FAKE_URI,
client,
factory);
fakeSeekable.seek(seekPosition);
final int READ_COUNT = 1024;
for (int i = 0; i < READ_COUNT; i++) {
final int expectedByte = (seekPosition + i) & (0xff);
assertEquals(expectedByte, fakeSeekable.read());
}
assertEquals(seekPosition + READ_COUNT, fakeSeekable.position());
fakeSeekable.close();
}
示例9: setup
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
@Override
protected void setup(Context context) throws IOException, InterruptedException {
Configuration conf = context.getConfiguration();
Path path = new Path(conf.get(GaeaVCFOutputFormat.OUT_PATH_PROP));
SeekableStream in = WrapSeekable.openPath(path.getFileSystem(conf), path);
header = VCFHeaderReader.readHeaderFrom(in);
in.close();
chrIndexs = new HashMap<String,Integer>();
List<VCFContigHeaderLine> lines = header.getContigLines();
for(int i = 0 ; i < lines.size() ; i++){
VCFContigHeaderLine line = lines.get(i);
chrIndexs.put(line.getID(), line.getContigIndex());
}
}
示例10: readBytes
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
/**
* Read the bytes between file position posStart and posEnd
*
* @throws IOException
*/
private byte[] readBytes(long posStart, long posEnd) throws IOException {
SeekableStream ss = null;
try {
ss = IGVSeekableStreamFactory.getInstance().getStreamFor(path);
int nBytes = (int) (posEnd - posStart);
byte[] bytes = new byte[nBytes];
ss.seek(posStart);
ss.readFully(bytes);
return bytes;
} finally {
if (ss != null) {
ss.close();
}
}
}
示例11: getSAMFileReader
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
private SAMFileReader getSAMFileReader(String samFile, long startPosition) {
try {
SeekableStream stream = IGVSeekableStreamFactory.getInstance().getStreamFor(samFile);
if (startPosition >= 0) {
stream.seek(startPosition);
}
SAMFileReader reader = new SAMFileReader(stream);
reader.setValidationStringency(ValidationStringency.SILENT);
//Need to keep the file source, if loading lazily
//TODO Can't reload from SAM files. See SAMTextReader.getIterator
//reader.enableFileSource(PicardAlignment.DEFAULT_LAZY_LOAD);
return reader;
} catch (IOException ex) {
log.error("Error opening sam file", ex);
throw new RuntimeException("Error opening: " + samFile, ex);
}
}
示例12: getSamReader
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
public SamReader getSamReader(ResourceLocator locator, boolean requireIndex) throws IOException {
if (requireIndex) {
final SamReaderFactory factory = SamReaderFactory.makeDefault().validationStringency(ValidationStringency.SILENT);
SeekableStream indexStream = getIndexStream(locator.getBamIndexPath());
this.indexed = true;
SeekableStream ss = new IGVSeekableBufferedStream(IGVSeekableStreamFactory.getInstance().getStreamFor(url), 128000);
SamInputResource resource = SamInputResource.of(ss).index(indexStream);
return factory.open(resource);
} else {
InputStream is = HttpUtils.getInstance().openConnectionStream(url);
return new SAMFileReader(new BufferedInputStream(is));
}
}
示例13: readContainerHeader
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
public void readContainerHeader(long position) throws IOException {
SeekableStream ss = IGVSeekableStreamFactory.getInstance().getStreamFor(path);
ss.seek(position);
BufferedInputStream bis = new BufferedInputStream(ss);
int length = CramInt.int32(bis);
int refSeqId = ITF8.readUnsignedITF8(bis);
int startPos = ITF8.readUnsignedITF8(bis);
int alignmentSpan = ITF8.readUnsignedITF8(bis);
int nRecords = ITF8.readUnsignedITF8(bis);
int recordCounter = ITF8.readUnsignedITF8(bis);
int bases = ITF8.readUnsignedITF8(bis);
int nBlocks = ITF8.readUnsignedITF8(bis);
int[] landmarks = CramArray.array(bis);
if (major >= 3) {
int checksum = CramInt.int32(bis);
}
readBlocks(bis, nBlocks);
}
示例14: readZoomHeaders
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
private int readZoomHeaders(SeekableStream fis, long fileOffset, int zoomLevels, boolean isLowToHigh) {
int level = 0;
BBZoomLevelHeader zoomLevelHeader;
if(zoomLevels < 1)
return 0;
// create zoom headers and data containers
zoomLevelHeaders = new ArrayList<BBZoomLevelHeader>();
// get zoom header information for each zoom levelsRead
for(int index = 0; index < zoomLevels; ++index) {
level = index + 1;
// read zoom level header - read error is returned as Runtime Exception
zoomLevelHeader = new BBZoomLevelHeader(fis, fileOffset, level, isLowToHigh);
zoomLevelHeaders.add(zoomLevelHeader);
fileOffset += BBZoomLevelHeader.ZOOM_LEVEL_HEADER_SIZE;
}
return level;
}
示例15: ZoomLevelIterator
import htsjdk.samtools.seekablestream.SeekableStream; //导入依赖的package包/类
/**
* Constructs a zoom level iterator over the specified chromosome region
* <p/>
* Parameters:
* fis - file input stream handle
* chromIDTree - B+ index tree returns chromId for chromosome name key
* zoomLevelTree - zoom level R+ chromosome index tree
* zoomLevel - zoom level represented by the R+ tree
* selectionRegion - chromosome region for selection of Bed feature extraction
* consists of:
* startChromID - ID of start chromosome
* startBase - starting base position for features
* endChromID - ID of end chromosome
* endBase - starting base position for features
* contained - specifies bed features must be contained by region, if true;
* else return any intersecting region features
*/
public ZoomLevelIterator(SeekableStream fis, BPTree chromIDTree, RPTree zoomDataTree,
int zoomLevel, RPChromosomeRegion selectionRegion, boolean contained) {
// check for valid selection region
if (selectionRegion == null)
throw new RuntimeException("Error: ZoomLevelIterator selection region is null\n");
this.fis = fis;
this.chromIDTree = chromIDTree;
this.zoomDataTree = zoomDataTree;
this.zoomLevel = zoomLevel;
this.selectionRegion = selectionRegion;
isContained = contained;
// set up hit list and read in the first data block
int hitCount = getHitRegion(selectionRegion, contained);
if (hitCount == 0) {
empty = true;
}
// Ready for next() data extraction
}