[R] merging nexus sequence files

David Winsemius dwinsemius at comcast.net
Fri Sep 16 00:40:45 CEST 2011


On Sep 15, 2011, at 6:00 PM, nikki22 wrote:

> Hi, newbie here,
>
> I was wondering if anyone can out, I have checked through the help  
> archives
> but cannot find my answer.
>
> I have three nexus files mostly with the same taxa but some are  
> different. I
> want to concatenate the DNA sequences from these three files into  
> one large
> nexus file but I cannot seem to accomplish it!
>
> This is an example:
>
> file1
> taxon1 aaggttcc
> taxon2 aagtttcg
> taxon3 aaggttcc
>
> file2
> taxon2 ctgctg
> taxon3 ctggtc
> taxon4 ctgctg
>
> file3
> taxon1 ggttggtta
> taxon2 ggttggttc
> taxon4 ggttggttc


dat.mrg <- merge(
              merge(file1,file2, by="V1", all=TRUE),
              file3,
               by="V1", all=TRUE)

 > dat.mrg$pseqs <- with(dat.mrg, paste(V2.x ,  V2.y  ,      V2,  
sep=""))
 > dat.mrg$pseqs <- gsub("NA", "??????", dat.mrg$pseqs)
 >  dat.mrg[ , c(1,5)]
       V1                   pseqs
1 taxon1 aaggttcc??????ggttggtta
2 taxon2 aagtttcgctgctgggttggttc
3 taxon3    aaggttccctggtc??????
4 taxon4   ??????ctgctgggttggttc

>
> this is what i want to end up with (where ? means missing data) in  
> nexus
> format:
>
> taxon1 aaggttcc??????ggttggtta
> taxon2 aagtttcgctgctgggttggttc
> taxon3 aaggttccctggtc????????
> taxon4 ??????????????ggttggttc
>
> Thanks in advance for any help!
>
>


David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list