/***********************************************************************/
-ReadCluster::ReadCluster(string distfile, float c){
+ReadCluster::ReadCluster(string distfile, float c, string o, bool s){
globaldata = GlobalData::getInstance();
m = MothurOut::getInstance();
distFile = distfile;
cutoff = c;
+ outputDir = o;
+ sortWanted = s;
+ list = NULL;
}
/***********************************************************************/
-void ReadCluster::read(NameAssignment* nameMap){
+int ReadCluster::read(NameAssignment* nameMap){
try {
if (format == "phylip") { convertPhylip2Column(nameMap); }
else { list = new ListVector(nameMap->getListVector()); }
- OutPutFile = sortFile(distFile);
+ if (m->control_pressed) { return 0; }
+
+ if (sortWanted) { OutPutFile = sortFile(distFile, outputDir); }
+ else { OutPutFile = distFile; } //for use by clusters splitMatrix to convert a phylip matrix to column
+
+ return 0;
}
catch(exception& e) {
}
/***********************************************************************/
-void ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
+int ReadCluster::convertPhylip2Column(NameAssignment* nameMap){
try {
//convert phylip file to column file
map<int, string> rowToName;
ofstream out;
string tempFile = distFile + ".column.temp";
- openInputFile(distFile, in);
+ openInputFile(distFile, in); gobble(in);
openOutputFile(tempFile, out);
float distance;
list->set(i, name);
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
for(int j=0;j<i;j++){
+
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap == NULL){
list->set(i, name);
for(int j=0;j<nseqs;j++){
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
if(nameMap->count(name)==0){ m->mothurOut("Error: Sequence '" + name + "' was not found in the names file, please correct"); m->mothurOutEndLine(); }
for(int j=0;j<nseqs;j++){
+ if (m->control_pressed) { in.close(); out.close(); remove(tempFile.c_str()); return 0; }
+
in >> distance;
if (distance == -1) { distance = 1000000; }
list->setLabel("0");
in.close();
out.close();
-
+
if(nameMap == NULL){
nameMap = new NameAssignment();
for(int i=0;i<matrixNames.size();i++){
float dist;
while (in2) {
+ if (m->control_pressed) { in2.close(); out2.close(); remove(tempFile.c_str()); remove(outputFile.c_str()); return 0; }
+
in2 >> first >> second >> dist;
out2 << rowToName[first] << '\t' << rowToName[second] << '\t' << dist << endl;
gobble(in2);
remove(tempFile.c_str());
distFile = outputFile;
+
+ if (m->control_pressed) { remove(outputFile.c_str()); }
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ReadCluster", "convertPhylip2Column");