PositionMatrix

Object interface for position-specific probability, background, log-odds, and motif plots.

Setup

PositionMatrix

PositionMatrix keeps the existing functional API available while adding cached methods such as prob(), bg_prob(), log_odds(), logo(), and heatmap().


PositionMatrix


def PositionMatrix(
    data:pandas.DataFrame | pandas.Series | collections.abc.Sequence[str] | None=None, seq_col:str='site_seq',
    bg_type:str='STY', name:str='Motif', pssm_df:pandas.DataFrame | None=None, bg_pssm:pandas.DataFrame | None=None,
    bg_seq:pandas.DataFrame | pandas.Series | collections.abc.Sequence[str] | None=None
)->None:

Position-specific matrix wrapper for probability, background, log-odds, and motif plots.

Examples

Probability matrix

df=Data.ks_dataset()
df_k=df[df.kinase_protein=='ABL1']
PositionMatrix?
Init signature:
PositionMatrix(
    data: pandas.DataFrame | pandas.Series | collections.abc.Sequence[str] | None = None,
    seq_col: str = 'site_seq',
    bg_type: str = 'STY',
    name: str = 'Motif',
    pssm_df: pandas.DataFrame | None = None,
    bg_pssm: pandas.DataFrame | None = None,
    bg_seq: pandas.DataFrame | pandas.Series | collections.abc.Sequence[str] | None = None,
) -> None
Docstring:      Position-specific matrix wrapper for probability, background, log-odds, and motif plots.
Type:           type
Subclasses:     
pm = PositionMatrix(df_k['site_seq'],name='ABL1')

