You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行annotate-gene-fusion遇TypeError及批量脚本问题求助

问题:批量运行annotate-gene-fusion脚本时遇到pandas参数错误

当前目录下的文件按第一个.前的子串作为唯一ID分组(例如A001C007.log的ID为A001C007),需要为每个ID对应的文件集运行annotate-gene-fusion批量脚本,但执行时触发以下错误:TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'。由于无源码修改权限,无法调整脚本中的pd.read_csv(...,error_bad_lines=False)语句;尝试安装pandas 1.4.0,但实际成功安装的是1.3.5,错误仍未解决。

循环脚本示例

#!/bin/bash
# 获取所有唯一ID
for id in $(ls | cut -d '.' -f1 | sort -u); do
    echo "Processing ID: $id"
    # 运行批量脚本
    annotate-gene-fusion --input-files $(ls $id.*) --output-dir ./output_$id
done

报错栈信息

Traceback (most recent call last):
  File "/path/to/annotate-gene-fusion", line 123, in <module>
    df = pd.read_csv(input_file, error_bad_lines=False)
TypeError: read_csv() got an unexpected keyword argument 'error_bad_lines'

当前目录文件示例

  • A001C007.log
  • A001C007.fusion.txt
  • B002D008.log
  • B002D008.fusion.txt
  • C003E009.csv

单ID运行的期望命令

annotate-gene-fusion --input-files A001C007.log A001C007.fusion.txt --output-dir ./output_A001C007

解决方法

  • 安装兼容的pandas版本:error_bad_lines参数在pandas 1.5.0及以后版本被移除,需安装1.4.x系列的稳定版本(如1.4.4)。执行以下命令强制重装:
    pip install pandas==1.4.4 --force-reinstall
    
    强制重装可确保替换现有版本,避免依赖残留导致的版本不匹配。
  • 验证版本正确性:安装完成后运行以下命令确认版本:
    python -c "import pandas; print(pandas.__version__)"
    
    输出应为1.4.4或其他1.4.x版本。
  • 无源码修改权限的临时补丁方案:若无法安装指定版本,可通过猴子补丁将旧参数映射为新参数。创建一个补丁脚本patch_pandas.py:
    import pandas as pd
    
    original_read_csv = pd.read_csv
    
    def patched_read_csv(*args, **kwargs):
        if 'error_bad_lines' in kwargs:
            # 将error_bad_lines=False转换为等价的on_bad_lines='skip'
            kwargs['on_bad_lines'] = 'skip'
            del kwargs['error_bad_lines']
        return original_read_csv(*args, **kwargs)
    
    pd.read_csv = patched_read_csv
    
    然后修改批量脚本的运行方式,先加载补丁再执行目标脚本:
    python -c "import sys; sys.path.insert(0, '.'); import patch_pandas; exec(open('/path/to/annotate-gene-fusion').read())"
    
    或者如果是通过命令行直接调用,可设置环境变量PYTHONPATH并预加载补丁:
    PYTHONPATH=. python -m patch_pandas /path/to/annotate-gene-fusion --input-files $(ls $id.*) --output-dir ./output_$id
    

内容的提问来源于stack exchange,提问作者Anon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 06:47:28