Skip to content

Commit 74f427a

Browse files
authored
Fix issue 161, 168 (#169)
* first compiling version after merging read-grouping module * now 1-based temporarily * implement SyncmerScanner_dna2aa * optimize read grouping * cadd parameters for ceateingcommon k-mer list * extract reference k-mers from six-frame translations * extract reference k-mers from six-frame translations * code clean * KmerDbReader only reads k-mer values not IDs * add parameters to read grouping module * use only k-mer values during common k-mer filtering * add yxml into lib * WIP: making read grouping flexible to original classification format * fix read index error in reporting updated results * fix tiny-size db creation error * regression test updated * hide developing features * fix errors in benchmark set generation * fix issue 108 * update database moudle * fix error in classifiedRefiner reported in issue168 * Fix error in --tax-id regex
1 parent b9ab2a3 commit 74f427a

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

src/commons/LocalParameters.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ LocalParameters::LocalParameters() :
221221
"Tax. ID of clade. -1 for unclassified reads",
222222
typeid(int),
223223
(void *) &targetTaxId,
224-
"^[0-9]+$"),
224+
"^(?:[0-9]+|-1)$"),
225225
EXTRACT_MODE(EXTRACT_MODE_ID,
226226
"--extract-format",
227227
"0: original format, 1: FASTA, 2: FASTQ",

src/util/classifiedRefiner.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,16 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
108108

109109
if (FileUtil::fileExists(refinedFileName.c_str())) {
110110
Debug(Debug::INFO) << refinedFileName << " is already exists.\n";
111+
delete taxonomy;
112+
delete reporter;
111113
return 0;
112114
}
113115
ofstream refinedFile(refinedFileName.c_str());
114116

115117
if (!refinedFile.is_open()) {
116118
Debug(Debug::ERROR) << "Could not open " << refinedFileName << " for writing\n";
119+
delete taxonomy;
120+
delete reporter;
117121
EXIT(EXIT_FAILURE);
118122
}
119123

@@ -142,6 +146,8 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
142146

143147
if (checktaxId(taxonomy, contamsTaxIds, targetId)) {
144148
Debug(Debug::ERROR) << "Excluded taxid is selected : " << target << "\n";
149+
delete taxonomy;
150+
delete reporter;
145151
EXIT(EXIT_FAILURE);
146152
}
147153

@@ -157,6 +163,8 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
157163
columnsIdx.push_back(stoi(column));
158164
if (stoi(column) > 7) {
159165
Debug(Debug::ERROR) << "Invalid column index: " << column;
166+
delete taxonomy;
167+
delete reporter;
160168
EXIT(EXIT_FAILURE);
161169
}
162170
}
@@ -172,6 +180,8 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
172180
// check if criterionRank is valid
173181
if (!criterionRank.empty() && taxonomy->findRankIndex(criterionRank) == -1) {
174182
Debug(Debug::ERROR) << "Invalid criterion rank: " << criterionRank << ". Rank not found in NcbiRanks.\n";
183+
delete taxonomy;
184+
delete reporter;
175185
EXIT(EXIT_FAILURE);
176186
}
177187

@@ -183,6 +193,8 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
183193
ofstream upperRankFile(upperRankFileName.c_str());
184194
if (!upperRankFile.is_open()) {
185195
Debug(Debug::ERROR) << "Could not open " << upperRankFileName << " for writing\n";
196+
delete taxonomy;
197+
delete reporter;
186198
EXIT(EXIT_FAILURE);
187199
}
188200
upperRankFile.close();
@@ -191,8 +203,10 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
191203
ifstream file(classifiedFile);
192204
ofstream refinedFileAppend(refinedFileName.c_str(), ios::app); // Append mode for parallel writes
193205
if (!file.is_open() || !refinedFileAppend.is_open()) {
194-
Debug(Debug::ERROR) << "Could not open input or output file\n";
195-
EXIT(EXIT_FAILURE);
206+
Debug(Debug::ERROR) << "Could not open input or output file\n";
207+
delete taxonomy;
208+
delete reporter;
209+
EXIT(EXIT_FAILURE);
196210
}
197211

198212
std::string firstLine;
@@ -221,7 +235,7 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
221235
std::vector<std::string> resultChunk;
222236
std::vector<std::string> upperRanks;
223237

224-
#pragma omp parallel default(none) shared(file, refinedFileAppend, taxonomy, extern2intern, contamsTaxIds, targetsTaxIds, columnsIdx, par, totalSeqCnt, resultChunk, taxcntSum,upperRanks, upperRankFileAppend, createUpperRanksFile, criterionRank)
238+
#pragma omp parallel default(none) shared(file, refinedFileAppend, cout, taxonomy, extern2intern, contamsTaxIds, targetsTaxIds, columnsIdx, par, totalSeqCnt, resultChunk, taxcntSum,upperRanks, upperRankFileAppend, createUpperRanksFile, criterionRank)
225239
{
226240

227241
#pragma omp single
@@ -317,9 +331,8 @@ int classifiedRefiner(const string &classifiedFile, const string&taxonomyDir, co
317331
if (data.fullLineage != "-" && par.selectColumns == "") {
318332
columnsIdx.push_back(7);
319333
}
320-
321334
data.taxonomyId = extern2intern[data.taxonomyId];
322-
if (data.fullLineage == "-") {
335+
if (data.fullLineage == "-" && data.isClassified == true) {
323336
data.fullLineage = taxonomy->taxLineage2(taxonomy->taxonNode(data.taxonomyId));
324337
fields.pop_back();
325338
fields.push_back(data.fullLineage);

0 commit comments

Comments
 (0)