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 Member Functions | Private Attributes
StochHMM::sequenceStream Class Reference

#include <sequenceStream.h>

Inheritance diagram for StochHMM::sequenceStream:
StochHMM::sequence

List of all members.

Public Member Functions

 sequenceStream ()
 sequenceStream (bool)
 sequenceStream (std::vector< double > *, track *)
 sequenceStream (char *, track *)
 sequenceStream (std::string &, track *)
 sequenceStream (size_t, size_t)
 sequenceStream (size_t, size_t, bool)
 sequenceStream (size_t, size_t, std::vector< double > *, track *)
 sequenceStream (size_t, size_t, std::string &, track *)
 sequenceStream (size_t, size_t, char *, track *)
bool getFasta (std::ifstream &, track *)
void setBuffer (size_t buff)
void setRetain (size_t ret)
- Public Member Functions inherited from StochHMM::sequence
 sequence ()
 Create a sequence datatype.
 sequence (bool)
 sequence (std::vector< double > *, track *)
 Create a sequence typ.
 sequence (std::string &, track *)
 sequence (char *, track *)
 ~sequence ()
 Destroy sequence type.
 sequence (const sequence &)
sequenceoperator= (const sequence &)
std::string * getUndigitized ()
size_t getLength ()
 Get the size of the sequence.
double getAttrib ()
ExDefSequencegetExDef ()
bool exDefDefined ()
double realValue (size_t)
uint8_t seqValue (size_t)
size_t size ()
trackgetTrack ()
void setTrack (track *tr)
void print ()
std::string stringify ()
std::string undigitize ()
void setAttrib (double attr)
void setHeader (std::string &head)
 Set the attribute value.
void setSeq (std::string &, track *)
void setRealSeq (std::vector< double > *, track *)
bool getFasta (std::ifstream &file)
bool getFasta (std::ifstream &, track *, stateInfo *)
bool getMaskedFasta (std::ifstream &, track *)
bool getFastq (std::ifstream &, track *)
bool getReal (std::ifstream &file)
bool getReal (std::ifstream &file, track *trk)
bool getReal (std::ifstream &, track *, stateInfo *)
int getMaxMask ()
int getMask (size_t)
 Return the mask at sequence position.
std::string getSymbol (size_t) const
void get_index (size_t position, int order, std::pair< Index, Index > &word_index)
std::string getHeader ()
 Returns the header of the sequence as a std::string.
bool reverseComplement ()
bool complement ()
bool reverse ()
bool digitize ()
 Converts sequence digital based on track alphabet.
void shuffle ()
 Shuffles the sequence using std::random_shuffle.
std::vector< uint8_t > * getDigitalSeq ()
uint8_t operator[] (size_t index)
void clear ()
 Empty Sequence.

Private Member Functions

void resetSeq ()
 Reset seq or realseq each time getfasta is called.

Private Attributes

size_t bufferSize
size_t retainSize
std::string previousSeq
 What is left in "getline" after the buffer has been filled.
std::string retain
 The retain sequence.
bool readingFile
 Keeps track of whether the sequence under the same header is being read.

Detailed Description

Definition at line 19 of file sequenceStream.h.


Constructor & Destructor Documentation

StochHMM::sequenceStream::sequenceStream ( )

