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::sequences Class Reference

#include <sequences.h>

List of all members.

Public Member Functions

 sequences ()
 sequences (size_t sz)
 sequences (tracks *tr)
 sequences (const sequences &)
sequencesoperator= (const sequences &)
 Assignment Operator.
 ~sequences ()
 Destroy sequences.
double realValue (int, size_t)
double realValue (size_t, size_t)
short seqValue (int, size_t)
sequencegetSeq (size_t)
double getAttrib (size_t iter)
std::string & getHeader ()
std::string & getHeader (size_t iter)
std::string * getUndigitized (size_t iter)
size_t size ()
size_t getLength (size_t iter)
size_t getLength ()
bool exDefDefined (size_t)
bool exDefDefined (size_t, size_t)
double getWeight (size_t, size_t)
bool exDefDefined ()
 Get Weight value for state at position.
void print ()
 Is External definition defined.
std::string stringify ()
std::string undigitize ()
 Get string of sequences.
void addSeq (sequence *sq)
 Get sequence based on alphabet.
void addSeq (sequence *, size_t)
void addSeq (sequence *, track *)
 Add sequence for track.
void setLength (size_t len)
 Set Length of sequences.
void setExDef (ExDefSequence *ex)
bool isSameSize ()
sequenceoperator[] (size_t index)
void getFastas (const std::string &, track *)

Private Attributes

ExDefSequenceexternal
std::vector< sequence * > seq
size_t length
size_t num_of_sequences
bool related_sequences
bool same_length

Detailed Description

Container hold the track sequence(s) Each sequence have to be the same length Created to pass multiple sequence tracks of different datasets to the HMM If you need multiple unrelated sequences, use std::vector<sequence> instead.

Definition at line 51 of file sequences.h.


Constructor & Destructor Documentation

StochHMM::sequences::sequences ( )

Definition at line 35 of file sequences.cpp.

References external, length, num_of_sequences, related_sequences, and same_length.

StochHMM::sequences::sequences ( size_t  sz)

Create an empty sequences

Parameters:
szNumber of sequences

Definition at line 46 of file sequences.cpp.

References external, length, num_of_sequences, related_sequences, and same_length.

:seq(sz,NULL){
length=-1;
external=NULL;
}
StochHMM::sequences::sequences ( tracks tr)

Create a sequences data t

Parameters:
szNumber of sequences

Definition at line 57 of file sequences.cpp.

References external, length, num_of_sequences, related_sequences, same_length, and StochHMM::tracks::size().

:seq(tr->size(),NULL){
length=-1;
external=NULL;
num_of_sequences=tr->size();
}
StochHMM::sequences::sequences ( const sequences rhs)

Definition at line 66 of file sequences.cpp.

References external, length, num_of_sequences, related_sequences, same_length, and seq.

{
external = (rhs.external==NULL) ? NULL : new(std::nothrow) ExDefSequence(*rhs.external);
if (rhs.external != NULL && external==NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
length = rhs.length;
same_length=rhs.same_length;
num_of_sequences=rhs.num_of_sequences;
related_sequences=rhs.related_sequences;
for(size_t i=0;i<seq.size();i++){
sequence* temp=NULL;
if (rhs.seq[i]!=NULL){
temp = new(std::nothrow) sequence(*rhs.seq[i]);
if (temp == NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
}
seq.push_back(temp);
}
}
StochHMM::sequences::~sequences ( )

Destroy sequences.

Definition at line 96 of file sequences.cpp.

References external, and seq.

{
for(size_t i=0;i<seq.size();i++){
delete seq[i];
seq[i]=NULL;
}
delete external;
external = NULL;
}

Member Function Documentation

void StochHMM::sequences::addSeq ( sequence sq)

Get sequence based on alphabet.

Add a sequence to the sequences *Sequence is added to a certain position based on the track used by the sequence

Parameters:
sqPointer to sequence

Definition at line 262 of file sequences.cpp.

References StochHMM::track::getIndex(), StochHMM::sequence::getLength(), StochHMM::sequence::getTrack(), num_of_sequences, related_sequences, seq, and setLength().

Referenced by addSeq(), getFastas(), and StochHMM::seqTracks::getNext().

{
track* trk = sq->getTrack();
seq[trk->getIndex()]=sq;
setLength(sq->getLength());
return;
}
else{
seq.push_back(sq);
setLength(sq->getLength());
}
}
void StochHMM::sequences::addSeq ( sequence sq,
size_t  iter 
)

Add sequence in the track position

Parameters:
Adda sequence to the sequences at a certain position *Sequence is added to a certain position based on the iterator
sqPointer to sequence
iterPosition in sequences to add sequence

Definition at line 281 of file sequences.cpp.

References StochHMM::sequence::getLength(), num_of_sequences, related_sequences, seq, and setLength().

{
if (seq.size()>iter){ //If position already exists just add it
seq[iter]=sq;
}
else{ //If the position doesn't exist extend the vector, then add
seq.resize(iter+1,NULL);
seq[iter]=sq;
}
setLength(sq->getLength());
}
return;
}
void StochHMM::sequences::addSeq ( sequence sq,
track tr 
)

