How to merge transcript sequence with same name in a FASTA file. Suppose we have a fasta file like

&gt;Seq1
GTTGAGAGGTGTATGGACACGAAAAACGAAACTGTATCCCGTGTTTAGCAAAGAAATCAT
&gt;Seq1
AAAAACGAAACTGTATCCCGTGTTT
&gt;Seq2
CGTGTTTAGCAAAGAAAT


I want to produce

&gt;Seq1
GTTGAGAGGTGTATGGACACGAAAAACGAAACTGTATCCCGTGTTTAGCAAAGAAATCATAAAAACGAAACTGTATCCCGTGTTT
&gt;Seq2
CGTGTTTAGCAAAGAAAT
Certainly this python script is not the most elegant solution but it will give you the desired result:

import sys

seqs = {}
with open(sys.argv[1], "r") as fh:
    curr = ""
    for line in fh:
        if line.startswith("&gt;"):
            curr = line
            if curr not in seqs:
                seqs[curr] = ""
        else:
            seqs[curr] += line.strip()

for ident, seq in seqs.items():
    print("{}{}".format(ident, seq))


If you saved the script in seq_merge.py just run it with:

python seq_merge.py your_file.fasta &gt; result.fasta