<p>Given the alignment you've presented, there are obvious groups of sequence similarity, but I'm seeing a lot of different peptide sequences in this (e.g. <code>CENEKGCIITSPSKDETMKVQDNSIXLGCN</code> and <code>GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR</code> as two obviously different peptides). Have you done a pre-filter for similarity to make sure you're looking at the same proteins for alignment?</p>
<p>Multiple alignment will not work properly with peptides that are very different from each other. You need to group proteins based on similarity first (e.g. with <a href="https://doi.org/10.1038%2Fs41467-018-04964-5" rel="nofollow noreferrer">Linclust</a>), then carry out multiple alignments within the groups.</p>

CC BY-SA 4.0
2022-05-26T02:54:40.567Z
2022-05-26T02:54:40.567Z
gringer
<pre><code>from Bio import AlignIO
from pathlib import Path
from Bio.Align import AlignInfo

path = '/my/path/'
test1 = 'testset.fa'
mypath = Path(path,test1)

myalign = AlignIO.read(mypath, &quot;fasta&quot;)
summary = AlignInfo.SummaryInfo(myalign)
consensus = summary.dumb_consensus()
print (consensus)
</code></pre>
<p>This will give a single consensus and 'X' low prevalence ambiguity. Easy to check whether its what is required because the code is ready to go.</p>

CC BY-SA 4.0
2022-05-25T12:17:12.680Z
2022-05-25T12:24:28.217Z
2022-05-25T12:24:28.217Z
M__
<p>I would like to know what would be the best way to generate a full-length consensus sequence?</p>
<p>I want to obtain a single representative sequence from a relatively gappy multiple sequence alignment of peptides.</p>
<p>See example below.</p>
<p>So far I have attempted <code>Consensus.py</code> from <a href="https://github.com/jrjhealey/bioinfo-tools" rel="nofollow noreferrer">https://github.com/jrjhealey/bioinfo-tools</a> but it just gives me gaps, even with a threshold close to zero.</p>
<pre><code>&gt;HX5_33766:7:1222:1022:72139
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
&gt;HX5_33766:7:1211:6319:29841
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1222:1022:72139.2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
&gt;HX5_33766:7:1219:12723:20928.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
&gt;HX5_33766:7:1119:11069:37612
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1219:12723:20928
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
&gt;HX5_33766:7:1211:6319:29841.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1219:12723:20928.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
&gt;HX5_33766:7:1107:2564:39757
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
&gt;HX5_33766:7:1211:6319:29841.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1212:30371:5686
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1119:11069:37612.2
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1212:30371:5686.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:10013:25165
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:10013:25165.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1106:31832:24286
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1117:3691:48881
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:9364:63314
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:10013:25165.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:9364:63314.2
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1212:30371:5686.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1221:9364:63314.1
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1119:11069:37612.1
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1107:2564:39757.1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
&gt;HX5_33766:7:1106:31832:24286.1
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1117:3691:48881.1
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1222:1022:72139.1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
&gt;HX5_33766:7:1107:2564:39757.2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
&gt;HX5_33766:7:1106:31832:24286.2
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1117:3691:48881.2
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1121:4320:48213
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1121:4320:48213.1
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1121:4320:48213.2
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1214:16701:50287
----------------------------------------------------------------------------------------------------------------------------------------------R--KQR--EXPKIEQLSAFTRSRSPESAFSNNHSVTYFHTLWGD------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
&gt;HX5_33766:7:1220:24545:3085
------------------------------------------------------------------------------------------------------------------------------------------------------------------RSRSPESAFSNNHSVTYFHTLWGD-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------R
</code></pre>

<fasta><phylogenetics><proteins><multiple-sequence-alignment>
Generate consensus protein sequence from relatively gappy alignment?
# Generate consensus protein sequence from relatively gappy alignment?

(Asked by: username_0 on 2022-05-25)

