Nazarshia2889 commited on
Commit
5fdf698
1 Parent(s): ac3d524

new feature

Browse files
Files changed (1) hide show
  1. app.py +57 -17
app.py CHANGED
@@ -13,12 +13,7 @@ model_type = st.radio(
13
  "Choose Linear Epitope Classifier",
14
  ('Linear T-Cells (MHC Class I Restriction)', 'Linear T-Cells (MHC Class II Restriction)', 'Linear B-Cell'))
15
 
16
- # windows length slider
17
- length = st.slider('Window Length', 1, 50, 10)
18
- threshold = st.slider('Probability Threshold', 0.0, 1.0, 0.75)
19
-
20
  model_checkpoint = "facebook/esm2_t6_8M_UR50D"
21
-
22
  tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
23
 
24
  if model_type == 'Linear T-Cells (MHC Class I Restriction)':
@@ -27,18 +22,20 @@ elif model_type == 'Linear T-Cells (MHC Class II Restriction)':
27
  model = TFAutoModelForSequenceClassification.from_pretrained('classifier2')
28
  elif model_type == 'Linear B-Cell':
29
  model = TFAutoModelForSequenceClassification.from_pretrained('bcell')
30
- # submit button
31
- if st.button('Submit'):
32
- if(length > len(sequence)):
33
- st.write("Please make sure that your window length is less than the sequence length!")
34
- else:
35
- # run model
 
 
 
36
  locations = []
37
- for i in range(len(sequence) - length + 1):
38
- peptide_name = sequence[i:i+length]
39
- peptide = tokenizer(peptide_name, return_tensors="tf")
40
- output = model(peptide)
41
- locations.append([peptide_name, output.logits.numpy()[0][0]])
42
 
43
  locations = pd.DataFrame(locations, columns = ['Peptide', 'Probability'])
44
 
@@ -62,4 +59,47 @@ if st.button('Submit'):
62
 
63
  return f'background-color: rgb({r}, {g}, {b})'
64
 
65
- st.table(locations.style.applymap(color_survived, subset=['Probability']))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  "Choose Linear Epitope Classifier",
14
  ('Linear T-Cells (MHC Class I Restriction)', 'Linear T-Cells (MHC Class II Restriction)', 'Linear B-Cell'))
15
 
 
 
 
 
16
  model_checkpoint = "facebook/esm2_t6_8M_UR50D"
 
17
  tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
18
 
19
  if model_type == 'Linear T-Cells (MHC Class I Restriction)':
 
22
  model = TFAutoModelForSequenceClassification.from_pretrained('classifier2')
23
  elif model_type == 'Linear B-Cell':
24
  model = TFAutoModelForSequenceClassification.from_pretrained('bcell')
25
+
26
+ propep = st.radio(
27
+ "Scan over an entire protein or run a peptide sequence?",
28
+ ('Protein', 'Peptide'))
29
+
30
+ if propep == 'Peptide':
31
+ threshold = st.slider('Probability Threshold', 0.0, 1.0, 0.75)
32
+
33
+ if st.button('Submit'):
34
  locations = []
35
+ peptide_name = sequence
36
+ peptide = tokenizer(peptide_name, return_tensors="tf")
37
+ output = model(peptide)
38
+ locations.append([peptide_name, output.logits.numpy()[0][0]])
 
39
 
40
  locations = pd.DataFrame(locations, columns = ['Peptide', 'Probability'])
41
 
 
59
 
60
  return f'background-color: rgb({r}, {g}, {b})'
61
 
62
+ st.table(locations.style.applymap(color_survived, subset=['Probability']))
63
+
64
+
65
+ elif propep == 'Protein':
66
+ # windows length slider
67
+ length = st.slider('Window Length', 1, 50, 10)
68
+ threshold = st.slider('Probability Threshold', 0.0, 1.0, 0.75)
69
+
70
+ # submit button
71
+ if st.button('Submit'):
72
+ if(length > len(sequence)):
73
+ st.write("Please make sure that your window length is less than the sequence length!")
74
+ else:
75
+ # run model
76
+ locations = []
77
+ for i in range(len(sequence) - length + 1):
78
+ peptide_name = sequence[i:i+length]
79
+ peptide = tokenizer(peptide_name, return_tensors="tf")
80
+ output = model(peptide)
81
+ locations.append([peptide_name, output.logits.numpy()[0][0]])
82
+
83
+ locations = pd.DataFrame(locations, columns = ['Peptide', 'Probability'])
84
+
85
+ # display table with sequence and probability as the headers
86
+ def color_survived(x: float): # x between 0 and 1
87
+ # red to green scale based on x
88
+ # 0 -> red
89
+ # 0.5 -> clear
90
+ # 1 -> green
91
+
92
+ # red
93
+ if x < threshold:
94
+ r = 179
95
+ g = 40
96
+ b = 2
97
+ # green
98
+ else:
99
+ r = 18
100
+ g = 150
101
+ b = 6
102
+
103
+ return f'background-color: rgb({r}, {g}, {b})'
104
+
105
+ st.table(locations.style.applymap(color_survived, subset=['Probability']))