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

使用gzip.open以wt模式写入导致生成无效压缩归档文件的问题求助

gzip.open以wt模式写入导致生成无效压缩归档文件的问题求助

我正在开发一个能预测特定序列的程序,希望把结果保存为gzip压缩的FASTA格式。但尝试写入文件后,得到的却是无效文件——在Windows系统上打开时,会弹出「压缩归档文件夹错误」的提示,没法正常打开或解压。

下面是相关的代码片段:

def annotate_fasta_file(model, input_path, output_path):
    """
    Annotates all sequences in a FASTA file with CpG island predictions.

    Parameters:
        model (object): A trained classifier model.
        input_path (str): Path to the input FASTA file.
        output_path (str): Path to the output FASTA file where annotations will be saved.

    Writes:
        A gzipped FASTA file containing predicted annotations for each input sequence.
    """

    sequences = parse_fasta_file(input_path)    
    with gzip.open(output_path, 'wt') as gzipped_file:
        for seq_id, sequence in sequences.items():
            annotation = annotate_sequence(model, sequence)
            gzipped_file.write(f">{seq_id}\n{annotation}\n")

当我尝试点击或提取这个输出文件时,就会出现上述的压缩文件无效错误。

备注:内容来源于stack exchange,提问作者Yoel Marcu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.14 16:49:51