diff --git a/src/map/include/computeMap.hpp b/src/map/include/computeMap.hpp index 562713d9..725d4a4c 100644 --- a/src/map/include/computeMap.hpp +++ b/src/map/include/computeMap.hpp @@ -721,21 +721,6 @@ namespace skch aggregator.join(); - // Filter mappings for this subset to reduce memory usage - for (auto& [querySeqId, mappings] : combinedMappings) { - if (param.filterMode == filter::MAP || param.filterMode == filter::ONETOONE) { - MappingResultsVector_t filteredMappings; - filterByGroup(mappings, filteredMappings, param.numMappingsForSegment - 1, false, *idManager, progress); - mappings = std::move(filteredMappings); - - // Also apply length and identity filters - filterWeakMappings(mappings, std::floor(param.block_length / param.segLength)); - if (param.filterLengthMismatches) { - filterFalseHighIdentity(mappings); - } - sparsifyMappings(mappings); - } - } // Reset flags and clear aggregatedMappings for next iteration reader_done.store(false); @@ -956,6 +941,20 @@ namespace skch mappingBoundarySanityCheck(input, output->results); + // Apply pre-filtering immediately after mapping against this subset + if (param.filterMode == filter::MAP || param.filterMode == filter::ONETOONE) { + MappingResultsVector_t filteredMappings; + filterByGroup(output->results, filteredMappings, param.numMappingsForSegment - 1, false, *idManager, input->progress); + output->results = std::move(filteredMappings); + + // Also apply length and identity filters + filterWeakMappings(output->results, std::floor(param.block_length / param.segLength)); + if (param.filterLengthMismatches) { + filterFalseHighIdentity(output->results); + } + sparsifyMappings(output->results); + } + return output; }