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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
---
title: Phosformer ST
emoji: 🐢
colorFrom: gray
colorTo: pink
sdk: gradio
sdk_version: 3.38.0
app_file: app.py
pinned: false
license: cc-by-nc-nd-4.0
---



<!-- This Github was Made By Nathan Gravel and tested with help of Mariah Salcedo--> 

# Phosformer-ST  <img src="https://github.com/gravelCompBio/Phosformer-ST/assets/75225868/f375e377-b639-4b8c-9792-6d8e5e9e6c39" width="60"> 

  

## Introduction   

  

   

  

  

  

   

  

This repository contains the code to run Phosformer-ST locally from the manuscript "Phosformer-ST: explainable machine learning 

uncovers the kinase-substrate interaction landscape" . This readme should also give you the specific versions for all packages used to run Phosformer-ST in a local environment. 

The model was created by Zhongliang Zhou and Wayland Yeung. The Phos-ST webtool is found from this link (https://phosformer.netlify.app/) and was generated by Saber Soleymani.  

  

</br> 

   

## Quick overview of the dependencies 

![Python](https://img.shields.io/badge/Python-FFD43B?style=for-the-badge&logo=python&logoColor=blue)
![Anaconda](https://img.shields.io/badge/Anaconda-%2344A833.svg?style=for-the-badge&logo=anaconda&logoColor=white)
![Jupyter](https://img.shields.io/badge/Jupyter-F37626.svg?&style=for-the-badge&logo=Jupyter&logoColor=white)
![PyTorch](https://img.shields.io/badge/PyTorch-EE4C2C?style=for-the-badge&logo=pytorch&logoColor=white)

  

![Numpy](https://img.shields.io/badge/Numpy-777BB4?style=for-the-badge&logo=numpy&logoColor=white) 
![Pandas](https://img.shields.io/badge/Pandas-2C2D72?style=for-the-badge&logo=pandas&logoColor=white) 
![Matplotlib](https://img.shields.io/badge/Matplotlib-%23ffffff.svg?style=for-the-badge&logo=Matplotlib&logoColor=black) 
![scikit-learn](https://img.shields.io/badge/scikit--learn-%23F7931E.svg?style=for-the-badge&logo=scikit-learn&logoColor=white) 

  

   

</br> 

  

  

## Included in this repository are the following:   

  

   

  

- `phos-ST_Example_Code.ipynb`: Jupyter File with example code to run Phosformer-ST 

  

- `modeling_esm.py`: Python file that has the architecture of Phosformer-ST 

  

- `configuration_esm.py`: Python file that has configuration/parameters of Phosformer-ST  

  

- `tokenization_esm.py`: Python file that contains code for the tokenizer  

  

  

- `multitask_MHA_esm2_t30_150M_UR50D_neg_ratio_8+8_shift_30_mask_0.2_2023-03-25_90.txt`: this txt file contains a link to a zenodo repository to download the proper folder  

  

  - This folder holds the files that contained the training weights for Phosformer-ST to run as advertised 

  - See section below (Downloading this repository) to be shown how to download this folder and where to put it 

  

- `phosST.yml`: This file is used to help create an environment for Phos-ST to work 

   

- `README.md`: You're reading it right now 

  

- `LICENSE`: Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International Public License 

  

  

    

  

</br> 

  

</br> 

  

    

  

## Installing dependencies with version info    

  

  

### From conda:    

  

![python=3.9.16](https://img.shields.io/badge/Python-3.9.16-green)  

  

![jupyterlab=4.0.0](https://img.shields.io/badge/jupyterlab-4.0.0-blue)  

  

Python == 3.9.16  

  

   

  

### From pip:  

  

   

  

![numpy=1.24.3](https://img.shields.io/badge/numpy-1.24.3-blue)  

  

![pandas=2.0.2](https://img.shields.io/badge/pandas-2.0.2-blue)  

  

![matplotlib=3.7.1](https://img.shields.io/badge/matplotlib-3.7.1-blue)  

  

![scikit-learn=1.2.2](https://img.shields.io/badge/scikitlearn-1.2.2-blue)  

  

![tqdm=4.65.0](https://img.shields.io/badge/tqdm-4.64.1-blue) 

  

![fair-esm=2.0.0](https://img.shields.io/pypi/v/fair-esm?label=fair-esm)   

  

![transformers=4.31.0](https://img.shields.io/badge/transformers-4.31.0-blue)  

  

![torch=2.0.1](https://img.shields.io/badge/torch-2.0.1-blue)      

  

### For torch/PyTorch 

  

Make sure you go to this website https://pytorch.org/get-started/locally/ 

  

Follow along with its recommendation  

  

Installing torch can be the most complex part  

  

  

</br> 

  

  

  

   

### The computer specs that we know that this model can run on (with gpu acceleration) 

  

</br> 

  

**Computer 1** 

  

Ubuntu 22.04.2 LTS 

  

Intel(R) Xeon(R) Bronze 3204 CPU @ 1.90GHz  (6 cores) x (1 thread per core) 

  

64 GB ram 

  

NVIDIA Quadro RTX 5000 (16 GB vRAM)(CUDA Version: 12.1)  

  

</br> 

  

**Computer 2** 

  

Ubuntu 20.04.6 LTS 

  

Intel(R) Xeon(R) Bronze 3204 CPU @ 1.90GHz  (6 cores) x (1 thread per core) 

  

64 GB ram 

  

NVIDIA RTX A4000 (16 GB vRAM)(CUDA Version: 12.2)  

  

  

  

</br> 

  

</br> 

  

   

  

## Downloading this repository   

  

```   
git clone https://huggingface.co/gravelcompbio/Phosformer-ST_with_trainging_weights
```   

  

```   
cd Phosformer-ST_with_trainging_weights
``` 

  

  

The `Phosformer-ST_with_trainging_weights` folder should have the following files/folder in it 

  

- file 1 `phos-ST_Example_Code.ipynb` 

  

- file 2 `modeling_esm.py` 

   

- file 3 `configuration_esm.py` 

  

- file 4 `tokenization_esm.py` 

  

- file 5 `multitask_MHA_esm2_t30_150M_UR50D_neg_ratio_8+8_shift_30_mask_0.2_2023-03-25_90.txt` 

  

- file 6 `phosST.yml` 

   

- file 7 `Readme.md`



- file 8 `LICENSE`



- folder 1 `multitask_MHA_esm2_t30_150M_UR50D_neg_ratio_8+8_shift_30_mask_0.2_2023-03-25_90` (make sure it is unzipped)



- zipped folder 2 `multitask_MHA_esm2_t30_150M_UR50D_neg_ratio_8+8_shift_30_mask_0.2_2023-03-25_90.zip` 


  

Once you have a folder with the files/folder above in it you have done all the downloading needed 

  

  

</br> 

  

</br> 

  

   

  

## ![Anaconda](https://img.shields.io/badge/Anaconda-%2344A833.svg?style=for-the-badge&logo=anaconda&logoColor=white) Installing dependencies with conda  

  

### PICK ONE of the options below  

### Option 1) Utilizing the PhosformerST.yml file 

here is a step-by-step guide to set up the environment with the yml file  

  

Just type these lines of code into the terminal after you download this repository (this assumes you have anaconda already installed) 

  

```   
conda env create -f phosST.yml -n PhosST  
```   

```   
conda deactivate 
```   

```   
conda activate phosST  
```   

  

### Option 2) Creating this environment without yml file 

(This is if torch is being weird with your version of cuda or any other problem) 

Just type these lines of code into the terminal after you download this repository (this assumes you have anaconda already installed) 

```   
conda create -n phosST python=3.9  
``` 

```   
conda deactivate 
``` 

```   
conda activate phosST  
``` 

```   
conda install -c conda-forge jupyterlab 
``` 

```   
pip3 install numpy==1.24.3 
``` 

```   
pip3 install pandas==2.0.2 
``` 

```   
pip3 install matplotlib==3.7.1 
``` 

```   
pip3 install scikit-learn==1.2.2 
``` 

```   
pip3 install tqdm==4.65.0 
``` 

```   
pip3 install fair-esm==2.0.0 
``` 

```   
pip3 install transformers==4.31.0 
``` 

### **For torch you will have to download to the torch's specification if you want gpu acceleration from this website** https://pytorch.org/get-started/locally/ 

  

```   
pip3 install torch torchvision torchaudio 
``` 

  

### the terminal line above might look different  for you  

  

We provided code to test Phos-ST (see section below) 

  

  

</br> 

  

</br> 

  

  

  

## Utilizing the Model with our example 

All the following code examples is done inside of the `phos-ST_Example_Code.ipynb` file using jupyter lab 

  

Once you have your environment resolved just use jupyter lab to access the example code by typing the comand below in your terminal (when you're in the `Phosformer-ST` folder)  

```   

jupyter lab 

``` 

Once you open the notebook on your browser, run each cell of notebook  

  

</br> 

  

### Testing Phos-ST with the example code 

There should be a positive control and a negative control example code at bottom of the `phos-ST_Example_Code.ipynb` file. This is here just to sanity check that the model is working. The positive and negative control is running the same code with known examples where Phos-ST should give an answered close to 1 (positive control) or 0 (negative control).  

  

**Positive Example** 

```Python 

# P17612 KAPCA_HUMAN 

kinDomain="FERIKTLGTGSFGRVMLVKHKETGNHYAMKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVMEYVPGGEMFSHLRRIGRFSEPHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYIQVTDFGFAKRVKGRTWTLCGTPEYLAPEIILSKGYNKAVDWWALGVLIYEMAAGYPPFFADQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKRFGNLKNGVNDIKNHKWF" 

# P53602_S96_LARKRRNSRDGDPLP 

substrate="LARKRRNSRDGDPLP" 

  

phosST(kinDomain,substrate).to_csv('PostiveExample.csv') 

``` 

  

  

**Negative Example** 

```Python 

# P17612 KAPCA_HUMAN 

kinDomain="FERIKTLGTGSFGRVMLVKHKETGNHYAMKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVMEYVPGGEMFSHLRRIGRFSEPHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYIQVTDFGFAKRVKGRTWTLCGTPEYLAPEIILSKGYNKAVDWWALGVLIYEMAAGYPPFFADQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKRFGNLKNGVNDIKNHKWF" 

# Q01831_T169_PVEIEIETPEQAKTR 

substrate="PVEIEIETPEQAKTR" 

  

phosST(kinDomain,substrate).to_csv('NegitiveExample.csv') 

``` 

Both scores should show up in a csv file in the same folder of this code 

  

</br> 

  

### Inputting your own data for novel predictions 

One can simply take the code from above and modify the string variables `kinDomain` and `substrate` to your prediction of interest 

  

**Formatting of the `kinDomain` and `substrate` for input for phos-ST are as followed:** 

  

  - `kinDomain` should just be the kinase domain (instead of the full sequence), preferably human, and a Serine/Threonine kinases   

     

  - `substrate` should be a 15mer with the center residue/char being the Serine or Threonine being phosphorylated 

  

Not following these rules will still give you and output at time but does not guarantee a prediction with the accuracy advertised  

  

  

</br> 

  

### How to interoperate Phosformer-ST's output 

This model was trained to use the cutoff of 0.5 as the difference between positive prediction and negative prediction  

  

If your custom prediction is above 0.5, the model is predicting the kinase-substrate pair is a positive prediction for a phosphorylation event  

  

Though the training data is ultimately based on a positional scanning peptide array, this model only takes into account kinase binding preference. 

  

Combining with other special, temporal, or other biologically relevant filters might be more accurate when modeling protein kinase. 

  

</br> 

  

  

  

  

### Modifying the code to take in a list of kinase domains and substrates 

Currenly, we have it only predicting one kinase domain + one substrate at a time. One can simply swap out the `helper function to use Phos-ST` code-block with the code-block below. The input arguments now require a list of strings for both the kinase domains and substrates. Make sure the list of both kinases and substrates are the same length and conserve the same format specified in the "Inputting your own data for novel predictions" section of the readme  

```Python 

# P17612 KAPCA_HUMAN listed twice 

kinDomains=["FERIKTLGTGSFGRVMLVKHKETGNHYAMKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVMEYVPGGEMFSHLRRIGRFSEPHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYIQVTDFGFAKRVKGRTWTLCGTPEYLAPEIILSKGYNKAVDWWALGVLIYEMAAGYPPFFADQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKRFGNLKNGVNDIKNHKWF","FERIKTLGTGSFGRVMLVKHKETGNHYAMKILDKQKVVKLKQIEHTLNEKRILQAVNFPFLVKLEFSFKDNSNLYMVMEYVPGGEMFSHLRRIGRFSEPHARFYAAQIVLTFEYLHSLDLIYRDLKPENLLIDQQGYIQVTDFGFAKRVKGRTWTLCGTPEYLAPEIILSKGYNKAVDWWALGVLIYEMAAGYPPFFADQPIQIYEKIVSGKVRFPSHFSSDLKDLLRNLLQVDLTKRFGNLKNGVNDIKNHKWF"] 

  

# P53602_S96_LARKRRNSRDGDPLP listed first and Q01831_T169_PVEIEIETPEQAKTR listed second 

substrates=["LARKRRNSRDGDPLP","PVEIEIETPEQAKTR"] 

  

  

def phosST(kinaseDomainSeqs,substrate15mers): 

    job = run_model( 

        substrate15mers, 

        kinaseDomainSeqs, 

        model=model,  

        tokenizer=tokenizer,  

        device='cuda',  

        batch_size=10, 

        output_hidden_states=False, 

        output_attentions=False, 

    ) 

     

    #total = dataset.shape[0] 

    results = { 

        'kinase' : [], 

        'peptide' : [], 

        'prob' : [], 

    } 

     

    for n, i in enumerate(job): 

        #sys.stderr.write(f'{n+1} / {total}\r') 

        results['kinase' ] += [i['kinase']] 

        results['peptide'] += [i['peptide']] 

        results['prob'   ] += [i['probability']] 

     

    result = pd.DataFrame(results) 

  

    return result 

  

  

  

phosST(kinDomains,substrates).to_csv('BatchExample.csv') 

  

  

  

  

``` 

</br> 

  

</br> 

  

## Troubleshooting 

  

If torch is not installing correctly or you do not have a GPU to run Phos-ST on, the CPU version of torch is perfectly fine to use 

  

Using the CPU version of torch might 10x to 1000x your run time so for large prediction datasets GPU acceleration is suggested 

  

If you just are here to test if it phos-ST works, the example code should not take too much time to run on the CPU version of torch   

  

Also depending on your GPU the `batch_size` argument might need to be adjusted



Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference