StochHMM  v0.34
Flexible Hidden Markov Model C++ Library and Application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
transitions.h
Go to the documentation of this file.
1 ///transitions.h
2  //Copyright (c) 2007-2012 Paul C Lott
3  //University of California, Davis
4  //Genome and Biomedical Sciences Facility
5  //UC Davis Genome Center
6  //Ian Korf Lab
7  //Website: www.korflab.ucdavis.edu
8  //Email: lottpaul@gmail.com
9  //
10  //Permission is hereby granted, free of charge, to any person obtaining a copy of
11  //this software and associated documentation files (the "Software"), to deal in
12  //the Software without restriction, including without limitation the rights to
13  //use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
14  //the Software, and to permit persons to whom the Software is furnished to do so,
15  //subject to the following conditions:
16  //
17  //The above copyright notice and this permission notice shall be included in all
18  //copies or substantial portions of the Software.
19  //
20  //THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21  //IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
22  //FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
23  //COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24  //IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25  //CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 #ifndef TRANSITIONS_H
27 #define TRANSITIONS_H
28 
29 #include <vector>
30 #include <string>
31 #include "text.h"
32 #include "track.h"
33 #include "stochMath.h"
34 #include "stochTypes.h"
35 #include "externalFuncs.h"
36 #include "weight.h"
37 #include "sequences.h"
38 #include "lexicalTable.h"
39 #include <stdlib.h>
40 namespace StochHMM{
41 
42  //! \file transitions.h
43  /*! Define transition class
44  */
45 
46  class state;
47 
48 
49  //! \class transition
50  /*! \brief Transition information for each state
51 
52  */
53 
54 class transition{
55 public:
56  transition(); // Constructor
57  transition(transType); // Constructor
58  transition(transType,valueType,bool); // Constructor
59 
60 
61  friend class model;
62  friend class state;
63 
64  //MUTATORS
65 
66  //
67  bool parse(std::string&, stringList&, valueType valtyp, tracks& ,weights*, StateFuncs*);
69 
70  //! Set the name of the state we are transitioning to
71  //! \param txt Name of the next state
72  inline void setName(std::string& txt){stateName=txt;};
73 
74  //! Set the pointer to the state we are transitioning to
75  //! \param st Pointer to state
76  inline void setState(state* st){toState=st;};
77 
78  //! Set the type of the transition (enum transType)
79  //! \param type enum Transtype
80  //! \sa enum transType
81  inline void setTransType(transType type){transition_type=type;};
82 
83  //Distributions
84  //! Sets teh Traceback Identifier used when doing a traceback during calculation of transition
85  //! \param tbIdt enum tracebackIdentifier
86  //! \sa enum tracebackIdentifier
88 
89  //! Set the traceback Label/GFF/StateName to use during traceback
90  //! \param txt String to use for traceback
91  inline void setTB_String(std::string& txt){traceback_string = txt;};
92 
93  //TODO: Check to see that distribution is survival function
94  //! Set the length distribution of the transition
95  //! Each position in the vector is a length 0=1, 99=100 length
96  //! Distribution should be a survival function but could be user defined
97  //! \param dst std::vector of double
98  inline void setDistribution(std::vector<double>* dst){distribution=dst;}; //Check that distribution is survival function
99 
100  //Standard
101  //! Set the standard transition probability of the transition
102  //! \param value log based 2 value of transitioin probabability
103  inline void setTransProb(double value){log_trans=value;};
104 
105 
106  //////////////////////// Lexical ////////////////////////
107 
108 // void addTrack(track*,int); //Add track and order
109 
110 // //TODO: check the table is correct size according to order and track
111 // //!Set the lexical probability table from vector of vectors
112 // //! \param tbl Vector of Vector of double (table of sequence frequencies (log2 value)
113 // inline void setLexicalProb(std::vector<std::vector<double> >* tbl){log_prob=tbl;};
114 //
115 // //TODO: check ambiguous character scoring ....
116 // //!Set the how to score unknown or ambiguous characters in the sequence
117 // //! \param type enum unknownCharScoringType
118 // inline void setUnkScoreType(unknownCharScoringType type){unknownScoreType=type;};
119 //
120 //
121 // //!Set unknown scoring value
122 // //!Value to use for unknown characters in the sequence
123 // inline void setUnkScore(double val){unknownDefinedScore=val;};
124 
125 
126  //ACCESSORS
127  //! Get the name of state that transition is to
128  //! \return std::string Name of the state that transition is to
129  inline std::string& getName(){return stateName;};
130 
131  //! Get pointer to stte that transition is to
132  //! \return state* Pointer to state that transitioning to
133  inline state* getState(){return toState;};
134 
135  //inline bool isDefined(){return defined;};
136 
137  //! Get the transition type
138  //! \return transType
139  //! \sa transType
141 
142  //! Get the tracebackIdentifier defined in the transitioin
143  //! \return tracebackIdentifier
144  //! \sa tracebackIdentifier
146 
147  //! Get the string (GFF/Label/State Name) Traceback is to
148  //! \return std::string name that traceback is to
149  inline std::string& getTracebackString(){return traceback_string;};
150 
151  double getTransition(size_t,sequences*); // get the transition using to and the position trellis
152  double get_reduced_order(int,sequences*);
153  double getTransition();
154 
155  //! Get pointer to externalFuncs
156  //! \return externalFuncs* Pointer to external function definition in transition
158  inline bool FunctionDefined(){if(func!=NULL){return true;} else {return false;}};
159 
160  inline bool LexFunctionDefined(){return function;}
161  std::string getLexicalFunctionName(){return lexFunc->getName();}
162 
163  inline bool isSimple(){
164  if (transition_type != DURATION && func == NULL && !function){
165  return true;
166  }
167  return false;
168  }
169 
170  inline bool isComplex(){
171  return !isSimple();
172  }
173 
174  void print();
175  std::string stringify();
176 
177 private:
178  transType transition_type; //0: standard 1:USER DISTRIBUTION 2:INTERNAL DISTRIBUTION 3:LEXICAL
179 
180  //Transition to State
181  std::string stateName; //What state we are transitioning to (Fill out when parsing)
182  state* toState; //pointer to the state (Filled during HMM finalization)
183 
184  /*--------------- STANDARD TRANSITIONS ----------------*/
185  double log_trans; //Log of standard transition probability
186 
187  /*--------------- EXPLICIT DURATION DISTRIBUTION TABLES ----------------*/
188  std::vector<double>* distribution; //! Transition Length Distribution
190 
191  tracebackIdentifier traceback_identifier; //0:until different state 1:STATE_NAME 2:STATE_LABEL 3:STATE_GFF_TAG 4:START(INIT)
192  //if not defined it should traceback until same state ends.... default to zero
193 
194  std::string traceback_string; //name,label,or gff tag to traceback to.
195 
196 
197  /*--------------- Lexical Table ----------------*/
198  bool function;
200 
202 
203 
204  /*--------------- External Functions ----------------*/
205  //Extern function Identifies function to be called at tagged transition;
206  //Function has to be initialized before importing the model
207  //Function parameters are <int> position, <string> sequence, <string> TracebackSequence
208  //Function return value should be double in log space;
209 
211  //track* externTrack;
212 
213 
214  //Private Methods
215  bool _parseStandard(std::string&,stringList&, valueType);
218  bool _processTags(std::string&, tracks& , weights*, StateFuncs*);
219 };
220 
221 
222 }
223 #endif //TRANSITIONS_H//