Biostar Beta. Not for public use.
merge two multifasta files
0
Entering edit mode
23 months ago
erick_rc93 • 0
@erick_rc9348006

I have two multifasta files that have almost the same headers, for example

file1.fasta
    >header_1
    dnasequenceoffastafile1
    >header_2
    dnasequenceoffastafile1
    >header_3
    dnasequenceoffastafile1

  file2.fasta
        >header_1_f2
        dnasequencefastafile2
        >header_2_f2
        dnasequencefastafile2
        >header_4_f2
        dnasequencefastafile2

and I would like the next output

    merged.fasta 
        >header_1_header_1_f2
        dnasequenceoffastafile1dnasequencefastafile2
        >header_2_header_2_f2
        dnasequenceoffastafile1dnasequencefastafile2
sequence • 240 views
ADD COMMENTlink
1
Entering edit mode

Two solutions at Combining two fasta sequences into one , do any of them work for you?

ADD REPLYlink
0
Entering edit mode

And why would you do that ?

ADD REPLYlink
1
Entering edit mode
23 months ago
Brice Sarver ♦ 2.6k
@Brice Sarver13598

Here's a quick R solution using Bioconductor. There are analogous examples using a variety of different tools and languages (see Biopython, etc.). For quick manipulations, I like to use Biostrings due to how efficiently it handles long strings once in memory.

library(Biostrings)
a <- readDNAStringSet("file1", format="fasta")
b <- readDNAStringSet("file2", format="fasta")
d <- DNAStringSet(paste0(a, b))
# reassign names
names(d) <- names(a)
writeXStringSet(d, "your_fila_name.fa")

Hope this helps.

ADD COMMENTlink

Login before adding your answer.

Similar Posts
Loading Similar Posts
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.3