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


Java BinaryCodec类代码示例

本文整理汇总了Java中htsjdk.samtools.util.BinaryCodec的典型用法代码示例。如果您正苦于以下问题:Java BinaryCodec类的具体用法?Java BinaryCodec怎么用?Java BinaryCodec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: writeFastqRecord

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
/**
 * Writes out a SAMRecord in Maq fastq format
 *
 * @param codec the code to write to
 * @param rec   the SAMRecord to write
 */
private void writeFastqRecord(final BinaryCodec codec, final SAMRecord rec) {

    // Trim the run barcode off the read name
    String readName = rec.getReadName();
    if (namePrefix != null && readName.startsWith(namePrefix)) {
        readName = readName.substring(nameTrim);
    }
    // Writes the length of the read name and then the name (null-terminated)
    codec.writeString(readName, true, true);

    final char[] seqs = rec.getReadString().toCharArray();
    final char[] quals = rec.getBaseQualityString().toCharArray();

    int retainedLength = seqs.length;
    if (clipAdapters){
        // adjust to a shorter length iff clipping tag exists
        Integer trimPoint = rec.getIntegerAttribute(ReservedTagConstants.XT);
        if (trimPoint != null) {
            assert (rec.getReadLength() == seqs.length);
            retainedLength = Math.min(seqs.length, Math.max(SEED_REGION_LENGTH, trimPoint -1));
        }
    }

    // Write the length of the sequence
    codec.writeInt(basesToWrite != null ? basesToWrite : seqs.length);

    // Calculate and write the sequence and qualities
    final byte[] seqsAndQuals = encodeSeqsAndQuals(seqs, quals, retainedLength);
    codec.writeBytes(seqsAndQuals);
}
 
开发者ID:broadinstitute,项目名称:picard,代码行数:37,代码来源:BamToBfqWriter.java

示例2: init

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
private void init(
		OutputStream output, SAMFileHeader header, boolean writeHeader)
	throws IOException
{
	origOutput = output;

	compressedOut = new BlockCompressedOutputStream(origOutput, null);

	binaryCodec = new BinaryCodec(compressedOut);
	recordCodec = new BAMRecordCodec(header);
	recordCodec.setOutputStream(compressedOut);

	if (writeHeader)
		this.writeHeader(header);
}
 
开发者ID:HadoopGenomics,项目名称:Hadoop-BAM,代码行数:16,代码来源:BAMRecordWriter.java

示例3: BinaryBAMShardIndexWriter

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
/**
 * @param nRef Number of reference sequences. If zero is passed then header is not written.
 * This is useful in sharded writing as we only want the header written for the first shard.
 * 
 * @param output BAM index output stream.  This stream will be closed when BinaryBAMIndexWriter.close() is called.
 */
public BinaryBAMShardIndexWriter(final int nRef, final OutputStream output) {
    try {
        codec = new BinaryCodec(output);
        if (nRef > 0) {
          writeHeader(nRef);
        }
    } catch (final Exception e) {
        throw new SAMException("Exception opening output stream", e);
    }
}
 
开发者ID:googlegenomics,项目名称:dataflow-java,代码行数:17,代码来源:BinaryBAMShardIndexWriter.java

示例4: writeBAMHeaderToStream

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
/**
 * Private helper method for {@link #convertHeaderlessHadoopBamShardToBam} that takes a SAMFileHeader and writes it
 * to the provided `OutputStream`, correctly encoded for the BAM format and preceded by the BAM magic bytes.
 *
 * @param samFileHeader SAM header to write
 * @param outputStream stream to write the SAM header to
 */
private static void writeBAMHeaderToStream( final SAMFileHeader samFileHeader, final OutputStream outputStream ) {
    final BlockCompressedOutputStream blockCompressedOutputStream = new BlockCompressedOutputStream(outputStream, null);
    final BinaryCodec outputBinaryCodec = new BinaryCodec(new DataOutputStream(blockCompressedOutputStream));

    final String headerString;
    final Writer stringWriter = new StringWriter();
    new SAMTextHeaderCodec().encode(stringWriter, samFileHeader, true);
    headerString = stringWriter.toString();

    outputBinaryCodec.writeBytes(ReadUtils.BAM_MAGIC);

    // calculate and write the length of the SAM file header text and the header text
    outputBinaryCodec.writeString(headerString, true, false);

    // write the sequences binarily.  This is redundant with the text header
    outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size());
    for (final SAMSequenceRecord sequenceRecord: samFileHeader.getSequenceDictionary().getSequences()) {
        outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true);
        outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength());
    }

    try {
        blockCompressedOutputStream.flush();
    } catch (final IOException ioe) {
        throw new RuntimeIOException(ioe);
    }
}
 
开发者ID:broadinstitute,项目名称:gatk,代码行数:35,代码来源:SparkUtils.java

示例5: Bam_OBA_Supplier

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
public Bam_OBA_Supplier(BufferedInputStream is) {
	this.is = is;
	codec = new BinaryCodec();
	codec.setInputStream(is);
	baos = new ByteArrayOutputStream();
	refId = Integer.MIN_VALUE;
	recordCounter = 0;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:9,代码来源:Bam_OBA_Supplier.java

示例6: readSequenceRecord

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
private static SAMSequenceRecord readSequenceRecord(final BinaryCodec stream, final String source) {
	final int nameLength = stream.readInt();
	if (nameLength <= 1) {
		throw new SAMFormatException("Invalid BAM file header: missing sequence name in file " + source);
	}
	final String sequenceName = stream.readString(nameLength - 1);
	// Skip the null terminator
	stream.readByte();
	final int sequenceLength = stream.readInt();
	return new SAMSequenceRecord(SAMSequenceRecord.truncateSequenceName(sequenceName), sequenceLength);
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:12,代码来源:SAMFileHeader_Utils.java

示例7: writeHeader

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
static void writeHeader(final BinaryCodec outputBinaryCodec, final SAMFileHeader samFileHeader,
		final String headerText) {
	outputBinaryCodec.writeBytes("BAM\1".getBytes());

	// calculate and write the length of the SAM file header text and the
	// header text
	outputBinaryCodec.writeString(headerText, true, false);

	// write the sequences binarily. This is redundant with the text header
	outputBinaryCodec.writeInt(samFileHeader.getSequenceDictionary().size());
	for (final SAMSequenceRecord sequenceRecord : samFileHeader.getSequenceDictionary().getSequences()) {
		outputBinaryCodec.writeString(sequenceRecord.getSequenceName(), true, true);
		outputBinaryCodec.writeInt(sequenceRecord.getSequenceLength());
	}
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:16,代码来源:SAMFileHeader_Utils.java

示例8: AlignmentsCodec

import htsjdk.samtools.util.BinaryCodec; //导入依赖的package包/类
public AlignmentsCodec() {
	binaryCodec = new BinaryCodec();
}
 
开发者ID:BGI-flexlab,项目名称:SOAPgaea,代码行数:4,代码来源:AlignmentsCodec.java

示例9: readHeader

import htsjdk.samtools.util.BinaryCodec; //导入依赖的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;
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:49,代码来源:SAMFileHeader_Utils.java


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