# also support:
# pm = PositionMatrix(df_k,seq_col='site_seq',name='ABL1')
pm.default_kind
'prob'
pm.prob()
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11 ... 11 12 13 14 15 16 17 18 19 20
aa
P 0.050061 0.048691 0.062349 0.055489 0.046988 0.054753 0.064787 0.055090 0.056683 0.048272 ... 0.052728 0.051140 0.069436 0.063164 0.057716 0.056639 0.051072 0.050697 0.052163 0.060703
G 0.080586 0.080341 0.069007 0.067551 0.082530 0.070397 0.093581 0.073054 0.077566 0.072706 ... 0.099939 0.070856 0.071916 0.075672 0.071518 0.064821 0.080076 0.088720 0.062341 0.090735
A 0.080586 0.080341 0.062954 0.054282 0.075301 0.071600 0.070186 0.070060 0.065632 0.070322 ... 0.064378 0.077634 0.069436 0.072545 0.063363 0.079924 0.088272 0.087452 0.057888 0.070927
C 0.017094 0.012781 0.013317 0.019903 0.012048 0.017449 0.007798 0.014371 0.013126 0.012515 ... 0.007357 0.017868 0.014879 0.012508 0.011920 0.018880 0.019546 0.014575 0.019084 0.014058
S 0.047619 0.035910 0.046610 0.030157 0.037349 0.042720 0.041992 0.041916 0.034010 0.039333 ... 0.024525 0.036352 0.047117 0.040025 0.042033 0.040277 0.039092 0.051965 0.041349 0.039617
T 0.039683 0.031041 0.046005 0.042220 0.029518 0.032491 0.037792 0.033533 0.031623 0.041716 ... 0.028817 0.035736 0.024799 0.040025 0.035132 0.041536 0.031526 0.029785 0.031807 0.036422
V 0.047009 0.057212 0.051453 0.075392 0.065060 0.048736 0.049790 0.059880 0.055489 0.049464 ... 0.061312 0.062230 0.050217 0.069418 0.063363 0.064821 0.050441 0.062104 0.048982 0.049840
I 0.046398 0.051735 0.044189 0.044632 0.053614 0.050542 0.050990 0.047904 0.038783 0.046484 ... 0.044758 0.050524 0.039678 0.058787 0.042660 0.041536 0.066835 0.044360 0.066794 0.053674
L 0.071429 0.088253 0.069007 0.085645 0.079518 0.077617 0.070186 0.080240 0.086516 0.076877 ... 0.072348 0.059150 0.083075 0.067542 0.065245 0.081183 0.073770 0.072877 0.105598 0.073482
M 0.028694 0.024954 0.029056 0.022316 0.021687 0.017449 0.028794 0.023353 0.015513 0.023242 ... 0.014102 0.014171 0.014259 0.021263 0.018821 0.011957 0.031526 0.025982 0.022901 0.031949
F 0.031136 0.032258 0.029056 0.052473 0.044578 0.034296 0.036593 0.029341 0.027446 0.032181 ... 0.027590 0.022797 0.037198 0.026892 0.043287 0.042794 0.031526 0.033587 0.033079 0.038339
Y 0.023199 0.014607 0.014528 0.014475 0.014458 0.013839 0.017397 0.022754 0.011933 0.017878 ... 0.014102 0.014171 0.019839 0.014384 0.013802 0.015733 0.015763 0.017744 0.017812 0.019169
W 0.006716 0.009738 0.009685 0.010253 0.006627 0.009627 0.010198 0.007186 0.007757 0.011323 ... 0.017167 0.007394 0.015499 0.006254 0.010038 0.011957 0.008827 0.010139 0.008270 0.007029
H 0.023199 0.018868 0.018765 0.015078 0.016265 0.022864 0.025795 0.018563 0.022076 0.014899 ... 0.019620 0.023413 0.025418 0.016260 0.025094 0.025802 0.013871 0.014575 0.013359 0.010224
K 0.089133 0.083993 0.076877 0.097105 0.083735 0.084838 0.091782 0.078443 0.106205 0.078069 ... 0.082771 0.094270 0.076255 0.076923 0.091593 0.067338 0.077554 0.057034 0.073791 0.081150
R 0.054945 0.064516 0.059322 0.047045 0.050000 0.051745 0.052789 0.053293 0.065036 0.081049 ... 0.065604 0.080099 0.058896 0.076923 0.057089 0.050975 0.054224 0.069708 0.055344 0.060064
Q 0.048840 0.040170 0.055085 0.032569 0.039759 0.057160 0.032993 0.048503 0.041169 0.040524 ... 0.041692 0.040049 0.038438 0.033771 0.045169 0.039018 0.040984 0.040558 0.045165 0.030671
N 0.039683 0.039562 0.042978 0.042823 0.037952 0.034296 0.036593 0.035928 0.040573 0.039333 ... 0.036787 0.047443 0.035338 0.037523 0.036386 0.039018 0.033417 0.032953 0.034351 0.033227
D 0.050672 0.056604 0.064165 0.059710 0.063855 0.075211 0.052190 0.067665 0.074582 0.061979 ... 0.075414 0.055453 0.063856 0.058787 0.064617 0.064821 0.062421 0.057034 0.076336 0.049201
E 0.067155 0.082775 0.093220 0.083836 0.078916 0.078821 0.077984 0.091617 0.078759 0.066746 ... 0.078479 0.079482 0.078115 0.066917 0.077164 0.075519 0.080076 0.074778 0.066794 0.086901
s 0.021368 0.021302 0.019370 0.022919 0.031928 0.024669 0.025195 0.029341 0.026850 0.033969 ... 0.031269 0.028959 0.033478 0.037523 0.039523 0.036501 0.022068 0.040558 0.035623 0.031310
t 0.018315 0.012781 0.015738 0.015078 0.014458 0.015042 0.011398 0.007186 0.009547 0.021454 ... 0.019620 0.011091 0.021699 0.015009 0.014429 0.019509 0.014502 0.014575 0.012087 0.015335
y 0.016484 0.011564 0.007264 0.009047 0.013855 0.013839 0.013197 0.010778 0.013126 0.019666 ... 0.019620 0.019717 0.011159 0.011882 0.010038 0.009440 0.012610 0.008238 0.019084 0.015974

23 rows × 41 columns

pm.logo();

pm.logo_heatmap()

pm.entropy()[:5]
-20    4.324108
-19    4.257291
-18    4.284732
-17    4.267691
-16    4.270273
dtype: float64
pm.ic()[:5]
-20    0.199454
-19    0.266271
-18    0.238830
-17    0.255871
-16    0.253289
dtype: float64
pm.specificity()
0.7516637031585568

Log odds

