42 for (
int i = 0; i < tam; i++) vector[i] = valor;
46 void initlVect(
float *vector,
int tam,
float valor) {
48 for (
int i = 0; i < tam; i++) vector[i] = valor;
51 void copyVect(
int *vect1,
int *vect2,
int tam) {
53 for (
int i = 0; i < tam; i++) vect2[i] = vect1[i];
57 void copyVect(
float *vect1,
float *vect2,
int tam) {
59 for (
int i = 0; i < tam; i++) vect2[i] = vect1[i];
65 return ((
int) number);
71 return ((
int) ((
double) number + 0.5));
77 return ((
int) ((
double) number + 1.0));
80 int max(
int x,
int y) {
86 float max(
float x,
float y) {
92 double max(
double x,
double y) {
98 int min(
int x,
int y) {
104 float min(
float x,
float y) {
110 double min(
double x,
double y) {
118 int tam = strlen(num);
119 if (tam == 0)
return false;
120 int i, flt = 1, expn = 1, sgn = 1;
122 for (i = 0; i < tam; i++) {
123 if (num[i] ==
'.' && flt)
126 else if (((num[i] ==
'e') || (num[i] ==
'E')) && expn)
129 else if (((num[i] ==
'+') || (num[i] ==
'-')) && sgn) {
131 }
else if (num[i] >
'9' || num[i] <
'0')
141 return (!strcmp(a, b));
146 unsigned int i, j = 0;
148 for (i = 0; i < strlen(in); i++) {
150 if (in[i] !=
' ' && in[i] !=
'\t') {
164 if ((ini >= fin) || (fin < 0))
167 elem_div = vect[fin];
173 while (vect[++i] < elem_div)
177 while (vect[--j] > elem_div)
193 void swap(
float *a,
float *b) {
208 if ((ini >= fin) || (fin < 0))
211 elem_div = vect[fin];
217 while (vect[++i] < elem_div)
221 while (vect[--j] > elem_div)
251 if ((ini >= fin) || (fin < 0))
254 elem_div = vect[fin][0];
260 while (vect[++i][0] < elem_div)
if (i == fin)
break;
261 while (vect[--j][0] > elem_div)
if (j == 0)
break;
263 if (i < j)
swap(&vect[i]
, &vect[j]
);
293 begin = file.tellg();
294 file.seekg(0, std::ios::end);
296 file.seekg(0, std::ios::beg);
305 StartTiming(
"char* readLine(std::ifstream &file) ");
312 char *line =
nullptr;
322 getline(file, nline);
325 state = nline.find(
' ', 0);
326 while (state != (
int) std::string::npos && state == 0) {
327 nline.erase(state, 1);
328 state = nline.find(
' ', state);
331 state = nline.find(
'\t', 0);
332 while (state != (
int) std::string::npos && state == 0) {
333 nline.erase(state, 1);
334 state = nline.find(
'\t', state);
343 line =
new char[nline.size() + 1];
344 strcpy(line, nline.c_str());
355 char *line =
nullptr;
366 getline(file, nline);
369 state = nline.find(
' ', 0);
370 while (state != (
int) std::string::npos && state == 0) {
371 nline.erase(state, 1);
372 state = nline.find(
' ', state);
375 state = nline.find(
'\t', 0);
376 while (state != (
int) std::string::npos && state == 0) {
377 nline.erase(state, 1);
378 state = nline.find(
'\t', state);
387 line =
new char[nline.size() + 1];
388 strcpy(line, &nline[0]);
405 pos = nline.find(
'\"', (pos + 1));
409 if (pos == (
int) std::string::npos)
413 next = nline.rfind(
'\"', nline.size());
416 if ((
int) nline.find(
'\"', (pos + 1)) == next) {
417 nline.erase(pos, (next - pos + 1));
436 while ((pos = nline.find(
'[', (pos + 1))) != (
int) std::string::npos)
443 if ((
int) nline.find(
']', 0) == (
int) std::string::npos)
451 pos = nline.find(
']', (next + 1));
454 if (pos == (
int) std::string::npos) {
460 nline.erase(next, (pos - next + 1));
469 line =
new char[nline.size() + 1];
470 strcpy(line, &nline[0]);
477 std::string line(toReverse.size(),
' ');
480 for (i = toReverse.size() - 1, x = 0; i >= 0; i--, x++)
481 line[x] = toReverse[i];
489 pos = line.find(c, 0);
490 while (pos != (
int) std::string::npos) {
492 pos = line.find(c, pos);
502 static const auto check =
503 [](
const std::string &pattern,
505 const char &character) ->
void {
507 while ((pos = pattern.find(character, pos)) != std::string::npos) {
514 static const std::string COMMON =
"ACG";
515 static const std::string RNA =
"U";
516 static const std::string DNA =
"T";
518 static const std::string DEG_NN =
"RYSWKMBDHV";
520 static const std::string AA =
"PVLIMFYWHKRQEDSTUO";
521 static const std::string DEG_AA =
"BZ";
523 int rna = 0, dna = 0, deg_nn = 0, aa = 0, deg_aa = 0;
525 for (
int s = 0; s < seqNumber; s++) {
526 for (
char c : sequences[s]) {
527 if (c ==
'-' || c ==
'?' || c ==
'.')
continue;
531 check(DEG_NN, deg_nn, c);
533 check(DEG_AA, deg_aa, c);
536 while ((pos = COMMON.find(c, pos)) != std::string::npos) {
545 if (aa > dna && aa > rna) {
554 int i, j, k, l, hitDNA, hitRNA, degenerate, gDNA, gRNA, extDNA, extRNA;
555 float ratioDNA, ratioRNA;
557 static char listRNA[11] =
"AGCUNagcun";
558 static char listDNA[11] =
"AGCTNagctn";
561 static char degeneratedCodes[21] =
"MmRrWwSsYyKkVvHhDdBb";
566 for (i = 0, gDNA = 0, gRNA = 0, extDNA = 0, extRNA = 0; i < seqNumber; i++) {
571 residNumber = (
int) sequences[i].size();
572 for (j = 0, k = 0, hitDNA = 0, hitRNA = 0, degenerate = 0; j < residNumber; j++)
573 if (sequences[i][j] !=
'-' && sequences[i][j] !=
'.' && sequences[i][j] !=
'?') {
577 for (l = 0; l < (
int) strlen(listDNA); l++)
578 if (listDNA[l] == sequences[i][j])
581 for (l = 0; l < (
int) strlen(listRNA); l++)
582 if (listRNA[l] == sequences[i][j])
585 for (l = 0; l < (
int) strlen(degeneratedCodes); l++)
586 if (degeneratedCodes[l] == sequences[i][j])
593 ratioDNA =
float(degenerate + hitDNA) / k;
594 ratioRNA =
float(degenerate + hitRNA) / k;
596 if (ratioDNA < 0.95 && ratioRNA < 0.95)
601 else if (hitRNA > hitDNA && degenerate == 0)
603 else if (hitRNA > hitDNA && degenerate != 0)
605 else if (hitRNA < hitDNA && degenerate == 0)
607 else if (hitRNA < hitDNA && degenerate != 0)
612 if (extDNA != 0 && extDNA > extRNA)
614 else if (extRNA != 0 && extDNA < extRNA)
616 else if (gRNA > gDNA)
618 else if (gDNA >= gRNA)
629 size_t comma, separ, init;
632 while ((comma = line.find(
',', comma + 1)) != (
int) std::string::npos)
636 numbers =
new int[nElems + 1];
643 comma = line.find(
',', init);
644 separ = line.find(
'-', init);
646 if (((separ < comma) || (comma == (
int) std::string::npos)) && (separ != (
int) std::string::npos)) {
647 numbers[i++] = atoi(line.substr(init, separ - init).c_str());
648 numbers[i++] = atoi(line.substr(separ + 1, comma - separ - 1).c_str());
650 }
else if ((separ > comma) || (separ == (
int) std::string::npos)) {
651 numbers[i++] = atoi(line.substr(init, comma - init).c_str());
652 numbers[i++] = atoi(line.substr(init, comma - init).c_str());
656 if (numbers[i - 2] < 0)
661 if (numbers[i - 1] < numbers[i - 2])
666 if (comma == (
int) std::string::npos)
677 if (toupper(res) ==
'G')
680 else if (toupper(res) ==
'P')
683 else if (res !=
'-') {
684 switch (toupper(res)) {
793 bool lookForPattern(
const std::string &data,
const std::string &pattern,
const float threshold) {
798 for (i = 0; i < (
int) data.size(); i++) {
799 for (j = 0; j < (
int) pattern.size(); j++) {
807 return (count / data.size()) >= threshold;
811 const std::string &search,
812 const std::string &replace) {
814 while ((pos = subject.find(search, pos)) != std::string::npos) {
815 subject.replace(pos, search.length(), replace);
816 pos += replace.length();
821 const std::string &search,
822 const std::string &replace) {
824 while ((pos = subject.find(search, pos)) != std::string::npos) {
825 subject.replace(pos, search.length(), replace);
826 pos += replace.length();
837 if (*gapValue == sequenNumber)
840 float relativeGap = 1.F -
float(*gapValue) / sequenNumber;
842 if (relativeGap >= .750)
844 if (relativeGap >= .500)
846 if (relativeGap >= .350)
848 if (relativeGap >= .250)
850 if (relativeGap >= .200)
852 if (relativeGap >= .150)
854 if (relativeGap >= .100)
856 if (relativeGap >= .050)
858 if (relativeGap >= .001)
868 float relativeGap = 1.F -
float(*gapValue) * inverseSequenNumber;
870 if (relativeGap == 0.F)
872 if (relativeGap >= .750F)
874 if (relativeGap >= .500F)
876 if (relativeGap >= .350F)
878 if (relativeGap >= .250F)
880 if (relativeGap >= .200F)
882 if (relativeGap >= .150F)
884 if (relativeGap >= .100F)
886 if (relativeGap >= .050F)
888 if (relativeGap >= .001F)
895 if (*simValue == 0.F)
897 if (*simValue == 1.F)
899 if (*simValue >= .750F)
901 if (*simValue >= .500F)
903 if (*simValue >= .250F)
905 if (*simValue >= .100F)
907 if (*simValue >= .010F)
909 if (*simValue >= .001F)
911 if (*simValue >= 1e-4F)
913 if (*simValue >= 1e-5F)
915 if (*simValue >= 1e-6F)
922 if (*consValue == 1.F)
924 if (*consValue == 0.F)
927 if (*consValue >= .750)
929 if (*consValue >= .500)
931 if (*consValue >= .350)
933 if (*consValue >= .250)
935 if (*consValue >= .200)
937 if (*consValue >= .150)
939 if (*consValue >= .100)
941 if (*consValue >= .050)
943 if (*consValue >= .001)
950 return (stat(path.c_str(), &buffer) == 0);
955 return (stat(path.c_str(), &buffer) == 0);
959 if (c >=
'a' and c <=
'z')
960 return (
char) (c & (~(1 << 5)));
int GetSimStep(float *simValue)
Function that gives the similarity classification of a column of values.
void initlVect(float *vector, int tam, float valor)
Vector initialization.
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 origina...
#define StartTiming(name)
void removeSpaces(char *in, char *out)
Removing spaces method.
bool checkFile(std::ifstream &file)
Check if a given file exists and its size is greater than 0.
int min(int x, int y)
Minimum of two numbers method.
int GetGapStep(int *gapValue, int sequenNumber)
Function that gives the gap classification of a column of values.
char determineColor(char res, const std::string &column)
Checks the color that has to be used on the output report.
void initlVect(int *vector, int tam, int valor)
Vector initialization.
float min(float x, float y)
Minimum of two numbers method.
float max(float x, float y)
Maximum of two numbers method.
bool compare(char *a, char *b)
String comparing method.
void swap(float *a, float *b)
Swapping elements method.
double max(double x, double y)
Maximum of two numbers method.
int roundInt(double number)
Round double to integer method.
int checkAlignmentType(int seqNumber, int residNumber, std::string *sequences)
Checks an alignment type.
reporting::reportManager debug
bool fileExists(std::string &&path)
Method to check the existance of a file. Works exactly as fileExists(std::string & path)...
void quicksort(int *list, int ini, int fin)
Quicksort sorting method.
void copyVect(int *vect1, int *vect2, int tam)
Integer vector copying.
int GetGapStep(int *gapValue, float inverseSequenNumber)
Function that gives the gap classification of a column of values. This function should work faster th...
void swap(int **a, int **b)
Swaps double pointers.
char * readLine(std::ifstream &file)
Read a new line from current input stream. This function is better than standard one since cares of o...
void copyVect(float *vect1, float *vect2, int tam)
Float vector copying.
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 firs...
void report(ErrorCode message, std::string *vars=nullptr)
Method to report an Error. It will be displayed if Level is equal or higher to VerboseLevel::ERROR...
int GetConsStep(float *consValue)
Function that gives the consistency classification of a column of values.
void quicksort(float *list, int ini, int fin)
Quicksort sorting method.
int roundToSup(double number)
Round double to greater integer method.
int max(int x, int y)
Maximum of two numbers method.
std::map< terminalColor, const std::string > colors
double min(double x, double y)
Minimum of two numbers method.
void quicksort(int **vect, int ini, int fin)
Quicksort sorting method.
std::string getReverse(const std::string &toReverse)
Reverses a string.
int * readNumbers(const std::string &line)
Reads a line and converts it to an array of number.
char * readLine(std::istream &file)
Read a new line from current input stream. This function is better than standard one since cares of o...
char * trimLine(std::string nline)
Remove all content surrounded by ("") or ([]). It warns as well when a mismatch for these flags is f...
Utilities class. This class contains shared methods to be used in multiple parts of the code...
std::string removeCharacter(char c, std::string line)
Removes a determined char from the string.
int roundToInf(double number)
Round double to inferior integer method.
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...
void swap(int *a, int *b)
Swapping elements method.
bool fileExists(std::string &path)
Method to check the existance of a file.
bool isNumber(char *num)
String-is-number checking.