| 27 | #endif |
| 28 | |
| 29 | static void mergeFastaFiles(const string& outputPath, const string& inputPathPrefix, bool generateNewIds = false) |
| 30 | { |
| 31 | cout << "Concatenating fasta files to " << outputPath << endl; |
| 32 | |
| 33 | // write merged FASTA file |
| 34 | |
| 35 | FastaWriter writer(outputPath.c_str()); |
| 36 | uint64_t seqid = 0; |
| 37 | for(int i = 0; i < opt::numProc; i++) { |
| 38 | ostringstream filename; |
| 39 | filename << inputPathPrefix << i << FASTA_SUFFIX; |
| 40 | assert(filename.good()); |
| 41 | string str(filename.str()); |
| 42 | FastaReader reader(str.c_str(), FastaReader::NO_FOLD_CASE); |
| 43 | for (FastaRecord rec; reader >> rec;) { |
| 44 | if (generateNewIds) |
| 45 | writer.WriteSequence(rec.seq, seqid++, rec.comment); |
| 46 | else |
| 47 | writer.WriteSequence(rec.seq, rec.id, rec.comment); |
| 48 | } |
| 49 | assert(reader.eof()); |
| 50 | } |
| 51 | |
| 52 | // remove temp FASTA files |
| 53 | |
| 54 | bool die = false; |
| 55 | for (int i = 0; i < opt::numProc; i++) { |
| 56 | ostringstream s; |
| 57 | s << inputPathPrefix << i << FASTA_SUFFIX; |
| 58 | string str(s.str()); |
| 59 | const char* path = str.c_str(); |
| 60 | if (unlink(path) == -1) { |
| 61 | cerr << "error: removing `" << path << "': " |
| 62 | << strerror(errno) << endl; |
| 63 | die = true; |
| 64 | } |
| 65 | } |
| 66 | if (die) |
| 67 | exit(EXIT_FAILURE); |
| 68 | } |
| 69 | |
| 70 | int main(int argc, char** argv) |
| 71 | { |