Definition at line 12 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(){
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( bool  realTrack)

Definition at line 18 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(realTrack){
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( std::vector< double > *  vec,
track tr 
)

Definition at line 24 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(vec, tr){
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( char *  seq,
track tr 
)

Definition at line 30 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(seq, tr){
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( std::string &  sq,
track tr 
)

Definition at line 36 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(sq, tr){
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( size_t  buff,
size_t  ret 
)

Definition at line 42 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(){
bufferSize=buff;
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( size_t  buff,
size_t  ret,
bool  realTrack 
)

Definition at line 48 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(realTrack){
bufferSize=buff;
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( size_t  buff,
size_t  ret,
std::vector< double > *  vec,
track tr 
)

Definition at line 54 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(vec, tr){
bufferSize=buff;
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( size_t  buff,
size_t  ret,
std::string &  sq,
track tr 
)

Definition at line 66 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(sq, tr){
bufferSize=buff;
readingFile = false;
}
StochHMM::sequenceStream::sequenceStream ( size_t  buff,
size_t  ret,
char *  seq,
track tr 
)

Definition at line 60 of file sequenceStream.cpp.

References bufferSize, readingFile, and retainSize.

: sequence(seq, tr){
bufferSize=buff;
readingFile = false;
}

Member Function Documentation

bool StochHMM::sequenceStream::getFasta ( std::ifstream &  file,
track trk 
)

Reimplemented from StochHMM::sequence.

Definition at line 81 of file sequenceStream.cpp.

References StochHMM::sequence::_digitize(), bufferSize, StochHMM::sequence::header, StochHMM::sequence::length, previousSeq, readingFile, resetSeq(), retain, retainSize, StochHMM::sequence::seq, StochHMM::sequence::seqtrk, and StochHMM::sequence::undigitized.

{
seqtrk=trk;
if (readingFile == false) {
//Find next header mark
while(file.peek() != '>'){
std::string temp;
getline(file,temp,'\n');
if (!file.good()){
return false;
}
}
getline(file,header,'\n');
//std::cout << header << std::endl;
readingFile = true;
}
bool success;
size_t fillBuffer=0;
//Sequence always begins with whatever was retained
fillBuffer+=retain.size();
retain.clear();
//The following clears up the previousSeq when the "getline" size
//is 2 or more times the buffer size
fillBuffer+=previousSeq.size();
if (fillBuffer >= bufferSize) {
size_t overhanging, charsToKeep;
overhanging = fillBuffer - bufferSize;
if (overhanging == 0) {
previousSeq.clear();
}
else{
charsToKeep = previousSeq.size() - overhanging;
undigitized+=previousSeq.substr(0,charsToKeep);
std::string temp = previousSeq;
previousSeq.clear();
previousSeq+=temp.substr(charsToKeep);
}
//
//std::cout << "1: " << undigitized << std::endl;
//
success = _digitize();
length=seq->size();
return success;
}
//The remaining line sequence (if any) after the last buffer filled up goes to the next buffer
previousSeq.clear();
//For the case where the buffer filled right before the next header or eof;
//the "nl_peek" portion inside the loop would be skipped, and when overhanging!=0,
//there is still some sequence to deal with in the final line
char nl_peek = file.peek();
if (nl_peek =='>' || nl_peek == EOF) {
if (undigitized.size() >= 1) {
//
// std::cout << "2: " << undigitized << std::endl;
//
if (!_digitize()) {
std::cerr << "sequence was not digitized" << std::endl;
}
}
success = false;
readingFile = false;
length=seq->size();
return success;
}
std::string line;
while(getline(file,line,'\n')) {
fillBuffer+=line.size();
//When the buffer fills up, the entire line may fill it up
//or some of the line is left overhanging
if (fillBuffer >= bufferSize) {
size_t overhanging, charsToKeep;
overhanging = fillBuffer - bufferSize;
if (overhanging == 0) {
undigitized+=line;
}
else{
//Overhanging is stored in previousSeq and accounted for in the next calling
//of this function
charsToKeep = line.size() - overhanging;
undigitized+=line.substr(0,charsToKeep);
previousSeq+=line.substr(charsToKeep);
}
//
// std::cout << "3: " << undigitized << std::endl;
//
success = _digitize();
break;
}
undigitized+=line;
//For the case where the buffer has not filled up but the file has reached the next header or eof
char nl_peek = file.peek();
if (nl_peek =='>' || nl_peek == EOF) {
//
// std::cout << "4: " << undigitized << std::endl;
//
if (!_digitize()) {
std::cerr << "sequence was not digitized" << std::endl;
}
success = false;
readingFile = false;
break;
}
}
length = seq->size();
return success;
}
void StochHMM::sequenceStream::resetSeq ( )
private

Reset seq or realseq each time getfasta is called.

Definition at line 220 of file sequenceStream.cpp.

References StochHMM::sequence::real, StochHMM::sequence::realSeq, and StochHMM::sequence::seq.

Referenced by getFasta().

{
if (realSeq) {
real=new(std::nothrow) std::vector<double>;
if (real==NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
seq=NULL;
}
else{
real=NULL;
seq=new(std::nothrow) std::vector<short>;
if (seq==NULL){
std::cerr << "OUT OF MEMORY\nFile" << __FILE__ << "Line:\t"<< __LINE__ << std::endl;
exit(1);
}
}
}
void StochHMM::sequenceStream::setBuffer ( size_t  buff)
inline

Definition at line 39 of file sequenceStream.h.

References bufferSize.

{ bufferSize = buff; }
void StochHMM::sequenceStream::setRetain ( size_t  ret)
inline

Definition at line 40 of file sequenceStream.h.

References retainSize.

{ retainSize = ret; }

Member Data Documentation

size_t StochHMM::sequenceStream::bufferSize
private

Definition at line 43 of file sequenceStream.h.

Referenced by getFasta(), sequenceStream(), and setBuffer().

std::string StochHMM::sequenceStream::previousSeq
private

What is left in "getline" after the buffer has been filled.

Definition at line 47 of file sequenceStream.h.

Referenced by getFasta().

bool StochHMM::sequenceStream::readingFile
private

Keeps track of whether the sequence under the same header is being read.

Definition at line 53 of file sequenceStream.h.

Referenced by getFasta(), and sequenceStream().

std::string StochHMM::sequenceStream::retain
private

The retain sequence.

Definition at line 50 of file sequenceStream.h.

Referenced by getFasta().

size_t StochHMM::sequenceStream::retainSize
private

Definition at line 44 of file sequenceStream.h.

Referenced by getFasta(), sequenceStream(), and setRetain().


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