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