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