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

Stringlist is an list of strings that contains parsed comments and can be used to split string or remove whitespace from a string. More...

#include <text.h>

List of all members.

Public Member Functions

 stringList ()
 stringList (std::string &, std::string &, std::string &, bool)
void setRemoveWS ()
 Set remove whitespace flag. When splitting string it will remove Whitespace first and then split the string.
void unsetRemoveWS ()
 Unset remove whitespace flag. When splitting string it will remove Whitespace first and then split the string.
void setWhitespace (const std::string &txt)
void setDelimiters (const std::string &txt)
void getLine (std::istream &)
void processString (std::string &)
void splitString (const std::string &)
void splitString (const std::string &, const std::string &)
void splitString (const std::string &, size_t)
void splitND (const std::string &, const std::string &)
void removeLWS (const std::string &)
void removeComments ()
void clear ()
 Clears all values from the stringList, including comments, whitespace, and delimiters.
bool fromTable (std::string &)
bool fromTable (std::istream &)
bool fromTrack (std::string &)
bool fromTrack (std::istream &)
bool fromAlpha (const std::string &, size_t)
bool fromAlpha (std::istream &, size_t)
bool fromTxt (std::string &)
bool fromTxt (std::istream &)
bool fromNext (std::string &)
bool fromNext (std::istream &)
bool fromDef (std::string &, std::string &, std::string &)
bool fromDef (std::istream &, std::string &, std::string &)
void operator<< (std::string &txt)
void push_back (std::string &txt)
std::string pop_ith (size_t)
void operator= (stringList &lst)
std::string & operator[] (size_t iter)
std::string & getComment ()
 Return any comments parsed from the line.
std::vector< double > toVecDouble ()
 Returns the list as a Vector of Doubles.
void toVecInt (std::vector< int > &)
 Returns the values in the stringList as std::vector of integers.
size_t indexOf (const std::string &)
size_t indexOf (const std::string &, size_t)
bool contains (const std::string &)
bool containsExact (const std::string &txt)
void print ()
 Print each line to stdout.
std::string stringify ()
size_t size ()
 Return the amount of strings in the stringList.

Private Member Functions

void _splitIndividual (std::string &, size_t)
bool foundAlphaDelimiter (const std::string &)

Private Attributes

std::vector< std::string > line
std::string comment
bool removeWS
std::string whitespace
std::string delimiters

Detailed Description

Stringlist is an list of strings that contains parsed comments and can be used to split string or remove whitespace from a string.

Definition at line 55 of file text.h.


Constructor & Destructor Documentation

StochHMM::stringList::stringList ( )

Create a new stringList Remove whitespace set to true by default.

Definition at line 32 of file text.cpp.

References removeWS.

{
removeWS=true;
return;
}
StochHMM::stringList::stringList ( std::string &  txt,
std::string &  ws,
std::string &  del,
bool  remove 
)

Create a new StringList

Parameters:
txtString to be split
wsWhitespace characters to remove from string before splitting
delDelimiter characters to use to split string
removeTrue will remove whitespace, False will leave whitespace

Definition at line 43 of file text.cpp.

References splitString().

:removeWS(remove), whitespace(ws),delimiters(del)
{
return;
}

Member Function Documentation

void StochHMM::stringList::_splitIndividual ( std::string &  ,
size_t   
)
private
void StochHMM::stringList::clear ( )
inline

Clears all values from the stringList, including comments, whitespace, and delimiters.

Definition at line 86 of file text.h.

References comment, delimiters, line, and whitespace.

Referenced by StochHMM::splitString().

{line.clear();comment.clear();whitespace.clear();delimiters.clear();};
bool StochHMM::stringList::contains ( const std::string &  txt)
bool StochHMM::stringList::containsExact ( const std::string &  txt)

Definition at line 60 of file text.cpp.

References line.

Referenced by StochHMM::model::_getOrderedStateNames().

{
for (size_t i=0;i<line.size();i++){
if (line[i].compare(txt) == 0){
return true;
}
}
return false;
}
bool StochHMM::stringList::foundAlphaDelimiter ( const std::string &  txt)
private

