gggenomes
gggenomes copied to clipboard
Different genome scales 2
Dear Developer,
I want to add breaks in my genomes, like described in issue #119 I could reproduce the example from #119 successfully but it did not work with my data. I created a subset of my data below and pasted my code. Could you please help me with this?
The code below works fine and I get a plot. If I uncomment line # add_clusters(links=cluster) +
it does not work anymore. I get the error below:
Error in UseMethod("add_clusters") :
no applicable method for 'add_clusters' applied to an object of class "c('tbl_df', 'tbl', 'data.frame')"
Code:
alv_seqs <- data.frame(
seq_id = c("DSW1", "DSM2041"),
seq_desc = c("alv_genes", "alv_genes"),
length = c(1625585, 705550)
)
alv_genes <- data.frame(
seq_id = c("DSM2041", "DSM2041", "DSW1", "DSW1" , "DSM2041"),
start = c(101291, 704479, 130905, 1625135, 159575),
end = c(101530, 705540, 131330, 1625575, 160342),
strand = c("+", "+", "+", "+", "+"),
type = c("CDS", "CDS", "CDS", "CDS", "CDS"),
feat_id = c("moaD_DSM2041", "moeZ_DSM2041", "moeZ_DSW1", "moeZ_DSW1", "sumT_DSM2041"),
width = c(238, 1060, 424, 439, 766),
name = c("moaD", "moeZ", "moeZ", "moeZ", "sumT")
)
alv_operons <- data.frame(
seq_id = c("DSM2041"),
start = c(99079),
end = c(103911),
strand = c("+"),
type = c("CDS"),
feat_id = c("operon"),
width = c(4831),
name = c("operon")
)
alv_ava <- data.frame(
seq_id = c("DSW1"),
length = c(1494680),
start = c(1),
end = c(1494680),
strand = c("+"),
seq_id2 = c("DSM2041"),
length2 = c(606471),
start2 = c(1),
end2 = c(606471)
)
alv_prot_ava <- data.frame(
feat_id = c("moeZ_DSW1", "moeZ_DSW1"),
feat_id2 = c("moeZ_DSM2041", "moeZ_DSM2041"),
length = c(424, 439),
start = c(1, 1),
end = c(424, 439),
start2 = c(1, 1),
end2 = c(1060, 1060)
)
alv_prot_ava <- as_tibble(alv_prot_ava)
cluster <- data.frame(feat_id = alv_genes$feat_id)
cluster$seq_id <- alv_genes$seq_id
cluster$cluster_id <- ""
# Add a new column "cluster_id_new" based on the conditions
cluster <- cluster %>%
group_by(seq_id) %>%
mutate(cluster_id = row_number()) %>%
ungroup()
cluster$cluster_id <- as.character(cluster$cluster_id)
cluster <- as_tibble(cluster)
gggenomes(
genes = alv_genes,
feats = alv_operons,
seqs = alv_seqs,
links = alv_ava
) |>
add_sublinks(alv_prot_ava) |> # Add grey synteny
sync() +
geom_feat(size = 5) +
geom_feat_note(aes(label = ""), nudge_y = -.1) +
geom_gene(aes(fill = name)) +
geom_seq() +
geom_link(data=links(2)) + # Add grey synteny
# add_clusters(links=cluster) +
geom_bin_label() + # Genes label on the right side
geom_gene(aes(fill=name)) + # removes middle black line on colored genes
geom_gene_tag(aes(label=name), nudge_y=0.1, check_overlap = TRUE) + # Adds gene names on top of colored blocks
scale_fill_brewer("Genes", palette = "Dark2", na.value = "cornsilk3") +
theme(text = element_text(size = 12)) # Increase axis text size