//assumptions about the blast file:
//1. if duplicate lines occur the first line is always best and is chosen
//2. blast scores are grouped together, ie. a a .... score, a b .... score, a c ....score...
-void ReadBlast::read(NameAssignment* nameMap) {
+int ReadBlast::read(NameAssignment* nameMap) {
try {
//if the user has not given a names file read names from blastfile
if (nameMap->size() == 0) { readNames(nameMap); }
int nseqs = nameMap->size();
+
+ if (m->control_pressed) { return 0; }
ifstream fileHandle;
openInputFile(blastfile, fileHandle);
openOutputFile(overlapFile, outOverlap);
openOutputFile(distFile, outDist);
}
-
+
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ return 0;
+ }
+
Progress* reading = new Progress("Reading blast: ", nseqs * nseqs);
//this is used to quickly find if we already have a distance for this combo
//read file
while(!fileHandle.eof()){
+
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
//read in line from file
fileHandle >> firstName >> secondName >> percentId >> numBases >> mismatch >> gap >> startQuery >> endQuery >> startRef >> endRef >> eScore >> score;
thisRowsBlastScores.clear();
dists.clear();
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { outOverlap.close(); remove(overlapFile.c_str()); outDist.close(); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
+
if (!hclusterWanted) {
sort(overlap.begin(), overlap.end(), compareOverlap);
}else {
outOverlap.close();
}
+ if (m->control_pressed) {
+ fileHandle.close();
+ if (!hclusterWanted) { delete matrix; }
+ else { remove(overlapFile.c_str()); remove(distFile.c_str()); }
+ delete reading;
+ return 0;
+ }
+
reading->finish();
delete reading;
fileHandle.close();
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "ReadBlast", "read");
}
}
/*********************************************************************************************/
-void ReadBlast::readNames(NameAssignment* nameMap) {
+int ReadBlast::readNames(NameAssignment* nameMap) {
try {
m->mothurOut("Reading names... "); cout.flush();
ifstream in;
openInputFile(blastfile, in);
+ ofstream outName;
+ openOutputFile("tempOutNames", outName);
+
//read first line
in >> prevName;
+
for (int i = 0; i < 11; i++) { in >> hold; }
gobble(in);
-
+
//save name in nameMap
nameMap->push_back(prevName);
while (!in.eof()) {
+ if (m->control_pressed) { in.close(); return 0; }
//read line
in >> name;
+
for (int i = 0; i < 11; i++) { in >> hold; }
gobble(in);
//openOutputFile(outNames, out);
//nameMap->print(out);
//out.close();
+ if (m->control_pressed) { return 0; }
m->mothurOut(toString(num) + " names read."); m->mothurOutEndLine();
+ return 0;
+
}
catch(exception& e) {
m->errorOut(e, "ReadBlast", "readNames");