Returns true if text delimiters ":,[space]\\t" are found in the string

Parameters:
txtString used to find delimiter

Definition at line 284 of file text.cpp.

Referenced by fromAlpha().

{
for(size_t i=0;i<txt.size();i++){
switch(txt[i]){
case ':':
return true;
case ',':
return true;
case ' ':
return true;
case '\t':
return true;
default:
break;
}
}
return false;
}
bool StochHMM::stringList::fromAlpha ( const std::string &  txt,
size_t  alpha 
)

Remove whitespace characters '' and then splits string by delimiters ':' or '
'

Parameters:
txtString to be split

Definition at line 264 of file text.cpp.

References comment, foundAlphaDelimiter(), line, size(), and splitString().

Referenced by fromAlpha().

{
line.clear();
comment.clear();
splitString(txt,";, \t");
}
else{
splitString(txt,alpha);
}
if (this->size()>0){
return true;
}
return false;
}
bool StochHMM::stringList::fromAlpha ( std::istream &  in,
size_t  alpha 
)

Remove whitespace characters '' and then splits string by delimiters ':' or '
'

Parameters:
instd::istream stream
alphaSize of alphabet

Definition at line 308 of file text.cpp.

References fromAlpha().

{
std::string temp;
getline(in, temp, '\n');
return fromAlpha(temp,alpha);
}
bool StochHMM::stringList::fromDef ( std::string &  txt,
std::string &  ws,
std::string &  del 
)

Splits a definition from model file

Parameters:
txtstring to split
wsWhitespace characters to use
delDelimiters characters to use

Definition at line 319 of file text.cpp.

References delimiters, processString(), size(), and whitespace.

Referenced by fromDef(), and StochHMM::ExDefSequence::parse().

{
delimiters = del;
if (size()>0){
return true;
}
else{
return false;
}
}
bool StochHMM::stringList::fromDef ( std::istream &  in,
std::string &  ws,
std::string &  del 
)

Splits a definition from model file

Parameters:
instd::istream to get line from
wsWhitespace characters to use
delDelimiters characters to use

Definition at line 337 of file text.cpp.

References delimiters, fromDef(), and whitespace.

{
delimiters = del;
std::string temp;
getline(in, temp, '\n');
return fromDef(temp, ws, del);
}
bool StochHMM::stringList::fromNext ( std::string &  txt)

Remove whitespace characters '','
' or space and then splits string by delimiters ':' or comma

Parameters:
txtString to be split

Definition at line 241 of file text.cpp.

References processString(), setDelimiters(), setWhitespace(), and size().

Referenced by fromNext(), and StochHMM::track::parse().

{
setWhitespace("\t\n ");
if (size()>0){
return true;
}
return false;
}
bool StochHMM::stringList::fromNext ( std::istream &  in)

Remove whitespace characters '','
' or space and then splits string by delimiters ':' or comma

Parameters:
txtstd::istream reference

Definition at line 255 of file text.cpp.

References fromNext().

{
std::string temp;
getline(in, temp, '\n');
return fromNext(temp);
}
bool StochHMM::stringList::fromTable ( std::string &  )
bool StochHMM::stringList::fromTable ( std::istream &  )
bool StochHMM::stringList::fromTrack ( std::string &  txt)

Remove whitespace characters '' and then splits string by delimiters ':', '
', comma or space

Parameters:
txtString to be split

Definition at line 220 of file text.cpp.

References processString(), setDelimiters(), setWhitespace(), and size().

Referenced by fromTrack().

{
setDelimiters(":, \n");
if (size()>0){
return true;
}
return false;
}
bool StochHMM::stringList::fromTrack ( std::istream &  in)

Remove whitespace characters '' and then splits string by delimiters ':', '
', comma or space

Parameters:
instd::istream reference

Definition at line 233 of file text.cpp.

References fromTrack().

