Skip to content

Commit 59553c4

Browse files
authored
Update Compreplots_tlhcrs.R
correct for issues in missing samples when generating heatmap-tree plots
1 parent 8b95f5d commit 59553c4

1 file changed

Lines changed: 36 additions & 1 deletion

File tree

bin/Compreplots_tlhcrs.R

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,23 @@ tip_order=tree$data %>%
2727
###plotting repeat similarities using global ANI in tile colours
2828
within_gANI=read.csv(file="gANI.within_repeats.tsv", header=T, sep='\t')
2929

30+
##add the missing samples that are in the tree
31+
missing <- setdiff(tip_order, within_gANI$sample)
32+
33+
##add blank rows
34+
if(length(missing) > 0){
35+
blank_rows <- data.frame(
36+
sample = missing,
37+
average_gANI = NA,
38+
count = NA,
39+
repeat_representative = missing
40+
)
41+
within_gANI <- rbind(within_gANI, blank_rows)
42+
}
43+
44+
##reorder after adding blanks
45+
within_gANI$sample = factor(within_gANI$sample, levels = tip_order)
46+
3047
within_gANI$gANI = within_gANI$average_gANI*100
3148

3249
##rearrange order of genomes by tree
@@ -42,9 +59,27 @@ within=suppressMessages(suppressWarnings(print(ggplot(data=within_gANI, aes(x=""
4259
theme_classic()+
4360
theme(axis.text.x = element_blank(), axis.title.x = element_blank(), axis.ticks.x = element_blank(), axis.text.y = element_blank(), axis.title.y = element_blank(), legend.position = "NA"))))
4461

45-
###
62+
###read in gANI comparisons between samples
4663
rep_gANI=read.csv(file="gANI.between_repeat_representatives.tsv", header=T, sep='\t')
4764

65+
##add missing samples
66+
all_pairs <- expand.grid(
67+
query_sample = tip_order,
68+
ref_sample = tip_order,
69+
stringsAsFactors = FALSE
70+
)
71+
72+
##left-join your data into the complete matrix
73+
rep_gANI_full <- dplyr::left_join(all_pairs, rep_gANI,
74+
by = c("query_sample","ref_sample"))
75+
76+
##reorder
77+
rep_gANI_full$query_sample = factor(rep_gANI_full$query_sample, levels = tip_order)
78+
rep_gANI_full$ref_sample = factor(rep_gANI_full$ref_sample, levels = tip_order)
79+
80+
rep_gANI = rep_gANI_full
81+
82+
4883
rep_gANI$gANI = rep_gANI$gANI*100
4984

5085
##rearrange order of genomes by tree

0 commit comments

Comments
 (0)