Skip to contents

A comparison or list of comparisons is updated using a matching list of dna_segs. This can be used to update the region_plot, col, or position columns of the comparisons, by linking them with dna_seg features.

Usage

update_comparisons(
  dna_seg_input,
  comparison_input,
  seg_id = "locus_id",
  comparison_id = "auto",
  update_positions = FALSE,
  update_region_plot = TRUE,
  color_var = NULL,
  default_color = "grey80",
  update_from_top = TRUE
)

Arguments

dna_seg_input

Either a single dna_seg or a list of dna_seg objects.

comparison_input

Either a single comparison or a list of comparison objects.

seg_id

The name of a dna_seg column, whose values will be used to make the links to the comparisons.

comparison_id

The shared name of the comparison columns, whose values will be used to make the links to the dna_segs. See details.

update_positions

Logical. If TRUE, updates the plotted positions of the comparisons to match the dna_segs. start1 and end1 will be updated using the dna_seg above the comparison in plotting order, while start2 and end2 will be updated using the dna_seg under the comparison in plotting order.

update_region_plot

Logical. If TRUE, updates the region_plot column of the comparisons. This only serves the purpose of being able to transfer this information to other dna_segs, the region_plot column has no other function in comparison objects.

color_var

The color column to update the comparisons with. If it is col or fill, then that column will be taken from the dna_segs to update the col column in the comparisons. Must be either col, fill, or left as the default NULL, which will result in no color column being updated.

default_color

A character string providing the default color of the dna_segs, must be either NULL or a valid color. The color given by this argument will be ignored when updating, never overwriting any color in the comparisons.

update_from_top

Logical. If TRUE, updates the comparisons with the dna_segs above them in the plotting order. Setting this to FALSE will make it update the comparisons using the dna_segs below them in the plotting order, but this also means that the dna_segs and comparisons need to be provided in reverse plotting order. Therefore, it is recommended to be used only when providing a single dna_seg and comparison.

Value

Either a single comparison object or a list of comparison objects, matching the input given using comparison_input.

Details

If dna_seg_input is a single dna_seg, it will be updated using the first (or only) comparison from comparison_input.

The objects are linked together through shared values. The columns for these shared values are determined by the seg_id and comparison_id arguments, for the dna_segs and comparisons, respectively. comparison_id refers to 2 columns, and defaults to "auto", which will attempt to determine which columns to use automatically. If for example, comparison_id is set as "name", it will look for the "name1" and "name2" columns to match to the seg_id in the dna_segs above, and under it, respectively.

When update_from_top is TRUE, it assumes the list of dna_segs and comparisons are in plotting order. The first dna_seg will not be updated as there is no comparison above it to update it with. If instead update_from_top is FALSE, the dna_segs and comparisons would have to be supplied in reverse plot order, which is why this is not recommended. In this case the last dna_seg in plot order will not be updated, as there was no comparison below it to update it with.

Author

Mike Puijk

Examples

## Prepare dna_seg
names1 <- c("1A", "1B", "1C")
names2 <- c("2A", "2C", "2B")
names3 <- c("3B", "3A", "3C")

## Make dna_segs
dna_seg1 <- dna_seg(data.frame(name = names1,
                               start = (1:3) * 3,
                               end = (1:3) * 3 + 2,
                               strand = rep(1, 3)))
dna_seg2 <- dna_seg(data.frame(name = names2,
                               start = (1:3) * 3,
                               end = (1:3) * 3 + 2,
                               strand = rep(1, 3)))
dna_seg3 <- dna_seg(data.frame(name = names3,
                               start = (1:3) * 3,
                               end = (1:3) * 3 + 2,
                               strand = rep(1, 3)))
dna_segs <- list("Genome 1" = dna_seg1,
                 "Genome 2" = dna_seg2,
                 "Genome 3" = dna_seg3)

## Add colors based on the presence of a string in the feature names
id_grep <- c("A", "B")
fill_grep <- c("red", "blue")
dna_segs <- edit_dna_segs(dna_seg_input = dna_segs,
                          ids = data.frame(id = id_grep, fill = fill_grep))

## Make comparisons
comp1 <- comparison(data.frame(start1 = c(3, 6, 8), end1 = c(5, 8, 10),
                               start2 = c(3, 9, 7), end2 = c(5, 11, 9),
                               name1 = c("1A", "1B", "1C"),
                               name2 = c("2A", "2B", "2C"),
                               direction = c(1, 1, 1)))
comp2 <- comparison(data.frame(start1 = c(3, 9, 7), end1 = c(5, 11, 9),
                               start2 = c(6, 3, 8), end2 = c(8, 5, 10),
                               name1 = c("2A", "2B", "2C"),
                               name2 = c("3A", "3B", "3C"),
                               direction = c(1, 1, 1)))

## Before using update_comparisons
plot_gene_map(dna_segs = dna_segs, 
              comparisons = list(comp1, comp2),
              alpha_comparisons = 0.6)


## Apply update_comparisons to fix the positions and update the colors
comps <- update_comparisons(dna_seg_input = dna_segs,
                            comparison_input = list(comp1, comp2),
                            seg_id = "name",
                            color_var = "fill",
                            update_positions = TRUE)

## After using update_comparisons
plot_gene_map(dna_segs = dna_segs, 
              comparisons = comps,
              alpha_comparisons = 0.6)