本文整理汇总了Java中htsjdk.samtools.BAMRecordCodec类的典型用法代码示例。如果您正苦于以下问题:Java BAMRecordCodec类的具体用法?Java BAMRecordCodec怎么用?Java BAMRecordCodec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BAMRecordCodec类属于htsjdk.samtools包,在下文中一共展示了BAMRecordCodec类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RevertSamSorter
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
RevertSamSorter(
final boolean outputByReadGroup,
final Map<String, SAMFileHeader> headerMap,
final SAMFileHeader singleOutHeader,
final int maxRecordsInRam) {
this.outputByReadGroup = outputByReadGroup;
if (outputByReadGroup) {
for (final Map.Entry<String, SAMFileHeader> entry : headerMap.entrySet()) {
final String readGroupId = entry.getKey();
final SAMFileHeader outHeader = entry.getValue();
final SortingCollection<SAMRecord> sorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(outHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
sorterMap.put(readGroupId, sorter);
}
singleSorter = null;
} else {
singleSorter = SortingCollection.newInstance(SAMRecord.class, new BAMRecordCodec(singleOutHeader), new SAMRecordQueryNameComparator(), maxRecordsInRam);
}
}
示例2: write
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
@Override
public void write(DataOutput out) throws IOException {
// In theory, it shouldn't matter whether we give a header to
// BAMRecordCodec or not, since the representation of an alignment in BAM
// doesn't depend on the header data at all. Only its interpretation
// does, and a simple read/write codec shouldn't really have anything to
// say about that. (But in practice, it already does matter for decode(),
// which is why LazyBAMRecordFactory exists.)
final BAMRecordCodec codec = new BAMRecordCodec(record.getHeader());
codec.setOutputStream(new DataOutputWrapper(out));
codec.encode(record);
}
示例3: init
import htsjdk.samtools.BAMRecordCodec; //导入依赖的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);
}
示例4: BAMSplitGuesser
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
public BAMSplitGuesser(
SeekableStream ss, InputStream headerStream, Configuration conf)
throws IOException
{
inFile = ss;
header = SAMHeaderReader.readSAMHeaderFrom(headerStream, conf);
referenceSequenceCount = header.getSequenceDictionary().size();
bamCodec = new BAMRecordCodec(null, new LazyBAMRecordFactory());
}
示例5: write
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
@Override public void write(DataOutput out) throws IOException {
// In theory, it shouldn't matter whether we give a header to
// BAMRecordCodec or not, since the representation of an alignment in BAM
// doesn't depend on the header data at all. Only its interpretation
// does, and a simple read/write codec shouldn't really have anything to
// say about that. (But in practice, it already does matter for decode(),
// which is why LazyBAMRecordFactory exists.)
final BAMRecordCodec codec = new BAMRecordCodec(record.getHeader());
codec.setOutputStream(new DataOutputWrapper(out));
codec.encode(record);
}
示例6: CramToBam_OBA_Function
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
CramToBam_OBA_Function(CramHeader header, ReferenceSource referenceSource) {
this.header = header;
parser = new ContainerParser(header.getSamFileHeader());
f = new Cram2SamRecordFactory(header.getSamFileHeader());
codec = new BAMRecordCodec(header.getSamFileHeader());
n = new CramNormalizer(header.getSamFileHeader(), referenceSource);
log.info("converter created");
}
示例7: toSAMRecord
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
private List<SAMRecord> toSAMRecord(BAMRecordView view, SAMFileHeader samHeader) {
BAMRecordCodec bc = new BAMRecordCodec(samHeader);
bc.setInputStream(new ByteArrayInputStream(view.buf, 0, view.start));
List<SAMRecord> records = new ArrayList<SAMRecord>();
SAMRecord record;
while ((record = bc.decode()) != null) {
records.add(record);
}
return records;
}
示例8: test1
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
@Test
public void test1() {
BAMRecordView view = new BAMRecordView(new byte[1024]);
view.setReadName("readName");
view.setFlags(4);
view.setRefID(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
view.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START);
view.setMappingScore(SAMRecord.NO_MAPPING_QUALITY);
view.setCigar(new Cigar());
view.setMateRefID(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX);
view.setMateAlStart(SAMRecord.NO_ALIGNMENT_START);
view.setInsertSize(0);
view.setBases("A".getBytes());
view.setQualityScores(new byte[] { 0 });
view.addTag(SAMTagUtil.getSingleton().AM, new byte[] { 'c', 0 }, 0, 1);
view.finish();
SAMFileHeader samHeader = new SAMFileHeader();
BAMRecordCodec bc = new BAMRecordCodec(samHeader);
bc.setInputStream(new ByteArrayInputStream(view.buf));
SAMRecord record = bc.decode();
assertThat(record.getReadName(), is("readName"));
assertThat(record.getFlags(), is(4));
assertThat(record.getReferenceIndex(), is(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX));
assertThat(record.getAlignmentStart(), is(SAMRecord.NO_ALIGNMENT_START));
assertThat(record.getMappingQuality(), is(SAMRecord.NO_MAPPING_QUALITY));
assertThat(record.getCigar().getCigarElements().size(), is(0));
assertThat(record.getMateReferenceIndex(), is(SAMRecord.NO_ALIGNMENT_REFERENCE_INDEX));
assertThat(record.getMateAlignmentStart(), is(SAMRecord.NO_ALIGNMENT_START));
assertThat(record.getInferredInsertSize(), is(0));
assertThat(record.getReadString(), is("A"));
assertThat(record.getBaseQualityString(), is("!"));
Object amTag = record.getAttribute("AM");
assertTrue(amTag instanceof Byte);
Byte amValue = (Byte) amTag;
assertThat(amValue, equalTo((byte) 0));
}
示例9: initialize
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
@Override
public void initialize(InputSplit spl, TaskAttemptContext ctx) throws IOException {
// This method should only be called once (see Hadoop API). However,
// there seems to be disagreement between implementations that call
// initialize() and Hadoop-BAM's own code that relies on
// {@link BAMInputFormat} to call initialize() when the reader is
// created. Therefore we add this check for the time being.
if (isInitialized)
close();
isInitialized = true;
final Configuration conf = ContextUtil.getConfiguration(ctx);
final FileVirtualSplit split = (FileVirtualSplit) spl;
final Path file = split.getPath();
final FileSystem fs = file.getFileSystem(conf);
this.stringency = SAMHeaderReader.getValidationStringency(conf);
final FSDataInputStream in = fs.open(file);
codec = new BAMRecordCodec(SAMHeaderReader.readSAMHeaderFrom(in, conf));
in.seek(0);
bci = new BlockCompressedInputStream(
new WrapSeekable<FSDataInputStream>(in, fs.getFileStatus(file).getLen(), file));
final long virtualStart = split.getStartVirtualOffset();
fileStart = virtualStart >>> 16;
virtualEnd = split.getEndVirtualOffset();
bci.seek(virtualStart);
codec.setInputStream(bci);
if (GaeaBamInputFormat.DEBUG_BAM_SPLITTER) {
final long recordStart = virtualStart & 0xffff;
System.err.println(
"XXX inizialized BAMRecordReader byte offset: " + fileStart + " record offset: " + recordStart);
}
}
示例10: SortingSAMRecordCollection
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
private SortingSAMRecordCollection(SAMRecord[] recordArray, SAMFileHeader header, java.util.Comparator<SAMRecord> comparator, int maxRecordsInRAM, String tempDir) {
reads = SortingCollection2.newInstance(recordArray, SAMRecord.class, new BAMRecordCodec(header), comparator, maxRecordsInRAM, new File(tempDir));
}
示例11: Codec
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
Codec(final int numRecords, final BAMRecordCodec bamCodec) {
this.numRecords = numRecords;
this.bamCodec = bamCodec;
}
示例12: RandSamRecordCodec
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
RandSamRecordCodec(SAMFileHeader header)
{
this.header=header;
this.bamRecordCodec=new BAMRecordCodec(this.header);
}
示例13: doWork
import htsjdk.samtools.BAMRecordCodec; //导入依赖的package包/类
@Override
public int doWork(List<String> args) {
SamReader in=null;
SAMFileWriter out=null;
SAMRecordIterator iter=null;
CloseableIterator<SAMRecord> iter2=null;
SortingCollection<SAMRecord> sorter=null;
try
{
in = openSamReader(oneFileOrNull(args));
final SAMFileHeader header= in.getFileHeader();
final BAMRecordCodec bamRecordCodec=new BAMRecordCodec(header);
final RefNameComparator refNameComparator=new RefNameComparator();
sorter =SortingCollection.newInstance(
SAMRecord.class,
bamRecordCodec,
refNameComparator,
this.writingSortingCollection.getMaxRecordsInRam(),
this.writingSortingCollection.getTmpPaths()
);
sorter.setDestructiveIteration(true);
final SAMSequenceDictionaryProgress progress=new SAMSequenceDictionaryProgress(header);
iter = in.iterator();
while(iter.hasNext())
{
sorter.add( progress.watch(iter.next()));
}
in.close();in=null;
sorter.doneAdding();
final SAMFileHeader header2=header.clone();
header2.addComment(getProgramName()+" "+getVersion()+" "+getProgramCommandLine());
header2.setSortOrder(SortOrder.unsorted);
out = this.writingBamArgs.openSAMFileWriter(outputFile,header2, true);
iter2 = sorter.iterator();
while(iter2.hasNext())
{
out.addAlignment(iter2.next());
}
out.close();out=null;
sorter.cleanup();
progress.finish();
LOG.info("done");
return RETURN_OK;
}
catch(Exception err)
{
LOG.error(err);
return -1;
}
finally
{
CloserUtil.close(iter2);
CloserUtil.close(iter);
CloserUtil.close(out);
CloserUtil.close(in);
}
}