I would like to know what would be the best way to generate a full-length consensus sequence?
I want to obtain a single representative sequence from a relatively gappy multiple sequence alignment of peptides.
See example below.
So far I have attempted Consensus.py from https://github.com/jrjhealey/bioinfo-tools but it just gives me gaps, even with a threshold close to zero.
>HX5_33766:7:1222:1022:72139
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
>HX5_33766:7:1211:6319:29841
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1222:1022:72139.2
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
>HX5_33766:7:1219:12723:20928.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
>HX5_33766:7:1119:11069:37612
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1219:12723:20928
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
>HX5_33766:7:1211:6319:29841.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1219:12723:20928.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------T-ISTSYKDIQVNGGELILIHQNPGGFCAY--------------
>HX5_33766:7:1107:2564:39757
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
>HX5_33766:7:1211:6319:29841.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIIINCDGY------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1212:30371:5686
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1119:11069:37612.2
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1212:30371:5686.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:10013:25165
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:10013:25165.2
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1106:31832:24286
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1117:3691:48881
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:9364:63314
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:10013:25165.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMK-------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:9364:63314.2
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1212:30371:5686.1
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------CENEKGCIITSPSKDETMKVQDNSIXLGCN--------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1221:9364:63314.1
-------------------------------GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1119:11069:37612.1
----------------------------------------------------------------------------------------------------------------------------------------VLLGAAIIQGLGLLLC--F----------------------TYI----------------------CLHFYASQ-V----------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1107:2564:39757.1
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
>HX5_33766:7:1106:31832:24286.1
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1117:3691:48881.1
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1222:1022:72139.1
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------SEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFKDKVYFNVT--------------------------------------------
>HX5_33766:7:1107:2564:39757.2
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------VFSLKGYFSEEL---SLSLYYRKGRGPLF-------SLSKVTSVDSIGVAYLAFK----------------------------------------------------
>HX5_33766:7:1106:31832:24286.2
----------------------------------------------------------------------SVYLRL--IVFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1117:3691:48881.2
-------------------------------------------------------------------------------VFP-PSPPLWRRG---QSP------SGLLPFATV-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1121:4320:48213
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1121:4320:48213.1
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1121:4320:48213.2
MTVISQSLKSELECHKNNSLLAQ-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1214:16701:50287
----------------------------------------------------------------------------------------------------------------------------------------------R--KQR--EXPKIEQLSAFTRSRSPESAFSNNHSVTYFHTLWGD------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>HX5_33766:7:1220:24545:3085
------------------------------------------------------------------------------------------------------------------------------------------------------------------RSRSPESAFSNNHSVTYFHTLWGD-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------R

**Tags:** fasta, phylogenetics, proteins, multiple-sequence-alignment

---

## 2 answers

### Answer by username_1 on 2022-05-26. Score: 1

Given the alignment you've presented, there are obvious groups of sequence similarity, but I'm seeing a lot of different peptide sequences in this (e.g. `CENEKGCIITSPSKDETMKVQDNSIXLGCN` and `GKFRLVTKKFPRLPAEAAVLKLRECVLLFQLPLISAPGTSVYLR` as two obviously different peptides). Have you done a pre-filter for similarity to make sure you're looking at the same proteins for alignment?

Multiple alignment will not work properly with peptides that are very different from each other. You need to group proteins based on similarity first (e.g. with [Linclust](https://doi.org/10.1038%2Fs41467-018-04964-5)), then carry out multiple alignments within the groups.


---

### Answer by username_2 on 2022-05-25. Score: 0

from Bio import AlignIO
from pathlib import Path
from Bio.Align import AlignInfo

path = '/my/path/'
test1 = 'testset.fa'
mypath = Path(path,test1)

myalign = AlignIO.read(mypath, "fasta")
summary = AlignInfo.SummaryInfo(myalign)
consensus = summary.dumb_consensus()
print (consensus)

This will give a single consensus and 'X' low prevalence ambiguity. Easy to check whether its what is required because the code is ready to go.


---

