How to use the cutadapt.modifiers.AdapterCutter function in cutadapt

To help you get started, we’ve selected a few cutadapt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github marcelm / cutadapt / tests / test_modifiers.py View on Github external
def test_adapter_cutter():
    from cutadapt.adapters import BackAdapter
    a1 = BackAdapter("GTAGTCCCGC")
    a2 = BackAdapter("GTAGTCCCCC")
    match = AdapterCutter.best_match([a1, a2], Sequence("name", "ATACCCCTGTAGTCCCC"))
    assert match.adapter is a2
github marcelm / cutadapt / tests / test_trim.py View on Github external
def test_anywhere_with_errors():
    adapter = AnywhereAdapter("CCGCATTTAG", max_error_rate=0.1)
    for seq, expected_trimmed in (
        ('AACCGGTTccgcatttagGATC', 'AACCGGTT'),
        ('AACCGGTTccgcgtttagGATC', 'AACCGGTT'),  # one mismatch
        ('AACCGGTTccgcatttag', 'AACCGGTT'),
        ('ccgcatttagAACCGGTT', 'AACCGGTT'),
        ('ccgtatttagAACCGGTT', 'AACCGGTT'),  # one mismatch
        ('ccgatttagAACCGGTT', 'AACCGGTT'),  # one deletion
    ):
        read = Sequence('foo', seq)
        cutter = AdapterCutter([adapter], times=1)
        trimmed_read = cutter(read, ModificationInfo(read))
        assert trimmed_read.sequence == expected_trimmed
github marcelm / cutadapt / tests / test_parser.py View on Github external
def test_anywhere_parameter_front():
    parser = AdapterParser(max_error_rate=0.2, min_overlap=4, read_wildcards=False,
        adapter_wildcards=False, indels=True)
    adapter = list(parser.parse('CTGAAGTGAAGTACACGGTT;anywhere', 'front'))[0]
    assert isinstance(adapter, FrontAdapter)
    assert adapter._force_anywhere

    # TODO move the rest to a separate test
    read = Sequence('foo1', 'AAAAAAAAAACTGAAGTGAA')
    from cutadapt.modifiers import AdapterCutter
    cutter = AdapterCutter([adapter])
    trimmed_read = cutter(read, ModificationInfo(read))
    assert trimmed_read.sequence == ''
github marcelm / cutadapt / src / cutadapt / __main__.py View on Github external
action: str,
    times: int,
    reverse_complement: bool,
):
    if pair_adapters:
        if reverse_complement:
            raise CommandLineError("Cannot use --revcomp with --pair-adapters")
        try:
            cutter = PairedAdapterCutter(adapters, adapters2, action)
        except PairedAdapterCutterError as e:
            raise CommandLineError("--pair-adapters: " + str(e))
        pipeline.add_paired_modifier(cutter)
    else:
        adapter_cutter, adapter_cutter2 = None, None
        if adapters:
            adapter_cutter = AdapterCutter(adapters, times, action)
        if adapters2:
            adapter_cutter2 = AdapterCutter(adapters2, times, action)
        if paired:
            if reverse_complement:
                raise CommandLineError("--revcomp not implemented for paired-end reads")
            if adapter_cutter or adapter_cutter2:
                pipeline.add(adapter_cutter, adapter_cutter2)
        elif adapter_cutter:
            if reverse_complement:
                modifier = ReverseComplementer(
                    adapter_cutter
                )  # type: Union[AdapterCutter,ReverseComplementer]
            else:
                modifier = adapter_cutter
            pipeline.add(modifier)
github marcelm / cutadapt / src / cutadapt / __main__.py View on Github external
reverse_complement: bool,
):
    if pair_adapters:
        if reverse_complement:
            raise CommandLineError("Cannot use --revcomp with --pair-adapters")
        try:
            cutter = PairedAdapterCutter(adapters, adapters2, action)
        except PairedAdapterCutterError as e:
            raise CommandLineError("--pair-adapters: " + str(e))
        pipeline.add_paired_modifier(cutter)
    else:
        adapter_cutter, adapter_cutter2 = None, None
        if adapters:
            adapter_cutter = AdapterCutter(adapters, times, action)
        if adapters2:
            adapter_cutter2 = AdapterCutter(adapters2, times, action)
        if paired:
            if reverse_complement:
                raise CommandLineError("--revcomp not implemented for paired-end reads")
            if adapter_cutter or adapter_cutter2:
                pipeline.add(adapter_cutter, adapter_cutter2)
        elif adapter_cutter:
            if reverse_complement:
                modifier = ReverseComplementer(
                    adapter_cutter
                )  # type: Union[AdapterCutter,ReverseComplementer]
            else:
                modifier = adapter_cutter
            pipeline.add(modifier)
github mhalushka / miRge / src / mirge / utils / trim_file.py View on Github external
def __init__(self, queue=None, results=None, adapter=None, phred64=False):
		super(Worker, self).__init__()
		self.queue=queue
		self.results = results
		self.phred = 64 if phred64 else 33
		self.modifiers = [QualityTrimmer(0, 10, self.phred)]
		self.adapters = []
		self.error_rate = 0.12
		self.min_length = 16
		if adapter.startswith('+'):
			self.modifiers.append(UnconditionalCutter(int(adapter)))
		elif adapter == 'none':
			self.adapter = None
		else:
			self.adapters = parse_adapters(adapter, error_rate=self.error_rate)
			adapter_cutter = AdapterCutter(self.adapters)
			self.modifiers.append(adapter_cutter)