我用Click编写了一个小而简单的界面,出现此错误“错误:收到了意外的额外参数”,但我不知道为什么会发生这种情况?
这是我的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,
)
这是我的cli.py文件:
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)
这是调用程序时出现的错误:
$ 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)
有人知道为什么会这样吗?我错过了什么吗?
您的preprocess
函数调用自身,导致此错误(类似情况请参见Click: "Got unexpected extra arguments" when passing string)。这是因为其定义隐藏了您从.preprocessor
导入的定义。
您应该改用其他名称导入外部preprocess
函数,例如:
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)