{
std::string temp;
getline(in, temp, '\n');
return fromTrack(temp);
}
bool StochHMM::stringList::fromTxt ( std::string &  txt)

Remove whitespace characters '\t' and then splits string by delimiters ':' or '\n'

Parameters:
txtString to be split

Definition at line 195 of file text.cpp.

References processString(), setDelimiters(), setWhitespace(), and size().

Referenced by StochHMM::model::_parseHeader(), and fromTxt().

{
setDelimiters(":\n");
if (size()>0){
return true;
}
else{
return false;
}
}
bool StochHMM::stringList::fromTxt ( std::istream &  in)

Remove whitespace characters '\t' and then splits string by delimiters ':' or '\n' Uses std::istream::getline(...,\n) and splits string

Parameters:
instd::istream reference

Definition at line 211 of file text.cpp.

References fromTxt().

{
std::string temp;
getline(in, temp, '\n');
return fromTxt(temp);
}
std::string& StochHMM::stringList::getComment ( )
inline

Return any comments parsed from the line.

Definition at line 121 of file text.h.

References comment.

Referenced by StochHMM::track::parse().

{return comment;};
void StochHMM::stringList::getLine ( std::istream &  )
size_t StochHMM::stringList::indexOf ( const std::string &  txt)

Searches the stringList for matching string and returns the index position of first match

Parameters:
txtString to search stringList for

Definition at line 71 of file text.cpp.

References line, and SIZE_MAX.

Referenced by StochHMM::transition::_parseDuration(), StochHMM::state::_parseHeader(), StochHMM::model::_parseHeader(), StochHMM::transition::_parseLexical(), StochHMM::model::_processTemplateState(), StochHMM::transitionFuncParam::parse(), StochHMM::emm::parse(), StochHMM::track::parse(), and StochHMM::emissionFuncParam::parse().

{
for (size_t i=0;i<line.size();i++){
if (line[i].find(txt) != std::string::npos){
return i;
}
}
return SIZE_MAX;
}
size_t StochHMM::stringList::indexOf ( const std::string &  txt,
size_t  pos 
)

Searches the stringList for matching string and returns the index position of a given string from the starting position

Parameters:
txtString to search stringList for
posPosition to start search from

Definition at line 83 of file text.cpp.

References line, and SIZE_MAX.

{
for (size_t i=pos;i<line.size();i++){
if (line[i].find(txt) != std::string::npos){
return i;
}
}
return SIZE_MAX;
}
void StochHMM::stringList::operator<< ( std::string &  txt)
inline

Add string to StringList

Parameters:
txtString to add to the stringList

Definition at line 103 of file text.h.

References line.

{line.push_back(txt);};
void StochHMM::stringList::operator= ( stringList lst)
inline

Copy StringList

Parameters:
lststringList to copy

Definition at line 113 of file text.h.

References comment, delimiters, line, and whitespace.

{line=lst.line; comment=lst.comment; whitespace=lst.whitespace; delimiters=lst.delimiters;};
std::string& StochHMM::stringList::operator[] ( size_t  iter)
inline

Access string at iterator

Parameters:
iterPosition to return;

Definition at line 118 of file text.h.

References line.

{return line[iter];};
std::string StochHMM::stringList::pop_ith ( size_t  pos)

Definition at line 346 of file text.cpp.

References line.

Referenced by StochHMM::transition::_parseLexical(), and StochHMM::emm::parse().

{
if (pos>=line.size()){
return "";
}
std::string temp=line[pos];
line.erase(line.begin()+pos);
return temp;
}
void StochHMM::stringList::print ( )

Print each line to stdout.

Definition at line 392 of file text.cpp.

References comment, and line.

Referenced by StochHMM::model::_processTemplateState().

{
for(size_t i=0;i<line.size();i++){
std::cout << line[i] << std::endl;
}
std::cout << "#" << comment << std::endl;
}
void StochHMM::stringList::processString ( std::string &  txt)

Removes Comments, Removes Whitespace, and splits the string Whitespace and Split delimiters are required to be previously set in stringList

