Package {ARGHelpR}


Title: Summarize and Visualize Ancestral Recombination Graphs
Version: 1.0.0
Description: Summarize and visualize ancestral recombination graphs. 'ARGHelpR' uses bed files output from ancestral recombination graph (ARG) estimation programs to calculate various statistics that can be used to identify different forms of natural selection. 'ARGHelpR' also allows users to visualize ARGs and provides educational resources on its website.
URL: https://kfarleigh.github.io/ARGHelpR/
BugReports: https://github.com/kfarleigh/ARGHelpR/issues
License: GPL (≥ 3)
Encoding: UTF-8
Config/roxygen2/version: 8.1.0
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
Imports: ape, dplyr, magrittr, parallel, phangorn, phytools, stats
Depends: R (≥ 4.6)
LazyData: true
VignetteBuilder: knitr
Config/Needs/website: rmarkdown
NeedsCompilation: no
Packaged: 2026-11-13 15:40:14 UTC; keaka
Author: Keaka Farleigh ORCID iD [aut, cre, cph], Dylan K. Highland ORCID iD [aut, ctb], Megan G. Alderman ORCID iD [aut, ctb], Ellie M. Faber ORCID iD [aut, ctb], Lukas Westermann Salas ORCID iD [aut, ctb], Drew R. Schield ORCID iD [aut, cph, ctb]
Maintainer: Keaka Farleigh <keakafarleigh@gmail.com>
Repository: CRAN
Date/Publication: 2026-12-05 15:50:13 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling rhs(lhs).


Visualize ancestral recombination graphs.

Description

Visualize ancestral recombination graphs.

Usage

argplot(
  arg,
  pop1,
  pop2,
  col = c("#6C6EA0", "#1A1F16"),
  scale = NULL,
  font.size = 1
)

Arguments

arg

a newick string of ancestral recombination graph to be visualized.

pop1

a vector of individuals in population one.

pop2

a vector of individuals in population two.

col

a vector of two colors. The first color will be used to color the tips of population 1 and the second will color population 2 tips.

scale

a vector of two numbers. The first number will set the lower bounds of the scale and the second will set the upper bounds. This is useful when you want to compare two args.

font.size

a numeric indicating the size of the tip labels, this is supplied to the cex argument in phytools plotTree function.

Value

a phylogeny with tips colored according to population.

Examples


data(rattlesnake_args)
data(rattlesnake_pops)

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

test_plot <- argplot(arg = rattlesnake_args[[1]][1,4], pop1 = pop1$sample,
pop2 = pop2$sample, col = c("#71BED6","#EDAF49"))

Calculate ancestral recombination graph summary statistics.

Description

Calculate ancestral recombination graph summary statistics.

Usage

argstats(arg.dat, pop1, pop2, pop1.name, pop2.name, n.cores = 1, n.haps = 2)

Arguments

arg.dat

a list where each element is an ancestral recombiation graph represented by a data frame. The data frame columns should be chromosome, start, end, and the phylogeney estimated in ARG analysis.

pop1

a vector of individuals in one population.

pop2

a vector of individuals in the other population.

pop1.name

a character string that tells us the name of population 1.

pop2.name

a character string that tells us the name of population 2.

n.cores

a numeric value indicating the number of cores to run. Default is 1. Anything greater than 1 will run calcualtions in parallel. WARNING increasing this number too high can crash your computer depending on your dataset.

n.haps

a numeric value indicating the minimum number of haplotypes to identify a clade.

Value

A list of elements. Each element is a data frame containing the calculated statistics, the relevant window, and relevant arg. The statistics include the time to the most recent common ancestor between populations/species (tmrca) and estimates of the time to most recent common ancestor within populations/species (tmrcaw). The output also indicates if populations/species are monophyletic and which population/species corresponds to which population.

Author(s)

Keaka Farleigh

Examples

data(rattlesnake_args)
data(rattlesnake_pops)

rattlesnake_test <- rattlesnake_args[1:5]

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

Test <- argstats(arg.dat = rattlesnake_test, pop1 = pop1$sample,
pop2 = pop2$sample, pop1.name = "pop1", pop2.name = "pop2")

An internal helper function to calculate ARG statistics. This is used by argstats.

Description

An internal helper function to calculate ARG statistics. This is used by argstats.

Usage

argstats_helper(arg.dat, pop1, pop2, pop1.name, pop2.name, n.haps = 2)

Arguments

arg.dat

a list element that contains a dataframe. The data frame columns should be chromosome, start, end, and the phylogeney estimated in ARG analysis.

pop1

a vector of individuals in one population.

pop2

a vector of individuals in the other population.

pop1.name

a character string that tells us the name of population 1.

pop2.name

a character string that tells us the name of population 2.

n.haps

a numeric value indicating the minimum number of haplotypes to identify a clade.

Value

A data frame containing the calculated statistics, the relevant window, and relevant arg. The statistics include the time to the most recent common ancestor between populations/species (tmrca), estimates of the time to most recent common ancestor within populations/species (tmrcaw), the tmrca.50; the generations it takes for 50% of the haplotypes to coalesce, and the relative half life (rth); a normalized version of tmrca which is generated by dividing tmrca.50 by the tmrca (tmrca.50/tmrca). The output also indicates if populations/species are monophyletic and which population/species corresponds to which population.

Author(s)

Keaka Farleigh

Examples

data(rattlesnake_args)
data(rattlesnake_pops)

rattlesnake_test <- rattlesnake_args[1:5]

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

Test <- argstats(arg.dat = rattlesnake_test, pop1 = pop1$sample,
pop2 = pop2$sample, pop1.name = "pop1", pop2.name = "pop2")

Identify ancestral recombination graphs under selection that correspond to models of divergence.

Description

Identify ancestral recombination graphs under selection that correspond to models of divergence.

Usage

identify_argcandidates_divergence(
  dat,
  analysis = "all",
  background = NULL,
  tmrca.threshold = NULL,
  pop1.threshold = NULL,
  pop2.threshold = NULL,
  tmrca.iqr.low.threshold = NULL,
  tmrca.iqr.high.threshold = NULL
)

Arguments

dat

a dataframe of ancestral recombination graph statistics calculated using the argstats function.

analysis

a character vector indicating the types of args you want to identify. Options are "all" for all types, "RI", "DS", "RS", "RIDS".

background

a dataframe of ancestral recombination graph statistics calculated using the argstats function. If supplied this will be used to define thresholds and the dat argument will be treated as the test set.

tmrca.threshold

a numeric value to customize the tmrca threshold used to identify ARGs associated with reproductive isolation.

pop1.threshold

a numeric value to customize the pop1 tmrcaw threshold used to identify ARGs associated with within-population selection and recurrent selection.

pop2.threshold

a numeric value to customize the pop2 tmrcaw threshold used to identify ARGs associated with within-population selection and recurrent selection.

tmrca.iqr.low.threshold

a numeric value to customize the lower tmrca threshold used to identify ARGs associated with within-population selection and recurrent selection.

tmrca.iqr.high.threshold

a numeric value to customize the upper tmrca threshold used to identify ARGs associated with within-population selection and recurrent selection.

Value

a list containing ARGs that were identified as candidates

Examples

data("rattlesnake_args")
data("rattlesnake_pops")

rattlesnake_test <- rattlesnake_args[1:5]

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

stat_res <- argstats(arg.dat = rattlesnake_test, pop1 = pop1$sample,
pop2 = pop2$sample, pop1.name = "pop1", pop2.name = "pop2")

stat_df <- do.call("rbind", stat_res)

Test <- identify_argcandidates_divergence(dat = stat_df, analysis = "all")

Identify ancestral recombination graphs under selection that correspond to models of shared variation (introgression and balancing selection).

Description

Identify ancestral recombination graphs under selection that correspond to models of shared variation (introgression and balancing selection).

Usage

identify_argcandidates_shared(
  dat,
  analysis = "all",
  background = NULL,
  tmrca.high.threshold = NULL,
  pop1.threshold = NULL,
  pop2.threshold = NULL,
  tmrca.iqr.low.threshold = NULL,
  tmrca.50.threshold = NULL,
  pop1.tmrcaw.95threshold = NULL,
  pop2.tmrcaw.95threshold = NULL
)

Arguments

dat

a dataframe of ancestral recombination graph statistics calculated using the argstats function.

analysis

a character vector indicating the types of args you want to identify. Options are "all" for all types, "BS" for balancing selection, "INT" for introgression, and "BSINT" for balancing selection + introgression.

background

a dataframe of ancestral recombination graph statistics calculated using the argstats function. If supplied this will be used to define thresholds and the dat argument will be treated as the test set.

tmrca.high.threshold

a numeric value to customize the tmrca threshold used to identify ARGs associated with balancing selection.

pop1.threshold

a numeric value to customize the pop1 tmrcaw threshold used to identify ARGs associated with introgression.

pop2.threshold

a numeric value to customize the pop2 tmrcaw threshold used to identify ARGs associated with introgression.

tmrca.iqr.low.threshold

a numeric value to customize the lower tmrca threshold used to identify ARGs associated with introgression.

tmrca.50.threshold

a numeric value to customize the tmrca.50 threshold used to identify ARGs associated with the combined balancing selection + introgression scenario.

pop1.tmrcaw.95threshold

a numeric value to customize the pop1.tmrcaw.95 threshold used to identify ARGs associated with the combined balancing selection + introgression scenario.

pop2.tmrcaw.95threshold

a numeric value to customize the pop2.tmrcaw.95 threshold used to identify ARGs associated with the combined balancing selection + introgression scenario.

Value

a list containing ARGs that were identified as candidates

Examples

data("rattlesnake_args")
data("rattlesnake_pops")

rattlesnake_test <- rattlesnake_args[1:5]

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

stat_res <- argstats(arg.dat = rattlesnake_test, pop1 = pop1$sample,
pop2 = pop2$sample, pop1.name = "pop1", pop2.name = "pop2")

stat_df <- do.call("rbind", stat_res)

Test <- identify_argcandidates_shared(dat = stat_df, analysis = "all")

Example list where each element is a data frame representing a single ancestral recombination graph; this was generated using data from Farleigh et al. (2026); sample IDs have been anonymized.

Description

A list where each element is a data frame representing a single ancestral recombination graph.

Usage

data(rattlesnake_args)

Format

A list with data frames with four columns:

chromosome

The chromsome information for each ARG.

start

The start position of each ARG.

end

The end position of each ARG.

tree

The ARG for the interval.

...

Source

Farleigh, K., Highland, D. K., Alderman, M. G., Francioli, Y., Hirst, S. R., Faber, E. M., ... & Schield, D. R. (2026). Evolution of genome-wide barriers to gene flow during complex speciation in rattlesnakes. Proceedings of the National Academy of Sciences, 123(21), e2609058123.

Examples

data(rattlesnake_args)
data(rattlesnake_pops)

rattlesnake_test <- rattlesnake_args[1:5]

pop2 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop2"),]
pop1 <- rattlesnake_pops[which(rattlesnake_pops$species == "pop1"),]

Test <- argstats(arg.dat = rattlesnake_test, pop1 = pop1$sample,
pop2 = pop2$sample, pop1.name = "pop1", pop2.name = "pop2")




A data frame containing the population assignments for different haplotypes in the rattlesnake_args data.

Description

Data frame containing 2 columns and 30 rows

Usage

data(rattlesnake_pops)

Format

A data frame with 2 columns and 30 rows:

sample

All haplotypes in the data

species

Population assignment

...

Source

Farleigh, K., Highland, D. K., Alderman, M. G., Francioli, Y., Hirst, S. R., Faber, E. M., ... & Schield, D. R. (2026). Evolution of genome-wide barriers to gene flow during complex speciation in rattlesnakes. Proceedings of the National Academy of Sciences, 123(21), e2609058123.

Examples

data(rattlesnake_pops)
Test <- rattlesnake_pops[,1]