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
|
#ifndef POLYARULES
#define POLYARULES
#include<cstdio>
#include<cstdlib>
#include<cassert>
#include<set>
#include<cstring>
#include<fstream>
/**
Isoform id starts from 1 !
*/
class PolyARules {
public:
PolyARules() {
polyAChoice = 0;
polyALen = 0;
exceptionList.clear();
}
//Assume parameters are valid here
PolyARules(int polyAChoice, int polyALen, char* exceptionF) {
this->polyAChoice = polyAChoice;
this->polyALen = polyALen;
if (polyAChoice == 2) {
exceptionList.clear();
std::string transcript_id;
std::ifstream fin(exceptionF);
if (!fin.is_open()) { fprintf(stderr, "Cannot open %s! It may not exist.\n", exceptionF); exit(-1); }
while (fin>> transcript_id) {
exceptionList.insert(transcript_id);
}
fin.close();
}
}
//get the length of padding poly As
int getLenAt(const std::string& transcript_id) {
switch(polyAChoice) {
case 0 : return polyALen;
case 1 : return 0;
case 2 : iter = exceptionList.find(transcript_id);
return (iter == exceptionList.end() ? polyALen : 0);
default : assert(false);
}
}
private:
int polyAChoice; // 0, pad; 1, do not pad; 2 pad all but those in exceptionList
int polyALen;
std::set<std::string> exceptionList; // exception list of transcript_ids
std::set<std::string>::iterator iter;
};
#endif
|