jonathang commited on
Commit
a8b401c
1 Parent(s): 471543f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -25,6 +25,27 @@ import tensorflow as tf
25
  from huggingface_hub import hf_hub_url, cached_download
26
 
27
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  def residual_block(data, filters, d_rate):
29
  """
30
  _data: input
@@ -76,7 +97,7 @@ def get_model():
76
 
77
  def greet(name):
78
  get_model()
79
- return "Hello " + name + "!!"
80
 
81
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
82
  iface.launch()
 
25
  from huggingface_hub import hf_hub_url, cached_download
26
 
27
 
28
+ class Sequence:
29
+ codes = {c: i+1 for i, c in enumerate(['A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y'])}
30
+
31
+ @classmethod
32
+ def integer_encoding(cls, data):
33
+ """
34
+ - Encodes code sequence to integer values.
35
+ - 20 common amino acids are taken into consideration
36
+ and remaining four are categorized as 0.
37
+ """
38
+ return np.array([cls.codes.get(code, 0) for code in data])
39
+
40
+ @classmethod
41
+ def prepare(cls, sequence):
42
+ ie = cls.integer_encoding(sequence)
43
+ max_length = 100
44
+ padded_ie = pad_sequences([ie], maxlen=max_length, padding='post', truncating='post')
45
+ all_ohe = np.array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20] + [0]*(100-21))
46
+ return to_categorical(np.array([padded_ie[0], all_ohe]))[0]
47
+
48
+
49
  def residual_block(data, filters, d_rate):
50
  """
51
  _data: input
 
97
 
98
  def greet(name):
99
  get_model()
100
+ return f"Input is {name}. Processed input is {Sequence.process(name)}"
101
 
102
  iface = gr.Interface(fn=greet, inputs="text", outputs="text")
103
  iface.launch()