utils Namespace Reference

Utilities class. This class contains shared methods to be used in multiple parts of the code. More...

Namespaces

 TerminalColors
 

Functions

void initlVect (int *vector, int tam, int valor)
 Vector initialization. More...
 
void initlVect (float *vector, int tam, float valor)
 Vector initialization. More...
 
void copyVect (int *vect1, int *vect2, int tam)
 Integer vector copying. More...
 
void copyVect (float *vect1, float *vect2, int tam)
 Float vector copying. More...
 
int roundToInf (double number)
 Round double to inferior integer method. More...
 
int roundInt (double number)
 Round double to integer method. More...
 
int roundToSup (double number)
 Round double to greater integer method. More...
 
int max (int x, int y)
 Maximum of two numbers method. More...
 
float max (float x, float y)
 Maximum of two numbers method. More...
 
double max (double x, double y)
 Maximum of two numbers method. More...
 
int min (int x, int y)
 Minimum of two numbers method. More...
 
float min (float x, float y)
 Minimum of two numbers method. More...
 
double min (double x, double y)
 Minimum of two numbers method. More...
 
bool isNumber (char *num)
 String-is-number checking. More...
 
bool compare (char *a, char *b)
 String comparing method. More...
 
void removeSpaces (char *in, char *out)
 Removing spaces method. More...
 
void quicksort (float *list, int ini, int fin)
 Quicksort sorting method. More...
 
void swap (float *a, float *b)
 Swapping elements method. More...
 
void quicksort (int *list, int ini, int fin)
 Quicksort sorting method. More...
 
void swap (int *a, int *b)
 Swapping elements method. More...
 
bool checkFile (std::ifstream &file)
 Check if a given file exists and its size is greater than 0. More...
 
char * readLine (std::ifstream &file)
 Read a new line from current input stream.
This function is better than standard one since cares of operative system compatibility.
It is useful as well because removes tabs and blank spaces at lines at beginning/ending.
. More...
 
char * readLine (std::istream &file)
 Read a new line from current input stream.
This function is better than standard one since cares of operative system compatibility.
It is useful as well because removes tabs and blank spaces at lines at beginning/ending.
. More...
 
char * trimLine (std::string nline)
 Remove all content surrounded by ("") or ([]).
It warns as well when a mismatch for these flags is found.
. More...
 
std::string getReverse (const std::string &toReverse)
 Reverses a string. More...
 
std::string removeCharacter (char c, std::string line)
 Removes a determined char from the string. More...
 
int checkAlignmentType (int seqNumber, int residNumber, std::string *sequences)
 Checks an alignment type. More...
 
int * readNumbers (const std::string &line)
 Reads a line and converts it to an array of number. More...
 
void quicksort (int **vect, int ini, int fin)
 Quicksort sorting method. More...
 
void swap (int **a, int **b)
 Swaps double pointers. More...
 
char determineColor (char res, const std::string &column)
 Checks the color that has to be used on the output report. More...
 
bool lookForPattern (const std::string &data, const std::string &pattern, const float threshold)
 Method to check for a pattern in a string.
The method will check, character by character of the first string if there is some equality for each character in the pattern.
When done, it will calculate the fraction of characters present in the pattern and compare to the threshold argument. More...
 
void ReplaceStringInPlace (std::string &subject, const std::string &search, const std::string &replace)
 Function that replaces a substring with another substring in a string. It does not make a copy of the original string, but modifies it. More...
 
std::string ReplaceString (std::string subject, const std::string &search, const std::string &replace)
 Function that replaces a substring with another substring in a string. It makes a copy of the original string. More...
 
int GetGapStep (int *gapValue, int sequenNumber)
 Function that gives the gap classification of a column of values. More...
 
int GetGapStep (int *gapValue, float inverseSequenNumber)
 Function that gives the gap classification of a column of values.
This function should work faster than it's sister utils::GetGapStep(int * gapValue, int sequenNumber), as it uses a precomputed (by the user) inverseSequenNumber (1F / Alignment::sequenNumber), instead of calculating it over again each time the function is called (which is equal to number of residues).
This comes with a precision cost that shouldn't be a problem. More...
 
int GetSimStep (float *simValue)
 Function that gives the similarity classification of a column of values. More...
 
int GetConsStep (float *consValue)
 Function that gives the consistency classification of a column of values. More...
 
bool fileExists (std::string &path)
 Method to check the existance of a file. More...
 
