]> git.donarmstrong.com Git - mothur.git/blob - nmdscommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / nmdscommand.cpp
1 /*
2  *  nmdscommand.cpp
3  *  mothur
4  *
5  *  Created by westcott on 1/11/11.
6  *  Copyright 2011 Schloss Lab. All rights reserved.
7  *
8  */
9
10 #include "nmdscommand.h"
11 #include "readphylipvector.h"
12
13 //**********************************************************************************************************************
14 vector<string> NMDSCommand::setParameters(){    
15         try {
16                 CommandParameter paxes("axes", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(paxes);
17                 CommandParameter pphylip("phylip", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pphylip);
18                 CommandParameter pmaxdim("maxdim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmaxdim);
19                 CommandParameter pmindim("mindim", "Number", "", "2", "", "", "",false,false); parameters.push_back(pmindim);
20                 CommandParameter piters("iters", "Number", "", "10", "", "", "",false,false); parameters.push_back(piters);
21                 CommandParameter pmaxiters("maxiters", "Number", "", "500", "", "", "",false,false); parameters.push_back(pmaxiters);
22                 CommandParameter pepsilon("epsilon", "Number", "", "0.000000000001", "", "", "",false,false); parameters.push_back(pepsilon);
23                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
24                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
25                 
26                 vector<string> myArray;
27                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
28                 return myArray;
29         }
30         catch(exception& e) {
31                 m->errorOut(e, "NMDSCommand", "setParameters");
32                 exit(1);
33         }
34 }
35 //**********************************************************************************************************************
36 string NMDSCommand::getHelpString(){    
37         try {
38                 string helpString = "";
39                 helpString += "The nmds command is modelled after the nmds code written in R by Sarah Goslee, using Non-metric multidimensional scaling function using the majorization algorithm from Borg & Groenen 1997, Modern Multidimensional Scaling.\n";
40                 helpString += "The nmds command parameters are phylip, axes, mindim, maxdim, maxiters, iters and epsilon.\n"; 
41                 helpString += "The phylip parameter allows you to enter your distance file.\n"; 
42                 helpString += "The axes parameter allows you to enter a file containing a starting configuration.\n";
43                 helpString += "The maxdim parameter allows you to select the maximum dimensions to use. Default=2\n"; 
44                 helpString += "The mindim parameter allows you to select the minimum dimensions to use. Default=2\n";
45                 helpString += "The maxiters parameter allows you to select the maximum number of iters to try with each random configuration. Default=500\n"; 
46                 helpString += "The iters parameter allows you to select the number of random configuration to try. Default=10\n"; 
47                 helpString += "The epsilon parameter allows you to select set an acceptable stopping point. Default=1e-12.\n"; 
48                 helpString += "Example nmds(phylip=yourDistanceFile).\n";
49                 helpString += "Note: No spaces between parameter labels (i.e. phylip), '=' and parameters (i.e.yourDistanceFile).\n";
50                 return helpString;
51         }
52         catch(exception& e) {
53                 m->errorOut(e, "NMDSCommand", "getHelpString");
54                 exit(1);
55         }
56 }
57 //**********************************************************************************************************************
58 string NMDSCommand::getOutputFileNameTag(string type, string inputName=""){     
59         try {
60         string outputFileName = "";
61                 map<string, vector<string> >::iterator it;
62         
63         //is this a type this command creates
64         it = outputTypes.find(type);
65         if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
66         else {
67             if (type == "nmds") {  outputFileName =  "nmds.axes"; }
68             else if (type == "stress") {  outputFileName =  "nmds.stress"; }
69             else if (type == "iters") {  outputFileName =  "nmds.iters"; }
70             else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
71         }
72         return outputFileName;
73         }
74         catch(exception& e) {
75                 m->errorOut(e, "NMDSCommand", "getOutputFileNameTag");
76                 exit(1);
77         }
78 }
79 //**********************************************************************************************************************
80 NMDSCommand::NMDSCommand(){     
81         try {
82                 abort = true; calledHelp = true; 
83                 setParameters();
84                 vector<string> tempOutNames;
85                 outputTypes["nmds"] = tempOutNames;
86                 outputTypes["stress"] = tempOutNames;
87                 outputTypes["iters"] = tempOutNames;
88         }
89         catch(exception& e) {
90                 m->errorOut(e, "NMDSCommand", "NMDSCommand");
91                 exit(1);
92         }
93 }
94 //**********************************************************************************************************************
95
96 NMDSCommand::NMDSCommand(string option)  {
97         try {
98                 abort = false; calledHelp = false;   
99                 
100                 //allow user to run help
101                 if(option == "help") { help(); abort = true; calledHelp = true; }
102                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
103                 
104                 else {
105                         vector<string> myArray = setParameters();
106                         
107                         OptionParser parser(option);
108                         map<string, string> parameters = parser. getParameters();
109                         
110                         ValidParameters validParameter;
111                         map<string, string>::iterator it;
112                         
113                         //check to make sure all parameters are valid for command
114                         for (it = parameters.begin(); it != parameters.end(); it++) { 
115                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
116                         }
117                         //if the user changes the input directory command factory will send this info to us in the output parameter 
118                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
119                         if (inputDir == "not found"){   inputDir = "";          }
120                         else {
121                                 string path;
122                                 it = parameters.find("phylip");
123                                 //user has given a template file
124                                 if(it != parameters.end()){ 
125                                         path = m->hasPath(it->second);
126                                         //if the user has not given a path then, add inputdir. else leave path alone.
127                                         if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
128                                 }
129                                 
130                                 it = parameters.find("axes");
131                                 //user has given a template file
132                                 if(it != parameters.end()){ 
133                                         path = m->hasPath(it->second);
134                                         //if the user has not given a path then, add inputdir. else leave path alone.
135                                         if (path == "") {       parameters["axes"] = inputDir + it->second;             }
136                                 }
137                         }
138                         
139                         //initialize outputTypes
140                         vector<string> tempOutNames;
141                         outputTypes["nmds"] = tempOutNames;
142                         outputTypes["iters"] = tempOutNames;
143                         outputTypes["stress"] = tempOutNames;
144                         
145                         //required parameters
146                         phylipfile = validParameter.validFile(parameters, "phylip", true);
147                         if (phylipfile == "not open") { phylipfile = ""; abort = true; }
148                         else if (phylipfile == "not found") {                           
149                                 //if there is a current phylip file, use it
150                                 phylipfile = m->getPhylipFile(); 
151                                 if (phylipfile != "") { m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
152                                 else {  m->mothurOut("You have no current phylip file and the phylip parameter is required."); m->mothurOutEndLine(); abort = true; }
153                         }else { m->setPhylipFile(phylipfile); } 
154                         
155                         axesfile = validParameter.validFile(parameters, "axes", true);
156                         if (axesfile == "not open") { axesfile = ""; abort = true; }
157                         else if (axesfile == "not found") { axesfile = "";  }                           
158                         
159                         //if the user changes the output directory command factory will send this info to us in the output parameter 
160                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
161                                 outputDir = ""; 
162                                 outputDir += m->hasPath(phylipfile); //if user entered a file with a path then preserve it      
163                         }
164                         
165                         string temp = validParameter.validFile(parameters, "mindim", false);    if (temp == "not found") {      temp = "2";     }
166                         m->mothurConvert(temp, mindim);
167                         
168                         temp = validParameter.validFile(parameters, "maxiters", false); if (temp == "not found") {      temp = "500";   }
169                         m->mothurConvert(temp, maxIters);
170                         
171                         temp = validParameter.validFile(parameters, "iters", false);    if (temp == "not found") {      temp = "10";    }
172                         m->mothurConvert(temp, iters);
173                         
174                         temp = validParameter.validFile(parameters, "maxdim", false);   if (temp == "not found") {      temp = "2";     }
175                         m->mothurConvert(temp, maxdim);
176                         
177                         temp = validParameter.validFile(parameters, "epsilon", false);  if (temp == "not found") {      temp = "0.000000000001";        }
178                         m->mothurConvert(temp, epsilon); 
179                         
180                         if (mindim < 1) { m->mothurOut("mindim must be at least 1."); m->mothurOutEndLine(); abort = true; }
181                         if (maxdim < mindim) { maxdim = mindim; }
182                 }
183                 
184         }
185         catch(exception& e) {
186                 m->errorOut(e, "NMDSCommand", "NMDSCommand");
187                 exit(1);
188         }
189 }
190 //**********************************************************************************************************************
191 int NMDSCommand::execute(){
192         try {
193                 
194                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
195                 
196                 cout.setf(ios::fixed, ios::floatfield);
197                 cout.setf(ios::showpoint);
198                 
199                 vector<string> names;
200                 vector< vector< double> > matrix; 
201                 
202                 //read in phylip file
203                 ReadPhylipVector readFile(phylipfile);
204                 names = readFile.read(matrix);
205                 if (m->control_pressed) { return 0; }
206                 
207                 //read axes
208                 vector< vector<double> > axes;
209                 if (axesfile != "") {  axes = readAxes(names);          }
210                 
211                 string outputFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("iters");
212                 string stressFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("stress");
213                 outputNames.push_back(outputFileName); outputTypes["iters"].push_back(outputFileName);
214                 outputNames.push_back(stressFileName); outputTypes["stress"].push_back(stressFileName);
215                 
216                 ofstream out, out2;
217                 m->openOutputFile(outputFileName, out);
218                 m->openOutputFile(stressFileName, out2);
219                 
220                 out2.setf(ios::fixed, ios::floatfield);
221                 out2.setf(ios::showpoint);
222                 out.setf(ios::fixed, ios::floatfield);
223                 out.setf(ios::showpoint);
224                 
225                 out2 << "Dimension\tIter\tStress\tRsq" << endl;
226                 
227                 double bestStress = 10000000;
228                 double bestR2 = 10000000;
229                 vector< vector<double> > bestConfig;
230                 int bestDim = 0;
231                 
232                 for (int i = mindim; i <= maxdim; i++) {
233                         m->mothurOut("Processing Dimension: " + toString(i)); m->mothurOutEndLine();
234                         
235                         for (int j = 0; j < iters; j++) {
236                                 m->mothurOut(toString(j+1)); m->mothurOutEndLine(); 
237                                 
238                                 //get configuration - either randomly generate or resize to this dimension
239                                 vector< vector<double> > thisConfig;
240                                 if (axesfile == "") {   thisConfig = generateStartingConfiguration(names.size(), i);            }
241                                 else                            {       thisConfig = getConfiguration(axes, i);                                                         }
242                                 if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) {     m->mothurRemove(outputNames[k]);        } return 0; }
243                                 
244                                 //calc nmds for this dimension
245                                 double stress;
246                                 vector< vector<double> > endConfig = nmdsCalc(matrix, thisConfig, stress);
247                                 if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) {     m->mothurRemove(outputNames[k]);        } return 0; }
248                                 
249                                 //calc euclid distances for new config
250                                 vector< vector<double> > newEuclid = linearCalc.calculateEuclidianDistance(endConfig);
251                                 if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) {     m->mothurRemove(outputNames[k]);        } return 0; }
252                                 
253                                 //calc correlation between original distances and euclidean distances from this config
254                                 double rsquared = linearCalc.calcPearson(newEuclid, matrix);
255                                 rsquared *= rsquared;
256                                 if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) {     m->mothurRemove(outputNames[k]);        } return 0; }
257                                 
258                                 //output results
259                                 out << "Config" << (j+1) << '\t';
260                                 for (int k = 0; k < i; k++) { out << "axis" << (k+1) << '\t'; }
261                                 out << endl;
262                                 out2 << i << '\t' << (j+1) << '\t' << stress << '\t' << rsquared << endl;
263                                 
264                                 output(endConfig, names, out);
265                                 
266                                 //save best
267                                 if (stress < bestStress) {
268                                         bestDim = i;
269                                         bestStress = stress;
270                                         bestR2 = rsquared;
271                                         bestConfig = endConfig;
272                                 }
273                                 
274                                 if (m->control_pressed) { out.close(); out2.close(); for (int k = 0; k < outputNames.size(); k++) {     m->mothurRemove(outputNames[k]);        } return 0; }
275                         }
276                 }
277                 
278                 out.close(); out2.close();
279                 
280                 //output best config
281                 string BestFileName = outputDir + m->getRootName(m->getSimpleName(phylipfile)) + getOutputFileNameTag("nmds");
282                 outputNames.push_back(BestFileName); outputTypes["nmds"].push_back(BestFileName);
283                 
284                 m->mothurOut("\nNumber of dimensions:\t" + toString(bestDim) + "\n");
285                 m->mothurOut("Lowest stress :\t" + toString(bestStress) + "\n");
286                 m->mothurOut("R-squared for configuration:\t" + toString(bestR2) + "\n");
287                 
288                 ofstream outBest;
289                 m->openOutputFile(BestFileName, outBest);
290                 outBest.setf(ios::fixed, ios::floatfield);
291                 outBest.setf(ios::showpoint);
292                 
293                 outBest << '\t';
294                 for (int k = 0; k < bestConfig.size(); k++) { outBest << "axis" << (k+1) << '\t'; }
295                 outBest << endl;
296                 
297                 output(bestConfig, names, outBest);
298                 
299                 outBest.close();
300                 
301                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]);        } return 0; }
302                 
303                 m->mothurOutEndLine();
304                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
305                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
306                 m->mothurOutEndLine();
307                 
308                 return 0;
309         }
310         catch(exception& e) {
311                 m->errorOut(e, "NMDSCommand", "execute");
312                 exit(1);
313         }
314 }
315 //**********************************************************************************************************************
316 vector< vector<double> > NMDSCommand::nmdsCalc(vector< vector<double> >& matrix, vector< vector<double> >& config, double& stress1) {
317         try {
318                 
319                 vector< vector<double> > newConfig = config;
320                 
321                 //calc euclid distances
322                 vector< vector<double> > euclid = linearCalc.calculateEuclidianDistance(newConfig);
323                 if (m->control_pressed) { return newConfig; }           
324                 
325                 double stress2 = calculateStress(matrix, euclid);
326                 stress1 = stress2 + 1.0 + epsilon;
327                 
328                 int count = 0;
329                 while ((count < maxIters) && (abs(stress1 - stress2) > epsilon)) {
330                         count++;
331                         
332                         stress1 = stress2;
333                         
334                         if (m->control_pressed) { return newConfig; }
335                         
336                         vector< vector<double> > b; b.resize(euclid.size());
337                         for (int i = 0; i < b.size(); i++) { b[i].resize(euclid[i].size(), 0.0); }
338                         
339                         vector<double> columnSums; columnSums.resize(euclid.size(), 0.0);
340                         for (int i = 0; i < euclid.size(); i++) {
341                                 for (int j = 0; j < euclid[i].size(); j++) {
342                                         //eliminate divide by zero error
343                                         if (euclid[i][j] != 0) { 
344                                                 b[i][j] = matrix[i][j] / euclid[i][j];
345                                                 columnSums[j] += b[i][j];
346                                                 b[i][j] *= -1.0;
347                                         }
348                                 }
349                         }
350                         
351                         //put in diagonal sums
352                         for (int i = 0; i < euclid.size(); i++) {  b[i][i] = columnSums[i]; }
353                         
354                         int numInLowerTriangle = matrix.size() * (matrix.size()-1) / 2.0;
355                         double n = (1.0 + sqrt(1.0 + 8.0 * numInLowerTriangle)) / 2.0;
356                         
357                         //matrix mult
358                         newConfig = linearCalc.matrix_mult(newConfig, b);
359                         for (int i = 0; i < newConfig.size(); i++) {
360                                 for (int j = 0; j < newConfig[i].size(); j++) {
361                                         newConfig[i][j] *= (1.0 / n);
362                                 }
363                         }
364                         
365                         euclid = linearCalc.calculateEuclidianDistance(newConfig);
366                         
367                         stress2 = calculateStress(matrix, euclid);
368                 }
369                 
370                 return newConfig;
371         }
372         catch(exception& e) {
373                 m->errorOut(e, "NMDSCommand", "generateStartingConfiguration");
374                 exit(1);
375         }
376 }
377
378 //**********************************************************************************************************************
379 //generate random config
380 vector< vector<double> > NMDSCommand::generateStartingConfiguration(int numNames, int dimension) {
381         try {
382                 vector< vector<double> > axes;  axes.resize(dimension);
383                 for (int i = 0; i < axes.size(); i++) {  axes[i].resize(numNames); }
384                 
385                 //generate random number between -1 and 1, precision 6
386                 for (int i = 0; i < axes.size(); i++) {
387                         for (int j = 0; j < axes[i].size(); j++) {
388                                 
389                                 if (m->control_pressed) { return axes; }
390                                 
391                                 //generate random int between 0 and 99999
392                                 int myrand = (int)((float)(rand()) / ((RAND_MAX / 99998) + 1));
393                                 
394                                 //generate random sign
395                                 int mysign = (int)((float)(rand()) / ((RAND_MAX / 99998) + 1));
396                                 
397                                 //if mysign is even then sign = positive, else sign = negative
398                                 if ((mysign % 2) == 0) { mysign = 1.0; }
399                                 else { mysign = -1.0; }
400                                 
401                                 axes[i][j] = mysign * myrand / (float) 100000;
402                         }
403                 }
404
405                 return axes;
406         }
407         catch(exception& e) {
408                 m->errorOut(e, "NMDSCommand", "generateStartingConfiguration");
409                 exit(1);
410         }
411 }
412 //**********************************************************************************************************************
413 //normalize configuration
414 int NMDSCommand::normalizeConfiguration(vector< vector<double> >& axes, int numNames, int dimension) {
415         try {
416                 vector<double> averageAxes; averageAxes.resize(dimension, 0.0);
417                 
418                 //find average
419                 for (int i = 0; i < axes.size(); i++) {
420                         for (int j = 0; j < axes[i].size(); j++) {      averageAxes[i] += axes[i][j];   }
421                         
422                         averageAxes[i] /= (float) numNames;
423                 }
424                 
425                 //normalize axes
426                 double sumDenom = 0.0;
427                 for (int i = 0; i < axes.size(); i++) {
428                         for (int j = 0; j < axes[i].size(); j++) {
429                                 sumDenom += ((axes[i][j] - averageAxes[i]) * (axes[i][j] - averageAxes[i]));
430                         }
431                 }
432                 
433                 double denom = sqrt((sumDenom / (float) (axes.size() * numNames)));
434                 
435                 for (int i = 0; i < axes.size(); i++) {
436                         for (int j = 0; j < axes[i].size(); j++) {
437                                 axes[i][j] = (axes[i][j] - averageAxes[i]) / denom;
438                         }
439                 }
440                 
441                 return 0;
442         }
443         catch(exception& e) {
444                 m->errorOut(e, "NMDSCommand", "normalizeConfiguration");
445                 exit(1);
446         }
447 }
448 //**********************************************************************************************************************
449 //get configuration
450 vector< vector<double> > NMDSCommand::getConfiguration(vector< vector<double> >& axes, int dimension) {
451         try {
452                 vector< vector<double> > newAxes; newAxes.resize(dimension);
453                 
454                 for (int i = 0; i < dimension; i++) {
455                         newAxes[i] = axes[i];
456                 }
457                                 
458                 return newAxes;
459         }
460         catch(exception& e) {
461                 m->errorOut(e, "NMDSCommand", "getConfiguration");
462                 exit(1);
463         }
464 }
465 //**********************************************************************************************************************
466 //find raw stress, and normalize using
467 double NMDSCommand::calculateStress(vector< vector<double> >& matrix, vector< vector<double> >& config) {
468         try {
469                 double normStress = 0.0;
470                 double denom = 0.0;
471                 double rawStress = 0.0;
472                 
473                 //find raw stress
474                 for (int i = 0; i < matrix.size(); i++) {
475                         for (int j = 0; j < matrix[i].size(); j++) {
476                                 if (m->control_pressed) { return normStress; }
477                                 
478                                 rawStress += ((matrix[i][j] - config[i][j]) * (matrix[i][j] - config[i][j]));
479                                 denom += (config[i][j] * config[i][j]);
480                         }
481                 }
482                 
483                 //normalize stress
484                 if ((rawStress != 0.0) && (denom != 0.0)) {
485                         normStress = sqrt((rawStress / denom));
486                 }
487
488                 return normStress;
489         }
490         catch(exception& e) {
491                 m->errorOut(e, "NMDSCommand", "calculateStress");
492                 exit(1);
493         }
494 }
495
496 //**********************************************************************************************************************
497 int NMDSCommand::output(vector< vector<double> >& config, vector<string>& names, ofstream& out) {
498         try {
499                 
500                 for (int i = 0; i < names.size(); i++) {
501                         
502                         out << names[i] << '\t';
503                         
504                         for (int j = 0; j < config.size(); j++) {
505                                 out << config[j][i] << '\t';
506                         }
507                         
508                         out << endl;
509                 }
510                 
511                 out << endl << endl;
512                         
513                 return 0;
514         }
515         catch(exception& e) {
516                 m->errorOut(e, "NMDSCommand", "output");
517                 exit(1);
518         }
519 }
520 /*****************************************************************/
521 vector< vector<double> > NMDSCommand::readAxes(vector<string> names){
522         try {
523                 ifstream in;
524                 m->openInputFile(axesfile, in);
525                 
526                 string headerLine = m->getline(in); m->gobble(in);
527                 
528                 //count the number of axis you are reading
529                 bool done = false;
530                 int count = 0;
531                 while (!done) {
532                         int pos = headerLine.find("axis");
533                         if (pos != string::npos) {
534                                 count++;
535                                 headerLine = headerLine.substr(pos+4);
536                         }else { done = true; }
537                 }
538                 
539                 if (maxdim > count) { 
540                         m->mothurOut("You requested maxdim = " + toString(maxdim) + ", but your file only includes " + toString(count) + ". Using " + toString(count) + "."); m->mothurOutEndLine(); 
541                         maxdim = count; 
542                         if (maxdim < mindim) { m->mothurOut("Also adjusting mindim to " + toString(maxdim-1) + "."); m->mothurOutEndLine(); }
543                 }
544                 
545                 vector< vector<double> > axes;  axes.resize(maxdim);
546                 for (int i = 0; i < axes.size(); i++) { axes[i].resize(names.size(), 0.0); }
547                 
548                 map <string, vector<double> > orderedAxes;
549                 map     <string, vector<double> >::iterator it;
550                 
551                 while (!in.eof()) {
552                         
553                         if (m->control_pressed) { in.close(); return axes; }
554                         
555                         string group = "";
556                         in >> group; m->gobble(in);
557                         
558                         bool ignore = false;
559                         if (!m->inUsersGroups(group, names)) { ignore = true; m->mothurOut(group + " is in your axes file and not in your distance file, ignoring."); m->mothurOutEndLine(); }
560                         
561                         vector<double> thisGroupsAxes;
562                         for (int i = 0; i < count; i++) {
563                                 float temp = 0.0;
564                                 in >> temp; 
565                                 
566                                 //only save the axis we want
567                                 if (i < maxdim) {  thisGroupsAxes.push_back(temp); }
568                         }
569                         
570                         if (!ignore) {  orderedAxes[group] = thisGroupsAxes; }
571                         
572                         m->gobble(in);
573                 }
574                 in.close();
575                                 
576                 //sanity check
577                 if (names.size() != orderedAxes.size()) { m->mothurOut("[ERROR]: your axes file does not match your distance file, aborting."); m->mothurOutEndLine(); m->control_pressed = true; return axes; }
578                 
579                 //put axes info in same order as distance file, just in case
580                 for (int i = 0; i < names.size(); i++) {
581                         it = orderedAxes.find(names[i]);
582                         
583                         if (it != orderedAxes.end()) {
584                                 vector<double> thisGroupsAxes = it->second;
585                                 
586                                 for (int j = 0; j < thisGroupsAxes.size(); j++) {
587                                         axes[j][i] = thisGroupsAxes[j];
588                                 }
589                                 
590                         }else { m->mothurOut("[ERROR]: your axes file does not match your distance file, aborting."); m->mothurOutEndLine(); m->control_pressed = true; return axes; }
591                 }
592                 
593                 return axes;
594         }
595         catch(exception& e) {
596                 m->errorOut(e, "NMDSCommand", "readAxes");      
597                 exit(1);
598         }
599 }
600 /**********************************************************************************************************************/
601
602
603