bg_pssms = Data.ks_background()
bg_pssm = recover_pssm(bg_pssms.loc['ks_STY'])
pm = PositionMatrix(df_k['site_seq'],name='ABL1',bg_pssm=bg_pssm)
pm.default_kind
'log_odds'
# log-odds matrix
pm.matrix()
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11 ... 11 12 13 14 15 16 17 18 19 20
aa
P -0.422531 -0.387170 -0.028101 -0.254776 -0.471573 -0.223829 0.035365 -0.249530 -0.217363 -0.394475 ... -0.400433 -0.308756 0.111171 -0.070105 -0.306397 -0.229673 -0.357582 -0.358156 -0.270985 -0.161588
G 0.231774 0.203880 -0.001472 -0.042913 0.256561 0.046311 0.353025 0.094236 0.182308 0.032609 ... 0.549747 0.105448 0.100101 0.200547 0.070216 -0.119584 0.227532 0.387864 -0.111499 0.392540
A 0.117253 0.153799 -0.147590 -0.375496 0.063693 -0.002326 -0.034051 -0.058344 -0.101303 -0.030614 ... -0.135387 0.183841 -0.006063 -0.000713 -0.141419 0.268701 0.284250 0.367866 -0.288109 0.040216
C 0.153007 -0.175656 -0.105521 0.366559 -0.328953 0.258748 -0.909333 0.038288 -0.120761 -0.126054 ... -0.817275 0.356512 -0.014272 -0.090580 -0.313412 0.348370 0.393326 -0.138164 0.445406 -0.094037
S -0.041499 -0.526956 -0.131178 -0.729693 -0.449989 -0.184067 -0.245230 -0.243271 -0.538793 -0.291065 ... -0.970558 -0.381593 0.010781 -0.337101 -0.207560 -0.300310 -0.390165 0.002572 -0.330924 -0.379184
T 0.076438 -0.234028 0.275799 0.088161 -0.316086 -0.246995 0.044902 -0.074589 -0.085961 0.362037 ... -0.204823 -0.000423 -0.505946 0.109445 0.065038 0.157059 -0.232022 -0.350491 -0.240026 0.029129
V -0.207914 0.107739 -0.165978 0.376977 0.241838 -0.188781 -0.063648 0.194766 0.040616 -0.076133 ... 0.181794 0.162176 -0.149095 0.349826 0.230249 0.205983 -0.077512 0.121504 -0.113104 -0.172417
I 0.156275 0.333622 0.097980 0.164573 0.302576 0.323788 0.241940 0.268817 -0.017884 0.247070 ... 0.239282 0.292980 -0.081770 0.546976 0.093546 -0.021086 0.654031 0.098219 0.702654 0.347996
L -0.218875 0.062076 -0.255322 0.052645 -0.041514 -0.066489 -0.184332 -0.038846 0.090330 -0.032114 ... -0.111650 -0.378894 0.038396 -0.296889 -0.303012 0.032072 -0.143648 -0.156046 0.345293 -0.168982
M 0.366215 0.121511 0.435047 0.073655 -0.022551 -0.239743 0.395868 0.110904 -0.476174 -0.036722 ... -0.353538 -0.395654 -0.466063 0.144440 -0.065176 -0.778159 0.710860 0.437619 0.286042 0.667587
F 0.008319 0.156483 -0.061290 0.774824 0.511690 0.106709 0.221428 -0.092057 -0.204140 0.127418 ... -0.018685 -0.266481 0.304289 -0.136528 0.523281 0.496521 0.105597 0.247409 -0.020385 0.196239
Y 0.312704 -0.254115 -0.275188 -0.242937 -0.136465 -0.239534 0.228076 0.519229 -0.282224 0.203087 ... -0.077610 -0.223359 0.182230 -0.286705 -0.208085 0.081889 -0.192648 -0.144462 0.130347 0.004758
W -0.313904 0.155186 0.428094 0.300870 -0.239921 0.067992 0.389232 -0.112303 -0.138178 0.506649 ... 0.878185 -0.524189 0.688056 -0.380086 0.285280 0.368860 -0.317619 0.254027 -0.258544 -0.284951
H 0.073143 -0.146958 -0.257119 -0.444166 -0.414833 0.052435 0.237170 -0.135689 0.088692 -0.521678 ... -0.079825 0.031352 0.107467 -0.281683 0.142720 0.168769 -0.598650 -0.573145 -0.727269 -1.046781
K 0.347531 0.233963 0.095545 0.423790 0.137612 0.187421 0.230255 0.071271 0.461431 0.016577 ... 0.146302 0.300766 0.025402 0.045125 0.385095 -0.118823 0.084783 -0.348696 0.035259 0.180567
R -0.051431 0.029871 -0.090437 -0.394851 -0.278305 -0.241898 -0.253028 -0.292073 -0.096880 0.193488 ... -0.140508 0.222299 -0.155191 0.201225 -0.185089 -0.341034 -0.296840 0.162848 -0.159060 0.019399
Q 0.095733 -0.216531 0.192349 -0.516490 -0.178244 0.215735 -0.465361 0.115986 -0.090739 -0.135494 ... -0.152827 -0.238668 -0.217588 -0.399159 -0.034858 -0.217765 -0.110754 -0.180951 -0.003352 -0.521990
N 0.114263 0.021691 0.291017 0.193895 0.122908 -0.082816 0.040855 -0.072351 0.148540 0.174890 ... 0.043811 0.351636 -0.070638 0.046796 -0.049190 0.068236 -0.030977 -0.203283 -0.210616 -0.154750
D -0.172644 0.017884 0.214403 0.109995 0.099394 0.410600 -0.088734 0.217295 0.377847 0.093124 ... 0.421223 -0.015030 0.141357 0.110932 0.124300 0.178915 0.193704 0.023231 0.412575 -0.188258
E -0.270580 0.055650 0.205496 0.110811 -0.013683 0.025120 -0.014221 0.168108 -0.015173 -0.232231 ... -0.078613 -0.096144 -0.039098 -0.286218 -0.087928 -0.137180 -0.015843 -0.139063 -0.289766 0.145802
s -0.678210 -0.756451 -0.871465 -0.655063 -0.156111 -0.562247 -0.621471 -0.374948 -0.562133 -0.210451 ... -0.370563 -0.491511 -0.194316 -0.066203 0.055284 0.022401 -0.818305 0.136221 -0.044513 -0.234855
t 0.259085 -0.213309 0.034558 0.052476 0.134729 -0.044440 -0.320721 -1.013674 -0.597347 0.359432 ... 0.319937 -0.485715 0.457734 -0.066203 -0.121387 0.437699 -0.005906 0.035783 -0.302972 -0.016146
y 0.774699 0.638926 -0.217240 0.096549 0.950317 0.462425 0.657012 0.428843 0.644083 0.794102 ... 0.753216 1.196260 0.441792 0.403308 0.242576 0.142840 0.726950 0.016395 1.217226 0.733595

