-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathpepfun.py
executable file
·1352 lines (1133 loc) · 58.3 KB
/
pepfun.py
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
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/python
"""
PepFun: open source protocols for peptide-related computational analysis
From publication "PepFun: open source protocols for peptide-related computational analysis"
Molecules
Authors: Rodrigo Ochoa, Pilar Cossio
Year: 2021
Third-party tools required:
BioPython: https://biopython.org/wiki/Download (recommended version 1.76)
RDKit: https://github.com/rdkit/rdkit/releases
NOTES:
1. The package can be installed using Conda as explained in the README.md file
2. If the script is called as a module from a different folder, the path can be added using the following commands:
import sys
sys.path.append('<PATH-TO-PEPFUN>')
3. The package was build under a Unix environment, but it can be used under any other OS based on the provided paths
"""
########################################################################################
# Authorship
########################################################################################
__author__ = "Rodrigo Ochoa"
__credits__ = ["Rodrigo Ochoa", "Pilar Cossio"]
__license__ = "MIT"
__version__ = "1.0"
__email__ = "rodrigo.ochoa@udea.edu.co"
########################################################################################
# Modules to import
########################################################################################
# External modules
import math
import itertools
import subprocess
import argparse
import re
import os
import numpy as np
import pickle
from random import randint
from igraph import *
# BioPython
from Bio import pairwise2
from Bio.SeqUtils.ProtParam import ProteinAnalysis
from Bio.PDB import *
from Bio import SeqIO
from Bio.Blast import NCBIWWW
from Bio.Blast import NCBIXML
# RDKit
from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit import DataStructs
from rdkit.Chem import Crippen
from rdkit.Chem import Lipinski
from rdkit.Chem import Descriptors
# Modeller
try:
import modeller
from modeller import *
from modeller.automodel import *
except ImportError:
pass
########################################################################################
# General Functions
########################################################################################
def aminoacidSMILES(amino):
"""
Obtain the SMILES representation of a particular amino acid
Arguments:
amino -- One-letter code of the amino acid
Return:
smiles -- 1D Chemical representation of the amino acid
"""
# Dictionary with the SMILES per amino acid
aminoacids = {'G':{'SMILES': 'NCC(=O)O'},
'A':{'SMILES': 'N[C@@]([H])(C)C(=O)O'},
'R':{'SMILES': 'N[C@@]([H])(CCCNC(=N)N)C(=O)O'},
'N': {'SMILES': 'N[C@@]([H])(CC(=O)N)C(=O)O'},
'D': {'SMILES': 'N[C@@]([H])(CC(=O)O)C(=O)O'},
'C': {'SMILES': 'N[C@@]([H])(CS)C(=O)O'},
'E': {'SMILES': 'N[C@@]([H])(CCC(=O)O)C(=O)O'},
'Q': {'SMILES': 'N[C@@]([H])(CCC(=O)N)C(=O)O'},
'H': {'SMILES': 'N[C@@]([H])(CC1=CN=C-N1)C(=O)O'},
'I': {'SMILES': 'N[C@@]([H])(C(CC)C)C(=O)O'},
'L': {'SMILES': 'N[C@@]([H])(CC(C)C)C(=O)O'},
'K': {'SMILES': 'N[C@@]([H])(CCCCN)C(=O)O'},
'M': {'SMILES': 'N[C@@]([H])(CCSC)C(=O)O'},
'F': {'SMILES': 'N[C@@]([H])(Cc1ccccc1)C(=O)O'},
'P': {'SMILES': 'N1[C@@]([H])(CCC1)C(=O)O'},
'S': {'SMILES': 'N[C@@]([H])(CO)C(=O)O'},
'T': {'SMILES': 'N[C@@]([H])(C(O)C)C(=O)O'},
'W': {'SMILES': 'N[C@@]([H])(CC(=CN2)C1=C2C=CC=C1)C(=O)O'},
'Y': {'SMILES': 'N[C@@]([H])(Cc1ccc(O)cc1)C(=O)O'},
'V': {'SMILES': 'N[C@@]([H])(C(C)C)C(=O)O'}}
# Store the SMILES in a variable
smiles=aminoacids[amino]['SMILES']
return smiles
########################################################################################
def generate_sequences(long_peptide,aa_type="natural"):
"""
Method to generate a combinatorial library of peptide sequences using natural and d-amino acids
Arguments:
long_peptide -- Lenght of the peptides that are going to be generated
aa_type -- Nature of the amino acids that can be included. Options: natural (default), d_aminoacids, combined
Return:
frags -- List with the sequences generated
"""
# List of the amino acids that can be included
natural=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y"]
d_aminoacids=["[dA]","[dC]","[dD]","[dE]","[dF]","[dH]","[dI]","[dK]","[dL]","[dM]","[dN]","[dP]","[dQ]","[dR]","[dT]","[dV]","[dW]"]
combined=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y",
"[dA]","[dC]","[dD]","[dE]","[dF]","[dH]","[dI]","[dK]","[dL]","[dM]","[dN]","[dP]","[dQ]","[dR]","[dT]","[dV]","[dW]"]
# List where the sequnces will be stored
frags=[]
if aa_type=="natural":
# Generate the combinatorial library
for i in itertools.product(natural, repeat=long_peptide):
frags.append(''.join(map(str, i)))
elif aa_type=="d_aminoacids":
# Generate the combinatorial library
for i in itertools.product(d_aminoacids, repeat=long_peptide):
frags.append(''.join(map(str, i)))
elif aa_type=="combined":
# Generate the combinatorial library
for i in itertools.product(combined, repeat=long_peptide):
if "[" in f: frags.append(''.join(map(str, i)))
else:
print("The type of amino acid is invalid")
# Return the list of peptide sequences
return frags
########################################################################################
def generate_peptide_pattern(pattern):
"""
Method to generate a peptide sequences following a pattern using only natural amino acids
Arguments:
pattern -- Pattern based on XX to generate the list of sequences
Return:
list_peptides -- List with the sequences generated
"""
# List of natural amino acids that can be included
natural=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y"]
list_peptides=[]
# Combination of possible sequences following the given pattern
for pep in itertools.product(natural, repeat=pattern.count('X')):
pep = list(pep)
mut_pep = []
for res in pattern:
# check if any amino acid can be included in the sequence
if res != 'X': mut_pep.append(res)
else: mut_pep.append(pep.pop(0))
list_peptides.append("".join(mut_pep))
# Return the list of peptide sequences
return list_peptides
########################################################################################
def combinatorial_library(long_peptide,aa_type="natural"):
"""
Method to generate a combinatorial library of peptide sequences but limiting the frequency of amino acids in certain positions
Arguments:
long_peptide -- Lenght of the peptides that are going to be generated
aa_type -- Nature of the amino acids that can be included. Options: natural (default), d_aminoacids, combined
Return:
peptides -- List with the sequences generated
"""
# List of the amino acids that can be included
natural=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y"]
d_aminoacids=["[dA]","[dC]","[dD]","[dE]","[dF]","[dH]","[dI]","[dK]","[dL]","[dM]","[dN]","[dP]","[dQ]","[dR]","[dT]","[dV]","[dW]"]
combined=["A","C","D","E","F","G","H","I","K","L","M","N","P","Q","R","S","T","V","W","Y",
"[dA]","[dC]","[dD]","[dE]","[dF]","[dH]","[dI]","[dK]","[dL]","[dM]","[dN]","[dP]","[dQ]","[dR]","[dT]","[dV]","[dW]"]
# List where the sequences will be stored
peptides=[]
if aa_type=="natural":
# Counter of the peptide length
for i in range(0,long_peptide):
for aa in natural:
# Run the process 3 times per amino acids
for j in range(0,3):
sequence=[None]*long_peptide
for k in range(0,long_peptide):
if k==i:
sequence[k]=aa
else:
# Loop to check that the sequence does not have more than 3 equal amino acids
accept_change=0
while accept_change==0:
posRand=randint(0,len(natural)-1)
new_aa=natural[posRand]
if sequence.count(new_aa)<=3:
accept_change=1
# Add the amino acid after checking the restraint
sequence[k]=new_aa
# Join the amino acids and append the new sequence
seq_string=''.join(sequence)
peptides.append(seq_string)
# Return the list
return peptides
########################################################################################
def frequencies_library(peptides):
"""
Calculate the frequency of each amino acid in a particular peptide library
Arguments:
peptides -- List of peptides in the library
Return:
count_dict -- Dictionary with the numbers per each natural amino acid
"""
# Create counter dictionary
count_dict={}
for i in range(1,len(peptides[0])+1):
count_dict[i]={"A":0,"R":0,"N":0,"D":0,"C":0,"Q":0,"E":0,"G":0,"H":0,"I":0,"L":0,"K":0,"M":0,"F":0,"P":0,"S":0,"T":0,"W":0,"Y":0,"V":0}
# Read the sequences and count each amino acid
for sequence in peptides:
for pos,aa in enumerate(sequence):
count_dict[pos+1][aa]+=1
# Return the dictionary
return count_dict
########################################################################################
# Classes and Functions
########################################################################################
class peptide_sequence:
"""
Class with functions to perform different type of analysis using a peptide sequence as an object
"""
def __init__(self,sequence):
"""
Inititalize the class calculating some basic properties
Arguments:
sequence -- Peptide sequence
Return
Based on the sequence, the class start with some counters, a neutral pH, the peptide length and the SMILES representation
"""
self.sequence=sequence
self.pH=7
self.solubility_rules_failed=0
self.set_sol_rules=[]
self.length_peptide=len(self.sequence)
self.synthesis_rules_failed=0
self.set_syn_rules=[]
# Loop to create the SMILES
connect_smiles='O'
for res in sequence:
connect_smiles=connect_smiles[:-1]
smiles=aminoacidSMILES(res)
connect_smiles=connect_smiles+smiles
self.smiles=connect_smiles
############################################################################
def align_position_matrix(self,peptide_to_match):
"""
Align position by position a peptide of reference with another one
Arguments:
peptide_to_match -- String with the sequence of a peptide that will be compared
matrix -- A dictionary of biopython with substitution scores.
Return:
score -- A numerical value to rank the alignment
"""
with open('auxiliar/matrix.pickle', 'rb') as handle:
matrix = pickle.load(handle)
self.score_matrix=0
for i,p in enumerate(self.sequence):
# Generate the tuples with the pair of amino acids to compare
pair1=(p,peptide_to_match[i])
pair2=(peptide_to_match[i],p)
# Obtain the score from the matrix and sum up the values
if pair1 in matrix: value=matrix[pair1]
else: value=matrix[pair2]
self.score_matrix+=value
############################################################################
def align_position_local(self,peptide_to_match):
"""
Align position by position a peptide of reference with another one
Arguments:
peptide_to_match -- String with the sequence of a peptide that will be compared
Return:
dismatch -
"""
self.dismatch=0
for i,p in enumerate(self.sequence):
# Generate the tuples with the pair of amino acids to compare
if p!=peptide_to_match[i]:
self.dismatch+=1
self.match=len(self.sequence)-self.dismatch
############################################################################
def similarity_pair(self,peptide1,peptide2):
"""
Function to calculate similarity between two peptide sequences
Arguments:
peptide1 -- Sequence of one of the input peptides
peptide2 -- Sequence of the second input peptide
matrix -- BioPython matrix chosen for running the analysis
Return:
sim_val -- similarity based on the aligments between the peptides and themselves - Max value is 1
"""
with open('auxiliar/matrix.pickle', 'rb') as handle:
matrix = pickle.load(handle)
# Alignment between peptide1 and peptide2
pep=peptide_sequence(peptide1)
pep.align_position_matrix(peptide2)
score1_2=pep.score_matrix
# Alignment between peptide1 with itself
pep.align_position_matrix(peptide1)
score1_1=pep.score_matrix
# Alignment between peptide2 with itself
pep2=peptide_sequence(peptide2)
pep2.align_position_matrix(peptide2)
score2_2=pep2.score_matrix
# Calculate similarity value
sim_val=float(score1_2)/math.sqrt(float(score1_1*score2_2))
# Return similarity
return sim_val
############################################################################
def similar_smiles(self,peptide_to_match):
"""
Calculate similarity but using SMILES representations of the peptides
Arguments:
peptide_to_match -- peptide sequence that will be compared
Return:
SMILES similarity based on Morgan Fingerprints and Tanimoto coefficient
"""
# Generate molecule from sequence
mol1 = Chem.MolFromSmiles(self.smiles)
mol1.SetProp("_Name",self.sequence)
connect_smiles='O'
for res in peptide_to_match:
connect_smiles=connect_smiles[:-1]
smiles=aminoacidSMILES(res)
connect_smiles=connect_smiles+smiles
mol2 = Chem.MolFromSmiles(connect_smiles)
mol2.SetProp("_Name",peptide_to_match)
# Calculate the fingerprints and the similarity
fp1=AllChem.GetMorganFingerprintAsBitVect(mol1,2,2048)
fp2=AllChem.GetMorganFingerprintAsBitVect(mol2,2,2048)
self.smiles_similarity=DataStructs.TanimotoSimilarity(fp1,fp2)
############################################################################
def compute_peptide_charges(self,pH_internal=7):
"""
Function to calculate the average net charge based on pka values
Arguments:
pH_internal -- By default is 7
Return:
The net charge based on reported pka values
"""
# Set the general variables and pka terms
self.pH=pH_internal
self.netCharge=0.0
pka_alpha_amino={'G':9.60,'A':9.69,'V':9.62,'L':9.60,'I':9.68,'M':9.21,'F':9.13,'W':9.39,'P':10.60,'S':9.15,
'T':9.10,'C':10.78,'Y':9.11,'N':8.84,'Q':9.13,'D':9.82,'E':9.67,'K':8.95,'R':9.04,'H':9.17}
pka_alpha_carboxy={'G':2.34,'A':2.34,'V':2.32,'L':2.36,'I':2.36,'M':2.28,'F':1.83,'W':2.38,'P':1.99,'S':2.21,
'T':2.63,'C':1.71,'Y':2.2,'N':2.02,'Q':2.17,'D':2.09,'E':2.19,'K':2.18,'R':2.17,'H':1.82}
pka_sidechain_positive={'K':10.79,'R':12.48,'H':6.04}
pka_sidechain_negative={'D':3.86,'E':4.25,'C':8.33,'Y':10.07}
# Calculate the net charge for the extreme groups (without modifications)
amino=self.sequence[0]
carboxy=self.sequence[-1]
self.netCharge=self.netCharge+(math.pow(10,pka_alpha_amino[amino])/(math.pow(10,pka_alpha_amino[amino])+math.pow(10,self.pH)))
self.netCharge=self.netCharge-(math.pow(10,self.pH)/(math.pow(10,pka_alpha_carboxy[carboxy])+math.pow(10,self.pH)))
# Calculate the net charge for the charged amino acid side chains
for aa in self.sequence:
if aa in pka_sidechain_positive:
self.netCharge=self.netCharge+(math.pow(10,pka_sidechain_positive[aa])/(math.pow(10,pka_sidechain_positive[aa])+math.pow(10,self.pH)))
if aa in pka_sidechain_negative:
self.netCharge=self.netCharge-(math.pow(10,self.pH)/(math.pow(10,pka_sidechain_negative[aa])+math.pow(10,self.pH)))
############################################################################
def calculate_properties_from_mol(self):
"""
Function to calculate some molecular properties based on RDKit functionalities
Return:
Static physico-chemical properties: molecular weight, crippen logP, number of hydrogen bond acceptors and donors
"""
# Generate molecule from sequence
mol = Chem.MolFromSmiles(self.smiles)
mol.SetProp("_Name",self.sequence)
# Calculate the descriptors
self.num_hdonors = Lipinski.NumHDonors(mol)
self.num_hacceptors = Lipinski.NumHAcceptors(mol)
self.mol_weight = Descriptors.MolWt(mol)
self.mol_logp = Crippen.MolLogP(mol)
############################################################################
def calculate_properties_from_sequence(self):
"""
Function to calculate some molecular properties based on RDKit functionalities
Arguments:
Sequence - amino acid sequence of the peptide
Return:
Average Eisenberg hydrophobicity
ProtParam parameters: Isolectric point, aromaticity, instability index, amino acid percentage
"""
# Hydrophobicity -> Eisenberg scale
hydrophobicity = {'A': 0.620,'R': -2.530,'N': -0.780,'D': -0.900,'C': 0.290,'Q': -0.850,'E': -0.740,'G': 0.480,'H': -0.400,'Y': 0.260,
'I': 1.380,'L': 1.060,'K': -1.500,'M': 0.640,'F': 1.190,'P': 0.120,'S': -0.180,'T': -0.050,'W': 0.810,'V': 1.080}
self.avg_hydro=sum([hydrophobicity[resi] for resi in self.sequence])
# ProParam properties
prot_parameters=ProteinAnalysis(self.sequence)
self.aromaticity=prot_parameters.aromaticity()
self.aa_percent=prot_parameters.get_amino_acids_percent()
self.instability_index=prot_parameters.instability_index()
self.isoelectric_point=prot_parameters.isoelectric_point()
############################################################################
def solubility_rules(self):
"""
Function to calculate some solubility rules based on recommendations of http://bioserv.rpbs.univ-paris-diderot.fr/services/SolyPep/
Output:
solubility_rules_failed - return the number of rules faild based on the criteria
"""
# Rule N1. Number of hydrophobic or charged residues
hydro_residues=['V','I','L','M','F','W','C']
charged_residues=['H','R','K','D','E']
count_hydro_charged=0
for aa in self.sequence:
if aa in hydro_residues or aa in charged_residues: count_hydro_charged+=1
# This condition should change depending on the sequence length
hydro_char_threshold=float(self.length_peptide)*0.45
if count_hydro_charged > hydro_char_threshold:
self.solubility_rules_failed+=1
self.set_sol_rules.append(1)
else:
self.set_sol_rules.append(0)
# Rule N2. Computed peptide charge
charge_threshold=1
self.compute_peptide_charges()
if self.netCharge > 1:
self.solubility_rules_failed+=1
self.set_sol_rules.append(1)
else:
self.set_sol_rules.append(0)
# Rule N3. Glycine or Proline content in the sequence
count_gly_pro=0
for aa in self.sequence:
if aa == "G" or aa=="P": count_gly_pro+=1
# Check threshold
if count_gly_pro > 1:
self.solubility_rules_failed+=1
self.set_sol_rules.append(1)
else:
self.set_sol_rules.append(0)
# Rule N4. First or last amino acid charged
count_charge=0
if self.sequence[0] in charged_residues:
count_charge+=1
if self.sequence[-1] in charged_residues:
count_charge+=1
# Check threshold
if count_charge > 0:
self.solubility_rules_failed+=1
self.set_sol_rules.append(1)
else:
self.set_sol_rules.append(0)
# Rule N5. Any amino acid represent more than 25% of the total sequence
prot_parameters=ProteinAnalysis(self.sequence)
aa_content=prot_parameters.get_amino_acids_percent()
flag5=0
for aa in aa_content:
if aa_content[aa]>=0.3:
self.solubility_rules_failed+=1
self.set_sol_rules.append(1)
flag5=1
break
if flag5==0: self.set_sol_rules.append(0)
############################################################################
def synthesis_rules(self):
"""
Function to check some synthesis rules based on empirical recommendations
Return:
synthesis_rules_failed - return the number of rules faild based on the criteria
"""
# Presence of forbiden motifs
forbidden_motifs = {'2-prolines':r'[P]{3,}','DG-DP':r'D[GP]','N-Q-Nterminal':r'^[NQ]',}
for motif in forbidden_motifs:
if re.search(forbidden_motifs[motif],self.sequence):
self.synthesis_rules_failed+=1
self.set_syn_rules.append(1)
else:
self.set_syn_rules.append(0)
# test if there are charged residues every 5 amino acids
charged_residues=['H','R','K','D','E']
counter_charged = 0
for residue in self.sequence:
counter_charged += 1
if residue in charged_residues:
counter_charged = 0
if counter_charged >= 5:
self.synthesis_rules_failed+=1
self.set_syn_rules.append(1)
else:
self.set_syn_rules.append(0)
# Check if there are oxidation-sensitive amino acids
aa_oxidation=['M','C','W']
flag5=0
for aa in self.sequence:
if aa in aa_oxidation:
self.synthesis_rules_failed+=1
self.set_syn_rules.append(1)
flag5=1
break
if flag5==0: self.set_syn_rules.append(0)
############################################################################
def generate_conformer(self):
"""
Function to generate basic conformer using RDKit
Return:
Structure predicted in PDB format
"""
# Generate molecule using the sequence and HELM notation
helm=".".join(list(self.sequence))
mol = Chem.MolFromHELM("PEPTIDE1{%s}$$$$" %helm)
mol.SetProp("_Name",self.sequence)
# Generate the conformer using UFF force field
print("Generating the basic conformer for peptide {}".format(self.sequence))
AllChem.EmbedMolecule(mol)
AllChem.UFFOptimizeMolecule(mol)
# Write PDB file
molfile=open('structure.pdb','w')
molfile.write(Chem.MolToPDBBlock(mol))
molfile.close()
# Add Remarks
remarks=open('remarks.pdb','w')
remarks.write('REMARK Conformer generated with RDKit\n')
remarks.write('REMARK The conformer is created using a distance geometry approach.\n')
remarks.write('REMARK The method is explained in the PepFun paper (Ochoa et. al. Molecules, 2021).\n')
remarks.close()
# Concatenate final structure
with open("structure_{}.pdb".format(self.sequence), "w") as outfile:
for filename in ["remarks.pdb","structure.pdb"]:
with open(filename) as infile:
contents = infile.read()
outfile.write(contents)
#Delete files
os.remove("remarks.pdb")
os.remove("structure.pdb")
############################################################################
def blast_online(self):
"""
Function to run online blast configured with parameters suitable to compare peptides
Return:
hits - List of hits with dictionary containing fields from the alignment result
"""
# Create a temporal fasta file with the sequence
fasta_file=open("{}.fasta".format(self.sequence),"w")
fasta_file.write(">sequence\n{}".format(self.sequence))
fasta_file.close()
record = SeqIO.read("{}.fasta".format(self.sequence), format="fasta")
result_handle = NCBIWWW.qblast("blastp", "nr", record.format("fasta"),word_size=2, expect=20000.0, matrix_name="PAM30", gapcosts="9 1", format_object="Alignment")
b_record = NCBIXML.read(result_handle)
# Parse the results
hits=[]
for alignment in b_record.alignments:
for hsp in alignment.hsps:
dict_hits={}
dict_hits["identities"]=hsp.identities
dict_hits["positives"]=hsp.positives
dict_hits["gaps"]=hsp.gaps
dict_hits["align_length"]=hsp.align_length
dict_hits["query_start"]=hsp.query_start
dict_hits["e-value"]=hsp.expect
dict_hits["query_sequence"]=hsp.query[0:75]
dict_hits["match_id"]=alignment.title[:100]
dict_hits["subject_sequence"]=hsp.sbjct[0:75]
hits.append(dict_hits)
return hits
########################################################################################
def run_psipred(self, path='./auxiliar/'):
'''
Run PSIPRED locally to assign the secondary structure
:param path: Folder containing the psipred software
:return: A string with the predicted SS. H: Helix, E: Strand,Sheet, C: Coil
'''
# Run PSIPRED
fastaFile = open('{}.fasta'.format(self.sequence), 'w')
fastaFile.write('>sequence\n')
fastaFile.write('{}\n'.format(self.sequence))
fastaFile.close()
os.system('{}runpsipred_single {}.fasta'.format(path, self.sequence))
bash = 'grep Pred {}.horiz | cut -f 2 -d " "'.format(self.sequence)
ss_PSI = str(subprocess.check_output(['bash', '-c', bash]).strip().decode('utf-8'))
os.system('rm {}*'.format(self.sequence))
print(ss_PSI)
return ss_PSI
############################################################################
def prepare_modeller(self, ss_ref):
'''
Protocol to generate all the parameters required for Modeller, including the RDKit template
:param ss_ref: Secondary structure assigned to the peptide
:return: Input parameters to run Modeller
'''
pos = int(len(self.sequence) / 2)
pepT = ""
pepM = ""
for i, ch in enumerate(self.sequence):
if i < pos:
pepT += "-"
pepM += ch
elif i == pos:
pepT += ch
pepM += ch
else:
pepT += "-"
pepM += ch
amino = self.sequence[pos:pos + 1]
baseMol = Chem.MolFromHELM("PEPTIDE1{%s}$$$$" % amino)
# baseMol = Chem.AddHs(baseMol)
ps = AllChem.ETKDGv3()
ps.randomSeed = 0xf00d
AllChem.EmbedMolecule(baseMol, ps)
# Write PDB file
molfile = open('template.pdb', 'w')
molfile.write(Chem.MolToPDBBlock(baseMol))
molfile.close()
rangeHelix = []
rangeBeta = []
if ss_ref.count('H') > 2 or ss_ref.count('G') > 2:
positions = {}
count_groups = 0
prev = '-'
for i, ele in enumerate(ss_ref):
if ele == 'H' or ele == 'G':
if ele != prev:
count_groups += 1
positions[count_groups] = [i + 1]
elif ele == prev:
positions[count_groups].append(i + 1)
prev = ele
rangeHelix = []
for group in positions:
rangeHelix.append((min(positions[group]), max(positions[group])))
if ss_ref.count('E') > 2 or ss_ref.count('B') > 2:
positions = {}
count_groups = 0
prev = '-'
for i, ele in enumerate(ss_ref):
if ele == 'E' or ele == 'B':
if ele != prev:
count_groups += 1
positions[count_groups] = [i + 1]
elif ele == prev:
positions[count_groups].append(i + 1)
prev = ele
rangeBeta = []
for group in positions:
rangeBeta.append((min(positions[group]), max(positions[group])))
# To add a cycle constraint
rangeCycle = ()
positions = []
for i, aa in enumerate(self.sequence):
if aa == 'C':
if i <= 1 or i >= len(self.sequence) - 2:
positions.append(i + 1)
if len(positions) == 2:
rangeCycle = (positions[0], positions[1])
return pepT, pepM, rangeHelix, rangeBeta, rangeCycle
########################################################################################
def modelling_modeller(self, pepT, pepM, rangeHelix, rangeBeta, rangeCycle):
'''
Function to use modeller in ab-initio mode based on a peptide template
:param pepT: Sequence used as template
:param pepM: Sequence to model
:param rangeHelix: List of tuples with regions containing alpha-helix
:param rangeBeta: List of tuples with regions containing beta sheets/strands
:param rangeCycle: Tuple with the residues creating the cycle
:return: A PDB file with the predicted peptide structure
'''
# Start the Modeller environment
code = 'template'
e = modeller.environ()
m = modeller.model(e, file=code)
aln = modeller.alignment(e)
aln.append_model(m, align_codes=code)
aln.write(file=code + '.seq')
# Edit the information of the sequence to store the sequences in the Modeller format
infoSeq = [x.strip() for x in open(code + '.seq')]
header = []
sequenceLine = ''
for info in infoSeq:
if ">" not in info and ":" not in info:
if info:
sequenceLine += info
else:
if info: header.append(info)
# Store the sequences in variables according to Modeller format
sequenceTemp = pepT + "*"
sequenceMod = pepM + "*"
seqTempList = [sequenceTemp]
seqModList = [sequenceMod]
# Create the alignment file
alignmentFile = open("alignment.ali", "w")
for h in header: alignmentFile.write(h + "\n")
for s in seqTempList: alignmentFile.write(s + "\n")
alignmentFile.write("\n>P1;template_fill\nsequence:::::::::\n")
for s in seqModList: alignmentFile.write(s + "\n")
alignmentFile.close()
# Directories for input atom files
e.io.atom_files_directory = ['.', '../atom_files']
if len(rangeHelix) >= 1 or len(rangeBeta) >= 1:
class MyModel(automodel):
def special_patches(self, aln):
if len(rangeCycle) >= 1:
self.patch(residue_type='DISU', residues=(self.residues['{}:A'.format(rangeCycle[0])],
self.residues['{}:A'.format(rangeCycle[1])]))
def special_restraints(self, aln):
rsr = self.restraints
at = self.atoms
if len(rangeHelix) >= 1:
for pairHelix in rangeHelix:
rsr.add(secondary_structure.alpha(
self.residue_range('{}:A'.format(pairHelix[0]), '{}:A'.format(pairHelix[1]))))
if len(rangeBeta) >= 1:
extremes = []
for j, pairBeta in enumerate(rangeBeta):
rsr.add(secondary_structure.strand(
self.residue_range('{}:A'.format(pairBeta[0]), '{}:A'.format(pairBeta[1]))))
if j == 0: extremes.append(pairBeta[0])
if j == 1: extremes.append(pairBeta[1])
rsr.add(secondary_structure.sheet(at['N:{}:A'.format(extremes[0])],
at['O:{}:A'.format(extremes[1])],
sheet_h_bonds=-5))
if len(rangeCycle) >= 1:
rsr.add(forms.gaussian(group=physical.xy_distance,
feature=features.distance(at['SG:{}:A'.format(rangeCycle[0])],
at['SG:{}:A'.format(rangeCycle[1])]),
mean=2.0, stdev=0.1))
a = MyModel(e, alnfile='alignment.ali', knowns='template', sequence='template_fill')
a.starting_model = 1
a.ending_model = 1
a.make()
else:
a = automodel(e, alnfile='alignment.ali', knowns='template', sequence='template_fill')
a.starting_model = 1
a.ending_model = 1
a.make()
os.system("mv template_fill.B99990001.pdb modeller_{}.pdb".format(self.sequence))
os.system("rm template* alignment.ali")
########################################################################################
class peptide_structure:
"""
Class with functions to perform different type of analysis using a peptide structure alone or in complex with a protein
"""
def __init__(self,pdb_file,chain):
"""
Inititalize the class calculating some basic properties
Arguments:
pdb_file -- PDB file with the required information
chain -- chain containing the peptide in the file
Return:
Based on the structure, the class start with some counters, the sequence derived from the structure, its lenght and a dictionary with the aa positions
"""
self.pdb_file=pdb_file
self.chain=chain
self.aminoacids_back={"ALA":"A","ASP":"D","GLU":"E","PHE":"F","HIS":"H","ILE":"I","LYS":"K","LEU":"L","MET":"M","GLY":"G",
"ASN":"N","PRO":"P","GLN":"Q","ARG":"R","SER":"S","THR":"T","VAL":"V","TRP":"W","TYR":"Y","CYS":"C"}
self.aminoacids={"A":"ALA","D":"ASP","E":"GLU","F":"PHE","H":"HIS","I":"ILE","K":"LYS","L":"LEU","M":"MET","G":"GLY",
"N":"ASN","P":"PRO","Q":"GLN","R":"ARG","S":"SER","T":"THR","V":"VAL","W":"TRP","Y":"TYR","C":"CYS"}
self.sequence=""
self.initial_id_residue=0
self.positions={}
# Read the structure in BioPython format
parser = PDBParser()
self.reference = parser.get_structure('REF',pdb_file)
for ch in self.reference[0]:
if ch.get_id()==chain:
for i,residue in enumerate(ch):
seq=self.aminoacids_back[residue.get_resname()]
# Save the sequence
self.sequence=self.sequence+str(seq)
if i==0: self.initial_id_residue=residue.get_full_id()[3][1]
# Save the positions
self.positions[i+1]={"aa":str(seq),"full_aa":residue.get_resname()}
# Store sequence lenght
self.len_sequence=len(self.sequence)
############################################################################
def get_secondary_structure(self,dssp_route):
"""
Function to calculate the secondary structure and the accessible surface area using the auxiliary program mkdssp
NOTE: mkdssp can be downloaded from the website:
Arguments:
dssp_route -- Route to the local mkdssp executable
Return:
The dictionary positions will store the calculated data of dssp and the asa values
total_dssp will contain the complete predicted secondary structure with the following conventions:
B - beta bridge
H - alpha helix
E - beta strand
S - bend
T - turn
G - 3/10 helix
"""
model=self.reference[0]
dssp = DSSP(model,self.pdb_file,dssp=dssp_route)
self.total_dssp=""
# Loop over the keys from the dssp response to store ss and asa values
counter=1
for keys in list(dssp.keys()):
if keys[0]==self.chain:
position=keys[1][1]
position=counter
self.positions[position]["dssp"]=dssp[keys][2]
self.positions[position]["asa"]=dssp[keys][3]
self.total_dssp=self.total_dssp+dssp[keys][2]
counter+=1
############################################################################
def get_hydrogen_bonds(self,dssp_route):
"""
Function to calculate hydrogen bonds with the other chains
Arguments:
dssp_route -- Route to the local mkdssp executable
Return:
Dictionary containing the peptide amino acids and the protein amino acids forming hydrogen bonds
File with the predicted hydrogen bonds
"""
# Read the protein structure
model=self.reference[0]
dssp = DSSP(model,self.pdb_file,dssp=dssp_route)
self.total_dssp=""
# Loop over the keys from the dssp response to store ss and asa values
total_index={}
list_chains=[]
reference_position=0
list_chains.append(list(dssp.keys())[0][0])
self.hbonds_peptide={}
# iterate over the dssp keys to store the corresponding hydrogen bonds based on the atoms positions
for keys in list(dssp.keys()):
if keys[0]==list_chains[-1]:
total_index[reference_position+keys[1][1]]=(keys[0],dssp[keys][1],keys[1][1])
last_position=reference_position+keys[1][1]
else:
list_chains.append(keys[0])
reference_position=last_position
total_index[reference_position+keys[1][1]]=(keys[0],dssp[keys][1],keys[1][1])
last_position=reference_position+keys[1][1]
if keys[0]==self.chain:
position=keys[1][1]
amino_name=dssp[keys][1]+str(keys[1][1])
if amino_name not in self.hbonds_peptide: self.hbonds_peptide[amino_name]=[]
if dssp[keys][6]<-5:
interactions_pos=last_position+dssp[keys][6]