Definition at line 94 of file text.cpp.

References StochHMM::clear_whitespace(), comment, line, StochHMM::parseComment(), removeWS, splitString(), and whitespace.

Referenced by fromDef(), fromNext(), fromTrack(), and fromTxt().

{
line.clear();
comment.clear();
//Extract Comments
comment=parseComment(txt, '#');
//Remove Whitespace
if (removeWS){
}
return;
}
void StochHMM::stringList::push_back ( std::string &  txt)
inline
void StochHMM::stringList::removeComments ( )

Parses out the comments and stores the comment delimited by "#" *Comment can be accessed by command getComment();

Definition at line 414 of file text.cpp.

References comment, line, and StochHMM::parseComment().

Referenced by StochHMM::state::_parseTransition().

{
for(size_t iter=0;iter<line.size();iter++){
comment+=parseComment(line[iter], '#');
}
}
void StochHMM::stringList::removeLWS ( const std::string &  ws)

Remove leading whitespace *Removes the leading whitespace from the sequence

Parameters:
wsString of whitespace characters to remove

Definition at line 185 of file text.cpp.

References StochHMM::removeLeadingWS(), and size().

Referenced by StochHMM::state::_parseTransition().

{
for(size_t i=0;i<this->size();i++){
removeLeadingWS((*this)[i],ws);
}
return;
}
void StochHMM::stringList::setDelimiters ( const std::string &  txt)
inline

Set delimiter characters. String will be split on these characters

Parameters:
txtString of text-delimiters to use in splitting string

Definition at line 74 of file text.h.

References delimiters.

Referenced by fromNext(), fromTrack(), and fromTxt().

{delimiters=txt;};
void StochHMM::stringList::setRemoveWS ( )
inline

Set remove whitespace flag. When splitting string it will remove Whitespace first and then split the string.

Definition at line 62 of file text.h.

References removeWS.

{removeWS=true;}; //!<
void StochHMM::stringList::setWhitespace ( const std::string &  txt)
inline

Set whitespace character. When splitting string it will remove defined whitespace characters before splitting the string.

Parameters:
txtString of whitespace characters to remove from sequence

Definition at line 70 of file text.h.

References whitespace.

Referenced by fromNext(), fromTrack(), and fromTxt().

{whitespace=txt;};
size_t StochHMM::stringList::size ( void  )
inline
void StochHMM::stringList::splitND ( const std::string &  txt,
const std::string &  del 
)

Non-destructive string split Splits the string up using an additional string as the delimiter. Unlike stringSplit the delimiter isn't deleted from the returned value;

Parameters:
txtString to be split
delDelimiter string to use to split

Definition at line 163 of file text.cpp.

References comment, and line.

Referenced by StochHMM::state::_parseEmission(), StochHMM::model::_parseScaling(), StochHMM::state::_parseTransition(), and StochHMM::matrixPosition::parse().

{
line.clear();
comment.clear();
size_t initial=txt.find(del);
do {
size_t found=txt.find(del,initial+1);
std::string st=txt.substr(initial,found-initial);
initial=found;
if (st.size()>0){
line.push_back(st);
}
} while (initial!=std::string::npos);
return;
}
void StochHMM::stringList::splitString ( const std::string &  txt)

Split string using delimiter Splits the string up according to character delimiters defined in stringList. The char delimiters are deleted from the returned value. Delimiters allows you supply multiple delimiters in a single string.

Parameters:
txtString to be split

Definition at line 116 of file text.cpp.

References comment, delimiters, line, and SIZE_MAX.

Referenced by StochHMM::sequence::_digitize(), StochHMM::PWM::_parseAmbiguous(), StochHMM::model::_parseAmbiguous(), StochHMM::transition::_parseDuration(), StochHMM::transition::_parseLexical(), StochHMM::PWM::_parseSpacer(), StochHMM::transition::_parseStandard(), StochHMM::PWM::_parseTrack(), StochHMM::model::_parseTracks(), StochHMM::model::_processTemplateState(), StochHMM::extractTag(), fromAlpha(), StochHMM::getKeyValue(), StochHMM::sequence::getMaskedFasta(), StochHMM::sequence::getReal(), StochHMM::emm::parse(), StochHMM::matrixPosition::parse(), StochHMM::weight::parse(), processString(), splitString(), StochHMM::splitString(), and stringList().

