diff --git a/src/cutadapt/cli.py b/src/cutadapt/cli.py index ab256275..b41b7509 100644 --- a/src/cutadapt/cli.py +++ b/src/cutadapt/cli.py @@ -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 @@ -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) @@ -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, @@ -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: @@ -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( @@ -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 diff --git a/src/cutadapt/files.py b/src/cutadapt/files.py index d32dd78a..7a0cb604 100644 --- a/src/cutadapt/files.py +++ b/src/cutadapt/files.py @@ -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, @@ -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 @@ -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 @@ -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()) diff --git a/src/cutadapt/pipeline.py b/src/cutadapt/pipeline.py index c6233777..9ffa4bf4 100644 --- a/src/cutadapt/pipeline.py +++ b/src/cutadapt/pipeline.py @@ -25,7 +25,6 @@ from .predicates import ( DiscardUntrimmed, Predicate, - TooLong, TooManyN, TooManyExpectedErrors, TooHighAverageErrorRate, @@ -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 @@ -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)) @@ -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): """ @@ -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