A SAM alignment of a single query. */
| 19 | |
| 20 | /** A SAM alignment of a single query. */ |
| 21 | struct SAMAlignment { |
| 22 | std::string rname; |
| 23 | int pos; |
| 24 | unsigned short flag; |
| 25 | unsigned short mapq; |
| 26 | std::string cigar; |
| 27 | |
| 28 | /** Flag */ |
| 29 | enum { |
| 30 | /** the read is paired in sequencing, no matter whether it is |
| 31 | * mapped in a pair */ |
| 32 | FPAIRED = 1, |
| 33 | /** the read is mapped in a proper pair */ |
| 34 | FPROPER_PAIR = 2, |
| 35 | /** the read itself is unmapped; conflictive with FPROPER_PAIR |
| 36 | */ |
| 37 | FUNMAP = 4, |
| 38 | /** the mate is unmapped */ |
| 39 | FMUNMAP = 8, |
| 40 | /** the read is mapped to the reverse strand */ |
| 41 | FREVERSE = 16, |
| 42 | /** the mate is mapped to the reverse strand */ |
| 43 | FMREVERSE = 32, |
| 44 | /** this is read1 */ |
| 45 | FREAD1 = 64, |
| 46 | /** this is read2 */ |
| 47 | FREAD2 = 128, |
| 48 | /** not primary alignment */ |
| 49 | FSECONDARY = 256, |
| 50 | /** QC failure */ |
| 51 | FQCFAIL = 512, |
| 52 | /** optical or PCR duplicate */ |
| 53 | FDUP = 1024, |
| 54 | }; |
| 55 | |
| 56 | SAMAlignment() : |
| 57 | rname("*"), |
| 58 | pos(-1), |
| 59 | flag(FUNMAP), |
| 60 | mapq(0) { } |
| 61 | |
| 62 | /** Consturct a single-end alignment. */ |
| 63 | SAMAlignment(const Alignment& a) : |
| 64 | rname(a.contig), |
| 65 | pos(a.contig_start_pos), |
| 66 | flag(a.isRC ? FREVERSE : 0), |
| 67 | mapq(255) |
| 68 | { |
| 69 | unsigned qend = a.read_start_pos + a.align_length; |
| 70 | int clip0 = a.read_start_pos; |
| 71 | int clip1 = a.read_length - qend; |
| 72 | assert(clip1 >= 0); |
| 73 | if (a.isRC) |
| 74 | std::swap(clip0, clip1); |
| 75 | std::ostringstream s; |
| 76 | if (clip0 > 0) |
| 77 | s << clip0 << 'S'; |
| 78 | s << a.align_length << 'M'; |