Return a SAM record of the specified match. */
| 204 | |
| 205 | /** Return a SAM record of the specified match. */ |
| 206 | static SAMRecord toSAM(const FastaIndex& faIndex, |
| 207 | const FMIndex& fmIndex, const Match& m, bool rc, |
| 208 | unsigned qlength) |
| 209 | { |
| 210 | SAMRecord a; |
| 211 | if (m.size() == 0) { |
| 212 | // No hit. |
| 213 | a.rname = "*"; |
| 214 | a.pos = -1; |
| 215 | a.flag = SAMAlignment::FUNMAP; |
| 216 | a.mapq = 0; |
| 217 | a.cigar = "*"; |
| 218 | } else { |
| 219 | FastaIndex::SeqPos seqPos = faIndex[fmIndex[m.l]]; |
| 220 | a.rname = seqPos.get<0>().id; |
| 221 | a.pos = seqPos.get<1>(); |
| 222 | a.flag = rc ? SAMAlignment::FREVERSE : 0; |
| 223 | |
| 224 | // Set the mapq to the alignment score. |
| 225 | assert(m.qstart < m.qend); |
| 226 | unsigned matches = m.qend - m.qstart; |
| 227 | assert (m.num != 0); |
| 228 | a.mapq = m.size() > 1 || m.num > 1 ? 0 : min(matches, 254U); |
| 229 | |
| 230 | ostringstream ss; |
| 231 | if (m.qstart > 0) |
| 232 | ss << m.qstart << 'S'; |
| 233 | ss << matches << 'M'; |
| 234 | if (m.qend < qlength) |
| 235 | ss << qlength - m.qend << 'S'; |
| 236 | a.cigar = ss.str(); |
| 237 | } |
| 238 | a.mrnm = "*"; |
| 239 | a.mpos = -1; |
| 240 | a.isize = 0; |
| 241 | return a; |
| 242 | } |
| 243 | |
| 244 | /** Return the position of the current contig. */ |
| 245 | static size_t getMyPos(const Match& m, const FastaIndex& faIndex, |