static void CheckRawData(const BamRecordImpl& bam) { // ensure raw data (lengths at least) matches API-facing data const uint32_t expectedNameLength = bam.Name().size() + 1; const uint32_t expectedNumCigarOps = bam.CigarData().size(); const int32_t expectedSeqLength = bam.Sequence().length(); const size_t expectedTagsLength = BamTagCodec::Encode(bam.Tags()).size(); // Name CIGAR Sequence Quals Tags // l_qname + (n_cigar * 4) + (l_qseq+1)/2 + l_qseq + << TAGS >> const int expectedTotalDataLength = expectedNameLength + (expectedNumCigarOps * 4) + (expectedSeqLength+1)/2 + expectedSeqLength + expectedTagsLength; EXPECT_TRUE((bool)bam.d_); EXPECT_EQ(expectedNameLength, bam.d_->core.l_qname); EXPECT_EQ(expectedNumCigarOps, bam.d_->core.n_cigar); EXPECT_EQ(expectedSeqLength, bam.d_->core.l_qseq); EXPECT_EQ(expectedTotalDataLength, bam.d_->l_data); }
void WriteBamRecords(BamWriter& ccsBam, unique_ptr<PbiBuilder>& ccsPbi, Results& counts, Results&& results) { counts += results; for (const auto& ccs : results) { BamRecordImpl record; TagCollection tags; stringstream name; // some defaults values record.Bin(0) .InsertSize(0) .MapQuality(255) .MatePosition(-1) .MateReferenceId(-1) .Position(-1) .ReferenceId(-1) .Flag(0) .SetMapped(false); name << *(ccs.Id.MovieName) << '/' << ccs.Id.HoleNumber << "/ccs"; vector<float> snr = { static_cast<float>(ccs.SignalToNoise.A), static_cast<float>(ccs.SignalToNoise.C), static_cast<float>(ccs.SignalToNoise.G), static_cast<float>(ccs.SignalToNoise.T) }; tags["RG"] = MakeReadGroupId(*(ccs.Id.MovieName), "CCS"); tags["zm"] = static_cast<int32_t>(ccs.Id.HoleNumber); tags["np"] = static_cast<int32_t>(ccs.NumPasses); tags["rq"] = static_cast<float>(ccs.PredictedAccuracy); tags["sn"] = snr; // TODO(lhepler) maybe remove one day tags["za"] = static_cast<float>(ccs.AvgZScore); vector<float> zScores; for (const double z : ccs.ZScores) zScores.emplace_back(static_cast<float>(z)); tags["zs"] = zScores; tags["rs"] = ccs.StatusCounts; #if DIAGNOSTICS if (ccs.Barcodes) { vector<uint16_t> bcs{ccs.Barcodes->first, ccs.Barcodes->second}; tags["bc"] = bcs; } tags["ms"] = ccs.ElapsedMilliseconds; tags["mt"] = static_cast<int32_t>(ccs.MutationsTested); tags["ma"] = static_cast<int32_t>(ccs.MutationsApplied); #endif record.Name(name.str()).SetSequenceAndQualities(ccs.Sequence, ccs.Qualities).Tags(tags); int64_t offset; ccsBam.Write(record, &offset); if (ccsPbi) ccsPbi->AddRecord(record, offset); } ccsBam.TryFlush(); }