AttributeError: 'int' object has no attribute 'seq'
1
0
Entering edit mode
23 months ago
Robert • 0

I am trying to read a saved model, such that it (the saved model) can complete a sequence, given the first few codons of a sequence (that are uploaded into the file_uploader)

The Code:

   import streamlit as st
   import tensorflow as tf
   import tensorflow_io as tfio
   import numpy as n
   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')

           uploaded_file = st.file_uploader('Upload a Sequence File:')
           if uploaded_file is not None:

             # To read file as bytes:
             protein_sequence = uploaded_file.getvalue()
             st.write('The File...', uploaded_file.name, '...Successfully Uploaded!')
             st.write(protein_sequence)

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

                protein_sample = protein_sequence[0].seq

                model = tf.saved_model.load('next_sequence_generator')

                states = None
                next_char = tf.constant([str(protein_sample)])

                result = [next_char]

                for n in range(1273):
                next_char, states = model.generate_one_step(next_char, states=states)
                result.append(next_char)

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

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


     if __name__ == '__main__':
        main()

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 51, in <module>
    main()
File "C:\Users\Sir Roberto\PycharmProjects\SARS_CoV_2_Mutation_Forecasting_GUI\SARS_CoV_2_Mutation_Forecasting_GUI.py", line 29, in main
    protein_sample = protein_sequence[0].seq
BioPython AttributeError • 1.9k views
ADD COMMENT
0
Entering edit mode

I think you may be under a wrong impression that we are here to troubleshoot all your app problems. Your membership is not even a day old, and already you asked several questions that are all of the same variety - something is wrong either with your script syntax, but error messages are always clear if you invest a bit of time to figure out where they are and what they mean.

ADD REPLY
1
Entering edit mode
23 months ago
Mensur Dlakic ★ 27k

With all due respect, for someone writing these apps you should be able to figure out these clear error messages.

The error message AttributeError: 'int' object has no attribute 'seq' on this line:

protein_sample = protein_sequence[0].seq

is very clear. It means that protein_sequence[0] is an integer object (has numeric value) and as such you can't take a .seq attribute from an integer. I am assuming you expected protein_sequence[0] to contain a sequence, but that's not the case. I don't know what causes the error - you will have to figure out that part by checking your uploading procedure.

ADD COMMENT
0
Entering edit mode

Without wishing to be unduly harsh, I would also go further and say that writing an app to use an AI black-box to predict SARS-COV-2 variants from a few sequence codons (which is what I gather the code is trying to achieve), is:

  1. Biting off more than you can chew when you're struggling with quite simple errors and opening files.
  2. Likely biologically meaningless.
ADD REPLY
0
Entering edit mode

Thank you so much for your help... Joe , Mensur Dlakic

I have few words to say.

  1. We all start small, we all start somewhere as newbies and on a daily basis we learn new skills and grow along the journey. For me this was my starting point, even my membership which is just less than a week old confirms I am new, and trying to learn. At some point you were as novice as I am, trying to learn something as much as I am doing, and through that and probably through other people's help as well you are now a skilled person, helping others on this platform. One day I will also become skilled and won't be asking naïve questions anymore.

  2. This project is not something being implemented now in the real world, but just an idea being researched in an academic setup, and for academic, not production purposes. Even great ideas which are now biologically meaningful started somewhere as meaningless ideas.

These are just my opinions. Once again thank you so much for the help and advice you gave me, I won't take it for granted.

ADD REPLY
0
Entering edit mode

I don't think there is any general bias on this site against "newbies" or else it would have way less traffic. According to my calculations from several months ago, there are on average 50 new users added each day. Conservatively, I answer at least 3-5 messages weekly to these new users. The same is true for many other established users, so I don't think there is any expectation that new users would be far along the learning curve. In fact, you got what I believe to be useful answers to all your questions, including one from me in this thread.

That said, your questions are decidedly of trivial variety, as they deal with misplaced commas, incorrect command interpretation or ignorance to very clear error messages. These are not character flaws by any means, and again all your questions have been answered. When you ask three questions like that in less than 24 hours after joining this site, you are giving an impression that you don't know what you are doing, and that you are using this site to troubleshoot your scripts almost line by line. Nothing wrong with being ambitious and aiming for more than one is capable of doing at the moment, but this site is not meant primarily as a script cleanup service. I suspect you will still get answers to your questions, but you may be better served to invest some time into learning programming before you continue writing web apps. Also, googling the error will often yield an answer. Here is what googling AttributeError: 'int' object has no attribute 'seq' will yield, and most of several top hits offer clear solutions.

Lastly, there is nothing insulting or demeaning intended in either of my two replies to your post, and I suspect the same is true for what Joe wrote. I think this would be the summary: there is nothing wrong with not knowing basic things, but in that case it may be more appropriate to aim a bit lower.

ADD REPLY
0
Entering edit mode

Exactly as Mensur said - I personally do think jumping in the deep end and writing some code to achieve a purpose is a good way to learn (rather than endless HelloWorld.py's). However, there is a sweet spot, and I think you've over-shot it.

Consequently, you're tying yourself in knots by trying to mash together multiple python libraries each of which on their own require months to master.

You're making your own life harder by not disentangling these things so you lose sight of where the error is coming from.

To be completely clear, as Mensur said again, there is absolutely no problem with you being a Newbie - there are plenty of my own stupid questions preserved for posterity on this very site - but there are ways to "be smart about being stupid".

ADD REPLY
0
Entering edit mode

well noted, thank you for the advice, I don't take it for granted.

ADD REPLY
0
Entering edit mode

well noted, thank you for the advice.

ADD REPLY

Login before adding your answer.

Traffic: 2620 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