1

I have written a small and simple interface with Click, I get this error "Error: Got unexpected extra arguments" and I just can't figure out why this occurs?

Here is my setup.py:

from setuptools import setup, find_packages

setup(
    name = "transcov",
    description = "A software for mapping coverage around transcription start sites",
    packages=find_packages("src"),
    package_dir={"": "src"},
    #test_suite="test",
    install_requires=['pysam>=0.15.4', 'numpy>=1.18.1', 'attrs>=19.3.0', 'click>=7.1.1'],
    entry_points={
        'console_scripts': ['transcov = transcov.cli:cli'],
    },
    include_package_data=True,
)

Here is my cli.py file:

import click

from .generator import generate_coverage_matrix
from .preprocessor import preprocess
from .collapser import collapse

@click.group()
def cli():
    pass

@cli.command()
@click.argument('annotation_file')
@click.option('-o', '--output-file', default='transcription_start_sites.tsv')
def preprocess(annotation_file, output_file):
    preprocess(annotation_file, output_file)

@cli.command()
@click.argument('bam_file')
@click.argument('tss_file')
@click.option('-k', '--region-size', default=10000)
@click.option('-o', '--output-file', default='coverage_matrix.npy')
def generate(bam_file, tss_file, region_size, output_file):
    generate_coverage_matrix(bam_file, tss_file, region_size, output_file)

@cli.command()
@click.argument('matrices', nargs=-1)
@click.option('-o', '--output-file', default='collapsed_matrix.npy')
@click.option('--uint32', is_flag=True)
def collapse(matrices, output_file, uint32):
    if len(matrices) > 0:
        collapse(matrices, output_file, uint32)

And here is the error that I get when calling my program:

$ transcov preprocess -o gencodes/gencode.v19.annotation.tss.tsv gencodes/gencode.v19.annotation.gff3
Usage: gencodes/gencode.v19.annotation.tss.tsv [OPTIONS] ANNOTATION_FILE
Try 'gencodes/gencode.v19.annotation.tss.tsv --help' for help.

Error: Got unexpected extra arguments (e n c o d e s / g e n c o d e . v 1 9 . a n n o t a t i o n . g f f 3)

Does anyone have any idea why this is happening? Have I missed something?

1 Answer 1

4

Your preprocess function calls itself, resulting in the "unexpected extra arguments" error (see Click: "Got unexpected extra arguments" when passing string for a similar case). This is because its definition hides the one that you imported from .preprocessor.

You should instead import the external preprocess function using a different name, e.g.:

from .preprocessor import preprocess as _preprocess

@cli.command()
@click.argument('annotation_file')
@click.option('-o', '--output-file', default='transcription_start_sites.tsv')
def preprocess(annotation_file, output_file):
    _preprocess(annotation_file, output_file)

Alternatively, you can import the preprocessor module:

from . import preprocessor

and then access the function using:

preprocessor.preprocess
Sign up to request clarification or add additional context in comments.

1 Comment

The same thing will happen for collapse, just so you're aware

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.