annotate PsiCLASS-1.0.2/support.hpp @ 0:903fc43d6227 draft default tip

Uploaded
author lsong10
date Fri, 26 Mar 2021 16:52:45 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
1 // The class that deals the number of alignments supporting blocks or edges
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
2 #ifndef _LSONG_RSCAF_SUPPORT_HEADER
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
3 #define _LSONG_RSCAF_SUPPORT_HEADER
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
4
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
5 extern int minimumSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
6
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
7 class Support
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
8 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
9 private:
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
10 int uniqSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
11 int multiSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
12
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
13 int plusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
14 int minusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
15
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
16 int clipSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
17 int nmSum ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
18 double multiSupportCoefficient ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
19
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
20 int64_t leftPos, rightPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
21 int coordCnt ; // Record how many coordinates showed up.
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
22 int64_t prevCoord ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
23 public:
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
24 Support()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
25 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
26 uniqSupport = multiSupport = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
27 plusSupport = minusSupport = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
28 leftPos = rightPos = -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
29 multiSupportCoefficient = 1.0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
30 nmSum = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
31 coordCnt = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
32 prevCoord = -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
33 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
34
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
35 ~Support()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
36 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
37 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
38
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
39 void Add( Alignments &align, bool ignoreCoord = false )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
40 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
41 if ( align.IsUnique() )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
42 ++uniqSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
43 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
44 ++multiSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
45
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
46 int strand = align.GetStrand() ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
47 if ( strand == 1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
48 ++plusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
49 else if ( strand == -1 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
50 ++minusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
51 int nm = align.GetFieldI( "NM" ) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
52 if ( nm >= 0 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
53 nmSum += nm ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
54
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
55 if ( !ignoreCoord )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
56 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
57 if ( leftPos == -1 || align.segments[0].a < leftPos )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
58 leftPos = align.segments[0].a ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
59 if ( align.segments[ align.segCnt - 1 ].b > rightPos )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
60 rightPos = align.segments[ align.segCnt - 1 ].b ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
61
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
62 if ( align.segments[0].a != prevCoord ) // This makes sense when the coordinates are sorted
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
63 ++coordCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
64 else if ( align.GetFieldZ( "SA" ) != NULL )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
65 ++coordCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
66 prevCoord = align.segments[0].a ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
67 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
68 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
69
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
70 void Add( Support &in )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
71 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
72 uniqSupport += in.uniqSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
73 multiSupport += in.multiSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
74
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
75 plusSupport += in.plusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
76 minusSupport += in.minusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
77
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
78 nmSum += in.nmSum ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
79
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
80 if ( in.leftPos != -1 && ( leftPos == -1 || in.leftPos < leftPos ) )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
81 leftPos = in.leftPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
82 if ( in.rightPos > rightPos )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
83 rightPos = in.rightPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
84
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
85 prevCoord = prevCoord > in.prevCoord ? prevCoord : in.prevCoord ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
86 coordCnt += in.coordCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
87 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
88
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
89 bool IsGood()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
90 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
91 if ( uniqSupport < 0.1 * ( uniqSupport + multiSupport ) || uniqSupport == 0 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
92 return false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
93 if ( nmSum / ( uniqSupport + multiSupport ) >= 2.5 )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
94 return false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
95 return true ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
96 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
97
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
98 bool IsUnique()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
99 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
100 if ( uniqSupport < 0.95 * ( uniqSupport + multiSupport ) )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
101 return false ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
102 return true ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
103 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
104
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
105 int GetCount()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
106 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
107 return (int)( uniqSupport + multiSupportCoefficient * multiSupport + 1e-6) ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
108 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
109
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
110 int GetUniqCount()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
111 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
112 return uniqSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
113 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
114
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
115 int GetStrand()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
116 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
117 if ( plusSupport == minusSupport )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
118 return 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
119 else if ( plusSupport > minusSupport )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
120 return 1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
121 else
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
122 return -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
123 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
124
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
125 int GetLeftMostPos()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
126 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
127 return leftPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
128 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
129
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
130 int GetRightMostPos()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
131 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
132 return rightPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
133 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
134
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
135 int GetCoordCnt()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
136 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
137 return coordCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
138 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
139
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
140 void operator=( const Support &in )
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
141 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
142 uniqSupport = in.uniqSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
143 multiSupport = in.multiSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
144
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
145 plusSupport = in.plusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
146 minusSupport = in.minusSupport ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
147
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
148 nmSum = in.nmSum ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
149
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
150 leftPos = in.leftPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
151 rightPos = in.rightPos ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
152
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
153 multiSupportCoefficient = in.multiSupportCoefficient ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
154
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
155 prevCoord = in.prevCoord ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
156 coordCnt = in.coordCnt ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
157 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
158
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
159 void Clear()
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
160 {
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
161 uniqSupport = multiSupport = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
162 plusSupport = minusSupport = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
163 nmSum = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
164 leftPos = rightPos = -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
165 multiSupportCoefficient = 1.0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
166
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
167 coordCnt = 0 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
168 prevCoord = -1 ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
169 }
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
170 } ;
903fc43d6227 Uploaded
lsong10
parents:
diff changeset
171 #endif