# Sequence-Structure Comparison¶

The part shows how to compare sequence conservation properties with structural mobility obtained from Gaussian network model (GNM) calculations.

```In : from prody import *

In : from matplotlib.pylab import *

In : ion()  # turn interactive mode on
```

## Entropy Calculation¶

First, we retrieve MSA for protein for protein family PF00074:

```In : fetchPfamMSA('PF00074')
Out: 'PF00074_full.sth'
```

We parse the MSA file:

```In : msa = parseMSA('PF00074_full.sth')
```

Then, we refine it using `refineMSA()` based on the sequence of RNAS1_BOVIN:

```In : msa_refine = refineMSA(msa, label='RNAS1_BOVIN', seqid=0.98)
```

We calculate the entropy for the refined MSA:

```In : entropy = calcShannonEntropy(msa_refine)
```

## Mobility Calculation¶

Next, we obtain residue fluctuations or mobility for protein member of the above family. We will use chain B of 2W5I.

```In : pdb = parsePDB('2W5I', chain='B')
```

We can use the function `alignSequenceToMSA()` to identify the part of the PDB file that matches with the MSA. In cases where this fails, a label keyword argument can be provided to the function as well.

```In : aln, idx_1, idx_2 = alignSequenceToMSA(pdb, msa_refine, label='RNAS1_BOVIN')

In : showAlignment(aln, indices=[idx_1, idx_2])

20        30        40        50        60

18        28        38        48        58

70        80        90       100       110       120
2W5IB          	KNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHF

68        78        88        98       108       118
RNAS1_BOVIN    	KNVACKNGQTNCYQSYSTMSITDCRETGSSKYPNCAYKTTQANKHIIVACEGNPYVPVHF

2W5IB          	DASV

RNAS1_BOVIN    	D---
```

This tells us that the first two residues are missing as are the last three, ending the sequence at residue 121. Hence, we make a selection accordingly:

```In : chB = pdb.select('resnum 3 to 121')
```

We can see from the sequence that this gives us the right portion:

```In : chB.ca.getSequence()
```

We write this selection to a PDB file for use later, e.g. with evol apps.

```In : writePDB('2W5IB_3-121.pdb', chB)
Out: '2W5IB_3-121.pdb'
```

We perform GNM as follows:

```In : gnm = GNM('2W5I')

In : gnm.buildKirchhoff(chB.ca)

In : gnm.calcModes(n_modes=None)  # calculate all modes
```

Now, let’s obtain residue mobility using the slowest mode, the slowest 8 modes, and all modes:

```In : mobility_1 = calcSqFlucts(gnm)

In : mobility_1to8 = calcSqFlucts(gnm[:8])

In : mobility_all = calcSqFlucts(gnm[:])
```

See Gaussian Network Model (GNM) for details.

## Comparison of mobility and conservation¶

We use the above data to compare structural mobility and degree of conservation. We can calculate a correlation coefficient between the two quantities:

```In : result = corrcoef(mobility_all, entropy)

In : result.round(3)[0,1]
Out: 0.396
```

We can plot the two curves simultaneously to visualize the correlation. We have to scale the values of mobility to display them in the same plot.

### Plotting¶

```In : indices = chB.ca.getResnums()

In : bar(indices, entropy, width=1.2, color='grey');

In : xlim(min(indices)-1, max(indices)+1);

In : plot(indices, mobility_all*(max(entropy)/max(mobility_all)), color='b',
....: linewidth=2);
....:
``` ## Writing PDB files¶

We can also write PDB with b-factor column replaced by entropy and mobility values respectively. We can then load the PDB structure in VMD or PyMol to see the distribution of entropy and mobility on the structure.

```In : selprot = chB.copy()

In : resindex = selprot.getResindices()

In : entropy_prot = [entropy[ind] for ind in resindex]

In : mobility_prot = [mobility_all[ind]*10 for ind in resindex]

In : selprot.setBetas(entropy_prot)

In : writePDB('2W5I_entropy.pdb', selprot)
Out: '2W5I_entropy.pdb'

In : selprot.setBetas(mobility_prot)

In : writePDB('2W5I_mobility.pdb', selprot)
Out: '2W5I_mobility.pdb'
```

We can see on the structure just as we could in the bar graph that there is some correlation with highly conserved (low entropy) regions having low mobility and high entropy regions have higher mobility.