4 * Created on: Sep 23, 2009
14 #include "random_source.h"
18 class PatternSourcePerThread;
22 SAM_FLAG_MAPPED_PAIRED = 2,
23 SAM_FLAG_UNMAPPED = 4,
24 SAM_FLAG_MATE_UNMAPPED = 8,
25 SAM_FLAG_QUERY_STRAND = 16,
26 SAM_FLAG_MATE_STRAND = 32,
27 SAM_FLAG_FIRST_IN_PAIR = 64,
28 SAM_FLAG_SECOND_IN_PAIR = 128,
29 SAM_FLAG_NOT_PRIMARY = 256,
30 SAM_FLAG_FAILS_CHECKS = 512,
31 SAM_FLAG_DUPLICATE = 1024
35 * Sink that prints lines in SAM format:
37 class SAMHitSink : public HitSink {
40 * Construct a single-stream VerboseHitSink (default)
42 SAMHitSink(OutFileBuf* out,
49 HitSink(out, PASS_HIT_DUMPS2),
50 offBase_(offBase), defaultMapq_(defaultMapq),
51 rmap_(rmap), amap_(amap), fullRef_(fullRef) { }
54 * Construct a multi-stream VerboseHitSink with one stream per
55 * reference string (see --refout)
57 SAMHitSink(size_t numOuts,
64 HitSink(numOuts, PASS_HIT_DUMPS2),
65 offBase_(offBase), defaultMapq_(defaultMapq),
66 rmap_(rmap), amap_(amap), fullRef_(fullRef) { }
69 * Append a SAM alignment to the given output stream.
71 static void append(ostream& ss,
75 const vector<string>* refnames,
82 * Append a SAM alignment for an aligned read to the given output
85 static void appendAligned(ostream& ss,
89 const vector<string>* refnames,
96 * Append a verbose, readable hit to the output stream
97 * corresponding to the hit.
99 virtual void append(ostream& ss, const Hit& h) {
100 SAMHitSink::append(ss, h, defaultMapq_, 0, _refnames, rmap_, amap_, fullRef_, offBase_);
104 * Append a verbose, readable hit to the output stream
105 * corresponding to the hit.
107 virtual void append(ostream& ss, const Hit& h, int mapq, int xms) {
108 SAMHitSink::append(ss, h, mapq, xms, _refnames, rmap_, amap_, fullRef_, offBase_);
112 * Write the SAM header lines.
114 void appendHeaders(OutFileBuf& os,
116 const vector<string>& refnames,
120 const uint32_t* plen,
130 void reportUnOrMax(PatternSourcePerThread& p,
135 * Report a verbose, human-readable alignment to the appropriate
138 virtual void reportHit(const Hit& h) {
139 reportHit(h, defaultMapq_, 0);
143 * Report a SAM alignment with the given mapping quality and XM
146 virtual void reportHit(const Hit& h, int mapq, int xms);
149 * Report a batch of SAM alignments (e.g. two mates that should be
150 * printed together) with the given mapping quality and XM field.
152 virtual void reportHits(vector<Hit>& hs,
161 virtual void reportMaxed(vector<Hit>& hs, PatternSourcePerThread& p);
166 virtual void reportUnaligned(PatternSourcePerThread& p) {
167 reportUnOrMax(p, NULL, true);
171 int offBase_; /// Add this to reference offsets before outputting.
172 /// (An easy way to make things 1-based instead of
174 int defaultMapq_; /// Default mapping quality to report when one is
176 ReferenceMap *rmap_; /// mapping to reference coordinate system.
177 AnnotationMap *amap_; ///
178 bool fullRef_; /// print full reference name, not just up to whitespace