美文网首页
R进行多序列比对及绘制进化树

R进行多序列比对及绘制进化树

作者: 花生学生信 | 来源:发表于2023-12-21 14:44 被阅读0次

    多序列比对Multiple sequence alignment(MSA,多序列比对)大家一定不陌生了吧,多序列比对是一种用于比较多个序列间相似性和差异性的分析方法。
    在Linux中,有一些常用的多序列比对工具可供选择,其中最常见的是ClustalW
    MuscleMAFFT等,在Windows中一般使用Mega。这里在R直接绘制多序列比对结果。
    下面是R语言实操部分,这里推荐跑10条左右的短序列,如果太多还是使用mega等软件比较好:

    ###BiocManager::install("msa")
    require(msa)
    mySequenceFile <- readAAStringSet(“sequence.txt”)
    
    #多序列比对
    myFirstAlignment <- msa(mySequenceFile)
    
    head(mySequenceFile)
    
    library(ggplot2)
    
    require(seqinr)
    myAlignment <- msaConvert(myFirstAlignment, type="seqinr::alignment")
    d <- dist.alignment(myAlignment, "identity")
    
    #构建NJ树
    require(ape)
    tree <- nj(d)
    
    #画树并输出到PDF文件ggtree.pdf
    require(ggtree)
    环形进化树
    
    ##环状图
    p1<-ggtree(tree, layout='circular', ladderize=FALSE, size=0.8, branch.length="none",col="red")+
      geom_tiplab2(hjust=-0.3)+
      geom_tippoint(size=1.5,col="blue")+ 
      geom_nodepoint(color="black", alpha=1/4, size=2) +
      theme(legend.title=element_text(face="bold"), legend.position="bottom", legend.box="horizontal", legend.text=element_text(size=rel(0.5)))
    # 图例位置、文字大小
    ###长方形图
    p2<- ggtree(tree, layout='rectangular', size=0.8, col="deepskyblue3") +
      
      geom_tiplab(size=3, color="purple4", hjust=-0.05)+
      geom_tippoint(size=1.5, color="deepskyblue3")+
      geom_nodepoint(color="pink", alpha=1/4, size=5)+
      theme_tree2() 
    ggsave(p1, file="tree_circular.pdf", width=9, height=9)
    ggsave(p2, file="tree_rectangular.pdf", width=9, height=9)
    
    环形 长方形图

    多序列比对logo图

    ###加载R包,如果没有安装则自动安装
    if(!require(ggmsa))install.packages("ggmsa")
    ####读取数据:
    fai<-"t.fa"
    ###画图并保存图片,如图不清晰或字体重叠,需要调整长宽,可输入序列比对数据
    pdf(file = "aligned_fasta.pdf",width = 30,height = 3)
    ggmsa(fai,char_width = 0.5, seq_name = TRUE)+
      geom_seqlogo() + geom_msaBar()
    dev.off()
    
    多序列logo图

    相关文章

      网友评论

          本文标题:R进行多序列比对及绘制进化树

          本文链接:https://www.haomeiwen.com/subject/ritfndtx.html