]> git.donarmstrong.com Git - rsem.git/blob - PolyARules.h
For genome BAM, modified MD tag accordingly
[rsem.git] / PolyARules.h
1 #ifndef POLYARULES
2 #define POLYARULES
3
4 #include<cstdio>
5 #include<cstdlib>
6 #include<cassert>
7 #include<set>
8 #include<cstring>
9 #include<fstream>
10
11 /**
12 Isoform id starts from 1 !
13 */
14
15 class PolyARules {
16 public:
17         PolyARules() {
18                 polyAChoice = 0;
19                 polyALen = 0;
20                 exceptionList.clear();
21         }
22
23         //Assume parameters are valid here
24         PolyARules(int polyAChoice, int polyALen, char* exceptionF) {
25                 this->polyAChoice = polyAChoice;
26                 this->polyALen =  polyALen;
27
28                 if (polyAChoice == 2) {
29                         exceptionList.clear();
30
31                         std::string transcript_id;
32                         std::ifstream fin(exceptionF);
33                         if (!fin.is_open()) { fprintf(stderr, "Cannot open %s! It may not exist.\n", exceptionF); exit(-1); }
34
35                         while (fin>> transcript_id) {
36                                 exceptionList.insert(transcript_id);
37                         }
38
39                         fin.close();
40                 }
41         }
42
43         //get the length of padding poly As
44         int getLenAt(const std::string& transcript_id) {
45                 switch(polyAChoice) {
46                 case 0 : return polyALen;
47                 case 1 : return 0;
48                 case 2 : iter = exceptionList.find(transcript_id);
49                                  return (iter == exceptionList.end() ? polyALen : 0);
50                 default : assert(false);
51                 }
52         }
53
54 private:
55         int polyAChoice; // 0, pad; 1, do not pad; 2 pad all but those in exceptionList
56         int polyALen;
57         std::set<std::string> exceptionList; // exception list of transcript_ids
58         std::set<std::string>::iterator iter;
59 };
60
61 #endif