Skip to content

Commit

Permalink
Omit runtime from report to make it reproducible
Browse files Browse the repository at this point in the history
Closes #819
  • Loading branch information
marcelm committed Dec 11, 2024
1 parent 2160ffb commit ec36e00
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ development version
Option ``-Z`` (equivalent to ``--compression-level=1``) is now deprecated.
* The previously hidden option ``--compression-level`` is now shown in the
``--help`` output.
* :issue:`819`: To enable reproducible output, the report no longer includes
the runtime (``Finished in XY.Z s``). Runtime is still shown as part of the
progress "bar".
* :issue:`812`: Fixed an issue where multithreaded reading of unaligned BAM
files would cause an error.
* :issue:`820`: On Bioconda, Cutadapt is now also available for ARM64 Macs (M1/M2).
Expand Down
9 changes: 0 additions & 9 deletions src/cutadapt/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
)
from .statistics import ReadLengthStatistics
from .steps import HasStatistics, HasFilterStatistics
from .utils import MICRO

FILTERS = {
"too_short": "that were too short",
Expand Down Expand Up @@ -609,20 +608,12 @@ def full_report(stats: Statistics, time: float, gc_content: float) -> str: # no
"""Print report to standard output."""
if stats.n == 0:
return "No reads processed!"
if time == 0:
time = 1e-6
sio = StringIO()

def print_s(*args, **kwargs):
kwargs["file"] = sio
print(*args, **kwargs)

print_s(
"Finished in {:.3F} s ({:.3F} {}s/read; {:.2F} M reads/minute).".format(
time, 1e6 * time / stats.n, MICRO, stats.n / time * 60 / 1e6
)
)

report = "\n=== Summary ===\n\n"
if stats.paired:
report += f"Total read pairs processed: {stats.n:13,d}\n"
Expand Down
20 changes: 20 additions & 0 deletions tests/test_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,23 @@ def test_non_utf8_locale():
[sys.executable, "-m", "cutadapt", "-o", os.devnull, datapath("small.fastq")],
env={"LC_CTYPE": "C"},
)


def test_reproducible_report(tmp_path):
# Run Cutadapt twice and ensure the log is identical
report_paths = [os.fspath(tmp_path / f"report{i}.txt") for i in (1, 2)]
for report_path in report_paths:
with open(report_path, "w") as report_file:
py = subprocess.Popen(
[
sys.executable,
"-m",
"cutadapt",
"-o",
os.devnull,
datapath("small.fastq"),
],
stdout=report_file,
)
_ = py.communicate()
assert_files_equal(*report_paths)

0 comments on commit ec36e00

Please sign in to comment.