-
Notifications
You must be signed in to change notification settings - Fork 17
/
AnnotationResult.h
113 lines (102 loc) · 3.3 KB
/
AnnotationResult.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
#ifndef _ANNOTATIONRESULT_H_
#define _ANNOTATIONRESULT_H_
#include "Priority.h"
/**
* For each gene, we use AnnotationResult to store all annotation results.
*/
class AnnotationResult{
public:
AnnotationResult() {
this->clear();
}
void clear() {
this->gene = NULL;
this->type.clear();
this->detail.clear();
};
void add(const Gene& g){
if (this->type.size() != 0) {
// we usually record gene name and its strand first
fprintf(stderr, "Something weired happen\n");
}
this->gene = &g;
};
void add(const AnnotationType& t) {
this->type.push_back(t);
};
// add extra details such as "(CCT/Pro->CAT/His)" to the last element
void addDetail(const AnnotationType& t, const std::string& s) {
this->detail[t] = s;
};
void sortByPriority(const Priority& p) {
Comparator compareFunction(p);
// for (size_t i = 0; i < this->type.size(); ++i) {
// fprintf(stderr, "%zu -> %s ", i, AnnotationString[type[i]]);
// p.getPriority(type[i]).dump();
// };
// puts("-----");
// fprintf(stderr, " sort %d elements: \n", this->type.end() - this->type.begin());
std::sort(this->type.begin(), this->type.end(), compareFunction);
// for (size_t i = 0; i < this->type.size(); ++i) {
// fprintf(stderr, "%zu -> %s ", i, AnnotationString[type[i]]);
// p.getPriority(type[i]).dump();
// };
// exit(1);
};
//////////////////////////////////////////////////////////////////////
// getters
const Gene& getGene() const {
return (*this->gene);
};
const std::string& getGeneName() const{
return this->gene->geneName;
};
const std::string& getTranscriptName() const {
return this->gene->transcriptName;
};
const std::string getFullName() const {
return this->gene->geneName + "/" + this->gene->transcriptName;
};
const size_t getExonNumber() const {
return this->gene->getExonNumber();
};
const std::vector<AnnotationType>& getType() const{
return this->type;
};
const std::map<AnnotationType, std::string>& getDetail() const {
return this->detail;
};
bool hasForwardStrand() const {
return this->gene->forwardStrand;
};
void dump() const { //debugging code
printf("[ %s ]", gene->geneName.c_str());
for (size_t i = 0; i < type.size(); ++i) {
printf(" %s ", AnnotationString[type[i]]);
};
puts("");
};
private:
const Gene* gene;
std::vector<AnnotationType> type;
std::map<AnnotationType, std::string> detail;
struct Comparator{
Comparator(const Priority& p): priority(p) {
//fprintf(stderr, "create priority comparator\n");
};
bool operator() (const AnnotationType& t1,
const AnnotationType& t2) const {
// this->priority.getPriority(t1) .dump();
// this->priority.getPriority(t2) .dump();
// fprintf(stderr, "do comparing\n");
// const Priority::Level& l1 = this->priority.getPriority(t1);
// const Priority::Level& l2 = this->priority.getPriority(t2);
// return (l1 < l2 );
return (this->priority.getPriority(t1)) < (this->priority.getPriority(t2));
};
private:
const Priority& priority;
};
// int topPriorityIndex; // this->type[this->topPriorityIndex] has top priority; <0, means unknown, will remove soon
}; // end AnnotationResult
#endif /* _ANNOTATIONRESULT_H_ */