@@ -122,6 +122,7 @@ po::positional_options_description printPathsArgumentDesc;
122122po::options_description indexDesc (" Indexing Command Line Arguments" );
123123po::positional_options_description indexArgumentDesc;
124124po::options_description printRootDesc (" Root Printer Command Line Arguments" );
125+ po::options_description printConsensusDesc (" Consensus Printer Command Line Arguments" );
125126po::positional_options_description printRootPositionArgumentDesc;
126127
127128
@@ -158,7 +159,7 @@ void setupOptionDescriptions() {
158159 (" acr,q" , " ACR method [fitch(default), mppa]" )
159160 (" index" ,po::value< bool >(0 ), " Generating indexes and print sequence (passed as reference) between x:y" )
160161 (" refFile" ,po::value< std::string >() ," reference sequence file" )
161- // ("printRoot ", "Print root sequence ")
162+ ( " printConsensus " , " Print consensus sequences of each block in FASTA format " )
162163 // ("printNodePaths", "Print mutations from root to each node")
163164 (" toUsher" , " Convert a PanMAT in PanMAN to Usher-MAT" )
164165 // ("samples",po::value< bool >() ,"Samples in the PanMAN")
@@ -260,6 +261,9 @@ void setupOptionDescriptions() {
260261
261262 printRootDesc.add_options ()
262263 (" output-file,o" , po::value< std::string >(), " Output file name" );
264+
265+ printConsensusDesc.add_options ()
266+ (" output-file,o" , po::value< std::string >(), " Output file name" );
263267}
264268
265269void writePanMAN (po::variables_map &globalVm, panmanUtils::TreeGroup *TG) {
@@ -1208,6 +1212,39 @@ void printRoot(panmanUtils::TreeGroup *TG, po::variables_map &globalVm, std::ofs
12081212
12091213}
12101214
1215+ void printConsensus (panmanUtils::TreeGroup *TG, po::variables_map &globalVm, std::ofstream &outputFile, std::streambuf * buf) {
1216+ // Print raw sequences to output file
1217+ if (TG == nullptr ) {
1218+ std::cout << " No PanMAN selected" << std::endl;
1219+ return ;
1220+ }
1221+
1222+ panmanUtils::TreeGroup tg = *TG;
1223+
1224+ auto fastaStart = std::chrono::high_resolution_clock::now ();
1225+ for (int i = 0 ; i < tg.trees .size (); i++) {
1226+ panmanUtils::Tree * T = &tg.trees [i];
1227+ if (globalVm.count (" output-file" )) {
1228+ std::string fileName = globalVm[" output-file" ].as < std::string >();
1229+ outputFile.open (" ./info/" + fileName + " _" + std::to_string (i) + " .fasta" );
1230+ buf = outputFile.rdbuf ();
1231+ } else {
1232+ buf = std::cout.rdbuf ();
1233+ }
1234+ std::ostream fout (buf);
1235+
1236+
1237+ T->printConsensus (fout);
1238+
1239+ if (globalVm.count (" output-file" )) outputFile.close ();
1240+ }
1241+
1242+ auto fastaEnd = std::chrono::high_resolution_clock::now ();
1243+ std::chrono::nanoseconds fastaTime = fastaEnd - fastaStart;
1244+ std::cout << " \n FASTA execution time: " << fastaTime.count () << " nanoseconds\n " ;
1245+
1246+ }
1247+
12111248void toUsher (panmanUtils::TreeGroup *TG, po::variables_map &globalVm) {
12121249 // Print raw sequences to output file
12131250 if (TG == nullptr ) {
@@ -1549,6 +1586,8 @@ void parseAndExecute(int argc, char* argv[]) {
15491586 // } else if(globalVm.count("fasta-fast")){
15501587 // fastaFast(TG, globalVm, outputFile, buf);
15511588 // return;
1589+ } else if (globalVm.count (" printConsensus" )) {
1590+ printConsensus (TG, globalVm, outputFile, buf);
15521591 } else {
15531592 char ** splitCommandArray;
15541593
@@ -1691,6 +1730,12 @@ void parseAndExecute(int argc, char* argv[]) {
16911730 .options (printRootDesc)
16921731 .run (), printRootVm);
16931732 printRoot (TG, printRootVm, outputFile, buf);
1733+ } else if (strcmp (splitCommandArray[0 ], " printConsensus" ) == 0 ) {
1734+ po::variables_map printConsensusVm;
1735+ po::store (po::command_line_parser ((int )splitCommand.size (), splitCommandArray)
1736+ .options (printConsensusDesc)
1737+ .run (), printConsensusVm);
1738+ printConsensus (TG, printConsensusVm, outputFile, buf);
16941739 } else if (strcmp (splitCommandArray[0 ], " exit" ) == 0 || strcmp (splitCommandArray[0 ], " q" ) == 0 ) {
16951740 return ;
16961741 } else {
0 commit comments