当前位置: 首页>>代码示例>>Java>>正文


Java SeekableStream.seek方法代码示例

本文整理汇总了Java中htsjdk.samtools.seekablestream.SeekableStream.seek方法的典型用法代码示例。如果您正苦于以下问题:Java SeekableStream.seek方法的具体用法?Java SeekableStream.seek怎么用?Java SeekableStream.seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在htsjdk.samtools.seekablestream.SeekableStream的用法示例。


在下文中一共展示了SeekableStream.seek方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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();
        }
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:20,代码来源:FastaSequenceFile.java

示例2: 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();
}
 
开发者ID:epam,项目名称:htsjdk-s3-plugin,代码行数:20,代码来源:S3SeekableStreamTest.java

示例3: 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();
}
 
开发者ID:epam,项目名称:htsjdk-s3-plugin,代码行数:21,代码来源:S3SeekableStreamTest.java

示例4: 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();
        }
    }
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:22,代码来源:FastaIndexedSequence.java

示例5: 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);
    }
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:20,代码来源:SAMReader.java

示例6: 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);
    }
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:23,代码来源:CRAMFile.java

示例7: GaeaBamSplitGuesser

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
public GaeaBamSplitGuesser(SeekableStream ss, Configuration conf) throws IOException {
	this(ss, ss, conf);

	ss.seek(0);
	if (ss.read(buf.array(), 0, 4) != 4 || buf.getInt(0) != BGZF_MAGIC)
		throw new SAMFormatException("Does not seem like a BAM file");
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:8,代码来源:GaeaBamSplitGuesser.java

示例8: BAMSplitGuesser

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
/** The stream must point to a valid BAM file, because the header is read
 * from it.
 */
public BAMSplitGuesser(
		SeekableStream ss, Configuration conf)
	throws IOException
{
	this(ss, ss, conf);

	// Secondary check that the header points to a BAM file: Picard can get
	// things wrong due to its autodetection.
	ss.seek(0);
	if (ss.read(buf.array(), 0, 4) != 4 || buf.getInt(0) != BGZF_MAGIC)
		throw new SAMFormatException("Does not seem like a BAM file");
}
 
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:16,代码来源:BAMSplitGuesser.java

示例9: seek

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
private static long seek(List<CramIndex.Entry> index, int seqId, int start, int end, SeekableStream cramStream)
		throws IOException {
	List<Entry> found = CramIndex.find(index, seqId, start, end - start + 1);
	if (found == null || found.size() == 0)
		return -1;
	cramStream.seek(found.get(0).containerStartOffset);
	log.debug("Found query at offset: " + found.get(0).containerStartOffset);
	return found.get(0).containerStartOffset;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:10,代码来源:IndexAggregate.java

示例10: openCramInputStream

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
/**
 * A convenience method.
 * <p>
 * If a file is supplied then it will be wrapped into a SeekableStream. If
 * file is null, then the fromIS argument will be used or System.in if null.
 * Optionally the input can be decrypted using provided password or the
 * password read from the console.
 * </p>
 * The method also checks for EOF marker and raise error if the marker is
 * not found for files with version 2.1 or greater. For version below 2.1 a
 * warning will CRAM be issued.
 * 
 * @param decrypt
 *            decrypt the input stream
 * @param password
 *            a password to use for decryption
 * @return an InputStream ready to be used for reading CRAM file definition
 * @throws IOException
 * @throws URISyntaxException
 */
public static InputStream openCramInputStream(String cramURL, boolean decrypt, String password) throws IOException,
		URISyntaxException {

	InputStream is = null;
	if (cramURL == null)
		is = new BufferedInputStream(System.in);
	else
		is = openInputStreamFromURL(cramURL);

	if (decrypt) {
		char[] pass = null;
		if (password == null) {
			if (System.console() == null)
				throw new RuntimeException("Cannot access console.");
			pass = System.console().readPassword();
		} else
			pass = password.toCharArray();

		// TODO: SeekableCipherStream_256 relies on net.sf.samtools package
		// which has been renamed. Commenting out this for now:
		// if (is instanceof SeekableStream)
		// is = new SeekableCipherStream_256((SeekableStream) is, pass, 1,
		// 128);
		// else
		is = new CipherInputStream_256(is, pass, 128).getCipherInputStream();

	}

	if (is instanceof SeekableStream) {
		CramHeader cramHeader = CramIO.readCramHeader(is);
		SeekableStream s = (SeekableStream) is;
		if (!checkEOF(cramHeader.getVersion(), s))
			eofNotFound(cramHeader.getVersion());
		s.seek(0);
	} else
		log.warn("CRAM file/stream completion cannot be verified.");

	return is;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:60,代码来源:Utils.java

示例11: streamEndsWith

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
private static boolean streamEndsWith(SeekableStream seekableStream, byte[] marker) throws IOException {
	byte[] tail = new byte[marker.length];
	seekableStream.seek(seekableStream.length() - marker.length);
	InputStreamUtils.readFully(seekableStream, tail, 0, tail.length);
	if (Arrays.equals(tail, marker))
		return true;
	tail[8] = (byte) (tail[8] | 240);
	return Arrays.equals(tail, marker);
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:10,代码来源:Utils.java

示例12: BigBedDataBlock

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
public BigBedDataBlock(SeekableStream fis, RPTreeLeafNodeItem leafHitItem,
                       HashMap<Integer, String> chromosomeMap, boolean isLowToHigh, int uncompressBufSize) {

    this.leafHitItem = leafHitItem;
    this.chromosomeMap = chromosomeMap;
    this.isLowToHigh = isLowToHigh;

    dataBlockSize = this.leafHitItem.geDataSize();
    byte[] buffer = new byte[(int) dataBlockSize];

    fileOffset = this.leafHitItem.getDataOffset();

    // read Bed data block into a buffer
    try {
        fis.seek(fileOffset);
        fis.readFully(buffer);

        // decompress if necessary - the buffer size is 0 for uncompressed data
        // Note:  BBFile Table C specifies a decompression buffer size
        if (uncompressBufSize > 0)
            bedBuffer = (new CompressionUtils()).decompress(buffer, uncompressBufSize);
        else
            bedBuffer = buffer;    // use uncompressed read buffer directly

    } catch (IOException ex) {
        String error = String.format("Error reading Bed data for leaf item %d \n");
        log.error(error, ex);
        throw new RuntimeException(error, ex);
    }

    // wrap the bed buffer as an input stream
    if (this.isLowToHigh)
        lbdis = new LittleEndianInputStream(new ByteArrayInputStream(bedBuffer));
    else
        dis = new DataInputStream(new ByteArrayInputStream(bedBuffer));

    // initialize unread data size
    remDataSize = bedBuffer.length;

    // use methods getBedData or getNextFeature to extract block data
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:42,代码来源:BigBedDataBlock.java

示例13: BBZoomLevelFormat

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
public BBZoomLevelFormat(int zoomLevel, SeekableStream fis, long fileOffset,
                       long dataSize, boolean isLowToHigh, int uncompressBufSize) {

    // store file access info
    this.zoomLevel = zoomLevel;
    this.fis = fis;
    zoomFormatOffset = fileOffset;
    zoomDataSize = dataSize;
    this.isLowToHigh = isLowToHigh;

    // Note: a bad zoom data header will result in a 0 count returned
    // or an IOException

    // size of buffer is ZOOM_FORMAT_HEADER_SIZE to get the record count
    byte[] buffer = new byte[ZOOM_FORMAT_HEADER_SIZE];

    try {

        // Read zoom level data format into a buffer
        fis.seek(zoomFormatOffset);
        fis.readFully(buffer);

        // decode header - or fail
        if(this.isLowToHigh) {
            LittleEndianInputStream lbdis = new LittleEndianInputStream(new ByteArrayInputStream(buffer));
            zoomRecordCount = lbdis.readInt();
        }
        else {
            DataInputStream bdis = new DataInputStream(new ByteArrayInputStream(buffer));
            zoomRecordCount = bdis.readInt();
        }

    } catch (IOException ex) {
        log.error("Error reading zoom level data records (Table O) ", ex);
        throw new RuntimeException("Error reading zoom level data records (Table O)", ex);
        }

    // integrity check - should be > 0 or less than a max like 100M records?
        // Note: if trouble reading zoom data records, readAllZoomLevelRecords returns 0
        if(zoomRecordCount < 0 || zoomRecordCount > MAX_ZOOM_DATA_RECORDS)
            return;  // terminate if bad zoom level data encountered

        // Position file offset past the current zoom level header to pick up
        // the zoom data records which immediately follow.
        zoomDataOffset = zoomFormatOffset + ZOOM_FORMAT_HEADER_SIZE;

        // calculate the position of the R+ zoom index tree
        zoomIndexOffset = zoomDataOffset + zoomDataSize;
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:50,代码来源:BBZoomLevelFormat.java

示例14: loadAlignments

import htsjdk.samtools.seekablestream.SeekableStream; //导入方法依赖的package包/类
@Override
public List<MultipleAlignmentBlock> loadAlignments(String chr, int start, int end) throws IOException {

    IntervalTree ivTree = index.getIntervalTree(chr);
    if (ivTree == null) return null;

    List<Interval> intervals = ivTree.findOverlapping(start, end);
    if (intervals.isEmpty()) {
        return null;
    }


    // Find the starting (left most) interval.  Alignment blocks do not overlap, so we can start at the
    // minimum file offset and just proceed until the end of the interval.
    long startPosition = Long.MAX_VALUE;
    for (Interval iv : intervals) {
        startPosition = Math.min(startPosition, iv.getValue());
    }


    SeekableStream is = null;


    is = IGVSeekableStreamFactory.getInstance().getStreamFor(path);
    is.seek(startPosition);

    BufferedReader reader = new BufferedReader(new InputStreamReader(is), 256000);

    List<MultipleAlignmentBlock> alignments = new ArrayList<MultipleAlignmentBlock>();

    String line;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("a ")) {
            // TODO -- parse score (optional)
            MultipleAlignmentBlock block = parseBlock(reader);
            if(block.getEnd() < start) {
                continue;
            }
            if (block.getStart() > end || !block.getChr().equals(chr)) {
                break;
            } else {
                alignments.add(block);
            }
        }
    }
    return alignments;
}
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:48,代码来源:MAFParser.java


注:本文中的htsjdk.samtools.seekablestream.SeekableStream.seek方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。