Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #ifndef OPENMS_DATASTRUCTURES_SUFFIXARRAYSEQAN_H
00038 #define OPENMS_DATASTRUCTURES_SUFFIXARRAYSEQAN_H
00039
00040 #include <vector>
00041 #include <OpenMS/DATASTRUCTURES/String.h>
00042 #include <OpenMS/DATASTRUCTURES/SuffixArray.h>
00043 #include <OpenMS/DATASTRUCTURES/SeqanIncludeWrapper.h>
00044 #include <OpenMS/CHEMISTRY/WeightWrapper.h>
00045
00046
00047
00048 namespace OpenMS
00049 {
00050
00058 class OPENMS_DLLAPI SuffixArraySeqan :
00059 public SuffixArray
00060 , public WeightWrapper
00061 {
00062
00063 typedef seqan::TopDown<seqan::ParentLinks<> > TIterSpec;
00064 typedef seqan::Index<seqan::String<char>, seqan::IndexEsa<TIterSpec> > TIndex;
00065 typedef seqan::Iter<TIndex, seqan::VSTree<TIterSpec> > TIter;
00066
00067
00068
00069 public:
00070
00079 SuffixArraySeqan(const String & st, const String & filename, const WeightWrapper::WEIGHTMODE weight_mode = WeightWrapper::MONO);
00080
00084 SuffixArraySeqan(const SuffixArraySeqan & source);
00085
00089 virtual ~SuffixArraySeqan();
00090
00094 String toString();
00095
00104 void findSpec(std::vector<std::vector<std::pair<std::pair<SignedSize, SignedSize>, DoubleReal> > > & candidates, const std::vector<DoubleReal> & spec);
00105
00112 bool save(const String & filename);
00113
00121 bool open(const String & filename);
00122
00128 void setTolerance(DoubleReal t);
00129
00134 DoubleReal getTolerance() const;
00135
00142 bool isDigestingEnd(const char aa1, const char aa2) const;
00143
00149 void setTags(const std::vector<OpenMS::String> & tags);
00150
00155 const std::vector<OpenMS::String> & getTags();
00156
00161 void setUseTags(bool use_tags);
00162
00167 bool getUseTags();
00168
00173 void setNumberOfModifications(Size number_of_mods);
00174
00179 Size getNumberOfModifications();
00180
00181 void printStatistic();
00182
00183 protected:
00184
00197 inline void goNextSubTree_(TIter & it, DoubleReal & m, std::stack<DoubleReal> & allm, std::stack<std::map<DoubleReal, SignedSize> > & mod_map)
00198 {
00199
00200 if (!goRight(it))
00201 {
00202 while (true)
00203 {
00204 if (goUp(it))
00205 {
00206 m -= allm.top();
00207 allm.pop();
00208 mod_map.pop();
00209 }
00210 else
00211 {
00212 break;
00213 }
00214
00215 if (goRight(it))
00216 {
00217 m -= allm.top();
00218 allm.pop();
00219 mod_map.pop();
00220 break;
00221 }
00222 }
00223 }
00224 else
00225 {
00226 m -= allm.top();
00227 allm.pop();
00228 mod_map.pop();
00229 }
00230 if (isRoot(it))
00231 {
00232 clear(it);
00233 }
00234 }
00235
00241 inline void goNextSubTree_(TIter & it)
00242 {
00243
00244 if (!goRight(it))
00245 {
00246 while (true)
00247 {
00248 if (!goUp(it))
00249 {
00250 break;
00251 }
00252 if (goRight(it))
00253 {
00254 break;
00255 }
00256 }
00257 }
00258 if (isRoot(it))
00259 {
00260 clear(it);
00261 }
00262 }
00263
00276 inline void goNext_(TIter & it, DoubleReal & m, std::stack<DoubleReal> & allm, std::stack<std::map<DoubleReal, SignedSize> > & mod_map)
00277 {
00278
00279 if (!goDown(it))
00280 {
00281 goNextSubTree_(it, m, allm, mod_map);
00282 }
00283 }
00284
00285 inline void parseTree_(TIter & it, std::vector<std::pair<SignedSize, SignedSize> > & out_number, std::vector<std::pair<SignedSize, SignedSize> > & edge_length, std::vector<SignedSize> & leafe_depth)
00286 {
00287 SignedSize depth = 1;
00288 while (!atEnd(it))
00289 {
00290 SignedSize le = 0;
00291 bool isLeaf = false;
00292 if (length(parentEdgeLabel(it)) > 0)
00293 {
00294 if (countChildren(it) > 0)
00295 {
00296 edge_length.push_back(std::pair<SignedSize, SignedSize>(depth, length(parentEdgeLabel(it))));
00297 }
00298 else
00299 {
00300
00301
00302 }
00303 }
00304 if (countChildren(it) > 0)
00305 {
00306 out_number.push_back(std::pair<SignedSize, SignedSize>(depth, countChildren(it)));
00307 }
00308 else
00309 {
00310 leafe_depth.push_back(depth);
00311 }
00312 if (goDown(it))
00313 {
00314 depth++;
00315 }
00316 else if (!goRight(it))
00317 {
00318 while (!goRight(it))
00319 {
00320 goUp(it);
00321 if (isLeaf)
00322 {
00323 edge_length.push_back(std::pair<SignedSize, SignedSize>(depth, le - length(parentEdgeLabel(it))));
00324 isLeaf = false;
00325 }
00326 depth--;
00327 if (isRoot(it)) return;
00328 }
00329 }
00330 else
00331 {
00332 }
00333 }
00334 }
00335
00336 TIndex index_;
00337
00338 TIter * it_;
00339
00347 SignedSize findFirst_(const std::vector<DoubleReal> & spec, DoubleReal & m);
00348
00358 SignedSize findFirst_(const std::vector<DoubleReal> & spec, DoubleReal & m, SignedSize start, SignedSize end);
00359
00360 const String & s_;
00361
00362 DoubleReal masse_[255];
00363
00364 SignedSize number_of_modifications_;
00365
00366 std::vector<String> tags_;
00367
00368 bool use_tags_;
00369
00370 DoubleReal tol_;
00371 };
00372 }
00373
00374 #endif //OPENMS_DATASTRUCTURES_SUFFIXARRAYSEQAN_H