Skip to content

Commit

Permalink
Fix: discard_(un)trimmed were always none in JSON report
Browse files Browse the repository at this point in the history
This arose in commit 4fdeb12, where the
names of the classes DiscardUntrimmed and DiscardUntrimmed were changed to
IsTrimmed and IsUntrimmed because the name of the key in the JSON file is
(indirectly) derived from the class name.

Closes #824
  • Loading branch information
marcelm committed Dec 6, 2024
1 parent c601ad8 commit eacb914
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ development version
paired-end data.
* :issue:`820`: Fix division by zero problem if ``--max-ee`` is used with an
empty read. By @rhpvorderman.
* :issue:`824`: Fix: discard_(un)trimmed values were always ``none`` in JSON
report.
* Dropped support for Python 3.8.
* Added support for Python 3.13.

Expand Down
8 changes: 8 additions & 0 deletions src/cutadapt/predicates.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def __repr__(self):
def test(self, read, info: ModificationInfo):
return not info.matches

@classmethod
def descriptive_identifier(cls) -> str:
return "discard_untrimmed"


class IsTrimmed(Predicate):
"""
Expand All @@ -163,3 +167,7 @@ def __repr__(self):

def test(self, read, info: ModificationInfo):
return bool(info.matches)

@classmethod
def descriptive_identifier(cls) -> str:
return "discard_trimmed"
40 changes: 40 additions & 0 deletions tests/test_commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,44 @@ def test_terminates_correctly_on_error_in_subprocess(tmp_path):
main(params)


def test_json_report_and_discard_untrimmed(tmp_path):
stats = main(
[
"--json",
str(tmp_path / "cutadapt.json"),
"--discard-untrimmed",
"-a",
"name=ACGT",
"-o",
str(tmp_path / "trimmed.fastq"),
datapath("illumina.fastq.gz"),
]
)
assert stats.n == 100
assert stats.written == 64
js = stats.as_json()
assert js["read_counts"]["filtered"]["discard_untrimmed"] == 36


def test_json_report_and_discard_trimmed(tmp_path):
stats = main(
[
"--json",
str(tmp_path / "cutadapt.json"),
"--discard-trimmed",
"-a",
"name=ACGT",
"-o",
str(tmp_path / "trimmed.fastq"),
datapath("illumina.fastq.gz"),
]
)
assert stats.n == 100
assert stats.written == 36
js = stats.as_json()
assert js["read_counts"]["filtered"]["discard_trimmed"] == 64


def test_json_report_with_demultiplexing_and_discard_untrimmed(tmp_path):
stats = main(
[
Expand All @@ -1082,6 +1120,8 @@ def test_json_report_with_demultiplexing_and_discard_untrimmed(tmp_path):
)
assert stats.n == 100
assert stats.written == 64
js = stats.as_json()
assert js["read_counts"]["filtered"]["discard_untrimmed"] == 36


@pytest.mark.timeout(1)
Expand Down

0 comments on commit eacb914

Please sign in to comment.