python 点击:"got unexpected extra arguments"
python click: "got unexpected extra arguments"
我用 Click 写了一个小而简单的界面,我收到这个错误 "Error: Got unexpected extra arguments" 我只是想不通为什么会这样?
这是我的 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
函数调用自身,导致 "unexpected extra arguments" 错误(有关类似情况,请参阅 )。这是因为它的定义隐藏了您从 .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)
或者,您可以导入 preprocessor
模块:
from . import preprocessor
然后使用以下方法访问函数:
preprocessor.preprocess
我用 Click 写了一个小而简单的界面,我收到这个错误 "Error: Got unexpected extra arguments" 我只是想不通为什么会这样?
这是我的 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
函数调用自身,导致 "unexpected extra arguments" 错误(有关类似情况,请参阅 .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)
或者,您可以导入 preprocessor
模块:
from . import preprocessor
然后使用以下方法访问函数:
preprocessor.preprocess