X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=hclustercommand.cpp;h=dbc0e1bb9917b0d2cfdebfa83a5a97a17b6eb905;hb=d2cbe389d0e42eccb6bbb888462fe17e22a487a8;hp=6e3ec243addd289a6d44226adeddd6a3fccbb0d2;hpb=3c856e629e20261496b0433c2587f27b2c8ba3f6;p=mothur.git diff --git a/hclustercommand.cpp b/hclustercommand.cpp index 6e3ec24..dbc0e1b 100644 --- a/hclustercommand.cpp +++ b/hclustercommand.cpp @@ -21,7 +21,7 @@ HClusterCommand::HClusterCommand(string option){ else { //valid paramters for this command - string Array[] = {"cutoff","precision","method","showabund","timing","phylip","column","name","sorted"}; + string Array[] = {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); OptionParser parser(option); @@ -53,8 +53,8 @@ HClusterCommand::HClusterCommand(string option){ if (namefile == "not open") { abort = true; } else if (namefile == "not found") { namefile = ""; } - if ((phylipfile == "") && (columnfile == "")) { mothurOut("When executing a cluster command you must enter a phylip or a column."); mothurOutEndLine(); abort = true; } - else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When executing a cluster command you must enter ONLY ONE of the following: phylip or column."); mothurOutEndLine(); abort = true; } + if ((phylipfile == "") && (columnfile == "")) { mothurOut("When executing a hcluster command you must enter a phylip or a column."); mothurOutEndLine(); abort = true; } + else if ((phylipfile != "") && (columnfile != "")) { mothurOut("When executing a hcluster command you must enter ONLY ONE of the following: phylip or column."); mothurOutEndLine(); 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; } @@ -114,11 +114,12 @@ HClusterCommand::HClusterCommand(string option){ void HClusterCommand::help(){ try { - mothurOut("The cluster command can only be executed after a successful read.dist command.\n"); - mothurOut("The cluster command parameter options are method, cuttoff, precision, showabund and timing. No parameters are required.\n"); - mothurOut("The cluster command should be in the following format: \n"); - mothurOut("cluster(method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); - mothurOut("The acceptable cluster methods are furthest, nearest and average. If no method is provided then furthest is assumed.\n\n"); + mothurOut("The hcluster command parameter options are cutoff, precision, method, phylip, column, name, showabund, timing and sorted. Phylip or column and name are required.\n"); + mothurOut("The phylip and column parameter allow you to enter your distance file, and sorted indicates whether your column distance file is already sorted. \n"); + mothurOut("The name parameter allows you to enter your name file and is required if your distance file is in column format. \n"); + mothurOut("The hcluster command should be in the following format: \n"); + mothurOut("hcluster(column=youDistanceFile, name=yourNameFile, method=yourMethod, cutoff=yourCutoff, precision=yourPrecision) \n"); + mothurOut("The acceptable hcluster methods is furthest, but we hope to add nearest and average in the future.\n\n"); } catch(exception& e) { errorOut(e, "HClusterCommand", "help"); @@ -160,7 +161,7 @@ int HClusterCommand::execute(){ mothurOut("It took " + toString(time(NULL) - estart) + " seconds to sort. "); mothurOutEndLine(); estart = time(NULL); - + //list vector made by read contains all sequence names if(list != NULL){ rabund = new RAbundVector(list->getRAbundVector()); @@ -168,8 +169,6 @@ int HClusterCommand::execute(){ mothurOut("Error: no list vector!"); mothurOutEndLine(); return 0; } - - float previousDist = 0.00000; float rndPreviousDist = 0.00000; oldRAbund = *rabund; @@ -178,7 +177,7 @@ int HClusterCommand::execute(){ print_start = true; start = time(NULL); -//cout << "here" << endl; + ifstream in; openInputFile(distfile, in); string firstName, secondName; @@ -188,7 +187,7 @@ int HClusterCommand::execute(){ bool clusteredSomething; vector seqs; seqs.resize(1); // to start loop exitedBreak = false; //lets you know if there is a distance stored in next - + while (seqs.size() != 0){ seqs = getSeqs(in); @@ -206,12 +205,12 @@ int HClusterCommand::execute(){ print_start = false; } - ///cout << "before cluster update" << endl; + //cout << "before cluster update" << endl; if (seqs[i].seq1 != seqs[i].seq2) { clusteredSomething = cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist); float rndDist = roundDist(seqs[i].dist, precision); - //cout << "after cluster update clusterSomething = " << clusteredSomething << " rndDist = " << rndDist << " rndPreviousDist = " << rndPreviousDist << endl; + //cout << "after cluster update clusterSomething = " << clusteredSomething << " rndDist = " << rndDist << " rndPreviousDist = " << rndPreviousDist << endl; if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){ @@ -260,6 +259,7 @@ int HClusterCommand::execute(){ rabundFile.close(); listFile.close(); + delete cluster; //if (isTrue(timing)) { mothurOut("It took " + toString(time(NULL) - estart) + " seconds to cluster. "); mothurOutEndLine(); //} @@ -325,17 +325,18 @@ vector HClusterCommand::getSeqs(ifstream& filehandle){ //save first one if (prevDistance == -1) { prevDistance = distance; } - + //cout << prevDistance << endl; +//if (globaldata->nameMap == NULL) { cout << "null" << endl; } map::iterator itA = globaldata->nameMap->find(firstName); map::iterator itB = globaldata->nameMap->find(secondName); if(itA == globaldata->nameMap->end()){ - cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; + cerr << "AAError: Sequence '" << firstName << "' was not found in the names file, please correct\n"; exit(1); } if(itB == globaldata->nameMap->end()){ - cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; + cerr << "ABError: Sequence '" << secondName << "' was not found in the names file, please correct\n"; exit(1); } - + //cout << "here" << endl; //using cutoff if (distance > cutoff) { break; }