X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readdistcommand.cpp;h=7e81d7f1a3efe2535f1d9d11715bb2c517a508ec;hb=92f998cc7debc4bf3e8594848586b8153d96db16;hp=719740cf7589e121029197bb46e30bbdd62e6bda;hpb=3c856e629e20261496b0433c2587f27b2c8ba3f6;p=mothur.git diff --git a/readdistcommand.cpp b/readdistcommand.cpp index 719740c..7e81d7f 100644 --- a/readdistcommand.cpp +++ b/readdistcommand.cpp @@ -72,7 +72,7 @@ ReadDistCommand::ReadDistCommand(string option){ if (columnfile != "") { if (namefile == "") { cout << "You need to provide a namefile if you are going to use the column format." << endl; abort = true; } } - + //check for optional parameter and set defaults // ...at some point should added some additional type checking... //get user cutoff and precision or use defaults @@ -93,6 +93,7 @@ ReadDistCommand::ReadDistCommand(string option){ else if (format == "matrix") { groupMap = new GroupMap(groupfile); groupMap->readMap(); + if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; } globaldata->gGroupmap = groupMap; } @@ -163,6 +164,34 @@ int ReadDistCommand::execute(){ openInputFile(distFileName, in); matrix = new FullMatrix(in); //reads the matrix file in.close(); + + //if files don't match... + if (matrix->getNumSeqs() < groupMap->getNumSeqs()) { + mothurOut("Your distance file contains " + toString(matrix->getNumSeqs()) + " sequences, and your group file contains " + toString(groupMap->getNumSeqs()) + " sequences."); mothurOutEndLine(); + //create new group file + string newGroupFile = getRootName(groupfile) + "editted.groups"; + ofstream outGroups; + openOutputFile(newGroupFile, outGroups); + + for (int i = 0; i < matrix->getNumSeqs(); i++) { + Names temp = matrix->getRowInfo(i); + outGroups << temp.seqName << '\t' << temp.groupName << endl; + } + outGroups.close(); + + mothurOut(newGroupFile + " is a new group file containing only the sequence that are in your distance file. I will read this file instead."); mothurOutEndLine(); + + //read new groupfile + delete groupMap; groupMap = NULL; + groupfile = newGroupFile; + globaldata->setGroupFile(groupfile); + + groupMap = new GroupMap(groupfile); + groupMap->readMap(); + + globaldata->gGroupmap = groupMap; + } + //memory leak prevention if (globaldata->gMatrix != NULL) { delete globaldata->gMatrix; } globaldata->gMatrix = matrix; //save matrix for coverage commands @@ -177,6 +206,7 @@ int ReadDistCommand::execute(){ if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix; } globaldata->gSparseMatrix = read->getMatrix(); numDists = globaldata->gSparseMatrix->getNNodes(); + cout << "matrix contains " << numDists << " distances." << endl; int lines = cutoff / (1.0/precision); vector dist_cutoff(lines+1,0);