From e29c02342d051ab1bcb2e75982019b1b07abc2d8 Mon Sep 17 00:00:00 2001 From: Cole Lyman Date: Thu, 28 May 2026 17:03:43 -0600 Subject: [PATCH] Write remaining mergedOutput buffer when in --stdout mode, fixes #697 --- scripts/test_issue_697_stdout_merge.sh | 28 ++++++++++++++++++++++++++ src/peprocessor.cpp | 9 +++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) create mode 100755 scripts/test_issue_697_stdout_merge.sh diff --git a/scripts/test_issue_697_stdout_merge.sh b/scripts/test_issue_697_stdout_merge.sh new file mode 100755 index 00000000..1d2e6ed6 --- /dev/null +++ b/scripts/test_issue_697_stdout_merge.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Repro for issue #697: --stdout should emit merged reads in merge mode. + +python - <<'PY' > /tmp/fp_repro_697.interleaved.fq +seq='AATGTCCCCCAATGGGAAGTTCATCTGGCACTGCCCACAGGTGAGGAGGTCATGATCCCCTTCTGGAGC' +comp=str.maketrans('ACGTN','TGCAN') +rc=seq.translate(comp)[::-1] +qual='I'*len(seq) +print('@r1/1'); print(seq); print('+'); print(qual) +print('@r1/2'); print(rc); print('+'); print(qual) +PY + +./fastp \ + --disable_adapter_trimming --disable_trim_poly_g \ + --disable_quality_filtering --disable_length_filtering \ + --stdin --interleaved_in --merge --stdout \ + < /tmp/fp_repro_697.interleaved.fq \ + > /tmp/fp_697_stdout.fq 2> /tmp/fp_697_stdout.log + +lines=$(wc -l < /tmp/fp_697_stdout.fq) +if [[ "$lines" -ne 4 ]]; then + echo "FAIL: expected 4 FASTQ lines from --stdout merge mode, got $lines" + exit 1 +fi + +echo "PASS: issue #697 repro produced $lines lines as expected" diff --git a/src/peprocessor.cpp b/src/peprocessor.cpp index 04accbb1..c3355525 100644 --- a/src/peprocessor.cpp +++ b/src/peprocessor.cpp @@ -669,8 +669,13 @@ bool PairEndProcessor::processPairEnd(ReadPack* leftPack, ReadPack* rightPack, T mLeftWriter->input(tid, new string(std::move(outstr1))); mRightWriter->input(tid, new string(std::move(outstr2))); } else if(mLeftWriter) { - // write singleOutput - mLeftWriter->input(tid, new string(std::move(singleOutput))); + if(mOptions->merge.enabled && mOptions->outputToSTDOUT) { + // in merge+stdout mode, merged reads are buffered in mergedOutput + mLeftWriter->input(tid, new string(std::move(mergedOutput))); + } else { + // write singleOutput + mLeftWriter->input(tid, new string(std::move(singleOutput))); + } } // output unpaired reads if(mUnpairedLeftWriter && mUnpairedRightWriter) {