StochHMM  v0.34
Flexible Hidden Markov Model C++ Library and Application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Private Attributes
StochHMM::traceback_path Class Reference

#include <traceback_path.h>

List of all members.

Public Member Functions

 traceback_path (model *)
void push_back (int)
 Add state to traceback.
void clear ()
 Erase the traceback.
size_t size () const
 Returns the size (ie. length) of the traceback_path.
int val (size_t it)
 Returns the state index at a given position (it) within the traceback sequence.
modelgetModel () const
void setModel (model *mdl)
void fprint_path (std::ofstream &)
 Print the path to file stream.
void label (std::vector< std::string > &)
 Get the label of the traceback_path and assigns to vector<string> ref.
void label (std::string &)
 Get traceback as string of state labels.
void gff (std::vector< gff_feature > &, std::string &)
void name (std::vector< std::string > &)
void path (std::vector< int > &)
void print_path () const
 Path numbers correspond to state index in model.
void print_label () const
 Print traceback_path labels to stdout.
void print_gff (std::string, double, int, int, double) const
 Outputs the gff formatted output for the traceback to stdout.
void print_gff (std::string) const
 Outputs the gff formatted output for the traceback.
double getScore ()
 Get the score that is associated with the traceback.
void setScore (double scr)
 Set the score for the traceback;.
int operator[] (size_t val) const
bool operator== (const traceback_path &) const
 Check to see if paths are the same.
bool operator< (const traceback_path &) const
 Comparison operators for path.
bool operator> (const traceback_path &) const
 Comparison operators for path.
bool operator<= (const traceback_path &) const
 Comparison operators for path.
bool operator>= (const traceback_path &) const
 Comparison operators for path.

Private Attributes

modelhmm
std::vector< int > trace_path
double score

Detailed Description

Perform traceback of traceback table Stores one traceback path for a sequence

Definition at line 63 of file traceback_path.h.


Constructor & Destructor Documentation

StochHMM::traceback_path::traceback_path ( model modl)

Create a traceback_path

Parameters:
modlPointer to model file

Definition at line 35 of file traceback_path.cpp.

References hmm.

{
hmm=modl;
}

Member Function Documentation

void StochHMM::traceback_path::clear ( )

Erase the traceback.

Clears all traceback path information.

Definition at line 51 of file traceback_path.cpp.

References trace_path.

{
trace_path.clear();
}
void StochHMM::traceback_path::fprint_path ( std::ofstream &  file)

Print the path to file stream.

Definition at line 202 of file traceback_path.cpp.

References size(), SIZE_MAX, and trace_path.

{
int line=0;
for(size_t k=this->size()-1;k != SIZE_MAX; k--){
file << trace_path[k]<< " ";
line++;
}
file << std::endl;
}
model* StochHMM::traceback_path::getModel ( ) const
inline

Get the model used for the decoding

Returns:
model

Definition at line 88 of file traceback_path.h.

References hmm.

Referenced by StochHMM::trellis::traceback().

{return hmm;};
double StochHMM::traceback_path::getScore ( )
inline

Get the score that is associated with the traceback.

Definition at line 138 of file traceback_path.h.

References score.

Referenced by print_output().

{
return score;
}
void StochHMM::traceback_path::gff ( std::vector< gff_feature > &  pth,
std::string &  sequenceName 
)

Get traceback as vector of gff_features

Parameters:
[out]pthreference to vector of gff_feature
[in]sequenceNameName of Sequence to be used in GFF

Get GFF output of traceback path

Parameters:
[out]pth

Definition at line 109 of file traceback_path.cpp.

References StochHMM::gff_feature::attribute, StochHMM::gff_feature::end, StochHMM::gff_feature::feature, StochHMM::gff_feature::frame, StochHMM::state::getGFF(), StochHMM::model::getName(), StochHMM::model::getState(), hmm, StochHMM::gff_feature::score, StochHMM::gff_feature::seqname, size(), SIZE_MAX, StochHMM::gff_feature::source, StochHMM::gff_feature::start, StochHMM::gff_feature::strand, and trace_path.

