-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathBasicEndpoint.h
118 lines (96 loc) · 2.59 KB
/
BasicEndpoint.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
#ifndef BASIC_ENDPOINT_H_
#define BASIC_ENDPOINT_H_
/*
An endpoint is one of the ends of a fragment, where
a fragment is an exact match between two genomes.
So, a fragment is a 2D object that has a position and length,
and an endpoint is 1D, where it just has a position.
A fragment may be associated with a score that is the score
of the fragment in a maximum scoring chain. When finding a
maximum scoring chain using priority search trees, one must
be able to set the score of a fragment when indexing solely
a point.
*/
class Coordinate {
private:
UInt x;
UInt y;
public:
UInt GetX() const { return x;}
UInt GetY() const { return y;}
UInt SetX(UInt _x) { return (x = _x);}
UInt SetY(UInt _y) { return (y = _y);}
int operator<(const Coordinate &rhs) const {
if (x == rhs.GetX()) return y < rhs.GetY();
else return x < rhs.GetX();
}
int operator<=(const Coordinate &rhs) const {
return (*this.x < rhs.x) or (x == rhs.x && y <= rhs.y);
}
int Equals(const Coordinate &rhs) const {
return (x == rhs.GetX() and y == rhs.GetY());
}
//
// Synonym for Equals.
//
int operator==(const Coordinate &rhs) const {
return this->Equals(rhs);
}
Coordinate &operator=(const Coordinate &rhs) {
this->x = rhs.x;
this->y = rhs.y;
return *this;
}
};
template<typename T_ScoredFragment>
class BasicEndpoint {
T_ScoredFragment *fragmentPtr;
public:
enum WhichEnd {Start, End};
// typedef Coordinate KeyType;
typedef UInt KeyType;
class LessThan {
public:
int operator()(const BasicEndpoint<T_ScoredFragment> &lhs, const BasicEndpoint<T_ScoredFragment> &rhs) const {
return lhs.p <= rhs.p;
}
};
public:// private:
Coordinate p;
WhichEnd side;
WhichEnd GetSide() { return side; }
void FragmentPtrToStart(T_ScoredFragment *fragment) {
p.SetX(fragment->GetX());
p.SetY(fragment->GetY());
side = Start;
fragmentPtr = fragment;
}
void FragmentPtrToEnd(T_ScoredFragment *fragment) {
p.SetX(fragment->GetX() + fragment->GetXLength());
p.SetY(fragment->GetY() + fragment->GetYLength());
side = End;
fragmentPtr = fragment;
}
int GetScore() {
return fragmentPtr->GetScore();
}
int SetScore(int score) {
return (fragmentPtr->SetScore(score));
}
T_ScoredFragment* SetScoredReference(T_ScoredFragment *_fragmentPtr) {
return (fragmentPtr = _fragmentPtr);
}
int operator<(const BasicEndpoint &rhs) const {
return p < rhs.p;
}
KeyType GetKey() {
return p.GetY();
}
T_ScoredFragment* GetFragmentPtr() {
return fragmentPtr;
}
void SetChainPrev(T_ScoredFragment *prevChainFragment) {
fragmentPtr->SetChainPrev(prevChainFragment);
}
};
#endif