-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsignature.cpp
153 lines (133 loc) · 5.2 KB
/
signature.cpp
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
#include "signature.h"
#include <string.h>
#include "crelib/crelib.h"
#include <algorithm>
using namespace std;
Signature::Signature()
:Type(0), Tech(0), SupportedSV(0), Segment(), CN(-1), Covered(false), TemplateName(""), Quality(0), Length(0), InvLeft(false), InvRight(false), Artificial(false)DEBUG_CODE(COMMA MergeString(""))
{}
Signature::Signature(int Type, int Tech, int SupportedSV, int Begin, int End, string TemplateName, double Quality, const char * InsBases)
:Type(Type), Tech(Tech), SupportedSV(SupportedSV), Segment({Begin,End,InsBases}), CN(-1), Covered(false), TemplateName(TemplateName), Quality(Quality), Length(End-Begin), InvLeft(false), InvRight(false), Artificial(false)DEBUG_CODE(COMMA MergeString("")){}
Signature::Signature(int Type, int Tech, int SupportedSV, int Begin, int End, string TemplateName, double Quality, Segment Read1, Segment Read2, int ALength)
:Type(Type), Tech(Tech), SupportedSV(SupportedSV), Segment({Begin,End}), CN(-1), Covered(false), TemplateName(TemplateName), Quality(Quality), Segments(), Length(ALength), InvLeft(false), InvRight(false), Artificial(false)DEBUG_CODE(COMMA MergeString("")) {Segments.push_back(Read1), Segments.push_back(Read2);}
Signature::Signature(int Type, int Tech, int SupportedSV, int Begin, int End, string TemplateName, double Quality, vector<Segment> Segments)
:Type(Type), Tech(Tech), SupportedSV(SupportedSV), Segment({Begin,End}), CN(-1), Covered(false), TemplateName(TemplateName), Quality(Quality), Segments(Segments), Length(End-Begin), InvLeft(false), InvRight(false), Artificial(false)DEBUG_CODE(COMMA MergeString("")) {}
const char* Signature::SVTypeNames[]={"DEL","INS","DUP","INV"};
void Signature::setCN(int cn)
{
CN=cn;
}
void Signature::setInvLeft(bool b)
{
InvLeft=b;
}
void Signature::setInvRight(bool b)
{
InvRight=b;
}
void Signature::setID(unsigned d)
{
ID=d;
}
bool Signature::operator<(const Signature &Other) const
{
// char AL[100], BL[100];
// sprintf(AL,"%d",this->Length);
// sprintf(BL,"%d",Other.Length);
// int cmp=strcmp(AL,BL);
if (this->Begin<Other.Begin) return true;
else if (this->Begin>Other.Begin) return false;
else if (this->Length<Other.Length) return true;
else if (this->Length>Other.Length) return false;
else if (this->Quality>Other.Quality) return true;
else if (this->Quality<Other.Quality) return false;
else if (this->InsBases<Other.InsBases) return true;
else if (this->InsBases>Other.InsBases) return false;
// else if (cmp<0) return true;
// else if (cmp>0) return false;
else return this->TemplateName<Other.TemplateName;
}
Signature::operator std::string()
{
return TemplateName+", "+std::string(*((Segment*)this))+", "+std::to_string(Type)+" "+std::to_string(Tech)+" "+std::to_string(SupportedSV)+" "+std::to_string(CN)+" "+std::to_string(Covered)+" "+std::to_string(Tech)+" "+std::to_string(Length)+" "+std::to_string(Quality)+" "+std::to_string(Artificial);
}
bool Signature::operator==(const Signature &Other) const
{
return Tech==Other.Tech && SupportedSV==Other.SupportedSV && TemplateName==Other.TemplateName && Begin==Other.Begin && End==Other.End && Segments==Other.Segments;
}
Segment::Segment(int Begin,int End, const char * CInsBases)
:Begin(Begin),End(End),InsBases(CInsBases){}
bool Segment::operator==(const Segment & Other) const
{
return Begin==Other.Begin && End==Other.End && InsBases==Other.InsBases;
}
bool Segment::operator<(const Segment & Other) const
{
return Begin<Other.Begin;
}
Segment::operator std::string()
{
return "("+std::to_string(Begin)+", "+std::to_string(End)+"), ("+InsBases+")";
}
int precisionLevel(const Signature &A)
{
if (A.Tech==1 && A.Type==1) return 0;//drp sig, imprecise pricision
if (A.Tech==0) return 1;//SMRT CIGAR and CLIP, vague precision
return 2;//NGS CIGAR and clip, precise precision
}
int bestPrecision(const Signature &A,const Signature &B)
{
return MAX(precisionLevel(A),precisionLevel(B));
}
int worstPrecision(const Signature &A,const Signature &B)
{
return MIN(precisionLevel(A),precisionLevel(B));
}
std::tuple<int,int> SegmentSet::getInvolved(int Start, int End)
{
tuple<int,int> Result={0,0};
int SS=0, SE=Segments.size(), Mid;
while (SS<SE-1)
{
Mid=(SS+SE)/2;
if (MaxEnds[Mid]<Start) SS=Mid;
else SE=Mid;
}
get<0>(Result)=SS;
SS=0, SE=Segments.size();
while (SS<SE-1)
{
Mid=(SS+SE)/2;
if (Segments[Mid].Begin>End) SE=Mid;
else SS=Mid;
}
get<1>(Result)=SE;
return Result;
}
void SegmentSet::add(int Begin, int End)
{
Segments.push_back(Segment(Begin,End));
}
void SegmentSet::merge(SegmentSet& Other)
{
Segments.insert(Segments.end(),make_move_iterator(Other.Segments.begin()),make_move_iterator(Other.Segments.end()));
}
void SegmentSet::sortNStat()
{
sort(Segments.begin(),Segments.begin()+Segments.size());
if (Segments.size()>0)
{
MaxEnds.resize(Segments.size());
int MaxEnd=Segments[0].End;
for (int i=0;i<Segments.size();++i)
{
MaxEnd=MAX(MaxEnd,Segments[i].End);
MaxEnds[i]=MaxEnd;
}
}
}
Segment& SegmentSet::operator[](unsigned i)
{
return Segments[i];
}
SegmentSet::SegmentSet():Segments(),MaxEnds(){}