This tutorial has two parts, focusing on two related parts of ProDy for studying evolution:
We first make the required imports:
from prody import *
from pylab import *
%matplotlib inline
confProDy(auto_show=False)
@> ProDy is configured: auto_show=False
We also configure ProDy to put all the PDB files in a particular folder seeing as there are so many of them.
pathPDBFolder('./pdbs/')
@> Local PDB folder is set: '/Users/bentley/Dropbox/Pitt/Bahar/MMBioS/2021/notebooks/pdbs' @> A plain folder structure will be assumed.
The protein families database Pfam provides multiple sequence alignments of related protein domains, which we are often used as starting points for sequence evolution analyses. We can fetch such MSAs using the function fetchPfamMSA
as follows:
filename = fetchPfamMSA('PF00074')
filename
@> Pfam MSA for PF00074 is written as PF00074_full.sth.
'PF00074_full.sth'
We can then parse the MSA into ProDy using the parseMSA
function, which can handle various types of MSA files including Stockholm, SELEX, CLUSTAL, PIR and FASTA formats.
msa = parseMSA(filename)
msa
@> 1494 sequence(s) with 348 residues were parsed in 0.01s.
<MSA: PF00074_full (1494 sequences, 348 residues)>
This alignment can be indexed to extract individual sequences (rows) and residue positions (columns):
msa[:10,:10]
<MSA: PF00074_full (10 sequences, 10 residues)>
seq0 = msa[0]
seq0
<Sequence: G1ST62_RABIT (PF00074_full[0]; length 348; 119 residues and 229 gaps)>
str(seq0)
'..................................TKARWFEIQHIQP.NL.L.Q.---....--C...NR.AM..RG.V.NN......YT.........Q........HC..KP..FNTFL.H.D.........S.F......QD...V............AAV.....C...DF........P.N...V.TC....R........NG..RHNC....HQS....PK..PINMTNCRLT......-AGK..YP....D..CS..Y..S.D.A..T........Q.Y..K.F..FIV..A.CDpp.qkSDPP..YHLVPVHLD..........................'
This alignment contains many redundant sequences as well as lots of rows and columns with large numbers of gaps. Therefore, we refine it using refineMSA
, which we can do based on the sequence of RNAS1_BOVIN:
msa_refined = refineMSA(msa, label='RNAS1_BOVIN', rowocc=0.8, seqid=0.98)
msa_refined
@> Label refinement reduced number of columns from 348 to 119 in 0.00s. @> Row occupancy refinement reduced number of rows from 1494 to 1314 in 0.00s. @> Sequence identity refinement reduced number of rows from 1314 to 1054 in 0.28s.
<MSA: PF00074_full refined (label=RNAS1_BOVIN, rowocc>=0.8, seqid>=0.98) (1054 sequences, 119 residues)>
We calculate use calcShannonEntropy
to calculate the entropy of the refined MSA, which is a measure of sequence variability.
Shannon's entropy measures the degree of uncertainty that exists in a system. In the case of multiple sequence alignments, the Shannon entropy of each protein site (column) can be computed according to:
$$H(p_1, p_2, \ldots, p_n) = -\sum_{i=1}^n p_i \log_2 p_i $$where $p_i$ is the frequency of amino acid $i$ in that site. If a column is completely conserved then Shannon entropy is 0. The maximum variability, where each amino acid occurs with frequency 1/20, yields an entropy of 4.32
entropy = calcShannonEntropy(msa_refined)
We can also show the Shannon entropy on a bar chart:
showShannonEntropy(msa_refined);
@> Label L5K5X3_PTEAL start-end entry matches length of ungapped sequence. Setting resnums 31 to 149
Next, we obtain residue fluctuations or mobility for a protein member of the above family using the GNM.
We will use chain B of PDB structure 2W5I, which corresponds to our reference sequence RNAS1_BOVIN.
ag = parsePDB('2W5I', chain='B')
ag
@> Connecting wwPDB FTP server RCSB PDB (USA). @> 2w5i downloaded (2w5i.pdb.gz) @> PDB download via FTP completed (1 downloaded, 0 failed). @> 973 atoms and 1 coordinate set(s) were parsed in 0.05s. @> Secondary structures were assigned to 75 residues.
<AtomGroup: 2W5IB (973 atoms)>
The next step is to select the corresponding residues from the AtomGroup to match the sequence alignment. We can identify these using alignSequenceToMSA
. We give it the Calpha atoms only so the residue numbers aren't repeated.
aln, idx_1, idx_2 = alignSequenceToMSA(ag.ca, msa_refined, label='RNAS1_BOVIN')
showAlignment(aln, indices=[idx_1, idx_2])
20 30 40 50 60 2W5IB KETAAAKFERQHMDSSTSAASSSNYCNQMMKSRNLTKDRCKPVNTFVHESLADVQAVCSQ 18 28 38 48 58 RNAS1_BOVIN --TAAAKFERQHMDSSTSAASSSNYCNQMMKSRNLTKDRCKPVNTFVHESLADVQAVCSQ 70 80 90 100 110 120 2W5IB KNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHF 68 78 88 98 108 118 RNAS1_BOVIN KNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHF 2W5IB DASV RNAS1_BOVIN D---
We see that there are extra residues in the PDB sequence compared to the reference sequence so we identify their residue numbers to make a selection.
print(ag.ca.getResnums())
[ 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]
They are numbered from 1 to 124, two residues are missing from the beginning, and three residues are missing from the end, so we select residues 3 to 121. This now makes the two sequences match.
chB = ag.select('resid 3 to 121')
chB
<Selection: 'resid 3 to 121' from 2W5IB (879 atoms)>
print(msa_refined['RNAS1_BOVIN'])
print(chB.ca.getSequence())
tAAAKFERQHMDSSTSAASSsNYCNQMMKSRNLTKDRCKPVNTFVHESLADVQAVCSQKNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHFD TAAAKFERQHMDSSTSAASSSNYCNQMMKSRNLTKDRCKPVNTFVHESLADVQAVCSQKNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHFD
We perform GNM analysis as follows:
gnm = GNM('2W5I')
gnm.buildKirchhoff(chB.ca)
gnm.calcModes(n_modes=None) # calculate all modes
@> Kirchhoff was built in 0.01s. @> 118 modes were calculated in 0.00s.
We can then visually compare the behaviour at the individual residue level as follows:
mobility = calcSqFlucts(gnm)
figure(figsize=(13,6))
# plot entropy as grey bars
bar(chB.ca.getResnums(), entropy, width=1.2, color='grey', label='entropy');
# rescale mobility
mobility = mobility*(max(entropy)/max(mobility))
# plot mobility as a blue line
showAtomicLines(mobility, atoms=chB.ca, color='b', linewidth=2, label='mobility');
legend()
<matplotlib.legend.Legend at 0x7f42fc6c1940>
In addition to the conservation/variation of individual positions, we can also calculate the coevolution between positions due to correlated mutations.
One simple and common method for this is to compute the mutual information between the columns in the MSA:
mutinfo = buildMutinfoMatrix(msa_refined)
@> Mutual information matrix was calculated in 0.04s.
showMutinfoMatrix(msa_refined, cmap='inferno');
title(None);
@> Mutual information matrix was calculated in 0.04s. @> Label L5K5X3_PTEAL start-end entry matches length of ungapped sequence. Setting resnums 31 to 149
We can improve this with the widely used average product correction:
mi_apc = applyMutinfoCorr(mutinfo)
showMatrix(mi_apc, cmap='inferno');
We can change the colour scale normalisation to eliminate the effect of the diagonal. However, the mutual information matrix is still pretty noisy.
showMatrix(mi_apc, cmap='inferno', norm=Normalize(0, 0.5));
Therefore, more sophisticated analyses have also been developed including the Direct Information (DI; also known as direct coupling analysis (DCA), which is very successful for contact prediction. This method can also be used in ProDy as follows:
di = buildDirectInfoMatrix(msa_refined)
@> DI matrix was calculated in 0.73s.
showDirectInfoMatrix(msa_refined, cmap='inferno');
title(None);
@> DI matrix was calculated in 0.70s. @> Label L5K5X3_PTEAL start-end entry matches length of ungapped sequence. Setting resnums 31 to 149
If we compare the brighter regions on this map to the contact matrix then we see that they indeed match pretty well:
showContactMap(gnm, origin='lower', cmap='Greys');
We can also apply a rank-ordering to the DI and corrected MI matrix entries, which helps identify the strongest signals:
di_rank_row, di_rank_col, di_zscore_sort = calcRankorder(di, zscore=True)
print('row: ', di_rank_row[:5])
print('column:', di_rank_col[:5])
@> Zscore normalization has been applied. @> Matrix is symmetric, only lower triangle indices will be returned.
row: [ 79 92 64 69 110] column: [ 45 37 63 62 109]
mi_rank_row, mi_rank_col, mi_zscore_sort = calcRankorder(mi_apc, zscore=True)
print('row: ', mi_rank_row[:5])
print('column:', mi_rank_col[:5])
@> Zscore normalization has been applied. @> Matrix is symmetric, only lower triangle indices will be returned.
row: [ 79 115 69 111 92] column: [ 45 114 62 110 37]
This tutorial describes how to calculate signature dynamics for a family of proteins with similar structures using Elastic Network Models (ENMs). This method (also called ensemble normal mode analysis) creates an ensemble of aligned structures and calculates statistics such as means and standard deviations on various dynamic properties including mode profiles, mean square fluctuations and cross-correlation matrices. It also includes tools for classifying family members based on their sequence, structure and dynamics.
The theory and usage of this toolkit is described in our recent paper:
Zhang S, Li H, Krieger J, Bahar I. Shared signature dynamics tempered by local fluctuations enables fold adaptability and specificity. Mol. Biol. Evol. 2019 36(9):2053–2068
In this tutorial, we will have a quick walk-through on the SignDy calculations and functions using the example of type-I periplasmic binding protein (PBP-I) domains. The data is collected using the Dali server (http://ekhidna2.biocenter.helsinki.fi/dali/).
Holm L, Rosenström P. Dali server: conservation mapping in 3D. Nucleic Acids Res. 2010 10(38):W545-9
In addition to the previous imports, we also import time so that we can use the sleep
function to reduce the load on the Dali server.
import time
The first step in signature dynamics analysis is to collect a set of related protein structures and build a PDBEnsemble
. This can be achieved by multiple routes: a query search of the PDB using blastPDB
or Dali, extraction of PDB IDs from the Pfam database (as above) or the CATH database, or input of a pre-defined list.
We demonstrate the Dali method here in the first part of the tutorial. The usage of CATH methods is described in the website tutorial and the function blastPDB
is described in the Structure Analysis Tutorial.
We apply these methods to the PBP-I domains, a group of protein structures originally found in bacteria for transport of solutes across the periplasmic space and later seen in various eukaryotic receptors including ionotropic and metabotropic glutamate receptors. We use the N-terminal domain of AMPA receptor subunit GluA2 (gene name GRIA2; https://www.uniprot.org/uniprot/P42262) as a query.
The second step is then to calculate ENM normal modes for all members of the PDBEnsemble
, creating a ModeEnsemble
. We usually use the GNM for this as will be shown here, but the ANM can be used too.
The third step is then to analyse conserved and divergent behaviours to identify signature dynamics of the whole family or individual subfamilies. This is aided calculations of overlaps and distances between the mode spectra (step 4), which can be used to create phylogenetic trees that can be compared to sequence and structural conservation and divergence.
First we use the function searchDali
to search the PDB with Dali, which returns a DaliRecord
object that contains a list of PDB IDs and their corresponding mappings to the reference structure.
dali_rec = searchDali('3H5V','A')
dali_rec
@> Submitted Dali search for PDB "3H5VA". @> http://ekhidna2.biocenter.helsinki.fi/barcosel/tmp//3H5VA/ @> Dali results were fetched in 0.3s. @> Obtained 3692 PDB chains from Dali for 3H5VA.
<prody.database.dali.DaliRecord at 0x7f819fd2bac0>
The Dali search often remains in the queue longer than the timeout time. We therefore have a fetch
method, which can be run later to fetch the data. We can run this in a loop with a wait of a couple of minutes in between fetches to make sure we get the result.
while not dali_rec.isSuccess:
dali_rec.fetch()
time.sleep(120)
dali_rec
<prody.database.dali.DaliRecord at 0x7f819fd2bac0>
Next, we get the lists of PDB IDs and mappings from dali_rec, and parse the pdb_ids to get a list of AtomGroup
instances:
pdb_ids = dali_rec.filter(cutoff_len=0.7, cutoff_rmsd=1.0, cutoff_Z=30)
@> 3526 PDBs have been filtered out from 3692 Dali hits (remaining: 166).
mappings = dali_rec.getMappings()
ags = parsePDB(pdb_ids, subset='ca')
len(ags)
@> 166 PDBs were parsed in 22.18s.
166
Then we provide ags together with mappings to buildPDBEnsemble
. We set the keyword argument seqid=20
to account for the low sequence identity between some of the structures.
dali_ens = buildPDBEnsemble(ags, mapping=mappings, seqid=20, labels=pdb_ids)
dali_ens
@> Mapping 5l1fB_ca to the reference... [ 0%]@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u5cB_ca to the reference... [ 1%]@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5l1eB_ca to the reference... [ 1%]@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5l1hB_ca to the reference... [ 2%]@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5l1gB_ca to the reference... [ 3%] 22s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u1wD_ca to the reference... [ 4%] 22s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6ruqD_ca to the reference... [ 4%] 22s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6xsrB_ca to the reference... [ 5%] 21s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5welD_ca to the reference... [ 6%] 20s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5welB_ca to the reference... [ 6%] 20s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5welC_ca to the reference... [ 7%] 20s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5welA_ca to the reference... [ 7%] 22s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5wenB_ca to the reference... [ 9%] 20s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5wenC_ca to the reference... [ 10%] 19s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5wenD_ca to the reference... [ 10%] 19s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5wenA_ca to the reference... [ 11%] 19s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u2pA_ca to the reference... [ 14%] 19s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u1xA_ca to the reference... [ 15%] 19s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u1yA_ca to the reference... [ 19%] 16s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dlzD_ca to the reference... [ 22%] 15s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dlzC_ca to the reference... [ 22%] 15s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6o9gA_ca to the reference... [ 23%] 15s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm2A_ca to the reference... [ 24%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm2C_ca to the reference... [ 24%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm0B_ca to the reference... [ 25%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6o9gD_ca to the reference... [ 25%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6o9gC_ca to the reference... [ 26%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm1A_ca to the reference... [ 27%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm0C_ca to the reference... [ 27%] 14s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm0D_ca to the reference... [ 28%] 13s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u1xD_ca to the reference... [ 28%] 13s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dlzA_ca to the reference... [ 32%] 13s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4u1xB_ca to the reference... [ 37%] 12s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njmA_ca to the reference... [ 38%] 12s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njnC_ca to the reference... [ 39%] 12s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njmC_ca to the reference... [ 39%] 12s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ocaA_ca to the reference... [ 43%] 11s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7lddC_ca to the reference... [ 45%] 11s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7lddA_ca to the reference... [ 46%] 11s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm1B_ca to the reference... [ 47%] 11s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm1D_ca to the reference... [ 48%] 11s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ldeC_ca to the reference... [ 48%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njlC_ca to the reference... [ 50%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njlA_ca to the reference... [ 50%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ldeA_ca to the reference... [ 51%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6njnA_ca to the reference... [ 51%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dlzB_ca to the reference... [ 52%] 10s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ocaC_ca to the reference... [ 53%] 9s @> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm2D_ca to the reference... [ 53%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5weoC_ca to the reference... [ 54%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks0B_ca to the reference... [ 54%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks0D_ca to the reference... [ 55%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks3B_ca to the reference... [ 56%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks3D_ca to the reference... [ 56%] 9s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4uqqD_ca to the reference... [ 59%] 8s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 4uqqB_ca to the reference... [ 59%] 8s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5weoA_ca to the reference... [ 66%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5ideD_ca to the reference... [ 67%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5kufC_ca to the reference... [ 68%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5kufA_ca to the reference... [ 69%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6qkzC_ca to the reference... [ 69%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks3C_ca to the reference... [ 70%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks0C_ca to the reference... [ 71%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks0A_ca to the reference... [ 72%] 6s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 7ks3A_ca to the reference... [ 73%] 5s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6qkzA_ca to the reference... [ 75%] 5s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5ideB_ca to the reference... [ 76%] 5s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6jfyD_ca to the reference... [ 80%] 4s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm1C_ca to the reference... [ 81%] 4s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5idfB_ca to the reference... [ 83%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5idfD_ca to the reference... [ 83%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6jfyA_ca to the reference... [ 84%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5weoB_ca to the reference... [ 84%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5weoD_ca to the reference... [ 85%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm0A_ca to the reference... [ 86%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6l6fA_ca to the reference... [ 87%] 3s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6l6fC_ca to the reference... [ 88%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5kuhD_ca to the reference... [ 89%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6dm2B_ca to the reference... [ 89%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6o9gB_ca to the reference... [ 90%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5l2eA_ca to the reference... [ 90%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6lu9A_ca to the reference... [ 91%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6l6fB_ca to the reference... [ 92%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5l2eB_ca to the reference... [ 93%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6kzmA_ca to the reference... [ 93%] 2s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6jfzD_ca to the reference... [ 94%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6kzmB_ca to the reference... [ 95%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5kc9A_ca to the reference... [ 95%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6jfzA_ca to the reference... [ 96%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6kzmC_ca to the reference... [ 96%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 3td9A_ca to the reference... [ 97%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6jfzB_ca to the reference... [ 98%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 6lu9D_ca to the reference... [ 98%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Mapping 5kc9B_ca to the reference... [ 99%] 1s@> WARNING no atommaps were available. Consider adjusting accepting criteria @> Starting iterative superposition: @> Step #1: RMSD difference = 1.2288e+00 @> Step #2: RMSD difference = 1.0616e-02 @> Step #3: RMSD difference = 2.5476e-04 @> Step #4: RMSD difference = 7.5375e-06 @> Iterative superposition completed in 0.15s. @> Final superposition to calculate transformations. @> Superposition completed in 0.03 seconds. @> Ensemble (72 conformations) were built in 16.62s. @> WARNING 94 structures cannot be mapped.
<PDBEnsemble: Unknown (72 conformations; 376 atoms)>
Finally, we save the ensemble for later processing:
saveEnsemble(dali_ens, 'PBP-I')
'PBP-I.ens.npz'
For this analysis we'll build a ModeEnsemble
by calculating normal modes for each member of the PDBEnsemble
.
You can load a PDB ensemble at this stage if you already have one. We demonstrate this for the one we just saved.
dali_ens = loadEnsemble('PBP-I.ens.npz')
Then we calculate GNM
modes for each member of the ensemble using calcEnsembleENMs
. There are options to select the model (GNM
by default) and the way of considering non-aligned residues by setting the trim option (default is reduceModel
, which treats them as environment).
gnms = calcEnsembleENMs(dali_ens, model='GNM', trim='reduce')
gnms
@> 20 GNM modes were calculated for each of the 72 conformations in 6.14s. @> 20 modes across 72 modesets were matched in 0.51s.
<ModeEnsemble: 72 modesets (20 modes, 376 atoms)>
We can save the mode ensemble as follows:
saveModeEnsemble(gnms, 'PBP-I')
/Users/bentley/opt/anaconda3/envs/workshop21/lib/python3.8/site-packages/numpy/core/_asarray.py:171: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. return array(a, dtype, copy=False, order=order, subok=True)
'PBP-I.modeens.npz'
We can also load in a previously saved mode ensemble such as the one we saved above:
gnms = loadModeEnsemble('PBP-I.modeens.npz')
We can index the ModeEnsemble
object in two different dimensions. The first dimension corresponds to ensemble members as shown below for extracting the mode set for the first member (numbered 0).
gnms[0]
<ModeSet: 20 modes from MaskedGNM 3h5vA reduced>
The second dimension corresponds to particular modes of all ensemble members as shown below for extracting the first mode (numbered 0). The colon means we select everything from the first dimension.
gnms[:,0]
<ModeEnsemble: 72 modesets (1 mode, 376 atoms)>
We can also slice out ranges of members and modes and index them both at the same time. E.g. to get the five members from 5 up to but not including 10 (5, 6, 7, 8, 9), and the two modes from 2 up to but not including 4 (modes with indices 2 and 3 in the reference), we'd use the following code.
gnms[5:10,2:4]
<ModeEnsemble: 5 modesets (2 modes, 376 atoms)>
We can also use indexing to extract individual modes from individual members, e.g.
gnms[5,2]
<Mode: 3 from MaskedGNM 2wjxB reduced>
Remember that we usually talk about modes counting from 1 so this is "Mode 3" or "the 3rd global mode" in conversation but Python counts from 0 so it has index 2. Likewise this is the "6th member" of the ensemble but has index 5.
Signatures are calculated as the mean and standard deviation of various properties such as mode shapes and mean square fluctations.
For example, we can show the average and standard deviation of the shape of the first mode (second index 0). The first index of the mode ensemble is over conformations.
showSignatureMode(gnms[:, 0]);
We can also show such results for properties involving multiple modes such as the mean square fluctuations from the first 5 modes or the cross-correlations from the first 20.
showSignatureSqFlucts(gnms[:, :5]);
showSignatureCrossCorr(gnms[:, :20]);
We can also look at distributions over values across different members of the ensemble such as inverse eigenvalue. We can show a bar above this with individual members labelled like in
Krieger J, Bahar I, Greger IH. Structure, Dynamics, and Allosteric Potential of Ionotropic Glutamate Receptor N-Terminal Domains. Biophys. J. 2015 109(6):1136-48.
In this automated version, the bar is coloured from white to dark red depending on how many structures have values at that point.
We can select particular members to highlight with arrows by putting their names and labels in a dictionary:
highlights = {'3h5vA': 'GluA2','3o21C': 'GluA3',
'3h6gA': 'GluK2', '3olzA': 'GluK3',
'5kc8A': 'GluD2'}
We plot the variance bar for the first five modes (showing a function of the inverse eigenvalues related to the resultant relative size of motion) above the inverse eigenvalue distributions for each of those modes. To arrange the plots like this, we use the GridSpec
function of Matplotlib.
gs = GridSpec(ncols=1, nrows=2, height_ratios=[1, 10], hspace=0.15)
subplot(gs[0]);
showVarianceBar(gnms[:, :5], fraction=True, highlights=highlights);
xlabel('');
subplot(gs[1]);
showSignatureVariances(gnms[:, :5], fraction=True, bins=80, alpha=0.7);
xlabel('Fraction of inverse eigenvalue');
We can also extract the eigenvalues and eigenvectors directly from the mode ensemble and analyse them ourselves:
eigvals = gnms.getEigvals()
eigvals
sdarray([[0.40332629, 1.09698756, 1.4466639 , ..., 5.30924955, 5.5792069 , 5.77873354], [0.41578566, 1.12906523, 1.4632766 , ..., 5.77565607, 5.03060667, 5.65945268], [0.41366158, 1.07931586, 1.40302256, ..., 5.60784667, 4.76928731, 5.0126084 ], ..., [0.39875231, 1.14861099, 1.58945168, ..., 5.73761851, 5.68069539, 4.8536725 ], [0.39875231, 1.14861099, 1.58945168, ..., 5.73761851, 5.68069539, 4.8536725 ], [0.2452986 , 1.20065343, 1.38619425, ..., 5.01755708, 4.66115699, 4.26878977]])
eigvecs = gnms.getEigvecs()
eigvecs
sdarray([[[ 6.32823556e-02, -2.50192899e-02, 2.24757152e-02, ..., -2.75806462e-02, -2.91342858e-02, 2.35751313e-02], [ 6.14399172e-02, -2.55671762e-02, 1.82215962e-02, ..., 2.37048870e-02, 1.30948891e-02, 8.00770496e-03], [ 6.03893156e-02, -2.75289674e-02, 1.47023932e-02, ..., 6.27873120e-02, 4.50426791e-02, 7.48137751e-04], ..., [-3.45674867e-02, 5.36219952e-02, -8.18341574e-02, ..., 3.73431044e-03, -1.56226528e-02, 1.48147066e-02], [-3.58459460e-02, 5.83491556e-02, -8.68632869e-02, ..., 2.19044923e-04, -9.12061694e-03, 1.77561547e-02], [-3.86893737e-02, 6.78185627e-02, -1.09283894e-01, ..., -1.24293912e-01, 1.19842480e-01, -9.65913188e-02]], [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 6.26195354e-02, -1.86306909e-02, 3.54198419e-02, ..., 1.59074752e-02, -8.08406848e-02, 9.26191303e-02], [ 6.11619603e-02, -2.55164251e-02, 2.48636956e-02, ..., 9.21467324e-03, -1.63478462e-02, 2.82806029e-02], ..., [-3.31550817e-02, 6.14823652e-02, -7.99846405e-02, ..., 1.21072250e-02, 6.91858700e-03, 1.36501602e-02], [-3.57119564e-02, 7.24766520e-02, -8.70849570e-02, ..., 1.18748882e-02, 2.68064801e-03, 1.22261092e-02], [-3.81538579e-02, 7.88324088e-02, -9.40577127e-02, ..., 3.94138736e-02, -1.95224061e-02, -1.18914659e-01]], [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 6.15555711e-02, -2.36075312e-02, 1.92856007e-02, ..., -2.63711302e-01, 1.22835729e-01, 2.75585842e-02], [ 6.04578725e-02, -2.51940333e-02, 1.60829014e-02, ..., -1.71820640e-01, 1.07845661e-01, 2.16192703e-02], ..., [-3.58438460e-02, 5.72745098e-02, -8.14492120e-02, ..., -1.02361513e-01, -5.60937869e-02, 2.25927650e-02], [-3.55754360e-02, 6.12920488e-02, -8.20429364e-02, ..., -1.58671436e-01, -8.33516387e-02, 4.64514413e-02], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]], ..., [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 6.26386283e-02, -2.51539903e-02, 4.06441675e-02, ..., 1.24556612e-02, 9.82507745e-03, 1.48376078e-02], [ 6.10332991e-02, -2.65226588e-02, 3.23235560e-02, ..., 5.70342641e-02, 9.77598491e-03, -7.11702459e-03], ..., [-3.48534987e-02, 4.07979825e-02, -1.02628475e-01, ..., 6.61577028e-02, -4.15615160e-02, 8.79296801e-03], [-3.75181948e-02, 4.30152469e-02, -1.02249201e-01, ..., 1.17856437e-01, -8.80188732e-02, 1.60250778e-02], [-3.79952007e-02, 4.69015048e-02, -1.00454973e-01, ..., 2.30500578e-01, -1.89173790e-01, 2.17667557e-02]], [[ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00], [ 6.26386283e-02, -2.51539903e-02, 4.06441675e-02, ..., 1.24556612e-02, 9.82507745e-03, 1.48376078e-02], [ 6.10332991e-02, -2.65226588e-02, 3.23235560e-02, ..., 5.70342641e-02, 9.77598491e-03, -7.11702459e-03], ..., [-3.48534987e-02, 4.07979825e-02, -1.02628475e-01, ..., 6.61577028e-02, -4.15615160e-02, 8.79296801e-03], [-3.75181948e-02, 4.30152469e-02, -1.02249201e-01, ..., 1.17856437e-01, -8.80188732e-02, 1.60250778e-02], [-3.79952007e-02, 4.69015048e-02, -1.00454973e-01, ..., 2.30500578e-01, -1.89173790e-01, 2.17667557e-02]], [[ 5.92625164e-02, -3.80092028e-02, 1.93696992e-02, ..., -7.64038869e-02, -1.55296361e-01, 1.32080734e-02], [ 5.72439285e-02, -3.23813691e-02, 1.48363404e-02, ..., -7.49500731e-03, -3.14121577e-02, 6.55554064e-03], [ 5.69656645e-02, -3.84836647e-02, 9.37921915e-03, ..., 6.39603068e-03, -1.44156127e-02, 1.06056943e-02], ..., [-4.53609827e-02, 5.74638427e-02, -6.49376830e-02, ..., 4.50234609e-02, 1.17368081e-01, 1.22103313e-01], [-4.74569814e-02, 5.74899067e-02, -8.26159133e-02, ..., 4.63149439e-02, 1.29226536e-01, 1.18899247e-01], [ 0.00000000e+00, 0.00000000e+00, 0.00000000e+00, ..., 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]]]) weights= array([[[1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.]], [[0., 0., 0., ..., 0., 0., 0.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.]], [[0., 0., 0., ..., 0., 0., 0.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [0., 0., 0., ..., 0., 0., 0.]], ..., [[0., 0., 0., ..., 0., 0., 0.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.]], [[0., 0., 0., ..., 0., 0., 0.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.]], [[1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], ..., [1., 1., 1., ..., 1., 1., 1.], [1., 1., 1., ..., 1., 1., 1.], [0., 0., 0., ..., 0., 0., 0.]]])
These are stored in instances of the sdarray
class that we designed specifically for signature dynamics analysis. It is an extension of the standard NumPy ndarray
but has additional attributes and some modified methods. The first axis is reserved for ensemble members and the mean, min, max and std are altered to average over this dimension rather than all dimensions.
We can look at the shape of these arrays and index them just like ndarray
and ModeEnsemble
objects. The eigenvalues are arranged in eigvals such that the first axis is the members and the second is the modes as in the mode ensemble.
eigvals.shape
(72, 20)
eigvals[0:5,0:5]
sdarray([[0.40332629, 1.09698756, 1.4466639 , 1.73630206, 1.99349677], [0.41578566, 1.12906523, 1.4632766 , 1.93509855, 1.91409476], [0.41366158, 1.07931586, 1.40302256, 1.77505326, 1.83721084], [0.38353231, 1.09438353, 1.43541322, 1.86532372, 1.838075 ], [0.42414171, 1.08373853, 1.42553784, 1.79322051, 1.84047078]])
The eigenvectors are arranged in eigvecs such that the first axis is over the members, and the remaining dimensions are as in other eigenvector arrays - the second is over atoms and the third is mode index. Each atom has a weight, which varies between members and is important in calculating the mean, std, etc.
eigvecs.shape
(72, 376, 20)
Spectral overlap, also known as covariance overlap, measures the overlap between two covariance matrices, or the overlap of a subset of the modes (a mode spectrum). This can also be converted into a distance using its arccosine as will be shown below.
We can calculate a matrix of spectral overlaps (so_matrix) over any slice of the ModeEnsemble that is still a mode ensemble itself, e.g.
so_matrix = calcEnsembleSpectralOverlaps(gnms[:, :1])
figure(figsize=(8,8))
showMatrix(so_matrix);
We can also obtain a spectral distance matrix (sd_matrix) from calcEnsembleSpectralOverlaps
by giving it an additional argument:
sd_matrix = calcEnsembleSpectralOverlaps(gnms[:, :1], distance=True)
figure(figsize=(8,8)); showMatrix(sd_matrix);
We can then use this distance to calculate a tree. The labels from the mode ensemble as used as names for the leaves of the tree and are stored in their own variable/object for later use.
labels = dali_ens.getLabels()
so_tree = calcTree(names=labels, distance_matrix=sd_matrix, method='upgma')
We can show this tree using the function showTree
:
showTree(so_tree);
We can also use this tree to reorder the so_matrix and obtain indices for reordering other objects:
reordered_so, new_so_indices = reorderMatrix(names=labels, matrix=so_matrix, tree=so_tree)
figure(figsize=(8,8))
showMatrix(reordered_so, ticklabels=new_so_indices);
As in the tree, we see 2-3 clusters with some finer structure within them as in the tree. These correspond to different subtypes of iGluRs called AMPA receptors (subunit paralogues GluA1-4, top) and kainate receptors (subunit paralogues GluK1-5, bottom) based on their preferred agonists as well as delta receptors at the bottom (these are flipped relative to the tree).
To show the matrix in the same order as the tree, we can add the option origin='upper'
:
figure(figsize=(8,8))
showMatrix(reordered_so, ticklabels=new_so_indices, origin='upper');
We can also show the tree along the y-axis of the matrix as follows:
figure(figsize=(11,8))
showMatrix(reordered_so, ticklabels=new_so_indices, origin='upper',
y_array=so_tree);
We can also use the resulting indices to reorder the ModeEnsemble
and PDBEnsemble
:
so_reordered_ens = dali_ens[new_so_indices]
so_reordered_gnms = gnms[new_so_indices, :]
Lists can only be used for indexing arrays not lists so we need to perform a type conversion prior to indexing in order to reorder the labels:
so_reordered_labels = np.array(labels)[new_so_indices]
The sequence distance is given by the (normalized) Hamming distance, which is calculated by subtracting the percentage identity (fraction) from 1, and the structural distance is the RMSD. We can also calculate and show the matrices and trees for these from the PDB ensemble.
First we calculate the sequence distance matrix:
seqid_matrix = buildSeqidMatrix(so_reordered_ens.getMSA())
seqdist_matrix = 1. - seqid_matrix
@> Sequence identity matrix was calculated in 0.01s.
figure(figsize=(8,8));
showMatrix(seqdist_matrix);
We can also construct a tree based on seqdist_matrix and use that to reorder it:
seqdist_tree = calcTree(names=so_reordered_labels, distance_matrix=seqdist_matrix, method='upgma')
showTree(seqdist_tree);
We can reorder seqdist_matrix with seqdist_tree as we did above with so_tree:
reordered_seqdist_seqdist, new_seqdist_indices = reorderMatrix(names=so_reordered_labels,
matrix=seqdist_matrix, tree=seqdist_tree)
figure(figsize=(8,8));
showMatrix(reordered_seqdist_seqdist, ticklabels=new_seqdist_indices);
This shows us even clearer groups than the dynamic spectrum-based analysis. We see one subunit by itself at the bottom that is from a delta-type iGluR (GluD2), then two groups of kainate receptors (GluK5 and GluK2 with GluK3), and four groups of AMPARs (GluA1, GluA2, GluA4, and many structures from GluA3).
Similarily, once we obtain the RMSD matrix and tree using the getRMSDs
method of the PDBEnsemble
, we
can calculate the structure-based tree:
rmsd_matrix = so_reordered_ens.getRMSDs(pairwise=True)
figure(figsize=(8,8)); showMatrix(rmsd_matrix);
prody.__version__
'2.0'
rmsd_tree = calcTree(names=so_reordered_labels,
distance_matrix=rmsd_matrix,
method='upgma')
It could be of interest to put all three trees constructed based on different
distance metrics side by side and compare them. We can do this using the subplot
function from Matplotlib.
figure(figsize=(20,8));
subplot(1, 3, 1);
showTree(seqdist_tree, format='plt');
title('Sequence');
subplot(1, 3, 2);
showTree(rmsd_tree, format='plt');
title('Structure');
subplot(1, 3, 3);
showTree(so_tree, format='plt');
title('Dynamics');
Likewise, we can place the matrices side-by-side after having them all reordered the same way. We'll reorder by seqdist in this example:
reordered_rmsd_seqdist, new_seqdist_indices = reorderMatrix(names=so_reordered_labels,
matrix=rmsd_matrix, tree=seqdist_tree)
reordered_sd_seqdist, new_seqdist_indices = reorderMatrix(names=so_reordered_labels,
matrix=sd_matrix, tree=seqdist_tree)
figure(figsize=(20,8));
subplot(1, 3, 1);
showMatrix(reordered_seqdist_seqdist, ticklabels=new_seqdist_indices, origin='upper');
title('Sequence');
subplot(1, 3, 2);
showMatrix(reordered_rmsd_seqdist, ticklabels=new_seqdist_indices, origin='upper');
title('Structure');
subplot(1, 3, 3);
showMatrix(reordered_sd_seqdist, ticklabels=new_seqdist_indices, origin='upper');
title('Dynamics');
This analysis is quite sensitive to how many modes are used. As the number of modes approaches the full number, the dynamic distance order approaches the RMSD order. With smaller numbers, we see finer distinctions and there is a point where the dynamic distances are more in line with the sequence distances, which we call the low-to-intermediate frequency regime. In the current case where we used just one global mode (with the lowest frequency), we see small spectral distances but some subfamily differentiation is still apparent.
The same analysis could also be performed with a larger ensemble by selecting lower sequence identity and Z-score cutoffs as we did in our paper.
Now we have finished this tutorial, we reset the default path to the PDB folder, so that we aren't surprised next time we download PDBs and can't find them:
pathPDBFolder('')
@> PDB folder '/Users/bentley/Dropbox/Pitt/Bahar/MMBioS/2021/notebooks/pdbs' is released.
pathPDBFolder?
pathPDBFolder()