Add sequence for track.

Add a sequence to the sequences given a certain track *Sequence is added to a certain position based on the track

Parameters:
sqPointer to sequence
trTrack to use when adding sequence

Definition at line 303 of file sequences.cpp.

References addSeq(), StochHMM::track::getIndex(), and related_sequences.

{
if (tr!=NULL){
size_t index = tr->getIndex();
addSeq(sq,index);
}
else{
addSeq(sq);
}
}
else{
std::cerr << "Track is undefined for related sequences. Unable to add related sequences if track is not defined\n";
exit(1);
}
else{
addSeq(sq);
}
}
return;
}
bool StochHMM::sequences::exDefDefined ( size_t  pos)
bool StochHMM::sequences::exDefDefined ( size_t  pos,
size_t  stateIter 
)

Check to see if there is an external definition defined for a certain state at a certain position

Parameters:
posPosition within the sequence
Returns:
True if there is an external definition fo the the state and position

Definition at line 235 of file sequences.cpp.

References StochHMM::ExDefSequence::defined(), StochHMM::ExDefSequence::defs, and external.

{
if (external && external->defs[pos]){
if (external->defined(stateIter)){
return true;
}
}
return false;
}
bool StochHMM::sequences::exDefDefined ( )

Get Weight value for state at position.

Check to see if there are any external definitions defined

Returns:
true if there are external definitions defined

Definition at line 247 of file sequences.cpp.

References external.

{
return external;
}
double StochHMM::sequences::getAttrib ( size_t  iter)
inline

Get the attribute value for a particular sequence

Parameters:
iterSequence to get the attribute from
Returns:
double value of the attribute set for the sequence

Definition at line 79 of file sequences.h.

References num_of_sequences, and seq.

{
if (iter<num_of_sequences && seq[iter]!=NULL){
return seq[iter]->getAttrib(); //Returns attrib value for Track (i)
}
std::cerr << "No sequence defined at iterator " << iter << std::endl;
exit(1);
}
void StochHMM::sequences::getFastas ( const std::string &  filename,
track tr 
)

Definition at line 347 of file sequences.cpp.

References addSeq(), and StochHMM::sequence::getFasta().

Referenced by main().

{
std::ifstream file;
file.open(filename.c_str());
if (!file.is_open()){
std::cerr << "Couln't open the file:" << filename << "\n";
exit(2);
}
while(!file.eof()){
sequence* sq = new(std::nothrow) sequence(false);
if (sq==NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
bool success = sq->getFasta(file, tr);
if (!success){
delete sq;
}
addSeq(sq,tr);
}
return;
}
std::string& StochHMM::sequences::getHeader ( )
inline

Get the header for the first sequence

Returns:
std::string& The header for the first sequence in sequences

Definition at line 90 of file sequences.h.

References num_of_sequences, and seq.

Referenced by perform_nbest_decoding(), perform_posterior(), perform_stochastic_decoding(), perform_viterbi_decoding(), print_limited_posterior(), and print_posterior().

{
if (num_of_sequences>0 && seq[0]!=NULL){
return seq[0]->header;
}
std::cerr << "No sequence defined." << std::endl;
exit(1);
}
std::string& StochHMM::sequences::getHeader ( size_t  iter)
inline

Get the header for the ith sequence

Parameters:
itersize_t iterator for ith sequence
Returns:
std::string& The header for the ith sequence

Definition at line 102 of file sequences.h.

References num_of_sequences, and seq.

{
if (iter<num_of_sequences){
if (seq[iter]!=NULL){
return seq[iter]->header;
}
}
std::cerr << "No sequence defined at iterator " << iter << std::endl;
exit(1);
}
size_t StochHMM::sequences::getLength ( size_t  iter)
inline
size_t StochHMM::sequences::getLength ( )
inline

Get the length of sequences in general *All of the sequence(s) should be the same length

Returns:
size_t value of length of all sequences

Definition at line 145 of file sequences.h.

References length.

{
return length;
// if (related_sequences){
// return length; // Get length of related sequence
// }
// return 0;
};
sequence * StochHMM::sequences::getSeq ( size_t  iter)

Get pointer to ith sequence from sequences

Parameters:
iterIterator to use for extracting sequence;
Returns:
sequence* pointer to sequence
NULL if no sequence exists at iter

Definition at line 174 of file sequences.cpp.

References seq.

Referenced by StochHMM::PWM::scoreSimple(), StochHMM::PWM::scoreUndefSpacer(), StochHMM::PWM::scoreVariableSpacer(), and StochHMM::trellis::transitionFuncTraceback().

{
if(iter<seq.size()){
return seq[iter];
}
return NULL;
}
std::string* StochHMM::sequences::getUndigitized ( size_t  iter)
inline

Get the undigitized ith sequence from sequences

Parameters:
itersize_t iterator for ith sequence
Returns:
std::string of undigitized sequence at ith position

Definition at line 116 of file sequences.h.

References seq.

Referenced by StochHMM::emissionFuncParam::evaluate(), StochHMM::seqTracks::getNext(), and StochHMM::trellis::transitionFuncTraceback().

{
if (iter>seq.size()){
std::cerr << "getUndigitized(size_t iter) called where iter is out of range\n";
return NULL;
}
else{
return seq[iter]->getUndigitized();
}
};
double StochHMM::sequences::getWeight ( size_t  position,
size_t  stateIter 
)
bool StochHMM::sequences::isSameSize ( )
inline

Definition at line 185 of file sequences.h.

References same_length.

{
return same_length;
}
sequences & StochHMM::sequences::operator= ( const sequences rhs)

Assignment Operator.

Definition at line 107 of file sequences.cpp.

References external, length, num_of_sequences, related_sequences, same_length, and seq.

{
external = (rhs.external==NULL) ? NULL : new(std::nothrow) ExDefSequence(*rhs.external);
if (rhs.external != NULL && external==NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
length = rhs.length;
same_length=rhs.same_length;
num_of_sequences=rhs.num_of_sequences;
related_sequences=rhs.related_sequences;
for(size_t i=0;i<seq.size();i++){
sequence* temp=NULL;
if (rhs.seq[i]!=NULL){
temp = new(std::nothrow) sequence(*rhs.seq[i]);
if (temp == NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
}
seq.push_back(temp);
}
return *this;
}
sequence& StochHMM::sequences::operator[] ( size_t  index)
inline

Definition at line 189 of file sequences.h.

References seq.

{return *seq[index];}
void StochHMM::sequences::print ( )
inline

Is External definition defined.

Print the string representation of digitized sequencs to the stdout

Definition at line 160 of file sequences.h.

References stringify().

Referenced by main().

{std::cout<< stringify() << std::endl;}; //Print sequences to stdout
double StochHMM::sequences::realValue ( int  trck,
size_t  position 
)

Get the value from a real Number sequence for track trck at position

Parameters:
trckSequence track to use
positionPosition in sequence to get value from
Returns:
double value of the real sequence at the position

Definition at line 141 of file sequences.cpp.

References seq.

Referenced by StochHMM::emm::get_emission().

{
if (seq[trck]->realSeq){
return seq[trck]->realValue(position);
}
return -INFINITY;
}
double StochHMM::sequences::realValue ( size_t  trck,
size_t  position 
)

Get the value from a real Number sequence for track trck at position

Parameters:
trckSequence track to use
positionPosition in sequence to get value from
Returns:
double value of the real sequence at the position

Definition at line 153 of file sequences.cpp.

References seq.

{
if (seq[trck]->realSeq){
return seq[trck]->realValue(position);
}
return -INFINITY;
}
short StochHMM::sequences::seqValue ( int  trck,
size_t  position 
)

Get the digitized value from the sequence at trck at position

Parameters:
trckSequence track to use
positionPosition in sequence to get the value from
Returns:
short digitized value of the sequence based on track type

Definition at line 166 of file sequences.cpp.

References seq.

{
return seq[trck]->seqValue(position);
}
void StochHMM::sequences::setExDef ( ExDefSequence ex)
inline

Set external definition

Parameters:
exExternal definition to assign to the sequences

Definition at line 183 of file sequences.h.

References external.

Referenced by StochHMM::seqTracks::getNext().

{external=ex;};
void StochHMM::sequences::setLength ( size_t  len)

Set Length of sequences.

Set the length of the sequence(s) in sequence Because all the sequences should be the same size If there size differs when adding a sequence

Exceptions:
sDifferentSizeSequencesthrown if the sizes differ

Definition at line 329 of file sequences.cpp.

References length, StochHMM::max(), related_sequences, and same_length.

Referenced by addSeq(), and StochHMM::seqTracks::getNext().

{
length=len;
}
if (len==length){
return;
}
else{
same_length=false;
std::cerr << "Sequences have different lengths. Sequences should all have the same length because they are suppose to be related (from different datasets). For multiple unrelated sequence types, use a different structure.\n";
exit(20);
}
}
return;
}
size_t StochHMM::sequences::size ( void  )
inline

Get the number of sequence type in sequences

Returns:
size_t value of size

Definition at line 130 of file sequences.h.

References num_of_sequences.

Referenced by StochHMM::PWM::scoreSimple(), StochHMM::PWM::scoreUndefSpacer(), StochHMM::PWM::scoreVariableSpacer(), stringify(), and undigitize().

{return num_of_sequences;} //Get number of sequences
std::string StochHMM::sequences::stringify ( )

Get std:string representation of all the digitized sequence(s) in sequences

Returns:
std::string representation of all string (digitized)

Definition at line 184 of file sequences.cpp.

References StochHMM::track::getName(), StochHMM::int_to_string(), seq, and size().

Referenced by print().

{
std::string tmp;
for(size_t i=0; i<size(); i++){
if (seq[i]==NULL){
tmp+= ">TRACK: " + int_to_string(i) + ":\t" ;
tmp+= "<<EMPTY>>\n" ;
}
else{
track* trk = seq[i]->getTrack();
tmp+= ">" + trk->getName();
tmp+= seq[i]->stringify();
}
}
return tmp;
}
std::string StochHMM::sequences::undigitize ( )

Get string of sequences.

Get std::string representation of all the undigitized sequence(s) in sequences

Returns:
std::string representation of all string (digitized)

Definition at line 204 of file sequences.cpp.

References StochHMM::track::getName(), StochHMM::int_to_string(), seq, and size().

{
std::string output;
for(size_t i=0;i<size();i++){
if (seq[i]==NULL){
output+= ">TRACK: " + int_to_string(i) + ":\t" ;
output+= "<<EMPTY>>\n" ;
}
else{
track* trk = seq[i]->getTrack();
output+= ">" + trk->getName();
output+= seq[i]->undigitize();
}
}
return output;
}

Member Data Documentation

ExDefSequence* StochHMM::sequences::external
private

Definition at line 195 of file sequences.h.

Referenced by exDefDefined(), getWeight(), operator=(), sequences(), setExDef(), and ~sequences().

size_t StochHMM::sequences::length
private

Definition at line 199 of file sequences.h.

Referenced by getLength(), operator=(), sequences(), and setLength().

size_t StochHMM::sequences::num_of_sequences
private

Definition at line 200 of file sequences.h.

Referenced by addSeq(), getAttrib(), getHeader(), getLength(), operator=(), sequences(), and size().

bool StochHMM::sequences::related_sequences
private

Definition at line 202 of file sequences.h.

Referenced by addSeq(), operator=(), sequences(), and setLength().

bool StochHMM::sequences::same_length
private

Definition at line 203 of file sequences.h.

Referenced by isSameSize(), operator=(), sequences(), and setLength().

std::vector<sequence*> StochHMM::sequences::seq
private

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