Skip to content

Commit

Permalink
Use a proxy also for --too-long-output
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelm committed Jan 30, 2024
1 parent 2ba7cac commit 68c54ad
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 73 deletions.
33 changes: 12 additions & 21 deletions src/cutadapt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
PolyATrimmer,
PairedReverseComplementer,
)
from cutadapt.predicates import TooShort
from cutadapt.predicates import TooShort, TooLong
from cutadapt.report import full_report, minimal_report, Statistics
from cutadapt.pipeline import SingleEndPipeline, PairedEndPipeline
from cutadapt.runners import make_runner
Expand Down Expand Up @@ -475,12 +475,6 @@ def open_output_files(
]
)

too_long = too_long2 = None
if args.maximum_length is not None:
too_long, too_long2 = file_opener.xopen_pair(
args.too_long_output, args.too_long_paired_output, "wb"
)

if (
int(args.discard_trimmed)
+ int(args.discard_untrimmed)
Expand Down Expand Up @@ -549,8 +543,6 @@ def open_output_files(
return OutputFiles(
file_opener=file_opener,
proxied=proxied,
too_long=too_long,
too_long2=too_long2,
untrimmed=untrimmed,
untrimmed2=untrimmed2,
out=out,
Expand Down Expand Up @@ -833,6 +825,12 @@ def make_pipeline_from_args( # noqa: C901
args.too_short_paired_output,
TooShort,
),
(
args.maximum_length,
args.too_long_output,
args.too_long_paired_output,
TooLong,
),
]:
if length is None:
if path1 or path2:
Expand All @@ -841,6 +839,11 @@ def make_pipeline_from_args( # noqa: C901
"When --too-short-output or --too-short-paired-output are used, "
"a minimum length must be provided with -m/--minimum-length"
)
if predicate_class is TooLong:
raise CommandLineError(
"When --too-long-output or --too-long-paired-output are used, "
"a maximum length must be provided with -M/--maximum-length"
)
continue
if not paired and path2:
raise CommandLineError(
Expand Down Expand Up @@ -964,18 +967,6 @@ def make_pipeline_from_args( # noqa: C901
pipeline.override_untrimmed_pair_filter = True

# Set filtering parameters
# Maximum length
for attr in ("maximum_length",):
param = getattr(args, attr)
if param is not None:
lengths = parse_lengths(param)
if not paired and len(lengths) == 2:
raise CommandLineError(
"Two minimum or maximum lengths given for single-end data"
)
if paired and len(lengths) == 1:
lengths = (lengths[0], lengths[0])
setattr(pipeline, attr, lengths)
pipeline.max_n = args.max_n
pipeline.max_expected_errors = args.max_expected_errors
pipeline.max_average_error_rate = args.max_average_error_rate
Expand Down
8 changes: 0 additions & 8 deletions src/cutadapt/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,6 @@ def __init__(
out2: Optional[BinaryIO] = None,
untrimmed: Optional[BinaryIO] = None,
untrimmed2: Optional[BinaryIO] = None,
too_long: Optional[BinaryIO] = None,
too_long2: Optional[BinaryIO] = None,
demultiplex_out: Optional[Dict[str, BinaryIO]] = None,
demultiplex_out2: Optional[Dict[str, BinaryIO]] = None,
combinatorial_out: Optional[Dict[Tuple[str, str], BinaryIO]] = None,
Expand All @@ -227,8 +225,6 @@ def __init__(
self.out2 = out2
self.untrimmed = untrimmed
self.untrimmed2 = untrimmed2
self.too_long = too_long
self.too_long2 = too_long2
self.demultiplex_out = demultiplex_out
self.demultiplex_out2 = demultiplex_out2
self.combinatorial_out = combinatorial_out
Expand Down Expand Up @@ -287,8 +283,6 @@ def __iter__(self):
self.out2,
self.untrimmed,
self.untrimmed2,
self.too_long,
self.too_long2,
]:
if f is not None:
yield f
Expand Down Expand Up @@ -318,8 +312,6 @@ def as_bytesio(self) -> "OutputFiles":
"out2",
"untrimmed",
"untrimmed2",
"too_long",
"too_long2",
):
if getattr(self, attr) is not None:
setattr(result, attr, io.BytesIO())
Expand Down
44 changes: 0 additions & 44 deletions src/cutadapt/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from .predicates import (
DiscardUntrimmed,
Predicate,
TooLong,
TooManyN,
TooManyExpectedErrors,
TooHighAverageErrorRate,
Expand Down Expand Up @@ -65,7 +64,6 @@ def __init__(self) -> None:
self._textiowrappers: List[TextIO] = []

# Filter settings
self._maximum_length = None
self.max_n = None
self.max_expected_errors = None
self.max_average_error_rate = None
Expand Down Expand Up @@ -105,21 +103,6 @@ def _set_output(self, outfiles: OutputFiles) -> None: # noqa: C901
steps = []
files: List[Optional[BinaryIO]]

# minimum length and maximum length
for lengths, file1, file2, predicate_class in (
(self._maximum_length, outfiles.too_long, outfiles.too_long2, TooLong),
):
if lengths is None:
continue
files = [file1, file2] if self.paired else [file1]
writer = self._open_writer(*files) if file1 else None
f1 = predicate_class(lengths[0]) if lengths[0] is not None else None
if len(lengths) == 2 and lengths[1] is not None:
f2 = predicate_class(lengths[1])
else:
f2 = None
steps.append(self._make_filter(predicate1=f1, predicate2=f2, writer=writer))

if self.max_n is not None:
f1 = f2 = TooManyN(self.max_n)
steps.append(self._make_filter(f1, f2, None))
Expand Down Expand Up @@ -321,15 +304,6 @@ def _create_demultiplexer(self, outfiles: OutputFiles) -> Demultiplexer:
def _wrap_single_end_step(self, step: SingleEndStep):
return step

@property
def maximum_length(self):
return self._maximum_length

@maximum_length.setter
def maximum_length(self, value):
assert value is None or len(value) == 1
self._maximum_length = value


class PairedEndPipeline(Pipeline):
"""
Expand Down Expand Up @@ -471,21 +445,3 @@ def open_writer(file, file2):

def _wrap_single_end_step(self, step: SingleEndStep):
return PairedSingleEndStep(step)

@property
def minimum_length(self):
return self._minimum_length

@minimum_length.setter
def minimum_length(self, value):
assert value is None or len(value) == 2
self._minimum_length = value

@property
def maximum_length(self):
return self._maximum_length

@maximum_length.setter
def maximum_length(self, value):
assert value is None or len(value) == 2
self._maximum_length = value

0 comments on commit 68c54ad

Please sign in to comment.