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 write.nexus.data() function to write our new .nexus data. One thing worth mentioning is that the argument “format” in write.nexus.data()has two … Continue reading How to convert fasta files to nexus files in R

How to read amino acid or dna sequences in the fasta format in R

The easiest way to do it is to use “seqinr” package. There is some example code below Even if we save the sequences in the .txt format, we can still use read.fasta(). The resulting data as a list in r with length equal to the number of sequences in the fasta file. If you are reading DNA sequences, another option is to use “ape” package in R and use read.dna() function.   Continue reading How to read amino acid or dna sequences in the fasta format in R