Exemplo n.º 1
0
    def test_rc_template_varialbe(self):
        renamer = Renamer("{id} rc={rc} {comment}")
        read = Sequence("theid thecomment", "ACGT")
        info = ModificationInfo(read)
        assert renamer(read, info).name == "theid rc= thecomment"

        read = Sequence("theid thecomment", "ACGT")
        info.is_rc = True
        assert renamer(read, info).name == "theid rc=rc thecomment"
Exemplo n.º 2
0
def pipeline_from_parsed_args(args, paired, file_opener, adapters, adapters2) -> Pipeline:
    """
    Setup a processing pipeline from parsed command-line arguments.

    If there are any problems parsing the arguments, a CommandLineError is raised.

    Return an instance of Pipeline (SingleEndPipeline or PairedEndPipeline)
    """
    if args.action == 'none':
        args.action = None

    # Create the processing pipeline
    if paired:
        pair_filter_mode = 'any' if args.pair_filter is None else args.pair_filter
        pipeline = PairedEndPipeline(
            pair_filter_mode, file_opener
        )  # type: Any
    else:
        pipeline = SingleEndPipeline(file_opener)

    # When adapters are being trimmed only in R1 or R2, override the pair filter mode
    # as using the default of 'any' would regard all read pairs as untrimmed.
    if isinstance(pipeline, PairedEndPipeline) and (not adapters2 or not adapters) and (
            args.discard_untrimmed or args.untrimmed_output or args.untrimmed_paired_output):
        pipeline.override_untrimmed_pair_filter = True

    add_unconditional_cutters(pipeline, args.cut, args.cut2, paired)

    pipeline_add = pipeline.add_both if paired else pipeline.add

    if args.nextseq_trim is not None:
        pipeline_add(NextseqQualityTrimmer(args.nextseq_trim, args.quality_base))
    if args.quality_cutoff is not None:
        cutoffs = parse_cutoffs(args.quality_cutoff)
        pipeline_add(QualityTrimmer(cutoffs[0], cutoffs[1], args.quality_base))

    add_adapter_cutter(
        pipeline,
        adapters,
        adapters2,
        paired,
        args.pair_adapters,
        args.action,
        args.times,
        args.reverse_complement,
        not args.rename,  # no "rc" suffix if --rename is used
        args.index,
    )

    for modifier in modifiers_applying_to_both_ends_if_paired(args):
        pipeline_add(modifier)

    if args.rename and (args.prefix or args.suffix):
        raise CommandLineError(
            "Option --rename cannot be combined with --prefix (-x) or --suffix (-y)"
        )
    if args.rename and args.rename != "{header}":
        try:
            if paired:
                pipeline.add_paired_modifier(PairedEndRenamer(args.rename))
            else:
                pipeline_add(Renamer(args.rename))
        except InvalidTemplate as e:
            raise CommandLineError(e)
    # Set filtering parameters
    # Minimum/maximum length
    for attr in 'minimum_length', '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.discard_casava = args.discard_casava
    pipeline.discard_trimmed = args.discard_trimmed
    pipeline.discard_untrimmed = args.discard_untrimmed

    return pipeline
Exemplo n.º 3
0
 def test_cut_suffix_template_variable(self):
     renamer = Renamer("{id}_{cut_suffix} {comment}")
     read = Sequence("theid thecomment", "ACGT")
     info = ModificationInfo(read)
     info.cut_suffix = "TTAAGG"
     assert renamer(read, info).name == "theid_TTAAGG thecomment"
Exemplo n.º 4
0
 def test_comment_template_variable_missing_comment(self):
     renamer = Renamer("{id}_extra {comment}")
     read = Sequence("theid", "ACGT")
     info = ModificationInfo(read)
     assert renamer(read, info).name == "theid_extra "
Exemplo n.º 5
0
 def test_id_template_variable(self):
     renamer = Renamer("{id} extra")
     read = Sequence("theid thecomment", "ACGT")
     info = ModificationInfo(read)
     assert renamer(read, info).name == "theid extra"
Exemplo n.º 6
0
 def test_invalid_template_variable(self):
     with pytest.raises(InvalidTemplate):
         Renamer("{id} {invalid}")