{
line.clear();
comment.clear();
size_t found = SIZE_MAX;
size_t initial= SIZE_MAX;
do {
found++;
initial=found;
found=txt.find_first_of(delimiters.c_str(),found);
std::string st=txt.substr(initial,found-initial);
if (st.size()>0){
line.push_back(st);
}
} while (found!=std::string::npos);
return;
}
void StochHMM::stringList::splitString ( const std::string &  txt,
const std::string &  del 
)

Split string using delimiter Splits the string up according to character delimiters supplied in the delimiter string. The char delimiters are deleted from the returned value. Delimiters allows you supply multiple delimiters in a single string.

Parameters:
txtString to be split
delDelimiters to use to split evaluated as single characters, not whole string

Definition at line 145 of file text.cpp.

References delimiters, and splitString().

{
return;
}
void StochHMM::stringList::splitString ( const std::string &  txt,
size_t  charSize 
)

Definition at line 151 of file text.cpp.

References line.

{
for(size_t i=0;i<txt.size();i+=charSize){
line.push_back(txt.substr(i,charSize));
}
return;
}
std::string StochHMM::stringList::stringify ( )

Joins the stringList into string using "\t" and return string

Returns:
string of stringList joined by "\\t"

Definition at line 402 of file text.cpp.

References comment, StochHMM::join(), and line.

Referenced by StochHMM::transition::_parseDuration(), StochHMM::transition::_parseLexical(), StochHMM::emm::_processTags(), StochHMM::model::_processTemplateState(), and StochHMM::track::parse().

{
std::string output=join(line,'\t');
if (comment.size()>0){
output+="#"+ comment;
}
return output;
}
std::vector< double > StochHMM::stringList::toVecDouble ( )

Returns the list as a Vector of Doubles.

Returns the values in the stringList as std::vector of doubles.

Definition at line 358 of file text.cpp.

References line, and StochHMM::stringToDouble().

Referenced by StochHMM::transition::_parseLexical(), StochHMM::sequence::getReal(), and StochHMM::emm::parse().

{
std::vector<double> temp;
for(size_t iter=0;iter<line.size();iter++){
double val;
stringToDouble(line[iter], val);
temp.push_back(val);
}
return temp;
}
void StochHMM::stringList::toVecInt ( std::vector< int > &  ret_val)

Returns the values in the stringList as std::vector of integers.

Definition at line 371 of file text.cpp.

References line, and StochHMM::stringToInt().

Referenced by StochHMM::sequence::getMaskedFasta().

{
for(size_t iter=0;iter<line.size();iter++){
int val(0);
if (!stringToInt(line[iter], val)){
std::cerr << "Couldn't convert " << line[iter] << " to an integer\n";
}
else{
ret_val.push_back(val);
}
}
return;
}
void StochHMM::stringList::unsetRemoveWS ( )
inline

Unset remove whitespace flag. When splitting string it will remove Whitespace first and then split the string.

Definition at line 66 of file text.h.

References removeWS.

{removeWS=false;};

Member Data Documentation

std::string StochHMM::stringList::comment
private
std::string StochHMM::stringList::delimiters
private

Definition at line 149 of file text.h.

Referenced by clear(), fromDef(), operator=(), setDelimiters(), and splitString().

std::vector<std::string> StochHMM::stringList::line
private
bool StochHMM::stringList::removeWS
private

Definition at line 147 of file text.h.

Referenced by processString(), setRemoveWS(), stringList(), and unsetRemoveWS().

std::string StochHMM::stringList::whitespace
private

Definition at line 148 of file text.h.

Referenced by clear(), fromDef(), operator=(), processString(), and setWhitespace().


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