library(ggchord)

library(ggchord)
library(dplyr)
finish_dna <- plasmid_example_pUC19
finish_seq <- finish_dna[c("accver", "length")]
finish_features <- head(find_common_features(finish_dna), 6)
finish_circle <- ggchord(finish_seq) + geom_seq() + coord_circular()
finish_labels <- finish_features |>
  mutate(anno = paste0(anno, " [", start, "-", end, " bp]"))
finish_feature_base <- finish_circle + geom_feature(data = finish_labels)


p_comparefixedfeature <- finish_feature_base +
  geom_feature_label(data = finish_labels, label_orientation = "feature")
view_ggchord(p_comparefixedfeature, width = 9, height = 8, units = "in")


p_comparefixedhorizontal <- finish_feature_base +
  geom_feature_label(data = finish_labels, label_orientation = "horizontal")
view_ggchord(p_comparefixedhorizontal, width = 9, height = 8, units = "in")


p_comparefixedinside <- finish_feature_base +
  geom_feature_label(data = finish_labels, label_orientation = "feature", label_side = "inside")
view_ggchord(p_comparefixedinside, width = 9, height = 8, units = "in")


p_comparefixedrotate <- finish_feature_base +
  geom_feature_label(data = finish_labels, label_orientation = "feature", label_rotation = 30)
view_ggchord(p_comparefixedrotate, width = 9, height = 8, units = "in")


p_comparefeaturefit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "feature")
view_ggchord(p_comparefeaturefit, width = 9, height = 8, units = "in")


p_compareradialfit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "radial")
view_ggchord(p_compareradialfit, width = 9, height = 8, units = "in")


p_compareautofit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "auto")
view_ggchord(p_compareautofit, width = 9, height = 8, units = "in")


p_comparecalloutfit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "callout")
view_ggchord(p_comparecalloutfit, width = 9, height = 8, units = "in")


p_compareshrinkfit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "feature", label_fit = "shrink")
view_ggchord(p_compareshrinkfit, width = 9, height = 8, units = "in")


p_comparewrapfit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "feature", label_wrap = 14)
view_ggchord(p_comparewrapfit, width = 9, height = 8, units = "in")


p_compareellipsisfit <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "feature", label_wrap = 14, label_fit = "ellipsis")
view_ggchord(p_compareellipsisfit, width = 9, height = 8, units = "in")


p_compareexternaloff <- finish_feature_base +
  geom_feature_label_repel(data = finish_labels, label_layout = "feature", external = FALSE)
view_ggchord(p_compareexternaloff, width = 9, height = 8, units = "in")


geom_feature_label_repel(label_segment_layer = "above")


features <- find_common_features(plasmid_example_pTRE_Tight_BI)
feature_position <- position_feature_stack(base_position = position_plasmid())
ggchord(plasmid_example_pTRE_Tight_BI[c("accver", "length")], feature_data = features) +
  geom_seq(seq_style = "double") +
  geom_feature_plasmid(position = feature_position) +
  geom_feature_label_repel(
    position = feature_position,
    label_repeat = "bracket",
    label_fit = "shrink",
    label_min_size = 2.5
  ) +
  coord_circular() +
  theme_ggchord_plasmid()


geom_feature_label_repel(
  label_segment_colour = "grey50",
  label_segment_linetype = "dashed"
)