{
std::string current_label="";
long long start=0;
size_t path_size=size();
if ( hmm==NULL ){
std::cerr << "Model is NULL. traceback::gff(...) must have valid HMM model defined.\n";
exit(2);
}
for(size_t k = path_size-1;k != SIZE_MAX; k--){
state* st = hmm->getState(trace_path[k]);
std::string new_label=st->getGFF();
if (new_label.compare("")==0){
if (start>0){
gff_feature ln;
ln.seqname=sequenceName;
ln.source=hmm->getName();
ln.feature=current_label;
ln.start=start;
ln.end=path_size-(k+1);
ln.score='.';
ln.strand='+';
ln.frame='.';
ln.attribute="";
pth.push_back(ln);
start=0;
current_label=new_label;
}
else {
continue;
}
}
else {
if(k==0){
gff_feature ln;
ln.seqname=sequenceName;
ln.source=hmm->getName();
ln.feature=current_label;
ln.start=start;
ln.end=path_size-(k+1);
ln.score='.';
ln.strand='+';
ln.frame='.';
ln.attribute="";
pth.push_back(ln);
}
else if (start==0){
start=path_size-k;
current_label=new_label;
}
else if (new_label.compare(current_label)==0){
continue;
}
else {
gff_feature ln;
ln.seqname=sequenceName;
ln.source=hmm->getName();
ln.feature=current_label;
ln.start=start;
ln.end=path_size-(k+1);
ln.score='.';
ln.strand='+';
ln.frame='.';
ln.attribute="";
pth.push_back(ln);
start=path_size-k;
current_label=new_label;
}
}
}
return;
}
void StochHMM::traceback_path::label ( std::vector< std::string > &  pth)

Get the label of the traceback_path and assigns to vector<string> ref.

Get traceback as vector of state labels

Parameters:
[out]std::vector<std::string>Vector of Labels

Definition at line 65 of file traceback_path.cpp.

References StochHMM::state::getLabel(), StochHMM::model::getState(), hmm, SIZE_MAX, and trace_path.

{
for(size_t k=trace_path.size()-1; k!=SIZE_MAX; k--){
state* st = hmm->getState(trace_path[k]);
pth.push_back(st->getLabel());
}
return;
}
void StochHMM::traceback_path::label ( std::string &  pth)

Get traceback as string of state labels.

Get string of path label traceback

Parameters:
[out]pthstd::string

Definition at line 76 of file traceback_path.cpp.

References StochHMM::state::getLabel(), StochHMM::model::getState(), hmm, SIZE_MAX, and trace_path.

{
if (pth.size()>0){
pth.clear();
}
for(size_t k=trace_path.size()-1; k!=SIZE_MAX; k--){
state* st = hmm->getState(trace_path[k]);
pth+=st->getLabel();
}
return;
}
void StochHMM::traceback_path::name ( std::vector< std::string > &  pth)

Get names of traceback path

Parameters:
[out]pthvector<string>

Definition at line 92 of file traceback_path.cpp.

References StochHMM::state::getName(), StochHMM::model::getState(), hmm, SIZE_MAX, and trace_path.

{
if ( hmm==NULL ){
std::cerr << "Model is NULL. traceback::name(...) must have valid HMM model defined.\n";
exit(2);
}
for(size_t k = trace_path.size()-1; k != SIZE_MAX; k--){
state* st = hmm->getState(trace_path[k]);
pth.push_back(st->getName());
}
return;
}
bool StochHMM::traceback_path::operator< ( const traceback_path rhs) const

Comparison operators for path.

Definition at line 222 of file traceback_path.cpp.

References trace_path.

{
if (trace_path<rhs.trace_path){
return true;
}
else {
return false;
}
}
bool StochHMM::traceback_path::operator<= ( const traceback_path rhs) const

Comparison operators for path.

Definition at line 242 of file traceback_path.cpp.

References trace_path.

{
if (trace_path<=rhs.trace_path){
return true;
}
else {
return false;
}
}
bool StochHMM::traceback_path::operator== ( const traceback_path rhs) const

Check to see if paths are the same.

Definition at line 212 of file traceback_path.cpp.

