else {
//valid paramters for this command
- string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group"};
+ string Array[] = {"phylip", "column", "name", "cutoff", "precision", "group","outputdir","inputdir"};
vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
OptionParser parser(option);
map<string, string> parameters = parser.getParameters();
ValidParameters validParameter;
+ map<string,string>::iterator it;
//check to make sure all parameters are valid for command
- for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
+ for (it = parameters.begin(); it != parameters.end(); it++) {
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
globaldata->newRead();
+ //if the user changes the input directory command factory will send this info to us in the output parameter
+ string inputDir = validParameter.validFile(parameters, "inputdir", false);
+ if (inputDir == "not found"){ inputDir = ""; }
+ else {
+ string path;
+ it = parameters.find("phylip");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["phylip"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("column");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["column"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("name");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["name"] = inputDir + it->second; }
+ }
+
+ it = parameters.find("group");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["group"] = inputDir + it->second; }
+ }
+ }
+
+ //if the user changes the output directory command factory will send this info to us in the output parameter
+ outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
+
//check for required parameters
phylipfile = validParameter.validFile(parameters, "phylip", true);
if (phylipfile == "not open") { abort = true; }
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
else if (format == "phylip") { read = new ReadPhylipMatrix(distFileName); }
else if (format == "matrix") {
groupMap = new GroupMap(groupfile);
- groupMap->readMap();
- if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
- globaldata->gGroupmap = groupMap;
+ int error = groupMap->readMap();
+ if (error == 1) { delete groupMap; abort = true; }
+ else {
+ if (globaldata->gGroupmap != NULL) { delete globaldata->gGroupmap; }
+ globaldata->gGroupmap = groupMap;
+ }
}
if (format != "matrix" ) {
ReadDistCommand::~ReadDistCommand(){
if (abort == false) {
- if (format != "matrix") { delete read; delete nameMap; }
+ if (format != "matrix") {
+ delete read;
+ delete nameMap;
+ }
}
}
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
+ if(outputDir == "") { outputDir += hasPath(groupfile); }
+
+ string newGroupFile = outputDir + getRootName(getSimpleName(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
if (globaldata->gSparseMatrix != NULL) { delete globaldata->gSparseMatrix; }
globaldata->gSparseMatrix = read->getMatrix();
numDists = globaldata->gSparseMatrix->getNNodes();
-
- int lines = cutoff / (1.0/precision);
+ //cout << "matrix contains " << numDists << " distances." << endl;
+
+ /* int lines = cutoff / (1.0/precision);
vector<float> dist_cutoff(lines+1,0);
for (int i = 0; i <= lines;i++) {
dist_cutoff[i] = (i + 0.5) / precision;
}
}
}
-
- string dist_string = "Dist:";
- string count_string = "Count: ";
- for (int i = 0; i <= lines;i++) {
- dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
- count_string = count_string.append("\t").append(toString(dist_count[i]));
- }
- mothurOut(dist_string); mothurOutEndLine(); mothurOut(count_string); mothurOutEndLine();
+*/
+ // string dist_string = "Dist:";
+ // string count_string = "Count: ";
+ //for (int i = 0; i <= lines;i++) {
+ //dist_string = dist_string.append("\t").append(toString(dist_cutoff[i]));
+ // count_string = count_string.append("\t").append(toString(dist_count[i]));
+ // }
+ //mothurOut(dist_string); mothurOutEndLine(); mothurOut(count_string); mothurOutEndLine();
}
- mothurOut("It took " + toString(time(NULL) - start) + " secs to read " + toString(numDists) + " distances (cutoff: " + toString(cutoff) + ")"); mothurOutEndLine();
+ mothurOut("It took " + toString(time(NULL) - start) + " secs to read "); mothurOutEndLine();
return 0;
}