2
$\begingroup$

The issue im facing is I'm assignig the colour to the annotation label but when it is rendered the label in my metadata does't match with the final output not sure what exactly is the problem.

The code

data file ka_ks and metadata figure

As an example this sample Q6Q1S2 in my metadata is Alpha but in the figure it is labelled under Gamma

Any suggestion or help would be really appreciated

    data <- read.csv("ka_ks.txt",header = TRUE,row.names = 1,sep = ",")
head(data)


#metadata <- read.csv("NUC_META_AMINO_heatmap_metadata_sans_nucleotide.txt",sep = ",")
metadata <- read.csv('vir_meta.txt',sep = ",")
#head(data)
head(metadata)
#names(metadata)[3] = "Host"


#Set annotation
ann <- metadata[,c(2,3)]
colnames(ann) <- c("Class","Host")
#rownames(ann) = metadata$Sample
ann
#ann = metadata
colours <- list("Host"=c("Human SARS coronavirus 2"="green4",
                         "Human SARS coronavirus"="darkgreen",
                         "Bat coronavirus"="wheat4",
                         "Murine coronavirus"="turquoise","MERS"="orange",
                         "Bovine coronavirus"="coral",
                         "Rat coronavirus"="saddle brown",
                         "Human coronavirus"="dark green",
                         "Porcine hemagglutinating encephalomyelitis virus"="maroon",
                         "Avian infectious bronchitis virus"="dark slate gray",
                         "Porcine respiratory coronavirus"="slategrey",
                         "Canine coronavirus"="purple",
                         "Porcine transmissible gastroenteritis coronavirus"="pink",
                         "Feline coronavirus"="gold",
                         "Porcine epidemic diarrhea virus"="brown"),
                "Class"= c("Alpha" = "blue" ,"Beta" ="black","Gamma" ="red"))


heat <- scale((data))
head(heat)

colAnn <- HeatmapAnnotation(df=ann, which="col",col=colours, annotation_width=unit(c(1, 4), "cm"), gap=unit(1, "mm"))
myCol1 <- colorRampPalette(c("navyblue", "white", "red"))(100)
myBreaks1 <- seq(-4, 4, length.out=100)


#Add column boxplot
boxplotCol <- HeatmapAnnotation(
  boxplot = anno_boxplot(data.matrix(heat),
                         border = TRUE,
                         gp = gpar(fill = '#CCCCCC'),
                         pch = '.',
                         size = unit(2, 'mm'),
                         axis = TRUE,
                         axis_side = 'left',
                         axis_gp = gpar(fontsize = 12)),
  annotation_width = unit(c(1, 5.0), 'cm'),
  which = 'col')


hmap1 <- Heatmap(heat,
                 name = 'ks_score',
                 #name="Z-score",
                 col=colorRamp2(myBreaks1, myCol1),
                 heatmap_legend_param=list(color_bar="continuous", 
                                           legend_direction="vertical", legend_width=unit(5,"cm"),
                                           title_position="lefttop", title_gp=gpar(fontsize=10, fontface="bold")),
                 
                 #Split heatmap rows by gene family
                 #split=df$Family,
                 #split = NULL,
                 
                 #Row annotation configurations
                 cluster_rows=TRUE,
                 show_row_dend=TRUE,
                 row_dend_side = "left",
                 #row_title="Transcript", #overridden by 'split' it seems
                 row_title_side="left",
                 row_title_gp=gpar(fontsize=30,fontface="bold"),
                 row_names_gp = gpar(fontsize = 10),
                 show_row_names=TRUE,
                 row_names_side="right",
                 row_title_rot=0,
                 
                 column_dend_reorder = TRUE,
                 #row_dend_reorder = TRUE,
                 
                 #Column annotation configuratiions
                 cluster_columns=TRUE,
                 show_column_dend=FALSE,
                 column_title="Samples",
                 column_title_side="top",
                 column_title_gp=gpar(fontsize=20, fontface="bold"),
                 column_title_rot=0,
                 column_names_gp = gpar(fontsize = 10, fontface="bold"),
                 show_column_names=TRUE,
                 
                 #Dendrogram configurations: columns
                 #clustering_distance_columns="euclidean",
                 clustering_method_columns="ward.D2",
                 column_dend_height=unit(10,"mm"),
                 
                 #Dendrogram configurations: rows  
                 #clustering_distance_rows="euclidean",
                 clustering_method_rows="ward.D2",
                 row_dend_width=unit(15,"mm"),
                 
                 #top_annotation_height=unit(0.5,"cm"),
                 #top_annotation=ColAnn,
                 top_annotation=colAnn)

#bottom_annotation_height=unit(2, "cm"),
#bottom_annotation=boxplotCol)


draw(hmap1 ,heatmap_legend_side ='right',annotation_legend_side = 'right')
$\endgroup$
1
  • 1
    $\begingroup$ fixed it ..the orders between my metadata and the data matrix was not matching $\endgroup$
    – kcm
    Jun 22 '20 at 9:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.