bool fileExists (std::string &&path)
 Method to check the existance of a file. Works exactly as fileExists(std::string & path), but accepts r-value reference. More...
 
char toUpper (char c)
 

Detailed Description

Utilities class. This class contains shared methods to be used in multiple parts of the code.

Function Documentation

◆ checkAlignmentType()

int utils::checkAlignmentType ( int  seqNumber,
int  residNumber,
std::string *  sequences 
)

Checks an alignment type.

Parameters
seqNumberNumber of sequences to check it's type.
residNumberNumber of residues of the alignment.
sequencesSequences pointer
Returns
Integer that represents the alignment type.

Definition at line 499 of file utils.cpp.

References AA, DEG, DNA, NotDefined, RNA, and toUpper().

Referenced by Alignment::getAlignmentType().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ checkFile()

bool utils::checkFile ( std::ifstream &  file)

Check if a given file exists and its size is greater than 0.

Parameters
fileifstream to check

Definition at line 284 of file utils.cpp.

◆ compare()

bool utils::compare ( char *  a,
char *  b 
)

String comparing method.

Parameters
aThe first string that will be compared.
bThe second string that will be compared.
Returns
true if the two strings are the same, false if not.

This method compares the two strings given, and returns true if the two strings are equal.

Definition at line 139 of file utils.cpp.

◆ copyVect() [1/2]

void utils::copyVect ( int *  vect1,
int *  vect2,
int  tam 
)

Integer vector copying.

Parameters
vect1Vector that we want to copy.
[out]vect2Destination vector of the copy.
tamVectors size.

This method copies integer vector 1 to integer vector 2.

Definition at line 51 of file utils.cpp.

Referenced by statistics::Gaps::printGapsColumns().

+ Here is the caller graph for this function:

◆ copyVect() [2/2]

void utils::copyVect ( float *  vect1,
float *  vect2,
int  tam 
)

Float vector copying.

Parameters
vect1Vector that we want to copy.
[out]vect2Destination vector of the copy.
tamVectors size.

This method copies float vector 1 to float vector 2.

Definition at line 57 of file utils.cpp.

Referenced by statistics::Similarity::calcCutPoint(), Cleaner::cleanCompareFile(), statistics::Mold::printAccumulative(), statistics::Similarity::printConservationAcl(), and statistics::Consistency::printStatisticsFileAcl().

+ Here is the caller graph for this function:

◆ determineColor()

char utils::determineColor ( char  res,
const std::string &  column 
)

Checks the color that has to be used on the output report.

Parameters
resResiude to check its color
columnColumn to which this residue belongs.
Returns
Char that represents the color to be used.

Definition at line 675 of file utils.cpp.

References lookForPattern().

Referenced by Alignment::alignmentSummaryHTML(), and Alignment::alignmentSummarySVG().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fileExists() [1/2]

bool utils::fileExists ( std::string &  path)

Method to check the existance of a file.

Parameters
pathPath to the file to check
Returns
Wheter the file exists or not.

Definition at line 948 of file utils.cpp.

◆ fileExists() [2/2]

bool utils::fileExists ( std::string &&  path)

Method to check the existance of a file. Works exactly as fileExists(std::string & path), but accepts r-value reference.

Parameters
pathPath to the file to check
Returns
Wheter the file exists or not.

Definition at line 953 of file utils.cpp.

Referenced by FormatHandling::FormatManager::saveAlignments().

+ Here is the caller graph for this function:

◆ GetConsStep()

int utils::GetConsStep ( float *  consValue)

Function that gives the consistency classification of a column of values.

Parameters
consValueConsistency value.
Returns
Int representing the classification of this gap value.

Definition at line 920 of file utils.cpp.

◆ GetGapStep() [1/2]

int utils::GetGapStep ( int *  gapValue,
int  sequenNumber 
)

Function that gives the gap classification of a column of values.

Parameters
gapValueNumber of gaps present in the column.
sequenNumberNumber of sequences.
Returns
Int representing the classification of this gap value.

Definition at line 832 of file utils.cpp.

◆ GetGapStep() [2/2]

int utils::GetGapStep ( int *  gapValue,
float  inverseSequenNumber 
)

Function that gives the gap classification of a column of values.
This function should work faster than it's sister utils::GetGapStep(int * gapValue, int sequenNumber), as it uses a precomputed (by the user) inverseSequenNumber (1F / Alignment::sequenNumber), instead of calculating it over again each time the function is called (which is equal to number of residues).
This comes with a precision cost that shouldn't be a problem.

