# Evolution of sequence, structure and dynamics with Evol and SignDy¶

This tutorial has two parts, focusing on two related parts of ProDy for studying evolution:

1. The sequence sub-package Evol is for fetching, parsing and refining multiple sequence alignments (MSAs), and calculating residue-level properties such as conservation and coevolution as well as sequence-level properties such as percentage identity.
1. The signature dynamics module SignDy calculates ENM normal modes for ensembles of related protein structures and evaluates the conservation and differentiation of signature dynamics across families and subfamilies. It also allows classification of ensemble/family members based upon their dynamics, allowing the evolution of protein dynamics to be compared with the evolution of sequence and structure.

We first make the required imports:

We also configure ProDy to put all the PDB files in a particular folder seeing as there are so many of them.

## 1. Sequence evolution with Evol¶

### Fetching, parsing and refining MSAs from Pfam¶

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:

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.

This alignment can be indexed to extract individual sequences (rows) and residue positions (columns):

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:

### Measuring sequence conservation with Shannon entropy¶

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

We can also show the Shannon entropy on a bar chart:

### Comparisons of sequence evolution and structural dynamics¶

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.

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.

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.

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.

We perform GNM analysis as follows:

We can then visually compare the behaviour at the individual residue level as follows:

### Coevolution Calculation¶

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:

We can improve this with the widely used average product correction:

We can change the colour scale normalisation to eliminate the effect of the diagonal. However, the mutual information matrix is still pretty noisy.

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:

If we compare the brighter regions on this map to the contact matrix then we see that they indeed match pretty well:

We can also apply a rank-ordering to the DI and corrected MI matrix entries, which helps identify the strongest signals: