fix: Wall warning, OR symbol

This commit is contained in:
kuoi 2023-03-20 18:34:38 +08:00
parent 7d42ee1ba3
commit 26e358ffef

View file

@ -24,7 +24,7 @@ class Sample {
}; };
}; };
Basic_arg procargs(int nargs, char** arg, char* itn, char* otn); Basic_arg procargs(int nargs, char** arg);
Sample read_input(char* itn, int intype); Sample read_input(char* itn, int intype);
void show_help(int help_num); void show_help(int help_num);
Sample readFas(char* itn); Sample readFas(char* itn);
@ -59,7 +59,7 @@ Sample readPhy(char* itn) {
nchar = stoi(snseq); // string to int nchar = stoi(snseq); // string to int
Sample sam(ntax, nchar); Sample sam(ntax, nchar);
// read sequence // read sequence
int lennum; unsigned int lennum;
for (lennum = 0; lennum < sam.ntax; lennum++) { for (lennum = 0; lennum < sam.ntax; lennum++) {
getline(matrixfile, snall); getline(matrixfile, snall);
istringstream istr(snall); istringstream istr(snall);
@ -147,7 +147,7 @@ Sample readTnt(char* itn) {
// create class // create class
Sample sam(ntax, nchar); Sample sam(ntax, nchar);
// get class // get class
int lennum; unsigned int lennum;
for (lennum = 0; lennum < sam.ntax; lennum++) { for (lennum = 0; lennum < sam.ntax; lennum++) {
getline(matrixfile, stri); getline(matrixfile, stri);
istringstream istr(stri); istringstream istr(stri);
@ -171,10 +171,10 @@ Sample readNex(char* itn) {
matrixfile.open(itn); matrixfile.open(itn);
// some tem // some tem
string snall, stri, str_a, str_b; string snall, stri, str_a, str_b;
bool found = false, found_ntax = false, found_nchar = false, bool found_ntax = false, found_nchar = false, found_equal = false;
found_equal = false;
char x = '='; char x = '=';
int lnum, eulnum; int lnum;
unsigned int eulnum;
// getline line by line // getline line by line
for (lnum = 0; getline(matrixfile, snall); lnum++) { for (lnum = 0; getline(matrixfile, snall); lnum++) {
str_a = to_lower(snall); str_a = to_lower(snall);
@ -182,9 +182,7 @@ Sample readNex(char* itn) {
istringstream istr(str_b); istringstream istr(str_b);
// convert to words // convert to words
while (istr >> stri) { while (istr >> stri) {
if (stri == "dimensions") { if (stri == "ntax") {
found = true;
} else if (stri == "ntax") {
found_ntax = true; found_ntax = true;
} else if (stri == "nchar") { } else if (stri == "nchar") {
found_nchar = true; found_nchar = true;
@ -193,7 +191,6 @@ Sample readNex(char* itn) {
} else if (found_ntax && found_equal) { } else if (found_ntax && found_equal) {
if (stri.back() == ';') { if (stri.back() == ';') {
stri.pop_back(); stri.pop_back();
found = false;
} }
ntax = stoi(stri); ntax = stoi(stri);
found_equal = false; found_equal = false;
@ -201,7 +198,6 @@ Sample readNex(char* itn) {
} else if (found_nchar && found_equal) { } else if (found_nchar && found_equal) {
if (stri.back() == ';') { if (stri.back() == ';') {
stri.pop_back(); stri.pop_back();
found = false;
} }
nchar = stoi(stri); nchar = stoi(stri);
found_equal = false; found_equal = false;
@ -217,14 +213,14 @@ Sample readNex(char* itn) {
// create class // create class
Sample sam(ntax, nchar); Sample sam(ntax, nchar);
// some temp, z is line number, l is the string arrary number // some temp, z is line number, l is the string arrary number
int z = 0; unsigned int z = 0;
int l = 0; int l = 0;
// read line by line // read line by line
while (getline(matrixfile, snall)) { while (getline(matrixfile, snall)) {
// convert to word // convert to word
istringstream istr(snall); istringstream istr(snall);
// limit the read line number // limit the read line number
if (z > (eulnum - 1) && z < (eulnum + sam.ntax)) { if ((z > (eulnum - 1)) && (z < (eulnum + sam.ntax))) {
istr >> sam.taxas[l]; istr >> sam.taxas[l];
istr >> sam.chars[l]; istr >> sam.chars[l];
l++; l++;
@ -236,7 +232,7 @@ Sample readNex(char* itn) {
string add_space(char x, string str_old) { string add_space(char x, string str_old) {
int i; int i;
string str_new; string str_new;
for (i = 0; i < str_old.length(); i++) { for (i = 0; i < (int)str_old.length(); i++) {
if (str_old[i] != x) { if (str_old[i] != x) {
str_new = str_new + str_old[i]; str_new = str_new + str_old[i];
} else { } else {
@ -253,7 +249,7 @@ string to_lower(string stri) {
void writeFas(class Sample sam, char* otn) { void writeFas(class Sample sam, char* otn) {
ofstream matrixfile(otn); ofstream matrixfile(otn);
for (int i = 0; i < sam.ntax; i++) { for (unsigned int i = 0; i < sam.ntax; i++) {
matrixfile << ">" << sam.taxas[i] << endl; matrixfile << ">" << sam.taxas[i] << endl;
matrixfile << sam.chars[i] << endl; matrixfile << sam.chars[i] << endl;
} }
@ -263,7 +259,7 @@ void writeFas(class Sample sam, char* otn) {
void writePhy(class Sample sam, char* otn) { void writePhy(class Sample sam, char* otn) {
ofstream matrixfile(otn); ofstream matrixfile(otn);
matrixfile << sam.ntax << " " << sam.nchar << endl; matrixfile << sam.ntax << " " << sam.nchar << endl;
for (int i = 0; i < sam.ntax; i++) { for (unsigned int i = 0; i < sam.ntax; i++) {
matrixfile << sam.taxas[i] << "\t" << sam.chars[i] << endl; matrixfile << sam.taxas[i] << "\t" << sam.chars[i] << endl;
} }
matrixfile.close(); matrixfile.close();
@ -279,7 +275,7 @@ void writeNex(class Sample sam, char* otn) {
<< ";" << endl << ";" << endl
<< "\tFormat datatype=" << datatype << " missing=? gap=-;" << endl << "\tFormat datatype=" << datatype << " missing=? gap=-;" << endl
<< "\tMatrix" << endl; << "\tMatrix" << endl;
for (int i2 = 0; i2 < sam.ntax; i2++) { for (unsigned int i2 = 0; i2 < sam.ntax; i2++) {
matrixfile << "\t\t" << sam.taxas[i2] << "\t" << sam.chars[i2] << endl; matrixfile << "\t\t" << sam.taxas[i2] << "\t" << sam.chars[i2] << endl;
} }
matrixfile << "\t;" << endl << "End;" << endl; matrixfile << "\t;" << endl << "End;" << endl;
@ -325,16 +321,17 @@ void writeTnt(class Sample sam, char* otn) {
ofstream matrixfile(otn); ofstream matrixfile(otn);
matrixfile << "xread" << endl << "\' \'" << endl; matrixfile << "xread" << endl << "\' \'" << endl;
matrixfile << sam.nchar << " " << sam.ntax << endl; matrixfile << sam.nchar << " " << sam.ntax << endl;
for (int i = 0; i < sam.ntax; i++) { for (unsigned int i = 0; i < sam.ntax; i++) {
matrixfile << sam.taxas[i] << "\t" << sam.chars[i] << endl; matrixfile << sam.taxas[i] << "\t" << sam.chars[i] << endl;
} }
matrixfile << "proc / ;" << endl; matrixfile << "proc / ;" << endl;
matrixfile.close(); matrixfile.close();
} }
Basic_arg procargs(int nargs, char** arg, char* itn, char* otn) { Basic_arg procargs(int nargs, char** arg) {
int i, sta = 0, intype = 0, outype = 0; int i, sta = 0, intype = 0, outype = 0;
string para, inputfile, outputfile; string para, inputfile, outputfile;
char *itn, *otn;
// no arg, show help // no arg, show help
if (nargs == 1) { if (nargs == 1) {
show_help(0); show_help(0);
@ -345,28 +342,36 @@ Basic_arg procargs(int nargs, char** arg, char* itn, char* otn) {
for (i = 1; i < nargs; i++) { for (i = 1; i < nargs; i++) {
// to string // to string
string para(arg[i]); string para(arg[i]);
if (para == "-h" | para == "--help") { if ((para == "-h") || (para == "--help")) {
show_help(1); show_help(1);
sta = 2; sta = 2;
} else if (para == "-i" | para == "--input") { } else if ((para == "-i") || (para == "--input")) {
i++; if ((i + 1) < nargs) {
itn = arg[i]; i++;
string inputfile(arg[i]); itn = arg[i];
intype = checkextension(inputfile); string inputfile(arg[i]);
sta++; intype = checkextension(inputfile);
} else if (para == "-o" | para == "--output") { sta++;
i++; } else {
otn = arg[i]; cout << "MiMi:\tOInput file name must be defined" << endl;
string outputfile(arg[i]); }
outype = checkextension(outputfile); } else if (((para == "-o") || (para == "--output"))) {
sta++; if ((i + 1) < nargs) {
i++;
otn = arg[i];
string outputfile(arg[i]);
outype = checkextension(outputfile);
sta++;
} else {
cout << "MiMi:\tOutput file name must be defined" << endl;
}
} else { } else {
cout << "MiMi\tUnknown arguments, please use -h to check" << endl; cout << "MiMi:\tUnknown arguments, please use -h to check" << endl;
exit(0); exit(0);
} }
} }
if (sta != 2) { if (sta != 2) {
cout << "MiMi\tInput and Output can't be empty" << endl; cout << "MiMi:\tInput and Output can't be empty" << endl;
exit(0); exit(0);
} }
Basic_arg arguvar(intype, outype, itn, otn); Basic_arg arguvar(intype, outype, itn, otn);
@ -380,20 +385,20 @@ int checkextension(string str) {
if (loc) { if (loc) {
extension = str.substr(loc + 1); extension = str.substr(loc + 1);
} else { } else {
cout << "MiMi\tPlease sepecifc the extension name" << endl; cout << "MiMi:\tPlease sepecifc the extension name" << endl;
exit(0); exit(0);
} }
extension = to_lower(extension); extension = to_lower(extension);
if (extension == "fas" | extension == "fasta") { if ((extension == "fas") || (extension == "fasta")) {
type = 1; type = 1;
} else if (extension == "nex" | extension == "nexus") { } else if ((extension == "nex") || (extension == "nexus")) {
type = 2; type = 2;
} else if (extension == "phy" | extension == "phylip") { } else if ((extension == "phy") || (extension == "phylip")) {
type = 3; type = 3;
} else if (extension == "tnt" | extension == "ss") { } else if ((extension == "tnt") || (extension == "ss")) {
type = 4; type = 4;
} else { } else {
cout << "MiMi\tUnknown format" << endl; cout << "MiMi:\tUnknown format" << endl;
exit(0); exit(0);
} }
return type; return type;
@ -420,7 +425,7 @@ void show_help(int help_num) {
} }
Sample read_input(char* itn, int intype) { Sample read_input(char* itn, int intype) {
int ntax, nchar; int ntax = 0, nchar = 0;
Sample sam(ntax, nchar); Sample sam(ntax, nchar);
ifstream matrixfile; ifstream matrixfile;
matrixfile.open(itn); matrixfile.open(itn);
@ -430,7 +435,7 @@ Sample read_input(char* itn, int intype) {
if (intype == 3) sam = readPhy(itn); if (intype == 3) sam = readPhy(itn);
if (intype == 4) sam = readTnt(itn); if (intype == 4) sam = readTnt(itn);
} else { } else {
cout << "MiMi\tInput file can't be open" << endl; cout << "MiMi:\tInput file can't be open" << endl;
exit(0); exit(0);
} }
return sam; return sam;
@ -444,16 +449,17 @@ void write_output(class Sample sam, char* otn, int outype) {
if (outype == 3) writePhy(sam, otn); if (outype == 3) writePhy(sam, otn);
if (outype == 4) writeTnt(sam, otn); if (outype == 4) writeTnt(sam, otn);
} else { } else {
cout << "MiMi\tOutput file can't be open" << endl; cout << "MiMi:\tOutput file can't be open" << endl;
exit(0); exit(0);
} }
} }
bool checkalign(class Sample sam) { bool checkalign(class Sample sam) {
int a = 0, b = 0, x = 0; int a = 0, b = 0;
unsigned int x = 0;
a = sam.nchar; a = sam.nchar;
bool aligned = true; bool aligned = true;
for (int i = 0; i < sam.ntax; i++) { for (unsigned int i = 0; i < sam.ntax; i++) {
b = sam.chars[i].length(); b = sam.chars[i].length();
if (a == b) { if (a == b) {
x++; x++;
@ -466,8 +472,7 @@ bool checkalign(class Sample sam) {
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
char *itn, *otn; Basic_arg arguvar = procargs(argc, argv);
Basic_arg arguvar = procargs(argc, argv, itn, otn);
if (arguvar.intype != 0 && arguvar.outype != 0) { if (arguvar.intype != 0 && arguvar.outype != 0) {
Sample sam = read_input(arguvar.itn, arguvar.intype); Sample sam = read_input(arguvar.itn, arguvar.intype);
cout << "MiMi:\tInput\tfinished" << endl; cout << "MiMi:\tInput\tfinished" << endl;