00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _INTERVAL_H
00024 #define _INTERVAL_H
00025
00026 #include <map>
00027 #include <vector>
00028
00029 #include "global.h"
00030 #include "binomial.h"
00031 #include "gaussian.h"
00032
00033
00034
00035
00036 inline bool contains(MyNT low, MyNT high, MyNT coord)
00037 {
00038 return((coord >= low) && (coord <= high));
00039 }
00040
00041
00042
00043 class MyClusterParams;
00044 class MyPointSet;
00045
00046
00047 struct MyInterval
00048 {
00049 public:
00050 MyInterval()
00051 : start(), end(), width(), count(), pval()
00052 {}
00053
00054 MyInterval(MyNT s, MyNT e)
00055 : start(s), end(e), width(e - s), count(), pval()
00056 {}
00057
00058 MyInterval(MyNT s, MyNT e, MyNT w)
00059 : start(s), end(e), width(w), count(), pval()
00060 {}
00061
00062
00063
00064
00065 MyInterval(map< string, MyNT, ltstr >& init)
00066
00067
00068 : start(init["start"]), end(init["end"]), width(init["width"]),
00069 count(init["count"]), pval(init["pval"])
00070 {}
00071
00072 virtual ~MyInterval()
00073 {}
00074
00075 virtual bool operator==(const MyInterval& interval) const
00076 {
00077
00078 if (&interval == this)
00079 return(true);
00080 if (start != interval.start)
00081 return(false);
00082 if (end != interval.end)
00083 return(false);
00084 return(true);
00085 }
00086
00087
00088 virtual bool operator!=(const MyInterval& interval) const
00089 {
00090 return(!(*this == interval));
00091 }
00092
00093
00094 MyNT getStart() const
00095 {
00096 return(start);
00097 }
00098 void setStart(MyNT s)
00099 {
00100 start = s;
00101 setWidth();
00102 }
00103
00104 MyNT getEnd() const
00105 {
00106 return(end);
00107 }
00108 void setEnd(MyNT e)
00109 {
00110 end = e;
00111 setWidth();
00112 }
00113
00114 void setWidth()
00115 {
00116 width = end - start;
00117 }
00118
00119
00120 virtual void print(ostream& ostr) const
00121 {
00122 ostr << "Interval is pval = " << pval << ", start = " << start
00123 << ", end = " << end << ", width = " << width << ", count = " << count
00124 << endl;
00125 }
00126
00127
00128 virtual bool contains(const MyInterval& in) const
00129 {
00130 return(contains(in.getStart(), in.getEnd()));
00131 }
00132
00133
00134 virtual bool contains(MyNT p) const
00135 {
00136 return((start <= p) && (p <= end));
00137 }
00138
00139
00140 virtual bool contains(MyNT s, MyNT e) const
00141 {
00142 return((start <= s) && (e <= end));
00143 }
00144
00145
00146 virtual bool equals(MyNT s, MyNT e) const
00147 {
00148 return((start == s) && (e == end));
00149 }
00150
00151
00152 virtual MyNT softContains(MyNT s, MyNT e) const;
00153
00154
00155 MyNT start;
00156 MyNT end;
00157 MyNT width;
00158 MyNT count;
00159 double pval;
00160 };
00161
00162
00163 struct MyDimensionInterval : public MyInterval
00164 {
00165 MyDimensionInterval()
00166 : MyInterval(), dimension()
00167 {}
00168
00169 MyDimensionInterval(MyNT s, MyNT e, int d)
00170 : MyInterval(s, e), dimension(d)
00171 {}
00172
00173 MyDimensionInterval(MyNT s, MyNT e, MyNT w, int d)
00174 : MyInterval(s, e, w), dimension(d)
00175 {}
00176
00177 virtual ~MyDimensionInterval()
00178 {}
00179
00180
00181 virtual bool operator==(const MyDimensionInterval& interval) const
00182 {
00183
00184 if (&interval == this)
00185 return(true);
00186 if (dimension != interval.dimension)
00187 return(false);
00188
00189 return((*this).MyInterval::operator==(interval));
00190 }
00191
00192 unsigned int getDimension() const
00193 {
00194 return(dimension);
00195 }
00196
00197 void setDimension(unsigned int d)
00198 {
00199 dimension = d;
00200 }
00201
00202 bool isSignificant(const MyPointSet &points, const MyClusterParams ¶ms);
00203
00204
00205
00206
00207 double computePValueUniform(const MyPointSet &points);
00208
00209
00210
00211
00212 double computePValueGaussian(const MyPointSet &points);
00213
00214 void _locate(vector< MyNT > &coords, int& middle, int& left, int& right);
00215
00216
00217
00218
00219 unsigned int dimension;
00220 };
00221
00222
00223
00224 struct MySignificantInterval : public MyInterval
00225 {};
00226
00227
00228
00229
00230
00231 struct MyWidthRange
00232 {
00233 public:
00234 MyWidthRange()
00235 : start(), min_width(), max_width()
00236 {}
00237
00238 MyWidthRange(MyNT s, MyNT min, MyNT max)
00239 : start(s), min_width(min), max_width(max)
00240 {}
00241
00242
00243
00244
00245 MyWidthRange(map< string, MyNT, ltstr >& init)
00246 : start(init["start"]), min_width(init["min-width"]),
00247 max_width(init["max-width"])
00248 {}
00249
00250 virtual ~MyWidthRange()
00251 {}
00252
00253
00254 virtual bool operator==(const MyWidthRange& interval) const
00255 {
00256
00257 if (&interval == this)
00258 return(true);
00259 if (start != interval.start)
00260 return(false);
00261 if (min_width != interval.min_width)
00262 return(false);
00263 if (max_width != interval.max_width)
00264 return(false);
00265 return(true);
00266 }
00267
00268
00269 virtual bool operator!=(const MyWidthRange& interval) const
00270 {
00271 return(!(*this == interval));
00272 }
00273
00274
00275 MyNT getStart() const
00276 {
00277 return(start);
00278 }
00279 void setStart(MyNT s)
00280 {
00281 start = s;
00282 }
00283
00284 void setMinWidth(MyNT width)
00285 {
00286 min_width = width;
00287 }
00288
00289
00290 void setMaxWidth(MyNT width)
00291 {
00292 max_width = width;
00293 }
00294
00295
00296 virtual void print(ostream& ostr) const
00297 {
00298 ostr << "Interval is start = " << start
00299 << ", min-width = " << min_width << ", max-width = " << max_width
00300 << endl;
00301 }
00302
00303
00304 virtual bool contains(const MyInterval& in) const
00305 {
00306 return(contains(in.getStart(), in.getEnd()));
00307 }
00308
00309
00310 virtual bool contains(MyNT p) const
00311 {
00312 return((start + min_width <= p) && (p <= start + max_width));
00313 }
00314
00315
00316 virtual bool contains(MyNT s, MyNT e) const
00317 {
00318 return((start == s) && contains(e));
00319 }
00320
00321
00322
00323
00324
00325
00326
00327 MyNT start;
00328 MyNT min_width;
00329 MyNT max_width;
00330 };
00331
00332
00333
00334 #endif // _INTERVAL_H