Formatting data for ARGHelpR
Source:vignettes/articles/ARGHelpR_formatting.Rmd
ARGHelpR_formatting.RmdWritten by: Keaka Farleigh, Ph.D.
Date: September, 16th, 2026.
Date last modified: September, 17th, 2026
Purpose
To help you understand the input format for ARGHelpR and how to convert the output from ancestral recombination graph (ARG) estimation programs into this format.
Format expected by ARGHelpR
ARGHelpR uses bed files for analysis. There are four columns that are tab-delimited. The first column contains the chromosome, the second contains the start position, the third contains the end position, and the fourth column contains the ARG for that region.
The is natively output by ARGWeaver (Rasmussen
et al., 2014), using the smc2bed function, but we have
to convert output from other programs to bed format. We provide a couple
scripts below to help. Note that these are python
scripts.
The smc2bed will generate a bed file for each ARG
analysis, as will the scripts below. You can use the command
cat *.bed > my_args.bed to combine all of them if you
ran them seperately for different regions of the genome.
Converting output from ARG-Needle
This is a script to convert output from ARG-Needle (Zhang et al., 2023).
import arg_needle_lib
import tskit
def export_arg_to_tree_bed(argn_path, chromosome, output_bed):
# Load the inferred ARG from the .argn file
arg_obj = arg_needle_lib.load_arg(argn_path)
# Convert the ARG object to a tskit TreeSequence object
# This automatically splits the genome into non-recombining interval segments
ts = arg_needle_lib.arg_to_tskit(arg_obj)
# Write intervals in bed format
with open(output_bed, 'w') as bed_file:
# Iterate through each local tree segment along the sequence length
for tree in ts.trees():
# Get start and end positions for the interval
start = int(tree.interval.left)
end = int(tree.interval.right)
# Generate the Newick string phylogeny
newick_str = tree.newick()
# Write out bed file
bed_file.write(f"{chromosome}\t{start}\t{end}\t{newick_str}\n")
# Example Usage:
export_arg_to_tree_bed("myarg.argn", "chr1", "myarg_chr1_trees.bed")Then you can combine all of the ARGs for each chromosome for use in ARGHelpR (see cat command above).
Converting output from tsinfer
This is a script to convert output from tsinfer (Kelleher et al., 2019).
import tskit
def ts_to_bed(tree_sequence_path, chromosome, output_bed):
# Load the ARG
ts = tskit.load(tree_sequence_path)
with open(output_bed, "w") as bed_file:
# Iterate through every local tree along the genome
for tree in ts.trees():
# Get start and end positions for the interval
start = int(tree.interval.left)
end = int(tree.interval.right)
# Generate the Newick string phylogeny
newick_tree = tree.newick()
# Write out bed file
bed_file.write(f"{chromosome}\t{start}\t{end}\t{newick_tree}\n")
# Example Usage:
ts_to_bed("myarg.trees", "chr1", "myarg_chr1_trees.bed")Then you can combine all of the ARGs for each chromosome for use in ARGHelpR (see cat command above).
Please reach out to Keaka Farleigh if you have any questions.
Literature Cited
Kelleher, J., Wong, Y., Wohns, A. W., Fadil, C., Albers, P. K., & McVean, G. (2019). Inferring whole-genome histories in large population datasets. Nature genetics, 51(9), 1330-1338.
Rasmussen, M. D., Hubisz, M. J., Gronau, I., & Siepel, A. (2014). Genome-wide inference of ancestral recombination graphs. PLoS genetics, 10(5), e1004342.
Zhang, B. C., Biddanda, A., Gunnarsson, Á. F., Cooper, F., & Palamara, P. F. (2023). Biobank-scale inference of ancestral recombination graphs enables genealogical analysis of complex traits. Nature Genetics, 55(5), 768-776.