Esempio n. 1
0
 def test_read_number(self):
     renamer = PairedEndRenamer("{id} read no. is: {rn}")
     r1 = Sequence("theid cmtx", "ACGT")
     r2 = Sequence("theid cmty", "ACGT")
     info1 = ModificationInfo(r1)
     info2 = ModificationInfo(r2)
     renamed1, renamed2 = renamer(r1, r2, info1, info2)
     assert renamed1.name == "theid read no. is: 1"
     assert renamed2.name == "theid read no. is: 2"
Esempio n. 2
0
 def test_ids_not_identical(self):
     renamer = PairedEndRenamer("{id} abc {comment} xyz")
     r1 = Sequence("theid_a cmtx", "ACGT")
     r2 = Sequence("theid_b cmty", "ACGT")
     info1 = ModificationInfo(r1)
     info2 = ModificationInfo(r2)
     with pytest.raises(ValueError) as e:
         renamer(r1, r2, info1, info2)
     assert "not identical" in e.value.args[0]
Esempio n. 3
0
 def test_r2_comment(self):
     renamer = PairedEndRenamer("{id} abc {r2.comment} xyz")
     r1 = Sequence("theid cmtx", "ACGT")
     r2 = Sequence("theid cmty", "ACGT")
     info1 = ModificationInfo(r1)
     info2 = ModificationInfo(r2)
     renamed1, renamed2 = renamer(r1, r2, info1, info2)
     assert renamed1.name == "theid abc cmty xyz"
     assert renamed2.name == "theid abc cmty xyz"
Esempio n. 4
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
Esempio n. 5
0
 def test_invalid_template_variable(self):
     with pytest.raises(InvalidTemplate):
         PairedEndRenamer("{id} {invalid}")