/
sequenceParameters.py
1042 lines (725 loc) · 42.3 KB
/
sequenceParameters.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
"""
!--------------------------------------------------------------------------!
! LICENSE INFO: !
!--------------------------------------------------------------------------!
! This file is part of localCIDER. !
! !
! Version 0.1.7 !
!--------------------------------------------------------------------------!
File Description:
================
This is one of the key user interface/API files from which users (AKA you!)
should use to access localCIDER.
For a full description please see the documentation!
"""
from backend.sequence import Sequence
from backend.seqfileparser import SequenceFileParser
from backend.backendtools import status_message
from backend import plotting
from backend.localciderExceptions import SequenceException
from backend.localciderExceptions import SequenceComplexityException
class SequenceParameters:
def __init__(self, sequence="", sequenceFile=""):
# provide the flexibility to submit either a sequence
# file or an actual sequence as a string
if sequence=="" and sequenceFile=="":
raise SequenceException("Empty sequence/sequence file")
# if the sequence isn't empty constuct a local
# sequence object using the sequence
if not sequence == "":
# note we set the validate flag to check the sequence is valid and deal
# with whitespace
self.SeqObj = Sequence(sequence,validateSeq=True)
else:
parserMachine = SequenceFileParser()
self.SeqObj = Sequence(parserMachine.parseSeqFile(sequenceFile))
# ============================================ #
# ============= SETTER FUNCTIONS ============= #
#...................................................................................#
def set_phosphosites(self, phosphosites):
"""
Set putativly phosphorylated sites on your sequence.
You can call this multiple times to update, though it
will only ever add sites to the list. To clear sites
use the clear_phosphosites() method.
INPUT:
--------------------------------------------------------------------------------
phosphosites | list of site positions, indexed from 1
OUTPUT:
--------------------------------------------------------------------------------
None, but the underlying Sequence object has its properties
updated
"""
# note that we do all the relevant data validation
# in the calling function
self.SeqObj.setPhosPhoSites(phosphosites)
#...................................................................................#
def clear_phosphosites(self):
"""
Clears the putative phosphosites on the underlying
sequence object. Useful if you want to reset the phosphostatus.
OUTPUT:
--------------------------------------------------------------------------------
None, but the underlying Sequence object has its properties updated
"""
self.SeqObj.clear_phosphosites()
# ============================================ #
# ============= GETTER FUNCTIONS ============= #
#...................................................................................#
def get_sequence(self):
"""
Get the protein's primary amino acid sequence
OUTPUT:
--------------------------------------------------------------------------------
Single string with the protein sequence
"""
return self.SeqObj.seq
#...................................................................................#
def get_length(self):
"""
Get the protein's amino acid sequence length
OUTPUT:
--------------------------------------------------------------------------------
Integer equal to the sequence length
"""
return len(self.SeqObj.seq)
#...................................................................................#
def get_mean_hydropathy(self):
"""
Get a protein's mean hydropathy (a value between 0 and 9, where 0 is the least
hydrophobic and 9 is the most). This is simply a re-based Kyte-Doolittle scale,
which runs from 0 to 9 instead of from -4.5 to 4.5, as in the original paper.
********************************************************************************
Ref: Kyte, J., & Doolittle, R. F. (1982). A simple method for displaying the
hydropathic character of a protein. Journal of Molecular Biology, 157(1),
105-132.
********************************************************************************
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's mean hydropathy
"""
return self.SeqObj.meanHydropathy()
#...................................................................................#
def get_uversky_hydropathy(self):
"""
Get a protein's mean hydropathy as defined by Uversky,
using a normalized Kyte-Doolittle hydropathy table. Here, values range between
0 and 1, with 0 being the least hydrophobic and 1 the most hydrophobic.
OUTPUT:
--------------------------------------------------------------------------------
Float with the normalized Kyte-Doolittle hydropathy (between 0 and 1)
"""
return self.SeqObj.uverskyHydropathy()
#...................................................................................#
def get_fraction_disorder_promoting(self):
"""
Get a protein's fraction of residues which are considered '[D]isorder promoting'.
For more details see the reference below;
********************************************************************************
Ref: Campen A, Williams RM, Brown CJ, Meng J, Uversky VN, Dunker AK. (2008).
TOP-IDP-scale: a new amino acid scale measuring propensity for intrinsic disorder.
Protein Pept Lett. 15(9), 956-63.
********************************************************************************
OUTPUT:
--------------------------------------------------------------------------------
Float with the fraction of disorder promoting residues
"""
return self.SeqObj.fraction_disorder_promoting()
#...................................................................................#
def get_amino_acid_fractions(self):
"""
Returns a dictionary with the fractions of each amino acid in your sequence
OUTPUT:
--------------------------------------------------------------------------------
Dictionary of amino acids, where the keys are each of the 20 amino acids and the
values represents the fraction of that amino acid
"""
return self.SeqObj.amino_acid_fraction()
#...................................................................................#
def get_kappa(self):
"""
Get the kappa value associated with a sequence.
********************************************************************************
Ref: Das, R. K., & Pappu, R. V. (2013). Conformations of intrinsically disordered
proteins are influenced by linear sequence distributions of oppositely
charged residues. PNAS, 110(33), 13392-13397.
********************************************************************************
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's kappa value
"""
return self.SeqObj.kappa()
#...................................................................................#
def get_deltaMax(self):
"""
Get the maximum delta value for a sequence of this composition. Note kappa is
delta/deltaMax.
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's delta max (identical for all permutants)
"""
return self.SeqObj.deltaMax()
#...................................................................................#
def get_delta(self):
"""
Get the delta value for this specific sequence. Note kappa is delta/deltaMax.
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's delta max (will vary with permutants)
"""
return self.SeqObj.delta()
#...................................................................................#
def get_countPos(self):
"""
Get the number of positive residues in the sequence
OUTPUT:
--------------------------------------------------------------------------------
Integer with number of positive residues in your sequence
"""
return self.SeqObj.countPos()
#...................................................................................#
def get_countNeg(self):
"""
Get the number of negative residues in the sequence
OUTPUT:
--------------------------------------------------------------------------------
Integer with number of negative residues in your sequence
"""
return self.SeqObj.countNeg()
#...................................................................................#
def get_countNeut(self):
"""
Get the number of neutral residues in the sequence
OUTPUT:
--------------------------------------------------------------------------------
Integer with number of neutral residues in your sequence
"""
return self.SeqObj.countNeut()
#...................................................................................#
def get_fraction_positive(self):
"""
Get the fraction of positive residues in the sequence
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's fraction of positive residues (F+)
"""
return self.SeqObj.Fplus()
#...................................................................................#
def get_fraction_negative(self):
"""
Get the fraction of negative residues in the sequence
OUTPUT
--------------------------------------------------------------------------------:
Float with the sequence's fraction of positive residues (F+)
"""
return self.SeqObj.Fminus()
#...................................................................................#
def get_FCR(self):
"""
Get the fraction of charged residues in the sequence
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's fraction of charged residues
"""
return self.SeqObj.FCR()
#...................................................................................#
def get_NCPR(self):
"""
Get the net charge per residue of the sequence
OUTPUT:
--------------------------------------------------------------------------------
Float with the sequence's net charge per residue
"""
return self.SeqObj.NCPR()
#...................................................................................#
def get_mean_net_charge(self):
"""
Get the absolute magnitude of the mean net charge
OUTOUT:
--------------------------------------------------------------------------------
Float equal to the [absolute magnitude] of the mean net charge of the sequence
"""
return self.SeqObj.mean_net_charge()
#...................................................................................#
def get_phasePlotRegion(self):
"""
Returns the IDP diagram of states [REF 1] region based on the FCR/NCPR
rules. Possible return values are;
1 +-----------------------+---------------+
| + |
| + |
| 4 + |
F | + |
R | + |
A | + +
C | + + |
T | + + |
. | + 3 + |
0.5 | + + |
N | + + |
E + + |
G | + + |
+ 2 + + |
R | + + + 5 |
E | + 2 + + |
S | + + + |
| 1 + 2 + + |
0 +---------+---+-------------------------+
0 0.5 1
FRACTION OF POSITIVE RESIDUES
1) Weak polyampholytes and polyelectrolytes
2) Intermediate (Janus) sequences
3) Strong polyampholytes
4 and 5) Strong polyelectrolytes
OUTPUT:
--------------------------------------------------------------------------------
Returns an integer describing the region on the density of states
diagram (above)
"""
return self.SeqObj.phasePlotRegion()
#...................................................................................#
def get_phosphosites(self):
"""
Function which returns a list of currently assigned
phosphosites on your sequence.
OUTPUT: Returns a list of integers where each
integer represents a site currently defined as
phosphorylatable. Such sites *must*, by definition
by T/Y/S.
OUTPUT:
--------------------------------------------------------------------------------
Returns a list of integers corresponding to the sites
which are currently defined as being phosphorylatable based on
user input
"""
return self.SeqObj.get_phosphosites()
#...................................................................................#
def get_kappa_after_phosphorylation(self):
"""
Function which recomputes kappa after complete
phosphorylation based on the currently defined
phosphosites.
OUTPUT:
--------------------------------------------------------------------------------
returns a float corresponding to the sequence's kappa value if
all the currently defined phosphosites were phosphorylated
"""
if len(self.get_phosphosites()) == 0:
status_message("Be aware that there are no phosphosites currently set - getting 'naked' kappa")
return self.SeqObj.kappa_at_maxPhos()
#...................................................................................#
def get_all_phosphorylatable_sites(self):
"""
Function which returns a list of all the positions which *could* be
phosphorylated (i.e. are T/S/Y). NOTE this does not use any kind of
smart lookup, metadata, or analysis. It's literally, where are the Y/T/S
residues.
Note positions are returned as indexed from 1 (so you can feed these positions
directly into the set_phosphosites function.
OUTPUT:
--------------------------------------------------------------------------------
Returns a list of integers corresponding to S/T/Y positions in your sequence
"""
return self.SeqObj.get_STY_residues()
#...................................................................................#
def get_full_phosphostatus_kappa_distribution(self):
"""
This function calculates the kappa value of all possible phosphorylation
states, given the defined phosphosites.
This is computationally tractable for small numbers of phosphosites, but can
rapidly become extremely expensive.
OUTPUT:
--------------------------------------------------------------------------------
Returns a list of tuples, where each tuple corresponds to a unique phosphostate
of the protein of interest. Each position within the tuple is defined as follows;
0 - kappa of sequence
1 - Fraction of positive residues (F+) (does not change)
2 - Fraction of negative residues (F-)
3 - Fraction of charged residues (FCR)
4 - Net Charge Per Residue (NCRP)
5 - Mean hydropathy
6 - phosphostatus
These are all self explanatory, with the exception of phosphostatus, which defines
a tuple with a position for each phosphorylatable site, set to 0 if not phosphorylated
and 1 if phosphorylated. As an example, if I had a protein with three phosphosites
(S4,Y43,S105), the tuple for the fully unphosphorylated would be (0,0,0) and with
Y43 phosphorylated would be (0,1,0)
"""
# determine the number of calculations needed to run
ncalcs = self.SeqObj.calculateNumberDifferentPhosphoStates()
# print status message
status_message("Running exaustive kappa distribution analysis based on phosphorylation states")
status_message("This function will now make " + str(ncalcs) + " independent kappa calculations\nIf this is a big number you may want to investigate a subset of possible phosphosites or\nuse a Monte Carlo approach to subsample")
return self.SeqObj.calculateKappaDistOfPhosphoStates()
#...................................................................................#
def get_phosphosequence(self):
"""
Returns the sequence with phosphorylated sites set to E instead of S/Y/T
"""
return self.SeqObj.get_phosphosequence()
# ===========================---================= #
# ======= SEQUENCE COMPLEXITY FUNCTIONS ========= #
#...................................................................................#
def get_reduced_alphabet_sequence(self, alphabetSize=20, userAlphabet={}):
""""
Get your sequence converted into a lower resolution (reduced) alphabet. A set of reduced alphabets exist and are defined below, or the user can define their own alphabet.
INPUT:
--------------------------------------------------------------------------------
alphabetSize | Defines the size of the alphabet being used, where pre-defined
alphabets are then used based on the specific size. Those
pre-defined alphabets are defined below.
userAlphabet | Allows the user to define their own alphabet. The format here
is a dictionary where each key-value pair is amino-acid to translation.
This means you need a dictionary of length 20 where each amino acid
is mapped to another amino acid. This is kind of tedious, but it helps
avoid user-error where specific amino acids are missed.
OUTPUT:
--------------------------------------------------------------------------------
Returns an amino acid squence which has been reduced down to a simple composition
based on the defined alphabet. Note this returns the sequence only, not a
SequenceParameters object.
Predefined alphabets shown below - all except eleven are based on alphabets defined in
the reference below.
two - [(LVIMCAGSTPFYW), (EDNQKRH)]
three - [(LVIMCAGSTP), (FYW), (EDNQKRH)]
four - [(LVIMC), (AGSTP), (FYW), (EDNQKRH)]
five - [(LVIMC), (ASGTP), (FYW), (EDNQ), (KRH)]
six - [(LVIM), (ASGT), (PHC), (FYW), (EDNQ), (KR)]
eight - [(LVIMC), (AG), (ST), (P), (FYW), (EDNQ), (KR), (H)]
ten - [(LVIM), (C), (A), (G), (ST), (P), (FYW), (EDNQ), (KR), (H)]
eleven - [(LVIM), (C), (A), (G), (ST), (P), (FYW), (ED), (NQ), (KR), (H)]
twelve - [(LVIM), (C), (A), (G), (ST), (P), (FY), (W), (EQ), (DN), (KR), (H)]
fifteen - [(LVIM), (C), (A), (G), (S), (T), (P), (FY), (W), (E), (Q), (D), (N), (KR), (H)]
eighteen - [(LM), (VI), (C), (A), (G), (S), (T), (P), (F), (Y), (W), (E), (D), (N), (Q), (K), (R), (H)]
twenty - all twenty!
REF: Murphy, L. R., Wallqvist, A., & Levy, R. M. (2000). Simplified amino acid alphabets for
protein fold recognition and implications for folding. Protein Engineering, 13(3), 149-152.
"""
return self.SeqObj.get_reducedAlphabetSequence(alphabetSize, userAlphabet)
def get_linearComplexity(self, complexityType="WF", alphabetSize=20, userAlphabet={}, windowSize=10, stepSize=1, wordSize=3):
"""
Returns the linear sequence complexity as defined by complexityType. Optionally,
the sequence complexity of a reduced complexity alphabet can be returned, where
that reduced alphabet is defined by either the alphabetSize or the userAlphabet
dictionary.
INPUT:
--------------------------------------------------------------------------------
complexityType | Defines the complexity measure being employed. Is a string equal
to one of the opions described below;
WF - Wooton-Federhen complexity [1]
LC - Linqguistic complexity
(Default = 'WF')
alphabetSize | Defines the size of the alphabet being used, where pre-defined
alphabets are then used based on the specific size. Those
pre-defined alphabets are defined below. (Default = 20, i.e. no
reduction in amino acid complexity)
userAlphabet | Allows the user to define their own alphabet. The format here
is a dictionary where each key-value pair is amino-acid to translation.
This means you need a dictionary of length 20 where each amino acid
is mapped to another amino acid. This is kind of tedious, but it helps
avoid user-error where specific amino acids are missed. (default=None)
windowSize | Sliding window size over which complexity is calculated (default=10)
stepSize | Size of steps taken as we define a new sliding window. Default is
1 and should probably always be used...
wordSize | Relevant for linguistic complexity (need more details!)
OUTPUT:
--------------------------------------------------------------------------------
Returns a vector of values corresponding to the sliding window complexity of the
sequence, using the measure defined, and using the reduced alphabet complexity as
defined
Predefined alphabets shown below - all except eleven are based on alphabets defined in
the reference below.
two - [(LVIMCAGSTPFYW), (EDNQKRH)]
three - [(LVIMCAGSTP), (FYW), (EDNQKRH)]
four - [(LVIMC), (AGSTP), (FYW), (EDNQKRH)]
five - [(LVIMC), (ASGTP), (FYW), (EDNQ), (KRH)]
six - [(LVIM), (ASGT), (PHC), (FYW), (EDNQ), (KR)]
eight - [(LVIMC), (AG), (ST), (P), (FYW), (EDNQ), (KR), (H)]
ten - [(LVIM), (C), (A), (G), (ST), (P), (FYW), (EDNQ), (KR), (H)]
eleven - [(LVIM), (C), (A), (G), (ST), (P), (FYW), (ED), (NQ), (KR), (H)]
twelve - [(LVIM), (C), (A), (G), (ST), (P), (FY), (W), (EQ), (DN), (KR), (H)]
fifteen - [(LVIM), (C), (A), (G), (S), (T), (P), (FY), (W), (E), (Q), (D), (N), (KR), (H)]
eighteen - [(LM), (VI), (C), (A), (G), (S), (T), (P), (F), (Y), (W), (E), (D), (N), (Q), (K), (R), (H)]
twenty - all twenty!
[1] Wootton, J. C., & Federhen, S. (1993). Statistics of local complexity in amino acid sequences
and sequence databases. Computers & Chemistry, 17(2), 149-163.
[n]: Murphy, L. R., Wallqvist, A., & Levy, R. M. (2000). Simplified amino acid alphabets for
protein fold recognition and implications for folding. Protein Engineering, 13(3), 149-152.
"""
# set the allowed types of complexity here
allowed_types = ('WF', 'LC')
# provide case insensitivity
try:
complexityType = complexityType.upper()
except AttributeError:
pass
# check fi the type passed is actually one of the ones we know about
if complexityType not in allowed_types:
raise SequenceComplexityException("Complexity type %s is not a valid type - must be one of %s"%(complexityType, allowed_types))
if complexityType == "WF":
if not wordSize == 3:
print "WARNING: Ignoring wordSize argument for Wooton-Federhen complexity"
return self.SeqObj.get_linear_WF_complexity(alphabetSize, userAlphabet, windowSize, stepSize)
if complexityType == "LC":
return self.SeqObj.get_linear_LC_complexity(alphabetSize, userAlphabet, windowSize, stepSize, wordSize)
# ============================================ #
# ======= PLOTTING DIAGRAM FUNCTIONS ========= #
#...................................................................................#
def show_phaseDiagramPlot(self,label="", title="Diagram of states",legendOn=True, xLim=1, yLim=1, fontSize=10, getFig=False):
"""
Generates the Pappu-Das phase diagram (diagram of states), places
this sequence on that plot, and creates it on the screen
INPUT:
--------------------------------------------------------------------------------
label | A label for the point on the phase diagram
title | Plot title (DEFAULT = 'Diagram of states')
legendOn | Boolean for if the figure legend should be displayed or not
xLim | Max value for the x axis (fract. positive charge) (DEFAULT = 1)
yLim | Max value for the y axis (fract. negative charge) (DEFAULT = 1)
fontSize | Size of font for label (DEFAULT = 10)
getFig | Returns a matplotlib figure object instead of simply displaying the
| plot on the screen (DEFAULT = False)
OUTPUT:
--------------------------------------------------------------------------------
If the argument getFig is False (which it is by default) then the Uversky plot appears on
the screen. If getFig is set to True then the function returns a matplotlib plt object, which
can be further manipulated.
"""
if getFig:
return plotting.show_single_phasePlot(self.get_fraction_positive(), self.get_fraction_negative(),label, legendOn, xLim, yLim, fontSize, getFig)
else:
plotting.show_single_phasePlot(self.get_fraction_positive(), self.get_fraction_negative(),label, title, legendOn, xLim, yLim, fontSize, getFig)
#...................................................................................#
def save_phaseDiagramPlot(self, filename,label="", title="Diagram of states", legendOn=True, xLim=1, yLim=1, fontSize=10):
"""
Generates the Pappu-Das phase diagram (diagram of states), places
this sequence on that plot, and saves it at the <filename> location
INPUT:
--------------------------------------------------------------------------------
filename | Writeable filename
label | A label for the point on the phase diagram
title | Plot title (DEFAULT = 'Diagram of states')
legendOn | Boolean for if the figure legend should be displayed or not
xLim | Max value for the x axis (fract. positive charge) (DEFAULT = 1)
yLim | Max value for the y axis (fract. negative charge) (DEFAULT = 1)
fontSize | Size of font for label (DEFAULT = 10)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but creates a .png file at the filename location
"""
plotting.save_single_phasePlot(self.get_fraction_positive(), self.get_fraction_negative(), filename, label, title, legendOn, xLim, yLim, fontSize)
#...................................................................................#
def show_uverskyPlot(self, label="", title="Uversky plot", legendOn=True, xLim=1, yLim=1, fontSize=10, getFig=False):
"""
Generates the Uversky phase diagram (hydropathy vs NCPR), places
this sequence on that plot, and creates it on the screen
INPUT:
--------------------------------------------------------------------------------
label | A label for the point on the phase diagram
title | Plot title (DEFAULT = 'Uversky plot')
legendOn | Boolean for if the figure legend should be displayed or not
xLim | Max value for the x axis (mean net charge) (DEFAULT = 1)
yLim | Max value for the y axis (hydropathy) (DEFAULT = 1)
fontSize | Size of font for label (DEFAULT = 10)
getFig | Returns a matplotlib figure object instead of simply displaying the
plot on the screen (DEFAULT = False)
OUTPUT:
--------------------------------------------------------------------------------
If the argument getFig is False (which it is by default) then the Uversky plot appears on
the screen. If getFig is set to True then the function returns a matplotlib plt object, which
can be further manipulated.
"""
if getFig:
return plotting.show_single_uverskyPlot(self.get_uversky_hydropathy(), self.get_mean_net_charge(), label, title, legendOn, xLim, yLim, fontSize, getFig)
else:
plotting.show_single_uverskyPlot(self.get_uversky_hydropathy(), self.get_mean_net_charge(), label, title, legendOn, xLim, yLim, fontSize, getFig)
#...................................................................................#
def save_uverskyPlot(self, filename, label="", title="Uversky plot", legendOn=True, xLim=1, yLim=1, fontSize=10):
"""
Generates the Pappu-Das phase diagram (diagram of states), places
this sequence on that plot, and saves it at the <filename> location
INPUT:
--------------------------------------------------------------------------------
filename | A writeable filename
label | A label for the point on the phase diagram
title | Plot title (DEFAULT = 'Uversky plot')
legendOn | Boolean for if the figure legend should be displayed or not
xLim | Max value for the x axis (mean net charge) (DEFAULT = 1)
yLim | Max value for the y axis (hydropathy) (DEFAULT = 1)
fontSize | Size of font for label (DEFAULT = 10)
OUTPUT:
--------------------------------------------------------------------------------
If the argument getFig is False (which it is by default) then the Uversky plot appears on
the screen. If getFig is set to True then the function returns a matplotlib plt object, which
can be further manipulated.
"""
plotting.save_single_uverskyPlot(self.get_uversky_hydropathy(), self.get_mean_net_charge(), filename, label, title, legendOn, xLim, yLim, fontSize)
#...................................................................................#
def save_linearNCPR(self, filename, blobLen=5):
"""
Generates a plot of how the NCPR (net charge per residue) changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
INPUT:
--------------------------------------------------------------------------------
filename | Name of the file to write
bloblen | Set the windowsize (DEFAULT = 5)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but creates a .png file at the filename location
"""
plotting.save_linearplot(plotting.build_NCPR_plot, self.SeqObj, blobLen, filename)
#...................................................................................#
def save_linearFCR(self, filename, blobLen=5):
"""
Generates a plot of how the FCR (fraction of charged residues) changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
INPUT:
--------------------------------------------------------------------------------
filename | Name of the file to write
bloblen | Set the windowsize (DEFAULT = 5)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but creates a .png file at the filename location
"""
plotting.save_linearplot(plotting.build_FCR_plot, self.SeqObj, blobLen, filename)
#...................................................................................#
def save_linearSigma(self, filename, blobLen=5):
"""
Generates a plot of how the Sigma parameter changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
Recall that sigma is defined as
NCPR^2/FCR (net charge per residue squared divided by the fraction of charged residues)
INPUT:
--------------------------------------------------------------------------------
filename | Name of the file to write
bloblen | Set the windowsize (DEFAULT = 5)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but creates a .png file at the filename location
"""
plotting.save_linearplot(plotting.build_sigma_plot, self.SeqObj, blobLen, filename)
#...................................................................................#
def save_linearHydropathy(self, filename, blobLen=5):
"""
Generates a plot of how the mean hydropathy changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
Hydropathy here is calculated using a NORMALIZED Kyte-Doolittle scale, where 1 is
the most hydrophobic and 0 the least.
INPUT:
--------------------------------------------------------------------------------
filename | Name of the file to write
bloblen | Set the windowsize (DEFAULT = 5)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but creates a .png file at the filename location
"""
plotting.save_linearplot(plotting.build_hydropathy_plot, self.SeqObj, blobLen, filename)
#...................................................................................#
def show_linearNCPR(self, blobLen=5, getFig=False):
"""
Generates a plot of how the NCPR (net charge per residue) changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
INPUT:
--------------------------------------------------------------------------------
bloblen | Set the windowsize (DEFAULT = 5)
getFig | Do you want to get the matplotlib figure object (DEFAULY = FALSE)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but the plot is displayed on screen
"""
return plotting.show_linearplot(plotting.build_NCPR_plot, self.SeqObj, blobLen, getFig)
#...................................................................................#
def show_linearFCR(self, blobLen=5, getFig=False):
"""
Generates a plot of how the FCR (fraction of charged residues) changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
INPUT:
--------------------------------------------------------------------------------
bloblen | Set the windowsize (DEFAULT = 5)
getFig | Do you want to get the matplotlib figure object (DEFAULY = FALSE)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but the plot is displayed on screen
"""
return plotting.show_linearplot(plotting.build_FCR_plot, self.SeqObj, blobLen, getFig)
#...................................................................................#
def show_linearSigma(self, blobLen=5, getFig=False):
"""
Generates a plot of how the sigma parameter changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
Recall that sigma is defined as
NCPR^2/FCR (net charge per residue squared divided by the fraction of charged residues)
INPUT:
--------------------------------------------------------------------------------
bloblen | Set the windowsize (DEFAULT = 5)
getFig | Do you want to get the matplotlib figure object (DEFAULY = FALSE)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but the plot is displayed on screen
"""
return plotting.show_linearplot(plotting.build_sigma_plot, self.SeqObj, blobLen, getFig)
#...................................................................................#
def show_linearHydropathy(self, blobLen=5, getFig=False):
"""
Generates a plot of how the mean hydropathy changes as we move
along the linear amino acid sequence in blobLen size steps. This uses a sliding window
approach and calculates the average within that window.
Hydropathy here is calculated using a NORMALIZED Kyte-Doolittle scale, where 1 is
the most hydrophobic and 0 the least.
INPUT:
--------------------------------------------------------------------------------
bloblen | Set the windowsize (DEFAULT = 5)
getFig | Do you want to get the matplotlib figure object (DEFAULY = FALSE)
OUTPUT:
--------------------------------------------------------------------------------
Nothing, but the plot is displayed on screen
"""
return plotting.show_linearplot(plotting.build_hydropathy_plot, self.SeqObj, blobLen, getFig)
# ============================================== #
# ============ FORMATTING FUNCTIONS ============ #
#...................................................................................#
def set_HTMLColorResiduePalette(self, colorDict):
"""
Allows the user to define the colormapping used for the get_HTMLColorString.
The input parameter is a dictionary which contains amino acid single letter codes
as keys and colours as values. The colours must be one of the 17 standard HTML
color names. These are;
aqua, black, blue, fuchsia, gray, green, lime, maroon, navy, olive, orange,
purple, red, silver, teal, white, and yellow.
By default, polar residues are green, negative residues red, positive blue,
proline fuschia and all others are black.
The function carrys out checking to ensure that
1) Colors are valid (case insensitive)
2) All 20 amino acids are accounted for
No return value is provided, but an exception is raised if the operation
cannot be completed.
"""
self.SeqObj.set_HTMLColorResiduePalette(colorDict)