From c080629b637a155111ed3119f4e929daf79c4dd7 Mon Sep 17 00:00:00 2001 From: Kuoi Date: Mon, 20 Mar 2023 04:09:09 +0800 Subject: [PATCH] add: check aligned --- main.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 0af6c32..c966931 100644 --- a/main.cpp +++ b/main.cpp @@ -39,7 +39,9 @@ void writeTnt(class Sample sam); void writeNex(class Sample sam); bool isNum(string strnum); string to_lower(string stri); -string add_space (char x, string str_old); +string add_space(char x, string str_old); +string checktype(string str); +int countfre(string str, char c); Sample readPhy(){ //read file @@ -298,6 +300,8 @@ void writePhy(class Sample sam){ void writeNex(class Sample sam){ ofstream outputFile(otn); + string datatype; + datatype = checktype(sam.chars[0]); if (outputFile.is_open()) { outputFile << "#NEXUS" << endl; // outputFile << "Begin TAXA;" << endl << "\tDimensions ntax=" << sam.ntax << ";" << endl << "\tTaxLabels"; @@ -305,7 +309,7 @@ void writeNex(class Sample sam){ // outputFile << " " << sam.taxas[i1]; // } // outputFile << ";" << endl << "End;" << endl << endl; - outputFile << "Begin data;" << endl << "\tDimensions nchar=" << sam.nchar << " ntax=" << sam.ntax << ";" << endl << "\tFormat datatype=dna missing=? gap=-;" << endl << "\tMatrix" << endl; + outputFile << "Begin data;" << endl << "\tDimensions nchar=" << sam.nchar << " ntax=" << sam.ntax << ";" << endl << "\tFormat datatype=" << datatype << " missing=? gap=-;" << endl << "\tMatrix" << endl; for(int i2=0;i20.7){ + datatype = "dna"; + } else if ((standard/str.length())>0.7){ + datatype = "standard"; + } else { + datatype = "protein"; + } + return datatype; +} + +int countfre(string str, char c){ + int num; + str = to_lower(str); + num = count(str.begin(),str.end(),c); + return num; +} + void writeTnt(class Sample sam){ ofstream outputFile(otn); if (outputFile.is_open()) { @@ -398,6 +434,18 @@ void write_output (class Sample sam){ if (outype==4) writeTnt(sam); } +bool checkalign(class Sample sam){ + int a=0, b=0; + a = sam.chars[0].length(); + bool aligned = true; + for(int i=1;i<(sam.ntax-1)&&aligned;i++){ + b = sam.chars[i].length(); + aligned = (a==b); + } + return aligned; +} + + int main(int argc, char **argv){ procargs (argc, argv); if(intype!=0&&outype!=0){