How to convert fasta files to nexus files in R

Both .fasta and .nexus files are used to save the sequences information in phylogenetics and they are both widely used. However, for some software like MrBayes, it only reads the .nexus file. As a result, if you have a .fasta file at hand, you will need to be able to convert between different formats for files. R provides an easy way to achieve this.  We can use read.fasta() function in “seqinr” package to read the data first and then use function to write our new .nexus data. One thing worth mentioning is that the argument “format” in two options: one is “dna” and the other is “protein” so that we can write both DNA and amino acid sequence data.  Below is the example code to implement this in R:


data = read.fasta("~/5000alignsimutree.txt")

library(ape), file="~/",


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s