StreamModeError: Fasta files must be opened in text mode.
1
0
Entering edit mode
24 months ago
Robert • 0

I am facing the error below when I try to read a FASTA File in my Streamlit App, please Assist

StreamModeError: Fasta files must be opened in text mode.

Traceback:

File "C:\Users\Sir Roberto\AppData\Local\Programs\Python\Python310\lib\site-packages\streamlit\scriptrunner\script_runner.py", line 475, in _run_script
    exec(code, module.__dict__)
File "C:\Users\Sir Roberto\PycharmProjects\SARS_CoV_2_Mutation_Forecasting_GUI\SARS_CoV_2_Mutation_Forecasting_GUI.py", line 43, in <module>
    main()
File "C:\Users\Sir Roberto\PycharmProjects\SARS_CoV_2_Mutation_Forecasting_GUI\SARS_CoV_2_Mutation_Forecasting_GUI.py", line 19, in main
    protein_sample = SeqIO.read(seq_file, 'fasta',)
File "C:\Users\Sir Roberto\AppData\Local\Programs\Python\Python310\lib\site-packages\Bio\SeqIO\__init__.py", line 652, in read
    iterator = parse(handle, format, alphabet)
File "C:\Users\Sir Roberto\AppData\Local\Programs\Python\Python310\lib\site-packages\Bio\SeqIO\__init__.py", line 605, in parse
    return iterator_generator(handle)
File "C:\Users\Sir Roberto\AppData\Local\Programs\Python\Python310\lib\site-packages\Bio\SeqIO\FastaIO.py", line 183, in __init__
    super().__init__(source, mode="t", fmt="Fasta")
File "C:\Users\Sir Roberto\AppData\Local\Programs\Python\Python310\lib\site-packages\Bio\SeqIO\Interfaces.py", line 53, in __init__
    raise StreamModeError(

MY CODE:

import streamlit as st
import tensorflow as tf
import tensorflow_io as tfio
from Bio import SeqIO


def main():

    st.title('Covid-19 Mutation Forecasting App')

    menu = ['Forecast Mutation', 'About The App']
    choice = st.sidebar.selectbox('Select Activity', menu)
    if choice == 'Forecast Mutation':
        st.subheader('Mutation Forecasting Workspace')

        seq_file = st.file_uploader('Upload a Sequence File:', type=['fasta',])
        if seq_file is not None:

            protein_sample = SeqIO.read(seq_file, 'fasta',)
            st.write(protein_sample)
            loaded_model = tf.keras.models.load_model("")

            next_step = st.checkbox('Forecast')
            if next_step:

                states = None
                next_char = tfio.genome.read_fastaq(protein_sample)
                result = [next_char]

                for n in range(100):
                    next_char, states = one_step_reloaded.generate_one_step(next_char, states=states)
                    result.append(next_char)

                print(tf.strings.join(result)[0].numpy().decode("utf-8"))

    else:
        st.subheader('About The App')
        st.caption('Given the first few codons of a SARS-CoV-2 Spike Protein, '
                   'the App forecasts and display the complete sequence of the mutant')


if __name__ == '__main__':
    main()
BioPython StreamModeError • 2.1k views
ADD COMMENT
1
Entering edit mode

Please use the formatting bar (especially the code option) to present your post better. You can use backticks for inline code (`text` becomes text), or select a chunk of text and use the highlighted button to format it as a code block. If your code has long lines with a single command, break those lines into multiple lines with proper escape sequences so they're easier to read and still run when copy-pasted. I've done it for you this time.
code_formatting

ADD REPLY
0
Entering edit mode

Thank you so much

ADD REPLY
0
Entering edit mode

Why did you delete your posts, Robert ?

ADD REPLY
2
Entering edit mode
24 months ago
Trivas ★ 1.8k

This post seems to have the same issue as you with a potential fix.

ADD COMMENT

Login before adding your answer.

Traffic: 1572 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6