4003 |
15 Oct 20 |
peter |
// $Id$ |
4003 |
15 Oct 20 |
peter |
2 |
|
4003 |
15 Oct 20 |
peter |
3 |
/* |
4003 |
15 Oct 20 |
peter |
Copyright (C) 2020 Peter Johansson |
4003 |
15 Oct 20 |
peter |
5 |
|
4003 |
15 Oct 20 |
peter |
This file is part of the yat library, http://dev.thep.lu.se/yat |
4003 |
15 Oct 20 |
peter |
7 |
|
4003 |
15 Oct 20 |
peter |
The yat library is free software; you can redistribute it and/or |
4003 |
15 Oct 20 |
peter |
modify it under the terms of the GNU General Public License as |
4003 |
15 Oct 20 |
peter |
published by the Free Software Foundation; either version 3 of the |
4003 |
15 Oct 20 |
peter |
License, or (at your option) any later version. |
4003 |
15 Oct 20 |
peter |
12 |
|
4003 |
15 Oct 20 |
peter |
The yat library is distributed in the hope that it will be useful, |
4003 |
15 Oct 20 |
peter |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
4003 |
15 Oct 20 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
4003 |
15 Oct 20 |
peter |
General Public License for more details. |
4003 |
15 Oct 20 |
peter |
17 |
|
4003 |
15 Oct 20 |
peter |
You should have received a copy of the GNU General Public License |
4003 |
15 Oct 20 |
peter |
along with yat. If not, see <http://www.gnu.org/licenses/>. |
4003 |
15 Oct 20 |
peter |
20 |
*/ |
4003 |
15 Oct 20 |
peter |
21 |
|
4003 |
15 Oct 20 |
peter |
22 |
#include <config.h> |
4003 |
15 Oct 20 |
peter |
23 |
|
4003 |
15 Oct 20 |
peter |
24 |
#include "Cigar.h" |
4003 |
15 Oct 20 |
peter |
25 |
#include "Exception.h" |
4003 |
15 Oct 20 |
peter |
26 |
|
4003 |
15 Oct 20 |
peter |
27 |
#ifdef YAT_HAVE_HTSLIB |
4003 |
15 Oct 20 |
peter |
28 |
#include <htslib/sam.h> |
4003 |
15 Oct 20 |
peter |
29 |
#endif |
4003 |
15 Oct 20 |
peter |
30 |
|
4003 |
15 Oct 20 |
peter |
31 |
#include <sstream> |
4003 |
15 Oct 20 |
peter |
32 |
|
4003 |
15 Oct 20 |
peter |
33 |
namespace theplu { |
4003 |
15 Oct 20 |
peter |
34 |
namespace yat { |
4003 |
15 Oct 20 |
peter |
35 |
namespace utility { |
4003 |
15 Oct 20 |
peter |
36 |
|
4003 |
15 Oct 20 |
peter |
37 |
int8_t cigar_table(unsigned char c) |
4003 |
15 Oct 20 |
peter |
38 |
{ |
4003 |
15 Oct 20 |
peter |
39 |
#ifdef HAVE_BAM_CIGAR_TABLE |
4003 |
15 Oct 20 |
peter |
40 |
int8_t x = bam_cigar_table[c]; |
4003 |
15 Oct 20 |
peter |
41 |
#else |
4003 |
15 Oct 20 |
peter |
// taken from sam.c in htslib 1.11 |
4003 |
15 Oct 20 |
peter |
43 |
int8_t table[256] = { |
4003 |
15 Oct 20 |
peter |
// 0 .. 47 |
4003 |
15 Oct 20 |
peter |
45 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
46 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
47 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
48 |
|
4003 |
15 Oct 20 |
peter |
// 48 .. 63 (including =) |
4003 |
15 Oct 20 |
peter |
50 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, BAM_CEQUAL, -1, -1, |
4003 |
15 Oct 20 |
peter |
51 |
|
4003 |
15 Oct 20 |
peter |
// 64 .. 79 (including MIDNHB) |
4003 |
15 Oct 20 |
peter |
53 |
-1, -1, BAM_CBACK, -1, BAM_CDEL, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
54 |
BAM_CHARD_CLIP, BAM_CINS, -1, -1, -1, BAM_CMATCH, BAM_CREF_SKIP, -1, |
4003 |
15 Oct 20 |
peter |
55 |
|
4003 |
15 Oct 20 |
peter |
// 80 .. 95 (including SPX) |
4003 |
15 Oct 20 |
peter |
57 |
BAM_CPAD, -1, -1, BAM_CSOFT_CLIP, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
58 |
BAM_CDIFF, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
59 |
|
4003 |
15 Oct 20 |
peter |
// 96 .. 127 |
4003 |
15 Oct 20 |
peter |
61 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
62 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
63 |
|
4003 |
15 Oct 20 |
peter |
// 128 .. 255 |
4003 |
15 Oct 20 |
peter |
65 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
66 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
67 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
68 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
69 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
70 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
71 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
4003 |
15 Oct 20 |
peter |
72 |
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 |
4003 |
15 Oct 20 |
peter |
73 |
}; |
4003 |
15 Oct 20 |
peter |
74 |
int8_t x = table[c]; |
4003 |
15 Oct 20 |
peter |
75 |
|
4003 |
15 Oct 20 |
peter |
76 |
#endif |
4003 |
15 Oct 20 |
peter |
77 |
if (x == -1) { |
4003 |
15 Oct 20 |
peter |
78 |
std::ostringstream os; |
4003 |
15 Oct 20 |
peter |
79 |
os << "cigar_table: invalid argument: " << c; |
4003 |
15 Oct 20 |
peter |
80 |
throw invalid_argument(os.str()); |
4003 |
15 Oct 20 |
peter |
81 |
} |
4003 |
15 Oct 20 |
peter |
82 |
return x; |
4003 |
15 Oct 20 |
peter |
83 |
} |
4003 |
15 Oct 20 |
peter |
84 |
|
4003 |
15 Oct 20 |
peter |
85 |
}}} |