Chapters and reference
- 6.1Import sequences and annotations
- 6.2Import intervals and paired intervals
- 6.3Signals and coverage data
- 6.4Aligned characters and source coordinates
- 6.5Relationships, variants and annotations
- 6.6Import nucleotide and protein alignments
- 6.7BLASTp protein comparisons
- 6.8Protein-to-genome coordinate projection
- 6.9Data workflows
- 6.10Sequence comparisons from source files
- 6.11Flagship data sources and construction
Data and workflows · Section 3 of 12
6.2 Import intervals and paired intervals
On this page
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 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.
| accver | start | end | strand | .source_row | directionality | source_strand |
|---|---|---|---|---|---|---|
| a | 10 | 30 | + | 1 | forward | + |
| 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.