Parameters
gapValueNumber of gaps present in the column.
inverseSequenNumberInverse of number of sequences. (1F / sequenNumber)
Returns
Int representing the classification of this gap value.

Definition at line 863 of file utils.cpp.

◆ getReverse()

std::string utils::getReverse ( const std::string &  toReverse)

Reverses a string.

Parameters
toReverseString to get a reversed copy.
Returns
Reversed string of toReverse.

Definition at line 475 of file utils.cpp.

◆ GetSimStep()

int utils::GetSimStep ( float *  simValue)

Function that gives the similarity classification of a column of values.

Parameters
simValueSimilarity value.
Returns
Int representing the classification of this gap value.

Definition at line 893 of file utils.cpp.

◆ initlVect() [1/2]

void utils::initlVect ( int *  vector,
int  tam,
int  valor 
)

Vector initialization.

Parameters
[out]vectorThe vector that will be initialized.
tamThe size of the vector.
valorThe initialization value that will of all positions of the vector.

This method is used to initialize all positions of a vector with a given value.

Definition at line 40 of file utils.cpp.

Referenced by statistics::Gaps::applyWindow(), Cleaner::cleanCombMethods(), statistics::Consistency::forceComparison(), statistics::Gaps::Gaps(), statistics::similarityMatrix::loadSimMatrix(), and Alignment::sequencesMatrix::sequencesMatrix().

+ Here is the caller graph for this function:

◆ initlVect() [2/2]

void utils::initlVect ( float *  vector,
int  tam,
float  valor 
)

Vector initialization.

Parameters
[out]vectorThe vector that will be initialized.
tamThe size of the vector.
valorThe initialization value of all positions of the vector.

This method is used to initialize all positions of a vector with a given value.

Definition at line 46 of file utils.cpp.

Referenced by statistics::Gaps::calcCutPoint2ndSlope(), statistics::Gaps::calcCutPointMixSlope(), statistics::Consistency::compareAndChoose(), statistics::Consistency::forceComparison(), and statistics::Similarity::Similarity().

+ Here is the caller graph for this function:

◆ isNumber()

bool utils::isNumber ( char *  num)

String-is-number checking.

Parameters
numThe string we want to check.
Returns
true if the string is a number, false if not.

This method checks if the given string is a number (taking in mind the possibility of floating numbers and scientific notation)

Definition at line 116 of file utils.cpp.

Referenced by trimAlManager::block_argument(), trimAlManager::clusters_argument(), trimAlManager::conservation_threshold_argument(), trimAlManager::consistency_threshold_argument(), trimAlManager::consistency_window_argument(), trimAlManager::gap_threshold_argument(), trimAlManager::gap_window_argument(), main(), trimAlManager::max_identity_argument(), trimAlManager::min_coverage_argument(), trimAlManager::min_quality_argument(), trimAlManager::residue_overlap_argument(), trimAlManager::sequence_overlap_argument(), trimAlManager::similarity_threshold_argument(), trimAlManager::similarity_window_argument(), and trimAlManager::window_argument().

+ Here is the caller graph for this function:

◆ lookForPattern()

bool utils::lookForPattern ( const std::string &  data,
const std::string &  pattern,
const float  threshold 
)

Method to check for a pattern in a string.
The method will check, character by character of the first string if there is some equality for each character in the pattern.
When done, it will calculate the fraction of characters present in the pattern and compare to the threshold argument.

Parameters
datastring that will be compared against a pattern
patternstring that contains the pattern.
thresholdminimum ratio of hits to consider the pattern valid

Definition at line 793 of file utils.cpp.

References toUpper().

Referenced by determineColor().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ max() [1/3]

int utils::max ( int  x,
int  y 
)

Maximum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The maximum between the two given numbers.

This method returns the maximum between the two numbers given as parameters.

Definition at line 80 of file utils.cpp.

Referenced by Alignment::alignmentSummaryHTML(), Alignment::alignmentSummarySVG(), Alignment::printSeqIdentity(), and Alignment::printSeqOverlap().

+ Here is the caller graph for this function:

◆ max() [2/3]

float utils::max ( float  x,
float  y 
)

Maximum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The maximum between the two given numbers.

This method returns the maximum between the two numbers given as parameters.

Definition at line 86 of file utils.cpp.

◆ max() [3/3]

