OptionParser parser(option);
map<string, string> parameters = parser.getParameters();
- ValidParameters validParameter;
+ ValidParameters validParameter("align.seqs");
map<string, string>::iterator it;
//check to make sure all parameters are valid for command
if (pid == 0) {
#endif
- ableToOpen = openInputFile(candidateFileNames[i], in);
- in.close();
-
+ ableToOpen = openInputFile(candidateFileNames[i], in, "noerror");
+
+ //if you can't open it, try default location
+ if (ableToOpen == 1) {
+ if (m->getDefaultPath() != "") { //default path is set
+ string tryPath = m->getDefaultPath() + getSimpleName(candidateFileNames[i]);
+ m->mothurOut("Unable to open " + candidateFileNames[i] + ". Trying default " + tryPath); m->mothurOutEndLine();
+ ableToOpen = openInputFile(tryPath, in, "noerror");
+ candidateFileNames[i] = tryPath;
+ }
+ }
+ in.close();
#ifdef USE_MPI
for (int j = 1; j < processors; j++) {
MPI_Send(&ableToOpen, 1, MPI_INT, j, 2001, MPI_COMM_WORLD);
#endif
if (ableToOpen == 1) {
- m->mothurOut(candidateFileNames[i] + " will be disregarded."); m->mothurOutEndLine();
+ m->mothurOut("Unable to open " + candidateFileNames[i] + ". It will be disregarded."); m->mothurOutEndLine();
//erase from file list
candidateFileNames.erase(candidateFileNames.begin()+i);
i--;
#ifdef USE_MPI
int pid, end, numSeqsPerProcessor;
int tag = 2001;
- vector<long> MPIPos;
+ vector<unsigned long int> MPIPos;
MPIWroteAccnos = false;
MPI_Status status;
int outMode=MPI_MODE_CREATE|MPI_MODE_WRONLY;
int inMode=MPI_MODE_RDONLY;
-
- char outAlignFilename[alignFileName.length()];
+
+ char outAlignFilename[1024];
strcpy(outAlignFilename, alignFileName.c_str());
- char outReportFilename[reportFileName.length()];
+ char outReportFilename[1024];
strcpy(outReportFilename, reportFileName.c_str());
- char outAccnosFilename[accnosFileName.length()];
+ char outAccnosFilename[1024];
strcpy(outAccnosFilename, accnosFileName.c_str());
- char inFileName[candidateFileNames[s].length()];
+ char inFileName[1024];
strcpy(inFileName, candidateFileNames[s].c_str());
-
+
MPI_File_open(MPI_COMM_WORLD, inFileName, inMode, MPI_INFO_NULL, &inMPI); //comm, filename, mode, info, filepointer
MPI_File_open(MPI_COMM_WORLD, outAlignFilename, outMode, MPI_INFO_NULL, &outMPIAlign);
MPI_File_open(MPI_COMM_WORLD, outReportFilename, outMode, MPI_INFO_NULL, &outMPIReport);
MPIPos = setFilePosFasta(candidateFileNames[s], numFastaSeqs); //fills MPIPos, returns numSeqs
//send file positions to all processes
- MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //send numSeqs
- MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //send file pos
+ for(int i = 1; i < processors; i++) {
+ MPI_Send(&numFastaSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
+ MPI_Send(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
+ }
//figure out how many sequences you have to align
numSeqsPerProcessor = numFastaSeqs / processors;
- if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
int startIndex = pid * numSeqsPerProcessor;
+ if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
+
//align your part
driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos);
if (tempResult != 0) { MPIWroteAccnos = true; }
}
}else{ //you are a child process
- MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+ MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
MPIPos.resize(numFastaSeqs+1);
- MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
+ MPI_Recv(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
+
//figure out how many sequences you have to align
numSeqsPerProcessor = numFastaSeqs / processors;
- if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
int startIndex = pid * numSeqsPerProcessor;
+ if(pid == (processors - 1)){ numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor; }
+
//align your part
driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIAlign, outMPIReport, outMPIAccnos, MPIPos);
if(processors == 1){
ifstream inFASTA;
openInputFile(candidateFileNames[s], inFASTA);
- numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ getNumSeqs(inFASTA, numFastaSeqs);
inFASTA.close();
lines.push_back(new linePair(0, numFastaSeqs));
}
}
else{
- vector<int> positions;
+ vector<unsigned long int> positions;
processIDS.resize(0);
ifstream inFASTA;
while(!inFASTA.eof()){
input = getline(inFASTA);
if (input.length() != 0) {
- if(input[0] == '>'){ long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
+ if(input[0] == '>'){ unsigned long int pos = inFASTA.tellg(); positions.push_back(pos - input.length() - 1); }
}
}
inFASTA.close();
int numSeqsPerProcessor = numFastaSeqs / processors;
for (int i = 0; i < processors; i++) {
- long int startPos = positions[ i * numSeqsPerProcessor ];
+ unsigned long int startPos = positions[ i * numSeqsPerProcessor ];
if(i == processors - 1){
numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;
}
#else
ifstream inFASTA;
openInputFile(candidateFileNames[s], inFASTA);
- numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+ getNumSeqs(inFASTA, numFastaSeqs);
inFASTA.close();
lines.push_back(new linePair(0, numFastaSeqs));
}
//**********************************************************************************************************************
#ifdef USE_MPI
-int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& alignFile, MPI_File& reportFile, MPI_File& accnosFile, vector<long>& MPIPos){
+int AlignCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File& alignFile, MPI_File& reportFile, MPI_File& accnosFile, vector<unsigned long int>& MPIPos){
try {
string outputString = "";
MPI_Status statusReport;
if (pid == 0) {
outputString = report.getHeaders();
int length = outputString.length();
- char buf[length];
- strcpy(buf, outputString.c_str());
+
+ char* buf = new char[length];
+ memcpy(buf, outputString.c_str(), length);
MPI_File_write_shared(reportFile, buf, length, MPI_CHAR, &statusReport);
+
+ delete buf;
}
for(int i=0;i<num;i++){
//read next sequence
int length = MPIPos[start+i+1] - MPIPos[start+i];
- char buf4[length];
+
+ char* buf4 = new char[length];
+ memcpy(buf4, outputString.c_str(), length);
+
MPI_File_read_at(inMPI, MPIPos[start+i], buf4, length, MPI_CHAR, &status);
string tempBuf = buf4;
+
+ delete buf4;
+
if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
istringstream iss (tempBuf,istringstream::in);
//send results to parent
int length = outputString.length();
- char buf[length];
- strcpy(buf, outputString.c_str());
+
+ char* buf = new char[length];
+ memcpy(buf, outputString.c_str(), length);
MPI_File_write_shared(accnosFile, buf, length, MPI_CHAR, &statusAccnos);
+ delete buf;
MPIWroteAccnos = true;
}
//send results to parent
int length = outputString.length();
- char buf2[length];
- strcpy(buf2, outputString.c_str());
+ char* buf2 = new char[length];
+ memcpy(buf2, outputString.c_str(), length);
MPI_File_write_shared(alignFile, buf2, length, MPI_CHAR, &statusAlign);
+ delete buf2;
+
outputString = report.getReport();
//send results to parent
length = outputString.length();
- char buf3[length];
- strcpy(buf3, outputString.c_str());
+ char* buf3 = new char[length];
+ memcpy(buf3, outputString.c_str(), length);
MPI_File_write_shared(reportFile, buf3, length, MPI_CHAR, &statusReport);
-
+
+ delete buf3;
delete nast;
if (needToDeleteCopy) { delete copy; }
}