]> git.donarmstrong.com Git - mothur.git/blobdiff - kruskalwalliscommand.cpp
fixed io
[mothur.git] / kruskalwalliscommand.cpp
index 9064f49c747081ddde6c23edd82afbed8b83d6fe..39afca8c8acb0228a60d18b8df4da9a23eb6adef 100644 (file)
@@ -4,6 +4,7 @@
  *
  * Created on June 26, 2012, 11:06 AM
  */
+
 #include "kruskalwalliscommand.h"
 
 //**********************************************************************************************************************
@@ -123,9 +124,24 @@ int KruskalWallisCommand::execute(){
        try {
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
         
+        InputData* input = new InputData(sharedfile, "sharedfile");
+        vector<SharedRAbundVector*> lookup = input->getSharedRAbundVectors();
+               string lastLabel = lookup[0]->getLabel();
+               
+               //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+               set<string> processedLabels;
+               set<string> userLabels = labels;
+
+        ofstream out;
+               string outputFileName = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + getOutputFileNameTag("summary");
+        m->openOutputFile(outputFileName, out);
+        outputNames.push_back(outputFileName);  outputTypes["summary"].push_back(outputFileName);
+        out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
+        out << "H\tpvalue\n";
+        
         //math goes here
         
-        int N; //= thisLookUp.size();
+        int N = lookup.size();
         double H;
         double tmp = 0.0;
         vector<groupRank> vec;
@@ -186,22 +202,26 @@ void KruskalWallisCommand::assignRank(vector<groupRank> &vec) {
         while ( it != vec.end() ) {
             j = rank;
             oldit = it;
-            if (!equalvalue(*it, *it+1)) { *it->rank = rank; rank=rank+1; it++; }
+            if (!equalvalue(*it, *(it+1))) {
+                (*it).rank = rank; 
+                rank = rank+1; 
+                it++; }
             else {
-                while(equalrank(*it, *it+1)) {
-                    j = j + (j+1.0);
+                while(equalrank(*it, *(it+1))) {
+                    j = j + (j+1);
                     rank++;
                     it++;
                 }
                 numRanks = double (distance(oldit, it));
                 avgRank = j / numRanks;
                 while(oldit != it) {
-                    *oldit->rank = avgRank;
+                    (*oldit).rank = avgRank;
                     oldit++;
                 }
             }
 
         }
+        
 
     }
     catch(exception& e) {