23 rows × 41 columns

# still probability matrix from df only
pm.prob()
-20 -19 -18 -17 -16 -15 -14 -13 -12 -11 ... 11 12 13 14 15 16 17 18 19 20
aa
P 0.050061 0.048691 0.062349 0.055489 0.046988 0.054753 0.064787 0.055090 0.056683 0.048272 ... 0.052728 0.051140 0.069436 0.063164 0.057716 0.056639 0.051072 0.050697 0.052163 0.060703
G 0.080586 0.080341 0.069007 0.067551 0.082530 0.070397 0.093581 0.073054 0.077566 0.072706 ... 0.099939 0.070856 0.071916 0.075672 0.071518 0.064821 0.080076 0.088720 0.062341 0.090735
A 0.080586 0.080341 0.062954 0.054282 0.075301 0.071600 0.070186 0.070060 0.065632 0.070322 ... 0.064378 0.077634 0.069436 0.072545 0.063363 0.079924 0.088272 0.087452 0.057888 0.070927
C 0.017094 0.012781 0.013317 0.019903 0.012048 0.017449 0.007798 0.014371 0.013126 0.012515 ... 0.007357 0.017868 0.014879 0.012508 0.011920 0.018880 0.019546 0.014575 0.019084 0.014058
S 0.047619 0.035910 0.046610 0.030157 0.037349 0.042720 0.041992 0.041916 0.034010 0.039333 ... 0.024525 0.036352 0.047117 0.040025 0.042033 0.040277 0.039092 0.051965 0.041349 0.039617
T 0.039683 0.031041 0.046005 0.042220 0.029518 0.032491 0.037792 0.033533 0.031623 0.041716 ... 0.028817 0.035736 0.024799 0.040025 0.035132 0.041536 0.031526 0.029785 0.031807 0.036422
V 0.047009 0.057212 0.051453 0.075392 0.065060 0.048736 0.049790 0.059880 0.055489 0.049464 ... 0.061312 0.062230 0.050217 0.069418 0.063363 0.064821 0.050441 0.062104 0.048982 0.049840
I 0.046398 0.051735 0.044189 0.044632 0.053614 0.050542 0.050990 0.047904 0.038783 0.046484 ... 0.044758 0.050524 0.039678 0.058787 0.042660 0.041536 0.066835 0.044360 0.066794 0.053674
L 0.071429 0.088253 0.069007 0.085645 0.079518 0.077617 0.070186 0.080240 0.086516 0.076877 ... 0.072348 0.059150 0.083075 0.067542 0.065245 0.081183 0.073770 0.072877 0.105598 0.073482
M 0.028694 0.024954 0.029056 0.022316 0.021687 0.017449 0.028794 0.023353 0.015513 0.023242 ... 0.014102 0.014171 0.014259 0.021263 0.018821 0.011957 0.031526 0.025982 0.022901 0.031949
F 0.031136 0.032258 0.029056 0.052473 0.044578 0.034296 0.036593 0.029341 0.027446 0.032181 ... 0.027590 0.022797 0.037198 0.026892 0.043287 0.042794 0.031526 0.033587 0.033079 0.038339
Y 0.023199 0.014607 0.014528 0.014475 0.014458 0.013839 0.017397 0.022754 0.011933 0.017878 ... 0.014102 0.014171 0.019839 0.014384 0.013802 0.015733 0.015763 0.017744 0.017812 0.019169
W 0.006716 0.009738 0.009685 0.010253 0.006627 0.009627 0.010198 0.007186 0.007757 0.011323 ... 0.017167 0.007394 0.015499 0.006254 0.010038 0.011957 0.008827 0.010139 0.008270 0.007029
H 0.023199 0.018868 0.018765 0.015078 0.016265 0.022864 0.025795 0.018563 0.022076 0.014899 ... 0.019620 0.023413 0.025418 0.016260 0.025094 0.025802 0.013871 0.014575 0.013359 0.010224
K 0.089133 0.083993 0.076877 0.097105 0.083735 0.084838 0.091782 0.078443 0.106205 0.078069 ... 0.082771 0.094270 0.076255 0.076923 0.091593 0.067338 0.077554 0.057034 0.073791 0.081150
R 0.054945 0.064516 0.059322 0.047045 0.050000 0.051745 0.052789 0.053293 0.065036 0.081049 ... 0.065604 0.080099 0.058896 0.076923 0.057089 0.050975 0.054224 0.069708 0.055344 0.060064
Q 0.048840 0.040170 0.055085 0.032569 0.039759 0.057160 0.032993 0.048503 0.041169 0.040524 ... 0.041692 0.040049 0.038438 0.033771 0.045169 0.039018 0.040984 0.040558 0.045165 0.030671
N 0.039683 0.039562 0.042978 0.042823 0.037952 0.034296 0.036593 0.035928 0.040573 0.039333 ... 0.036787 0.047443 0.035338 0.037523 0.036386 0.039018 0.033417 0.032953 0.034351 0.033227
D 0.050672 0.056604 0.064165 0.059710 0.063855 0.075211 0.052190 0.067665 0.074582 0.061979 ... 0.075414 0.055453 0.063856 0.058787 0.064617 0.064821 0.062421 0.057034 0.076336 0.049201
E 0.067155 0.082775 0.093220 0.083836 0.078916 0.078821 0.077984 0.091617 0.078759 0.066746 ... 0.078479 0.079482 0.078115 0.066917 0.077164 0.075519 0.080076 0.074778 0.066794 0.086901
s 0.021368 0.021302 0.019370 0.022919 0.031928 0.024669 0.025195 0.029341 0.026850 0.033969 ... 0.031269 0.028959 0.033478 0.037523 0.039523 0.036501 0.022068 0.040558 0.035623 0.031310
t 0.018315 0.012781 0.015738 0.015078 0.014458 0.015042 0.011398 0.007186 0.009547 0.021454 ... 0.019620 0.011091 0.021699 0.015009 0.014429 0.019509 0.014502 0.014575 0.012087 0.015335
y 0.016484 0.011564 0.007264 0.009047 0.013855 0.013839 0.013197 0.010778 0.013126 0.019666 ... 0.019620 0.019717 0.011159 0.011882 0.010038 0.009440 0.012610 0.008238 0.019084 0.015974

23 rows × 41 columns

# background_pssm
# pm_lo.bg_prob()
pm.logo();

pm.logo_heatmap()