question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

trim argument parser errors

See original GitHub issue

For cutadapt 3.2 with Python 3.6.9. Using an example from a previous issue (#508), this command works: cutadapt -g 'ACCTGCGGARGGATCA;min_overlap=16;max_error_rate=0.3' -a 'AACTTTYARCAAYGGATCTC;min_overlap=20;max_error_rate=0.3' --times 1 --max-n 5 --revcomp --trimmed-only --cores 4 --output example_trim.fasta example.fasta

But if I want to use the “required” or “optional” arguments it crashes (only “anywhere” don’t give errors). Using “required”:

This is cutadapt 3.2 with Python 3.6.9
Command line parameters: -g ACCTGCGGARGGATCA;min_overlap=16;max_error_rate=0.3;required -a AACTTTYARCAAYGGATCTC;min_overlap=20;max_error_rate=0.3 --times 1 --max-n 5 --revcomp --trimmed-only --cores 4 --output example_trim.fasta example.fasta
Traceback (most recent call last):
  File "/home/fossandon/.local/bin/cutadapt", line 11, in <module>
    sys.exit(main_cli())
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 845, in main_cli
    main(sys.argv[1:])
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 895, in main
    adapters, adapters2 = adapters_from_args(args)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 738, in adapters_from_args
    adapters = adapter_parser.parse_multi(args.adapters)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 433, in parse_multi
    adapters.extend(self.parse(spec, cmdline_type))
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 410, in parse
    yield self._parse(spec, cmdline_type, name=None)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 313, in _parse
    return self._parse_not_linked(spec, name, cmdline_type)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 346, in _parse_not_linked
    sequence=aspec.sequence, name=aspec.name if name is None else name, **parameters)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/adapters.py", line 493, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'required'

Using “optional”:

Command line parameters: -g ACCTGCGGARGGATCA;min_overlap=16;max_error_rate=0.3;optional -a AACTTTYARCAAYGGATCTC;min_overlap=20;max_error_rate=0.3 --times 1 --max-n 5 --revcomp --trimmed-only --cores 4 --output example_trim.fasta example.fasta
Traceback (most recent call last):
  File "/home/fossandon/.local/bin/cutadapt", line 11, in <module>
    sys.exit(main_cli())
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 845, in main_cli
    main(sys.argv[1:])
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 895, in main
    adapters, adapters2 = adapters_from_args(args)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/__main__.py", line 738, in adapters_from_args
    adapters = adapter_parser.parse_multi(args.adapters)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 433, in parse_multi
    adapters.extend(self.parse(spec, cmdline_type))
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 410, in parse
    yield self._parse(spec, cmdline_type, name=None)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 313, in _parse
    return self._parse_not_linked(spec, name, cmdline_type)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/parser.py", line 346, in _parse_not_linked
    sequence=aspec.sequence, name=aspec.name if name is None else name, **parameters)
  File "/home/fossandon/.local/lib/python3.6/site-packages/cutadapt/adapters.py", line 493, in __init__
    super().__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'required'

Note that although I used “optional”, it complains about “required” again.

If I link them the crash dissapears: -g 'ACCTGCGGARGGATCA;min_overlap=16;max_error_rate=0.3;required...AACTTTYARCAAYGGATCTC;min_overlap=20;max_error_rate=0.3', so the problem only appears when the argument is used without linking (either using -g and -a together or alone).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marcelmcommented, Feb 4, 2021

For “historical reasons”, Cutadapt treats all the adapters that you provide as equal. So if you give it four 5’ adapters and seven 3’ adapters, Cutadapt just aligns all eleven of them in turn against the read and chooses the best one. It doesn’t assume that 5’ and 3’ adapters come in pairs or have any other relationship.

In particular, when you provide one 5’ adapter (-g) and one 3’ adapter (-a), Cutadapt removes either the 5’ adapter, the 3’ adapter, or none at all. The required and optional distinction only becomes relevant when you want to remove both at the same time in the normal case, but also want to be able to say what should happen when one of the two cannot be found.

1reaction
marcelmcommented, Jan 29, 2021

Thanks for the report – that’s definitely a bug. I’ll look into this next week.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handle invalid arguments with argparse in Python
The proper way to change those is to subclass ArgumentParser , though ... ArgumentParser() parser.error = myerror args=parser.parse_args().
Read more >
argparse — Parser for command-line options, arguments and ...
For a more gentle introduction to Python command-line parsing, ... exit_on_error - Determines whether or not ArgumentParser exits with error info when an ......
Read more >
Command line argument parsing in Rust using Clap
Manually parse command line arguments in Rust apps using Clap, a library that provides functionality to generate parsing logic for ...
Read more >
Command with arguments - discordjs-bot-guide - GitHub
Command with arguments. Creating an array of arguments. The first thing that we need to do to use arguments, is to actually separate...
Read more >
ParseIntError in std::num - Rust
An error which can be returned when parsing an integer. ... Using the str::trim() method ensures that no whitespace remains before parsing.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found