double utils::max ( double  x,
double  y 
)

Maximum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The maximum between the two given numbers.

This method returns the maximum between the two numbers given as parameters.

Definition at line 92 of file utils.cpp.

Referenced by statistics::Gaps::calcCutPoint().

+ Here is the caller graph for this function:

◆ min() [1/3]

int utils::min ( int  x,
int  y 
)

Minimum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The minumum between the two given numbers.

This method returns the minimum between the two numbers given as parameters.

Definition at line 98 of file utils.cpp.

Referenced by Alignment::checkCorrespondence().

+ Here is the caller graph for this function:

◆ min() [2/3]

float utils::min ( float  x,
float  y 
)

Minimum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The minumum between the two given numbers.

This method returns the minimum between the two numbers given as parameters.

Definition at line 104 of file utils.cpp.

Referenced by Cleaner::cleanCompareFile().

+ Here is the caller graph for this function:

◆ min() [3/3]

double utils::min ( double  x,
double  y 
)

Minimum of two numbers method.

Parameters
xThe first number.
yThe second number.
Returns
The minumum between the two given numbers.

This method returns the minimum between the two numbers given as parameters.

Definition at line 110 of file utils.cpp.

◆ quicksort() [1/3]

void utils::quicksort ( float *  list,
int  ini,
int  fin 
)

Quicksort sorting method.

Parameters
listThe vector that we want to sort.
iniThe first element of the vector.
finThe last element of the vector.

This method sorts the vector using the quicksort method.

Definition at line 159 of file utils.cpp.

References quicksort(), and swap().

Referenced by statistics::Similarity::calcCutPoint(), Cleaner::cleanByCutValueOverpassOrEquals(), Cleaner::cleanCombMethods(), Cleaner::cleanCompareFile(), statistics::Mold::printAccumulative(), statistics::Similarity::printConservationAcl(), statistics::Consistency::printStatisticsFileAcl(), quicksort(), and Alignment::statSVG().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quicksort() [2/3]

void utils::quicksort ( int *  list,
int  ini,
int  fin 
)

Quicksort sorting method.

Parameters
listThe vector that we want to sort.
iniThe first element of the vector.
finThe last element of the vector.

This method sorts the vector using the quicksort method.

Definition at line 204 of file utils.cpp.

References quicksort(), and swap().

Referenced by Cleaner::cleanByCutValueOverpass(), Cleaner::cleanByCutValueOverpassOrEquals(), and quicksort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ quicksort() [3/3]

void utils::quicksort ( int **  vect,
int  ini,
int  fin 
)

Quicksort sorting method.

Parameters
vectThe vector that we want to sort.
iniThe first element of the vector.
finThe last element of the vector.

Definition at line 246 of file utils.cpp.

References quicksort(), and swap().

Referenced by Cleaner::calculateRepresentativeSeq(), Cleaner::getCutPointClusters(), and quicksort().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ readLine() [1/2]

char * utils::readLine ( std::ifstream &  file)

Read a new line from current input stream.
This function is better than standard one since cares of operative system compatibility.
It is useful as well because removes tabs and blank spaces at lines at beginning/ending.
.

Parameters
fileifstream to read line from.
Returns

Line that has been read or nullptr if there is nothing to read.

Definition at line 304 of file utils.cpp.

◆ readLine() [2/2]

char * utils::readLine ( std::istream &  file)

Read a new line from current input stream.
This function is better than standard one since cares of operative system compatibility.
It is useful as well because removes tabs and blank spaces at lines at beginning/ending.
.

Parameters
fileifstream to read line from.
Returns

nullptr if there is nothing to read.
Line that has been read.

Definition at line 348 of file utils.cpp.

◆ readNumbers()

int * utils::readNumbers ( const std::string &  line)

Reads a line and converts it to an array of number.

Parameters
lineLine to convert to array of ints
Returns
Pointer to an array of numbers that contains line

Definition at line 624 of file utils.cpp.

Referenced by trimAlManager::select_cols_argument(), and trimAlManager::seqs_select_argument().

+ Here is the caller graph for this function:

◆ removeCharacter()

std::string utils::removeCharacter ( char  c,
std::string  line 
)

Removes a determined char from the string.

Parameters
cCharacter to remove from line
lineString to remove c from.
Returns
New string without c character

Definition at line 485 of file utils.cpp.

Referenced by Cleaner::calculateRepresentativeSeq(), Alignment::checkCorrespondence(), Cleaner::getCutPointClusters(), and Alignment::getSequences().

