library(ggchord)

library(dplyr)
foundation_source <- ribbon_data_example |>
  mutate(source_hsp_id = paste0("bundled:", row_number()))
foundation_pair <- foundation_source |>
  slice_head(n = 1) |>
  select(qaccver, saccver)
foundation_ids <- c(foundation_pair$qaccver, foundation_pair$saccver)
foundation_seqs <- seq_data_example |>
  filter(accver %in% foundation_ids) |>
  select(accver, length)
foundation_hsp <- foundation_source |>
  filter(qaccver %in% foundation_ids, saccver %in% foundation_ids,
    qaccver != saccver)
foundation_features <- gene_data_example |>
  filter(accver %in% foundation_ids) |>
  transmute(accver, start, end, strand = source_strand, anno)


foundation_order <- setNames(
  c(foundation_ids[1], foundation_ids[2], foundation_ids[1]),
  c("A_high", "B", "A_low")
)
foundation_split <- ceiling(nrow(foundation_hsp) / 2)
foundation_plot <- ggchord(foundation_seqs, feature_data = foundation_features) +
  geom_seq(seq_order = foundation_order) +
  geom_seq_label() +
  geom_feature(shape = "arrow") +
  geom_link_ribbon(
    data = foundation_hsp |> slice_head(n = foundation_split),
    between = c("A_high", "B")
  ) +
  geom_link_ribbon(
    data = foundation_hsp |> slice_tail(n = nrow(foundation_hsp) - foundation_split),
    between = c(2, 3)
  )
p_foundationvertical <- foundation_plot + coord_collinear(seq_axis = "vertical")
view_ggchord(p_foundationvertical, width = 9, height = 8, units = "in")

