TITLE: R editing of HMMSEARCH output: heatmap with associated with gene tree and protein illustration
AUTHORS: Kanae Nishii

[DESCRIPTION]
<div class = "text-blocks"><div class = "text-block">R codes used for phyml tree and profile HMM heatmap visualization, protein domain illustration</div></div>

[STEPS]
?. [R libraries]
#libraries for tree drawinglibrary(ggtree)library(ape)library(phytools)#libraries for heatmaplibrary(reshape2)library(dplyr)library(ggplot2)library(aplot)
?. [tree drawing]
#rooting tree#midpoint rooted treetree2 #rooted by outgroup samplestree2 #check tree2ggtree(tree2)
?. [tree drawing]
#read Newick format tree tree1 #check tree1ggtree(tree1)
?. [tree drawing]
#read data for groupingdat dat2  dat2 colnames(dat2) #import groupschlorophytes charophytes liverwortsmosseslycophytesgymnospermsangiospermsmonocotseudicotscls b.charophytes=charophytes$protein_ID,c.liverworts=liverworts$protein_ID,d.mosses=mosses$protein_ID,e.lycophytes=lycophytes$protein_ID,f.gymnosperms=gymnosperms$protein_ID,g.angiosperms=angiosperms$protein_ID,h.monocots=monocots$protein_ID,i.eudicots=eudicots$protein_ID)
?. [tree drawing]
#add group to treetree3
?. [tree drawing]
#only includes support values > 0.7q d d d$label d  0.7,]#tree drawingobj scale_color_manual(values=c("deepskyblue","green","seagreen","seagreen4","orange2","chocolate4","red","blue","gray40")) +geom_tiplab(size=6) +geom_text(data=d,aes(label=label,hjust=1.5,vjust=-0.5,size=6))ggsave("strongsupport.tree.pdf",obj,width=60, height=90,limitsize=FALSE)#done
?. [tree drawing]
#tree drawingobj scale_color_manual(values=c("deepskyblue","green","seagreen","seagreen4","orange2","chocolate4","red","blue","gray40")) +geom_tiplab() +geom_text2(aes(subset=!isTip,label=label,hjust=1.5,vjust=-0.5))ggsave("all_support_value.tree.pdf",obj, width=30, height=50, limitsize=FALSE)
?. [Making heatmap from output of HMMER website search]
#librarieslibrary(reshape2)library(dplyr)library(ggplot2)library(aplot)
?. [Making heatmap from output of HMMER website search]
#generate data frame from "dat"dat3 colnames(dat3) #remove duplicate, "i.Evalue" is ordered in the ascending manner dat4 #make table of i.Evalue, ordered by protein_ID and hmm_hamedat5 #format for ggtreedat6 colnames(dat6)
?. [Making heatmap from output of HMMER website search]
#order of domain, by preferencedomorder dat7 %mutate(hmm_name=factor(hmm_name,levels=domorder),ordered=TRUE)#dat7 is the data for heatmap
?. [Combining tree and heatmap]
#drawingobj2 hm geom_tile(aes(fill=i.Evalue),color="gray50") +scale_fill_gradient(low="blue",high="yellow",na.value="gray80",limits=c(0,0.001)) +scale_x_discrete(expand=c(1,0)) +theme_tree2(axis.text.x=element_text(angle=70,vjust=0.5,hjust=0.5,size=8),axis.text.y=element_text(size=8))obj3 % insert_left(obj2)ggsave("heatmap.pdf",obj3,width=10,height=50,limitsize=FALSE)#done
?. [Combining tree and heatmap]
tree2 #tree datadat7 #heatmap data
?. [Making protein domain illustration]
df df$hmm_name df$color
?. [Making protein domain illustration]
id id
?. [Making protein domain illustration]
for (i in 1:8){df1 df1
?. [Making protein domain illustration]
#set plot areascreen.width screen.height protlength file_a png(filea, width = 1500, height = 500 )plot(c(-10, screen.width),c(0,screen.height),type = "n",xlab = "Number of amino acids",ylab = "", yaxt='n')
?. [Making protein domain illustration]
#make the protein framerect(xleft = 1,ytop = screen.height/2+1.5,ybottom = screen.height/2-1.5,xright=protlength,col="gray")a for (i in 1:a){rect(xleft=df1$ali_from[i],ytop=screen.height/2+2.5,ybottom=screen.height/2-2.5,xright = df1$ali_to[i],col= df1$color[i])}text(max(df1$length[1])/2, screen.height-2.5, df1$protein_ID, cex=1.5)pos.text.x pos.text.y text (pos.text.x,pos.text.y,df1$hmm_name[1:a],cex = 1.5)text(df1$length[1], screen.height/2-3,df1$length[1],cex=1.5)text(1,screen.height/2-3,1,cex=1.5)dev.off()}#done
?. Table 1. Example data format  ABCDEFGHIJKL1  group    protein_ID    ID    length    hmm_name    i.Evalue    ali_from    ali_to    num_doms    overlap    bestdom    color  2  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    MCAfunc    3.80E-17    13    150    3    FALSE    1    mistyrose  3  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    U-box    1.10E-20    254    325    3    FALSE    1    honeydew2  4  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    Arm    1.90E-07    735    772    3    FALSE    1    royalblue  5  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    MCAfunc    4.10E-15    7    139    5    TRUE    1    mistyrose  6  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    U-box    1.10E-20    246    315    5    TRUE    1    honeydew2  7  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm_2    1.30E-05    1014    1206    5    TRUE    0    royalblue4  8  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm    2.70E-06    1046    1085    5    TRUE    1    royalblue  9  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm    2.00E-07    1131    1169    5    TRUE    1    royalblue
ABCDEFGHIJKL1  group    protein_ID    ID    length    hmm_name    i.Evalue    ali_from    ali_to    num_doms    overlap    bestdom    color  2  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    MCAfunc    3.80E-17    13    150    3    FALSE    1    mistyrose  3  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    U-box    1.10E-20    254    325    3    FALSE    1    honeydew2  4  charophytes    A0A1Y1HMH1_KLENI    A0A1Y1HMH1    986    Arm    1.90E-07    735    772    3    FALSE    1    royalblue  5  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    MCAfunc    4.10E-15    7    139    5    TRUE    1    mistyrose  6  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    U-box    1.10E-20    246    315    5    TRUE    1    honeydew2  7  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm_2    1.30E-05    1014    1206    5    TRUE    0    royalblue4  8  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm    2.70E-06    1046    1085    5    TRUE    1    royalblue  9  charophytes    A0A1Y1HNZ6_KLENI    A0A1Y1HNZ6    1311    Arm    2.00E-07    1131    1169    5    TRUE    1    royalblue