+ Here is the caller graph for this function:

◆ removeSpaces()

void utils::removeSpaces ( char *  in,
char *  out 
)

Removing spaces method.

Parameters
inThe string that we want to clean.
[out]outThe destination of the clean string.

This method removes spaces in the input string and put the result in the output string.

Definition at line 144 of file utils.cpp.

Referenced by statistics::similarityMatrix::loadSimMatrix().

+ Here is the caller graph for this function:

◆ ReplaceString()

std::string utils::ReplaceString ( std::string  subject,
const std::string &  search,
const std::string &  replace 
)

Function that replaces a substring with another substring in a string. It makes a copy of the original string.

Parameters
[in]subjectString to be modified
searchSubstring to search and change
replaceSubstring to put in place of search

Definition at line 820 of file utils.cpp.

Referenced by trimAlManager::output_reports(), trimAlManager::perform(), FormatHandling::FormatManager::replaceINtag(), and FormatHandling::FormatManager::saveAlignments().

+ Here is the caller graph for this function:

◆ ReplaceStringInPlace()

void utils::ReplaceStringInPlace ( std::string &  subject,
const std::string &  search,
const std::string &  replace 
)

Function that replaces a substring with another substring in a string. It does not make a copy of the original string, but modifies it.

Parameters
[in,out]subjectString to be modified
searchSubstring to search and change
replaceSubstring to put in place of search

Definition at line 810 of file utils.cpp.

Referenced by trimAlManager::examples(), trimAlManager::menu(), trimAlManager::output_reports(), trimAlManager::perform(), and FormatHandling::FormatManager::saveAlignments().

+ Here is the caller graph for this function:

◆ roundInt()

int utils::roundInt ( double  number)

Round double to integer method.

Parameters
numberThe number that will be rounded.
Returns
the rounded number.

This method rounds a double number to a integer.

Definition at line 68 of file utils.cpp.

Referenced by statistics::Gaps::applyWindow(), statistics::Gaps::calcCutPoint(), Cleaner::cleanByCutValueFallBehind(), Cleaner::cleanByCutValueOverpass(), Cleaner::cleanByCutValueOverpassOrEquals(), and Cleaner::cleanStrict().

+ Here is the caller graph for this function:

◆ roundToInf()

int utils::roundToInf ( double  number)

Round double to inferior integer method.

Parameters
numberThe number that will be rounded.
Returns
the rounded number.

This method rounds a double number to the inferior integer.

Definition at line 62 of file utils.cpp.

◆ roundToSup()

int utils::roundToSup ( double  number)

Round double to greater integer method.

Parameters
numberThe number that will be rounded.
Returns
the rounded number.

This method rounds a double number to the greater integer.

Definition at line 74 of file utils.cpp.

◆ swap() [1/3]

void utils::swap ( float *  a,
float *  b 
)

Swapping elements method.

Parameters
aOne element to swap.
bOther element to swap.

This method swaps the values in a and b.

Definition at line 193 of file utils.cpp.

Referenced by quicksort().

+ Here is the caller graph for this function:

◆ swap() [2/3]

void utils::swap ( int *  a,
int *  b 
)

Swapping elements method.

Parameters
aOne element to swap.
bOther element to swap.

This method swaps the values in a and b.

Definition at line 237 of file utils.cpp.

Referenced by quicksort().

+ Here is the caller graph for this function:

◆ swap() [3/3]

void utils::swap ( int **  a,
int **  b 
)

Swaps double pointers.

Parameters
aDouble pointer A
bDouble pointer B

Definition at line 275 of file utils.cpp.

Referenced by quicksort().

+ Here is the caller graph for this function:

◆ toUpper()

char utils::toUpper ( char  c)

Definition at line 958 of file utils.cpp.

Referenced by statistics::Similarity::calculateVectors(), checkAlignmentType(), and lookForPattern().

+ Here is the caller graph for this function:

◆ trimLine()

char * utils::trimLine ( std::string  nline)

Remove all content surrounded by ("") or ([]).
It warns as well when a mismatch for these flags is found.
.

Parameters
nlineLine to be trimmed.
Returns
Line trimmed of comments or nullptr if there has been a mismatch

Definition at line 392 of file utils.cpp.

References BracketsMissmatchFound, debug, PossibleMissmatch, and reporting::reportManager::report().

+ Here is the call graph for this function: