<h2>Q - Is there some parameter for this?</h2>

<p>No, there is no parameter for this. Getting the conserved regions is something that you will have to perform post-alignment. </p>

<h2>How to get the conserved regions?</h2>

<p>You will need to define what exactly you mean by conservation and calculate a conservation score for each position of the alignment.</p>

<p>For instance you can look at each column of the alignment and calculate the percent of queries that had the same base/AA at that position. If using AAs you can define conservation more loosely depending on what properties are important to you, or using a scoring matrix.</p>

<p>Once you have a co-occurrence matrix you can define the regions of interest based on a conservation threshold that you define.</p>

<h2>Is there software to find conserved columns?</h2>

<p>There is a program <a href="https://github.com/gcollet/MstatX" rel="nofollow noreferrer">MstatX</a> which outputs conservation scores of individual columns.</p>

<h2>How MstatX works</h2>

<p>The example of MstatX provides this example alignment. Each column is progressively less conserved than the last. The last column is conserved, but has some gaps -- this lowers the conservation score.</p>

<pre><code>   col          1
 seq1  1234567890
 seq2  DDDDDDIPDL
 seq3  DDDDDDIPVL
 seq4  DDDDDDIPYL
 seq5  DDDDDDIPA-
 seq6  DDDDDDLWT-
 seq7  DDEDEELWK-
 seq8  DDEDEELWP-
 seq9  DDEDEFVSR-
 seq10 DEEFFFVSH-
</code></pre>

<p>The conservation scores for each column were:</p>

<pre><code>1       2.71272e-08
2       0.243433
3       0.312789
4       0.243433
5       0.483364
6       0.480391
7       0.498757
8       0.498757
9       0.973514
10      0.267319
</code></pre>

<h2>How to get conserved regions</h2>

<p>The python program below will output all windows of conserved regions when using a fasta alignment and the default output from <code>MstatX</code>.</p>

<ul>
<li>Positional args 

<ul>
<li><strong>1.</strong> <code>MstatX_alignment_example.mali</code>, is the fasta alignment file. </li>
<li><strong>2.</strong> <code>output.txt</code> is the default output of <code>mstatx</code> when called with <code>mstatx -i MstatX_alignment_example.mali</code>. </li>
<li><strong>3.</strong> 0.4 is the minimum conservation score</li>
<li><strong>4.</strong> 3 is the minimum number of bases that must have that conservation score.</li>
</ul></li>
</ul>

<p>Calling this program with the following command on the above example: </p>

<p><code>python print_conserved_regions.py MstatX_alignment_example.mali output.txt 0.4 3</code> prints:</p>

<pre><code>{1,4}
</code></pre>

<p>Meaning that there was only one window at least 3 bases long in which all positions had a conservation score below 0.4. This window was positions 1 through 4 in the alignment.</p>

<pre class="lang-py prettyprint-override"><code>#call this file cons_windows.py
import sys
from Bio import AlignIO

align_filename = sys.argv[1]
cons_filename = sys.argv[2]
cutoff = float(sys.argv[3])
minchar = int(sys.argv[4])

def parse_conservation(filename):
    cons = {}
    with open(filename, "r") as f:
        for line in f:
            if line.strip():
                temp = line.split()
                cons[int(temp[0])] = float(temp[1])
    return cons

align = AlignIO.read(align_filename, "fasta")
cons = parse_conservation(sys.argv[2])

i = 1
while i &lt; max(cons):
    if cons[i] &lt;= cutoff:
        j = i
        done = False
        while j &lt; max(cons) and not done:
            if (cons[j] &gt; cutoff) and (j-i &gt;= minchar):
                print("{{{},{}}}".format(i,j-1))
                done = True
                i = j
            j+=1
    i+=1
</code></pre>

CC BY-SA 4.0
2019-01-30T20:19:03.780Z
2019-01-30T20:56:06.883Z
2019-01-30T20:56:06.883Z
conchoecia
<p>So I aligned roughly 5k sequences and I got my output using mafft. However, I want to restrict the output to only present conserved segments of a specific length (let's say 25bp). Does mafft have parameters to set this that I seem to be missing?</p>

<phylogenetics>
Restricting match output for multiple sequence alignment using mafft?
# Restricting match output for multiple sequence alignment using mafft?

(Asked by: username_0 on 2019-01-30)

So I aligned roughly 5k sequences and I got my output using mafft. However, I want to restrict the output to only present conserved segments of a specific length (let's say 25bp). Does mafft have parameters to set this that I seem to be missing?

**Tags:** phylogenetics

---

## 1 answers

### Answer by username_1 on 2019-01-30. Score: 2

Q - Is there some parameter for this?
No, there is no parameter for this. Getting the conserved regions is something that you will have to perform post-alignment. 
How to get the conserved regions?
You will need to define what exactly you mean by conservation and calculate a conservation score for each position of the alignment.
For instance you can look at each column of the alignment and calculate the percent of queries that had the same base/AA at that position. If using AAs you can define conservation more loosely depending on what properties are important to you, or using a scoring matrix.
Once you have a co-occurrence matrix you can define the regions of interest based on a conservation threshold that you define.
Is there software to find conserved columns?
There is a program MstatX which outputs conservation scores of individual columns.
How MstatX works
The example of MstatX provides this example alignment. Each column is progressively less conserved than the last. The last column is conserved, but has some gaps -- this lowers the conservation score.
   col          1
 seq1  1234567890
 seq2  DDDDDDIPDL
 seq3  DDDDDDIPVL
 seq4  DDDDDDIPYL
 seq5  DDDDDDIPA-
 seq6  DDDDDDLWT-
 seq7  DDEDEELWK-
 seq8  DDEDEELWP-
 seq9  DDEDEFVSR-
 seq10 DEEFFFVSH-

The conservation scores for each column were:
1       2.71272e-08
2       0.243433
3       0.312789
4       0.243433
5       0.483364
6       0.480391
7       0.498757
8       0.498757
9       0.973514
10      0.267319

How to get conserved regions
The python program below will output all windows of conserved regions when using a fasta alignment and the default output from MstatX.

Positional args 


1. MstatX_alignment_example.mali, is the fasta alignment file. 
2. output.txt is the default output of mstatx when called with mstatx -i MstatX_alignment_example.mali. 
3. 0.4 is the minimum conservation score
4. 3 is the minimum number of bases that must have that conservation score.


Calling this program with the following command on the above example: 
python print_conserved_regions.py MstatX_alignment_example.mali output.txt 0.4 3 prints:
{1,4}

Meaning that there was only one window at least 3 bases long in which all positions had a conservation score below 0.4. This window was positions 1 through 4 in the alignment.
#call this file cons_windows.py
import sys
from Bio import AlignIO

align_filename = sys.argv[1]
cons_filename = sys.argv[2]
cutoff = float(sys.argv[3])
minchar = int(sys.argv[4])

def parse_conservation(filename):
    cons = {}
    with open(filename, "r") as f:
        for line in f:
            if line.strip():
                temp = line.split()
                cons[int(temp[0])] = float(temp[1])
    return cons

align = AlignIO.read(align_filename, "fasta")
cons = parse_conservation(sys.argv[2])

i = 1
while i < max(cons):
    if cons[i] <= cutoff:
        j = i
        done = False
        while j < max(cons) and not done:
            if (cons[j] > cutoff) and (j-i >= minchar):
                print("{{{},{}}}".format(i,j-1))
                done = True
                i = j
            j+=1
    i+=1


---