References trace_path.

{
if (rhs.trace_path==trace_path){
return true;
}
else {
return false;
}
}
bool StochHMM::traceback_path::operator> ( const traceback_path rhs) const

Comparison operators for path.

Definition at line 232 of file traceback_path.cpp.

References trace_path.

{
if (trace_path>rhs.trace_path){
return true;
}
else {
return false;
}
}
bool StochHMM::traceback_path::operator>= ( const traceback_path rhs) const

Comparison operators for path.

Definition at line 252 of file traceback_path.cpp.

References trace_path.

{
if (trace_path>=rhs.trace_path){
return true;
}
else {
return false;
}
}
int StochHMM::traceback_path::operator[] ( size_t  val) const
inline

Definition at line 149 of file traceback_path.h.

References trace_path, and val().

{return trace_path[val];};
void StochHMM::traceback_path::path ( std::vector< int > &  pth)

Get the path to std::vector<int>

Parameters:
[out]pthstd::vector<int> that represents path

Definition at line 58 of file traceback_path.cpp.

References trace_path.

{
return ;
}
void StochHMM::traceback_path::print_gff ( std::string  sequence_name,
double  score,
int  ranking,
int  times,
double  posterior 
) const

Outputs the gff formatted output for the traceback to stdout.

Outputs the gff formatted output for the traceback to stdout *Allows user to provide additional information, that may be *pertinent to stochastic tracebacks

Parameters:
[in]sequence_nameName of sequence used
[in]scorescore to use in the GFF output
[in]rankingRank of traceback
[in]timesNumber of times that traceback occurred
[in]posteriorPosterior probability score

Definition at line 285 of file traceback_path.cpp.

References StochHMM::state::getGFF(), StochHMM::model::getState(), hmm, size(), SIZE_MAX, and trace_path.

Referenced by print_output().

{
std::string current_label="";
long long start=0;
size_t path_size=this->size();
if ( hmm==NULL ){
std::cerr << "Model is NULL. traceback::print_gff(...) must have valid HMM model defined.\n";
exit(2);
}
for(size_t k=path_size-1;k != SIZE_MAX;k--){
state* st = hmm->getState(trace_path[k]);
std::string new_label=st->getGFF();
if (new_label.compare("")==0){
if (start>0){
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size-(k+1) << "\t" << score << "\t+\t.\tRank:"<<ranking<<",Counts:" << times<<",Posterior:"<<posterior<<std::endl;
start=0;
current_label=new_label;
}
else {
continue;
}
}
else {
if(k==0){
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size << "\t" << score << "\t+\t.\tRank:"<<ranking<<",Counts:" << times<<",Posterior:"<<posterior<<std::endl;
}
else if (start==0){
start=path_size-k;
current_label=new_label;
}
else if (new_label.compare(current_label)==0){
continue;
}
else {
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size-(k+1) << "\t" << score << "\t+\t.\tRank:"<<ranking<<",Counts:" << times<<",Posterior:"<<posterior<<std::endl;
start=path_size-k;
current_label=new_label;
}
}
}
}
void StochHMM::traceback_path::print_gff ( std::string  sequence_name) const

Outputs the gff formatted output for the traceback.

outputs the gff formatted output for the traceback

Definition at line 331 of file traceback_path.cpp.

References StochHMM::state::getGFF(), StochHMM::model::getState(), hmm, size(), SIZE_MAX, and trace_path.

{
std::string current_label="";
long long start=0;
size_t path_size=size();
if (sequence_name[0] == '>'){
sequence_name = sequence_name.substr(1);
if ( hmm==NULL ){
std::cerr << "Model is NULL. traceback::print_gff(...) must have valid HMM model defined.\n";
exit(2);
}
}
for(size_t k = path_size-1; k != SIZE_MAX; k--){
state* st = hmm->getState(trace_path[k]);
std::string new_label=st->getGFF();
//If no label then print
if (new_label.compare("")==0){
if (start>0){
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size-(k+1) << "\t.\t+\t."<<std::endl;
start=0;
current_label=new_label;
}
else {
continue;
}
}
else {
if (start==0){
start=path_size-k;
current_label=new_label;
}
else if (new_label.compare(current_label)==0){
if(k==0){
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size << "\t.\t+\t."<<std::endl;
}
continue;
}
else {
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size-(k+1) << "\t.\t+\t."<<std::endl;
start=path_size-k;
current_label=new_label;
if(k==0){
std::cout << sequence_name << "\tStochHMM\t" << current_label <<"\t"<< start << "\t" << path_size << "\t.\t+\t."<<std::endl;
}
}
}
}
std::cout << std::endl<<std::endl;
}
void StochHMM::traceback_path::print_label ( ) const

Print traceback_path labels to stdout.

Print the traceback path as state labels State labels

Definition at line 263 of file traceback_path.cpp.

References StochHMM::state::getLabel(), StochHMM::model::getState(), hmm, SIZE_MAX, and trace_path.

Referenced by print_output().

{
int line=0;
if ( hmm==NULL ){
std::cerr << "Model is NULL. traceback::print_label() must have valid HMM model defined.\n";
exit(2);
}
for(size_t k = trace_path.size()-1;k != SIZE_MAX;k--){
// if(line==WID && WID>0){
// std::cout<< std::endl;
// line=0;
// }
state* st = hmm->getState(trace_path[k]);
std::cout << st->getLabel() << " ";
line++;
}
std::cout << std::endl << std::endl;
}
void StochHMM::traceback_path::print_path ( ) const

Path numbers correspond to state index in model.

Print the path to stdout.

Print the traceback path as path to stdout using cout

Definition at line 192 of file traceback_path.cpp.

References size(), SIZE_MAX, and trace_path.

Referenced by print_output().

{
int line=0;
for(size_t k = this->size()-1; k != SIZE_MAX; k--){
std::cout << trace_path[k]<< " ";
line++;
}
std::cout << std::endl << std::endl;
}
void StochHMM::traceback_path::push_back ( int  state)

Add state to traceback.

Pushes a state index onto the end of the path

Parameters:
stateIndex of state to add

Definition at line 41 of file traceback_path.cpp.

References trace_path.

Referenced by StochHMM::stochTable::traceback(), StochHMM::alt_simple_stochTable::traceback(), StochHMM::trellis::traceback(), StochHMM::trellis::traceback_nth(), StochHMM::trellis::traceback_posterior(), and StochHMM::trellis::traceback_stoch_posterior().

{
trace_path.push_back(state);
}
void StochHMM::traceback_path::setModel ( model mdl)
inline

Definition at line 89 of file traceback_path.h.

References hmm.

Referenced by StochHMM::trellis::traceback().

{hmm=mdl;};
void StochHMM::traceback_path::setScore ( double  scr)
inline

Set the score for the traceback;.

Definition at line 143 of file traceback_path.h.

References score.

Referenced by StochHMM::trellis::traceback(), and StochHMM::trellis::traceback_nth().

{
score = scr;
return;
};
size_t StochHMM::traceback_path::size ( void  ) const

Returns the size (ie. length) of the traceback_path.

Get the size of traceback

Returns:
size_t

Definition at line 46 of file traceback_path.cpp.

References trace_path.

Referenced by fprint_path(), gff(), print_gff(), and print_path().

{
return trace_path.size();
}
int StochHMM::traceback_path::val ( size_t  it)
inline

Returns the state index at a given position (it) within the traceback sequence.

Definition at line 78 of file traceback_path.h.

References trace_path.

Referenced by operator[]().

{
if (it>=trace_path.size()){
std::cerr << "Out of Range index\n ";
exit(2);
}
return trace_path[it];
}

Member Data Documentation

model* StochHMM::traceback_path::hmm
private

Definition at line 156 of file traceback_path.h.

Referenced by getModel(), gff(), label(), name(), print_gff(), print_label(), setModel(), and traceback_path().

double StochHMM::traceback_path::score
private

Definition at line 158 of file traceback_path.h.

Referenced by getScore(), and setScore().

std::vector<int> StochHMM::traceback_path::trace_path
private

The documentation for this class was generated from the following files: