This takes the tibble representation of a GSP and writes it to a dot file to be rendered into a graph using the dot command from the GraphViz package. You can easily get GraphViz using Miniconda or check out the GraphViz downloads page. If you have the dot executable in your PATH, then dot will be run on the dot file and an SVG and a PNG image of the graph.

gsp2dot(
  g,
  path = file.path(tempfile(), "file_prefix"),
  edge_label_font_size = 18,
  indiv_node_label_font_size = 18,
  sample_node_label_font_size = 18,
  haplo_origin_colors = c("lightblue", "orange", "blue", "green", "cadetblue",
    "dodgerblue3", "darkolivegreen1", "forestgreen", "lightpink", "red2", "sandybrown",
    "orangered", "plum3", "purple4", "palegoldenrod", "peru"),
  sam_node_color = "violet",
  sample_edge_label_color = "purple",
  parent_edge_label_color = "red"
)

Arguments

g

a GSP tibble.

path

the path to the file prefix to use (to this will be appended .dot, and .png or .svg, if dot is on your system). By default these paths are in a temporary directory, because packages are not allowed to write to user home directories by default. Supply a path with prefix, like my_path/myfile to get the output file mypath.myfile.dot

edge_label_font_size

The font size of the number annotations along the edges.

indiv_node_label_font_size

the font size of the labels for the individual nodes

sample_node_label_font_size

the font size of the labels for the individual nodes

haplo_origin_colors

The colors for different origins of haplotypes. By default there are only sixteen. If you have more populations that founders may come from, you should provide a vector with more than 16 colors.

sam_node_color

The color given to the sample nodes in the GSP.

sample_edge_label_color

Color for the numeric annotations along the edges leading to samples.

parent_edge_label_color

Color for the numeric annotations along the edges leading from parents to offspring.

Value

A vector of file paths. The first is the path of the dot file that was produced. The second and third are only present if dot was found in the PATH. They are the paths of the png and svg files that were produced.

Details

It can be tricky knowing whether or not R or Rstudio will read your Unix rc files and populate your paths appropriately. If you want to test whether dot in on your PATH as it is when running under R, try: Sys.which("dot") at your R console. If that returns an empty string, (""), then you need to do something else to make sure R can find dot on your system.

Examples

gsp_file <- system.file("extdata/13-member-ped.csv", package = "gscramble")
g <- readr::read_csv(gsp_file)
#> Rows: 13 Columns: 11
#> ── Column specification ────────────────────────────────────────────────────────
#> Delimiter: ","
#> chr (5): hap1, hap2, hpop1, hpop2, sample
#> dbl (6): ind, par1, par2, ipar1, ipar2, osample
#> 
#>  Use `spec()` to retrieve the full column specification for this data.
#>  Specify the column types or set `show_col_types = FALSE` to quiet this message.

paths <- gsp2dot(g)
#> Cannot find dot on the system path. Returning the path to just the dot file, but not the rendered png and svg files.
paths
#>                                                dot 
#> "/tmp/Rtmp2pzuif/file190b4d73b020/file_prefix.dot"