I am interested in running Uniprot's Protein descriptor model, ProtNLM, to add some bonus descriptors for a big chunk of protein sequence I have.
They have a trial notebook available here.
Here is the full code of the notebook:
!python3 -m pip install -q -U tensorflow==2.8.2
!python3 -m pip install -q -U tensorflow-text==2.8.2
import tensorflow as tf
import tensorflow_text
import numpy as np
import re
import IPython.display
from absl import logging
tf.compat.v1.enable_eager_execution()
logging.set_verbosity(logging.ERROR) # Turn down tensorflow warnings
def print_markdown(string):
IPython.display.display(IPython.display.Markdown(string))
! mkdir -p protnlm
! wget -nc https://storage.googleapis.com/brain-genomics-public/research/proteins/protnlm/uniprot_2022_04/savedmodel__20221011__030822_1128_bs1.bm10.eos_cpu/saved_model.pb -P protnlm -q --no-check-certificate
! mkdir -p protnlm/variables
! wget -nc https://storage.googleapis.com/brain-genomics-public/research/proteins/protnlm/uniprot_2022_04/savedmodel__20221011__030822_1128_bs1.bm10.eos_cpu/variables/variables.index -P protnlm/variables/ -q --no-check-certificate
! wget -nc https://storage.googleapis.com/brain-genomics-public/research/proteins/protnlm/uniprot_2022_04/savedmodel__20221011__030822_1128_bs1.bm10.eos_cpu/variables/variables.data-00000-of-00001 -P protnlm/variables/ -q --no-check-certificate
imported = tf.saved_model.load(export_dir="protnlm")
infer = imported.signatures["serving_default"]
sequence = "MVLSPADKTNVKAAWGKVGAHAGEYGAEALERMFLSFPTTKTYFPHFDLSHGSAQVKGHG KKVADALTNAVAHVDDMPNALSALSDLHAHKLRVDPVNFKLLSHCLLVTLAAHLPAEFTP AVHASLDKFLASVSTVLTSKYR" #@param {type:"string"}
sequence = sequence.replace(' ', '')
names, scores = run_inference(sequence)
for name, score, i in zip(names, scores, range(len(names))):
print_markdown(f"Prediction number {i+1}: **{name}** with a score of **{score:.03f}**")
The one change I have made is to update the tensorflow version on these lines:
!python3 -m pip install -q -U tensorflow==2.8.2
!python3 -m pip install -q -U tensorflow-text==2.8.2
to be >=2.8.2 since the 2.8.2 version couldn't be installed.
Now, I can't run the model whatsoever. The third cell, which intakes the sequence, can't find the run_inference() function:
NameError
Traceback (most recent call last)
<ipython-input-5-4a7325a0e004> in <cell line: 0>()
8 sequence = sequence.replace(' ', '')
9
---> 10 names, scores = run_inference(sequence)
11
12 for name, score, i in zip(names, scores, range(len(names))):
NameError: name 'run_inference' is not defined
I didn't see this function defined in the notebook, so I assumed it was internal to tensorflow (maybe only version 2.8.2, but I couldn't find anything in searching docs), or otherwise loaded with the model.
How can I get this script running again?
def run_inference(..):...orimport run_inference- so it can't run it? You could searchrun_inferencein Google - maybe it needs only somefrom ... import run_inferencerun_inference tensorflowinGoogleI found python - TensorFlow Inference - Stack Overflow with somedef run_inference()in question and answers. In this question someone wrote this function from scratch and it is not part any module