-
Notifications
You must be signed in to change notification settings - Fork 37
/
gencode.h
168 lines (143 loc) · 4.38 KB
/
gencode.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/* The MIT License
Copyright (c) 2014 Adrian Tan <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef GENCODE_H
#define GENCODE_H
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <string>
#include <iostream>
#include "htslib/faidx.h"
#include "htslib/kstring.h"
#include "htslib/tbx.h"
#include "hts_utils.h"
#include "utils.h"
#include "interval_tree.h"
#include "variant_manip.h"
#include "genome_interval.h"
#include "tbx_ordered_reader.h"
#define GC_FT_EXON 0
#define GC_FT_CDS 1
#define GC_FT_START_CODON 2
#define GC_FT_STOP_CODON 3
#define NT_N 0
#define NT_A 1
#define NT_C 2
#define NT_G 4
#define NT_T 8
#define ALA 0
#define ARG 1
#define ASN 2
#define ASP 3
#define CYS 4
#define GLN 5
#define GLU 6
#define GLY 7
#define HIS 8
#define ILE 9
#define LEU 10
#define LYS 11
#define MET 12
#define PHE 13
#define PRO 14
#define SER 15
#define THR 16
#define TRP 17
#define TYR 18
#define VAL 19
class GENCODERecord : public Interval
{
public:
std::string gene;
int32_t feature;
std::string chrom;
char strand;
int32_t frame;
int32_t *syn; // synonymous array for sequence, defined only if CDS.
int32_t exonNo;
bool fivePrimeConservedEssentialSpliceSite;
bool threePrimeConservedEssentialSpliceSite;
bool containsStartCodon;
bool containsStopCodon;
int32_t level;
GENCODERecord(std::string& chrom, int32_t start, int32_t end, char strand,
std::string& gene, int32_t feature, int32_t frame, int32_t exonNo,
bool fivePrimeConservedEssentialSpliceSite, bool threePrimeConservedEssentialSpliceSite,
bool containsStartCodon, bool containsStopCodon,
int32_t level);
/**
* Checks if base at position position is synonymous.
*/
bool is_synonymous(int32_t pos1, char base);
/**
* Prints this GENCODE record to STDERR.
*/
void print();
/**
* Converts feature to string.
*/
void feature2string(int32_t feature, kstring_t *s);
private:
};
KHASH_MAP_INIT_STR(aadict, int32_t)
class GENCODE
{
public:
std::string gencode_gtf_file;
std::string ref_fasta_file;
faidx_t *fai;
std::map<std::string, IntervalTree*> CHROM;
std::stringstream token;
khash_t(aadict) *codon2syn;
/**
* Constructs and initialize a GENCODE object.
*/
GENCODE(std::string& gencode_gtf_file, std::string& ref_fasta_file, std::vector<GenomeInterval>& intervals);
/**
* Constructs a GENCODE object.
*/
GENCODE(std::string& gencode_gtf_file, std::string& ref_fasta_file);
/**
* Initialize a vector of intervals.
*/
void initialize(std::vector<GenomeInterval>& intervals);
/**
* Initialize a chromosome in the GENCODE tree.
*/
void initialize(std::string& chrom);
/**
* Gets overlapping intervals with chrom:start1-end1.
*/
void search(std::string& chrom, int32_t start1, int32_t end1, std::vector<Interval*>& intervals);
/**
* Splits a line into a map - PERL style.
*/
void split_gtf_attribute_field(std::map<std::string, std::string>& map, std::string& str);
/**
* Generate array for ease of checking synonymous, non synonymous SNPs.
*/
void fill_synonymous(GENCODERecord *g);
};
#endif