Skip to contents
Chapters and reference

Data and workflows · Section 3 of 12

6.2 Import intervals and paired intervals

Download R scriptIncludes preparation and every page step. File examples need the input bundle; preview and save calls are retained.
On this page
R · Example code
library(ggchord)
library(dplyr)
Data preparation and settings (expand)
R · Example code
library(dplyr)
seqs <- seq_data_example |>
  select(accver, length)
links <- ribbon_data_example |>
  select(qaccver, saccver, qstart, qend, sstart, send)
# Recover biological strands from the source annotation field.
genes <- gene_data_example |>
  transmute(accver, start, end, strand = source_strand)

Extract the input bundle so the working directory contains examples/. Each section names its optional dependencies.

1 BED and PAF: convert coordinates once

BED starts at zero and excludes the right endpoint. Read the pUC19 origin interval and compare the coordinates before and after import.

R · Example code
bed_path <- tempfile(fileext = ".bed")
writeLines("pUC19\t866\t1455", bed_path)
bed_features <- read_bed(bed_path)
unlink(bed_path)
bed_features
accver start end strand directionality chromStart chromEnd .source_line
pUC19 867 1455 . none 866 1455 1

PAF gives the full sequence lengths and alignment spans. Select alignments with mapq ≥ 30, then collect both sequences and their lengths for plotting.

R · Example code
paf_source <- read_paf("examples/format-inputs/emales-pair.paf")
paf_links <- filter(paf_source, !is.na(mapq), mapq >= 30)
paf_seqs <- bind_rows(
  transmute(paf_source, accver = qaccver, length = qlen),
  transmute(paf_source, accver = saccver, length = slen)
) |> distinct()
head(select(paf_links, qaccver, qstart, qend, saccver, sstart, send), 3)
qaccver qstart qend saccver sstart send
BVI_023A 1728 11139 Cflag_017A 17357 7863
BVI_023A 15258 15450 Cflag_017A 4320 4129
R · Example code
p_paf <- ggchord(paf_seqs) +
  geom_seq() +
  geom_seq_label() +
  geom_link_ribbon(data = paf_links) +
  coord_collinear()
view_ggchord(p_paf, width = 10, height = 5, units = "in")
A real minimap2 PAF comparison between two EMALE genomes
A real minimap2 PAF comparison between two EMALE genomes · Open full-resolution figure

A reverse alignment has descending subject coordinates. Use the converted coordinates directly for plotting.

2 Optional interval objects

Convert one interval and then an interval pair. Full lengths come from seqlengths. Install GenomicRanges for the first example and InteractionSet for the second.

R · Example code
gr <- GenomicRanges::GRanges("a", IRanges::IRanges(10, 30), strand = "+", seqlengths = c(a = 100))
as_ggchord_feature(gr)
accver start end strand .source_row directionality source_strand
a 10 30 + 1 forward +
R · Example code
query <- GenomicRanges::GRanges("a", IRanges::IRanges(10, 30), seqlengths = c(a = 100))
subject <- GenomicRanges::GRanges("b", IRanges::IRanges(40, 60), seqlengths = c(b = 120))
pair <- InteractionSet::GInteractions(query, subject)
as_ggchord_link(pair)
qaccver saccver qstart qend sstart send qstrand sstrand .source_row .query_anchor .subject_anchor orientation_known direction query_directionality subject_directionality
a b 10 30 40 60 * * 1 1 2 FALSE None none none

3 Paired BED intervals

read_bedpe() reads six required tab-separated fields, optional name/score/two strands and additional metadata. The first anchor stays query and the second stays subject. Scores remain strings; neither Identity nor read support is inferred. The format follows the BEDPE description.

This example re-encodes the intervals of bundled observed alignments for a coordinate round trip; it is not paired-read evidence. Six columns contain no strand evidence, so the imported anchor strands and relative direction remain unknown. Supply real strand columns when known; do not infer them from ascending coordinates.

R · Example code
data(ribbon_data_example)
paired_rows <- ribbon_data_example |>
  transmute(
    chrom1 = qaccver, start1 = pmin(qstart, qend) - 1, end1 = pmax(qstart, qend),
    chrom2 = saccver, start2 = pmin(sstart, send) - 1, end2 = pmax(sstart, send)
  )
paired_file <- tempfile(fileext = ".bedpe")
write.table(paired_rows, paired_file,
  sep = "\t", quote = FALSE, row.names = FALSE, col.names = FALSE
)
paired_links <- read_bedpe(paired_file)
unlink(paired_file)
paired_links |>
  select(qaccver, saccver, qstart, qend, sstart, send, q_mapped, s_mapped)

Negative-strand anchors use decreasing canonical endpoints, consistent with paired-interval adapters; the original start/end and strand fields are also retained. Names are not assumed unique. Extra columns remain in bedpe_extra, named column_11 onwards. Unknown chromosomes (.) and boundaries (-1) fail by default. Explicit unmapped="keep" retains incomplete rows for auditing; filter q_mapped & s_mapped before adaptation or plotting. Invalid known coordinates and zero-width intervals always fail. For interval ribbons without Identity, set a constant fill explicitly rather than manufacturing pident.

Search documentation

↑ ↓ select · Enter open · Esc close; or browse by task. API and functions