本文整理汇总了Java中htsjdk.samtools.SAMTextHeaderCodec.decode方法的典型用法代码示例。如果您正苦于以下问题:Java SAMTextHeaderCodec.decode方法的具体用法?Java SAMTextHeaderCodec.decode怎么用?Java SAMTextHeaderCodec.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类htsjdk.samtools.SAMTextHeaderCodec
的用法示例。
在下文中一共展示了SAMTextHeaderCodec.decode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readSAMFileHeader
import htsjdk.samtools.SAMTextHeaderCodec; //导入方法依赖的package包/类
private static SAMFileHeader readSAMFileHeader(InputStream inputStream,
final String id) throws IOException {
final SecramBlock block = SecramBlock.readFromInputStream(inputStream);
inputStream = new ByteArrayInputStream(block.getRawContent());
final ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < 4; i++)
buffer.put((byte) inputStream.read());
buffer.flip();
final int size = buffer.asIntBuffer().get();
final DataInputStream dataInputStream = new DataInputStream(inputStream);
final byte[] bytes = new byte[size];
dataInputStream.readFully(bytes);
final BufferedLineReader bufferedLineReader = new BufferedLineReader(
new ByteArrayInputStream(bytes));
final SAMTextHeaderCodec codec = new SAMTextHeaderCodec();
return codec.decode(bufferedLineReader, id);
}
示例2: loadFastaDictionary
import htsjdk.samtools.SAMTextHeaderCodec; //导入方法依赖的package包/类
/**
* Given an InputStream connected to a fasta dictionary, returns its sequence dictionary
*
* Note: does not close the InputStream it's passed
*
* @param fastaDictionaryStream InputStream connected to a fasta dictionary
* @return the SAMSequenceDictionary from the fastaDictionaryStream
*/
public static SAMSequenceDictionary loadFastaDictionary( final InputStream fastaDictionaryStream ) {
// Don't close the reader when we're done, since we don't want to close the client's InputStream for them
final BufferedLineReader reader = new BufferedLineReader(fastaDictionaryStream);
final SAMTextHeaderCodec codec = new SAMTextHeaderCodec();
final SAMFileHeader header = codec.decode(reader, fastaDictionaryStream.toString());
// Make sure we have a valid sequence dictionary before continuing:
if (header.getSequenceDictionary() == null || header.getSequenceDictionary().isEmpty()) {
throw new UserException.MalformedFile (
"Could not read sequence dictionary from given fasta stream " +
fastaDictionaryStream
);
}
return header.getSequenceDictionary();
}
示例3: readHeader
import htsjdk.samtools.SAMTextHeaderCodec; //导入方法依赖的package包/类
static SAMFileHeader readHeader(final BinaryCodec stream, final ValidationStringency validationStringency,
final String source) throws IOException {
final byte[] buffer = new byte[4];
stream.readBytes(buffer);
if (!Arrays.equals(buffer, "BAM\1".getBytes())) {
throw new IOException("Invalid BAM file header");
}
final int headerTextLength = stream.readInt();
final String textHeader = stream.readString(headerTextLength);
final SAMTextHeaderCodec headerCodec = new SAMTextHeaderCodec();
headerCodec.setValidationStringency(validationStringency);
final SAMFileHeader samFileHeader = headerCodec.decode(new StringLineReader(textHeader), source);
final int sequenceCount = stream.readInt();
if (samFileHeader.getSequenceDictionary().size() > 0) {
// It is allowed to have binary sequences but no text sequences, so
// only validate if both are present
if (sequenceCount != samFileHeader.getSequenceDictionary().size()) {
throw new SAMFormatException("Number of sequences in text header ("
+ samFileHeader.getSequenceDictionary().size() + ") != number of sequences in binary header ("
+ sequenceCount + ") for file " + source);
}
for (int i = 0; i < sequenceCount; i++) {
final SAMSequenceRecord binarySequenceRecord = readSequenceRecord(stream, source);
final SAMSequenceRecord sequenceRecord = samFileHeader.getSequence(i);
if (!sequenceRecord.getSequenceName().equals(binarySequenceRecord.getSequenceName())) {
throw new SAMFormatException("For sequence " + i
+ ", text and binary have different names in file " + source);
}
if (sequenceRecord.getSequenceLength() != binarySequenceRecord.getSequenceLength()) {
throw new SAMFormatException("For sequence " + i
+ ", text and binary have different lengths in file " + source);
}
}
} else {
// If only binary sequences are present, copy them into
// samFileHeader
final List<SAMSequenceRecord> sequences = new ArrayList<SAMSequenceRecord>(sequenceCount);
for (int i = 0; i < sequenceCount; i++) {
sequences.add(readSequenceRecord(stream, source));
}
samFileHeader.setSequenceDictionary(new SAMSequenceDictionary(sequences));
}
return samFileHeader;
}
示例4: readHeader
import htsjdk.samtools.SAMTextHeaderCodec; //导入方法依赖的package包/类
/**
* read sam header from file
*
* @param LineReader for htsjdk
* @return SAMFileHeader
*/
public static SAMFileHeader readHeader(LineReader reader) {
SAMTextHeaderCodec codec = new SAMTextHeaderCodec();
SAMFileHeader mHeader = codec.decode(reader, null);
return mHeader;
}