[Python] gzip.open in wt mode results in an invalid archive

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I am writing a program that predicts certain sequences. I want it to save the results in a gzipped fasta format. However, when trying to write to such a file I am getting an invalid file (when trying to open it on Windows I get compressed archive folders error). This is the relevant code:

    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")


    This is the error I get when trying to click or extract the output file: enter image description here

    Continue reading...

Compartilhe esta Página