3212 |
05 May 14 |
peter |
1 |
#ifndef theplu_yat_utility_cigar |
3212 |
05 May 14 |
peter |
2 |
#define theplu_yat_utility_cigar |
3212 |
05 May 14 |
peter |
3 |
|
3212 |
05 May 14 |
peter |
// $Id$ |
3212 |
05 May 14 |
peter |
5 |
|
3212 |
05 May 14 |
peter |
6 |
/* |
4359 |
23 Aug 23 |
peter |
Copyright (C) 2014, 2015, 2018, 2020, 2023 Peter Johansson |
3212 |
05 May 14 |
peter |
8 |
|
3212 |
05 May 14 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
3212 |
05 May 14 |
peter |
10 |
|
3212 |
05 May 14 |
peter |
The yat library is free software; you can redistribute it and/or |
3212 |
05 May 14 |
peter |
modify it under the terms of the GNU General Public License as |
3212 |
05 May 14 |
peter |
published by the Free Software Foundation; either version 3 of the |
3212 |
05 May 14 |
peter |
License, or (at your option) any later version. |
3212 |
05 May 14 |
peter |
15 |
|
3212 |
05 May 14 |
peter |
The yat library is distributed in the hope that it will be useful, |
3212 |
05 May 14 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
3212 |
05 May 14 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3212 |
05 May 14 |
peter |
General Public License for more details. |
3212 |
05 May 14 |
peter |
20 |
|
3212 |
05 May 14 |
peter |
You should have received a copy of the GNU General Public License |
3751 |
17 Oct 18 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
3212 |
05 May 14 |
peter |
23 |
*/ |
3212 |
05 May 14 |
peter |
24 |
|
3212 |
05 May 14 |
peter |
// This file defines some PP macro for CIGAR |
3212 |
05 May 14 |
peter |
26 |
|
3212 |
05 May 14 |
peter |
27 |
|
3212 |
05 May 14 |
peter |
28 |
#include "config_public.h" |
3212 |
05 May 14 |
peter |
29 |
|
3212 |
05 May 14 |
peter |
// allow inclusion of config_bam.h so this file is available also without bam.h |
3888 |
25 Mar 20 |
peter |
31 |
#ifdef YAT_HAVE_HTSLIB |
3888 |
25 Mar 20 |
peter |
32 |
#include <htslib/sam.h> |
3414 |
30 Apr 15 |
peter |
33 |
#else // if sam.h is not available #define CIGAR |
4005 |
15 Oct 20 |
peter |
34 |
#include <cstdint> // needed for int8_t |
3212 |
05 May 14 |
peter |
/// describe how CIGAR operation/length is packed into a 32-bit |
3212 |
05 May 14 |
peter |
36 |
#define BAM_CIGAR_SHIFT 4 |
3212 |
05 May 14 |
peter |
/// operation is described in four lowest bits |
3212 |
05 May 14 |
peter |
38 |
#define BAM_CIGAR_MASK ((1 << BAM_CIGAR_SHIFT) - 1) |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: M = match or mismatch |
3212 |
05 May 14 |
peter |
40 |
#define BAM_CMATCH 0 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: I = insertion to the reference |
3212 |
05 May 14 |
peter |
42 |
#define BAM_CINS 1 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: D = deletion from the reference |
3212 |
05 May 14 |
peter |
44 |
#define BAM_CDEL 2 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: N = skip on the reference (e.g. spliced alignment) |
3212 |
05 May 14 |
peter |
46 |
#define BAM_CREF_SKIP 3 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: S = clip on the read with clipped sequence |
3212 |
05 May 14 |
peter |
/// present in qseq |
3212 |
05 May 14 |
peter |
49 |
#define BAM_CSOFT_CLIP 4 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: H = clip on the read with clipped sequence trimmed off |
3212 |
05 May 14 |
peter |
51 |
#define BAM_CHARD_CLIP 5 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: P = padding |
3212 |
05 May 14 |
peter |
53 |
#define BAM_CPAD 6 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: equals = match |
3212 |
05 May 14 |
peter |
55 |
#define BAM_CEQUAL 7 |
3212 |
05 May 14 |
peter |
/// \abstract CIGAR: X = mismatch |
3212 |
05 May 14 |
peter |
57 |
#define BAM_CDIFF 8 |
3212 |
05 May 14 |
peter |
58 |
#endif // end of YAT_HAVE_LIBBAM |
3212 |
05 May 14 |
peter |
59 |
|
3306 |
21 Aug 14 |
peter |
// BAM_CBACK is not defined in old versions of bam.h |
3306 |
21 Aug 14 |
peter |
61 |
#ifndef BAM_CBACK |
3306 |
21 Aug 14 |
peter |
62 |
#define BAM_CBACK 9 |
3306 |
21 Aug 14 |
peter |
63 |
#endif |
3306 |
21 Aug 14 |
peter |
64 |
|
3212 |
05 May 14 |
peter |
// backport #defines from samtools 0.1.19 |
3212 |
05 May 14 |
peter |
66 |
#ifndef BAM_CIGAR_STR |
3212 |
05 May 14 |
peter |
67 |
#define BAM_CIGAR_STR "MIDNSHP=XB" |
3212 |
05 May 14 |
peter |
// lookup table used in bam_cigar_type |
3212 |
05 May 14 |
peter |
69 |
#define BAM_CIGAR_TYPE 0x3C1A7 |
3212 |
05 May 14 |
peter |
70 |
|
3212 |
05 May 14 |
peter |
/// index of operation in range [0, 9], see below. |
3212 |
05 May 14 |
peter |
72 |
#define bam_cigar_op(c) ((c)&BAM_CIGAR_MASK) |
3212 |
05 May 14 |
peter |
// length of the operation |
3212 |
05 May 14 |
peter |
74 |
#define bam_cigar_oplen(c) ((c)>>BAM_CIGAR_SHIFT) |
3212 |
05 May 14 |
peter |
// char describing the operation, see column 2 in table below |
3212 |
05 May 14 |
peter |
76 |
#define bam_cigar_opchr(c) (BAM_CIGAR_STR[bam_cigar_op(c)]) |
3212 |
05 May 14 |
peter |
// Create a cigar element with length l and operation o |
3212 |
05 May 14 |
peter |
78 |
#define bam_cigar_gen(l, o) ((l)<<BAM_CIGAR_SHIFT|(o)) |
3212 |
05 May 14 |
peter |
// Returns a two-bits number describing the type of operation. The |
3212 |
05 May 14 |
peter |
// first bit, bam_cigar_type & 1, (4th column in table below) is 1 iff |
3212 |
05 May 14 |
peter |
// operation consumes query sequence. The second bit, bam_cigar_type & |
3212 |
05 May 14 |
peter |
// 2, (3rd column below) is 1 iff operation consumes reference |
3212 |
05 May 14 |
peter |
// sequence. |
4334 |
25 Mar 23 |
peter |
84 |
// |
4334 |
25 Mar 23 |
peter |
// CIGAR Type Reference Query String |
4334 |
25 Mar 23 |
peter |
// BAM_CMATCH 3 1 1 M |
4334 |
25 Mar 23 |
peter |
// BAM_CINS 1 0 1 I |
4334 |
25 Mar 23 |
peter |
// BAM_CDEL 2 1 0 D |
4334 |
25 Mar 23 |
peter |
// BAM_CREF_SKIP 2 1 0 N |
4334 |
25 Mar 23 |
peter |
// BAM_CSOFT_CLIP 1 0 1 S |
4334 |
25 Mar 23 |
peter |
// BAM_CHARD_CLIP 0 0 0 H |
4334 |
25 Mar 23 |
peter |
// BAM_CPAD 0 0 0 P |
4334 |
25 Mar 23 |
peter |
// BAM_CEQUAL 3 1 1 = |
4334 |
25 Mar 23 |
peter |
// BAM_CDIFF 3 1 1 X |
4334 |
25 Mar 23 |
peter |
// BAM_CBACK 0 0 0 B |
3212 |
05 May 14 |
peter |
96 |
#define bam_cigar_type(o) (BAM_CIGAR_TYPE>>((o)<<1)&3) |
3212 |
05 May 14 |
peter |
97 |
#endif // end of backport |
3212 |
05 May 14 |
peter |
98 |
|
4003 |
15 Oct 20 |
peter |
99 |
namespace theplu { |
4003 |
15 Oct 20 |
peter |
100 |
namespace yat { |
4003 |
15 Oct 20 |
peter |
101 |
namespace utility { |
4003 |
15 Oct 20 |
peter |
102 |
|
4003 |
15 Oct 20 |
peter |
103 |
/** |
4003 |
15 Oct 20 |
peter |
The inverse of BAM_CIGAR_STR[x], where BAM_CIGAR_STR is |
4003 |
15 Oct 20 |
peter |
"MIDNSHP=XB". |
4003 |
15 Oct 20 |
peter |
106 |
|
4003 |
15 Oct 20 |
peter |
\throws if input is not one of "MIDNSHP=XB". |
4003 |
15 Oct 20 |
peter |
108 |
|
4003 |
15 Oct 20 |
peter |
\since New in yat 0.19 |
4003 |
15 Oct 20 |
peter |
110 |
*/ |
4003 |
15 Oct 20 |
peter |
111 |
int8_t cigar_table(unsigned char c); |
4003 |
15 Oct 20 |
peter |
112 |
|
4003 |
15 Oct 20 |
peter |
113 |
}}} // end of namespace utility, yat and theplu |
4003 |
15 Oct 20 |
peter |
114 |
|
3212 |
05 May 14 |
peter |
115 |
#endif // end of file |