Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages

SuffixArraySeqan.h

Go to the documentation of this file.
00001 // --------------------------------------------------------------------------
00002 //                   OpenMS -- Open-Source Mass Spectrometry
00003 // --------------------------------------------------------------------------
00004 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
00005 // ETH Zurich, and Freie Universitaet Berlin 2002-2012.
00006 //
00007 // This software is released under a three-clause BSD license:
00008 //  * Redistributions of source code must retain the above copyright
00009 //    notice, this list of conditions and the following disclaimer.
00010 //  * Redistributions in binary form must reproduce the above copyright
00011 //    notice, this list of conditions and the following disclaimer in the
00012 //    documentation and/or other materials provided with the distribution.
00013 //  * Neither the name of any author or any participating institution
00014 //    may be used to endorse or promote products derived from this software
00015 //    without specific prior written permission.
00016 // For a full list of authors, refer to the file AUTHORS.
00017 // --------------------------------------------------------------------------
00018 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00019 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
00022 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00023 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00024 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00025 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00026 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00027 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00028 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00029 //
00030 // --------------------------------------------------------------------------
00031 // $Maintainer: Clemens Groepl,Andreas Bertsch$
00032 // $Authors: Chris Bauer $
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     // TODO ??? was: typedef seqan::Index<seqan::String<char>, seqan::Index_ESA<seqan::TopDown<seqan::ParentLinks<seqan::Preorder> > > > TIndex;
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       // preorder dfs
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       // preorder dfs
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       // preorder dfs
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             //le <- length(representative(it));
00301             //isLeaf = true;
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

OpenMS / TOPP release 1.10.0 Documentation generated on Thu Mar 7 2013 09:42:45 using doxygen 1.7.1