Skip to contents
Chapters and reference

Data and workflows · Section 2 of 12

6.1 Import sequences and annotations

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 Adapt an existing table

The preparation above loads the input tables. These examples rename columns of bundled source-backed sequences, links and genes; they do not invent alignments.

R · Example code
renamed_sequences <- seqs |>
  rename(chrom = accver, size = length)
sequence_input <- as_ggchord_seq(renamed_sequences, mapping = c(accver = "chrom", length = "size"))
renamed_features <- genes |>
  rename(chrom = accver, left = start, right = end)
feature_input <- as_ggchord_feature(renamed_features,
  mapping = c(accver = "chrom", start = "left", end = "right")
)
link_input <- as_ggchord_link(links)
Output / text
  .source_row    qaccver    saccver qstart  qend sstart  send
1           1 MT108731.1 MT118296.1  26298 51139   7121 31959
2           2 MT108731.1 MT118296.1  21513 25922   2365  6772
3           3 MT108731.1 MT118296.1  20376 20677    403   704
4           4 MT108731.1 OQ646790.1  45278 50839  27955 33476

Adapters return ordinary frames with ggchord_conversion provenance. IDs remain unchanged. Supply reliable full lengths rather than using maximum feature ends. See alignment input for minimal fields and coordinate units.

2 GenBank: retain record identity

R · Example code
# The original NCBI L09137.2 record identifies pUC19c; keep that identity.
genbank_result <- NULL
if (nzchar(Sys.which("python3")) && identical(suppressWarnings(system2("python3",
  c("-c", shQuote("from Bio import SeqIO")),
  stdout = FALSE, stderr = FALSE
)), 0L)) {
  genbank_result <- read_genbank("examples/format-inputs/pUC19c-L09137.2.gb")
}
Output / text
 NULL

This is the original NCBI L09137.2 record, named pUC19c; do not rename it to the bundled pUC19. Results include seq_data, features$annotation and report, retaining segmented locations and record/feature provenance. The selected Python needs Biopython already installed; no automatic installation occurs. unsupported = "report" records unsupported locations rather than guessing bounds.

The GenBank example was rerun with Python Biopython 1.85 enabled: it returned L09137.2, length 2686 bp and one annotation row. For a separate documentation environment, install Biopython with that Python’s python3 -m pip install biopython, then put its executable on PATH before starting R. Do not treat an optional-dependency skip or NULL as successful import.

An explicit python path keeps the selected virtual environment, including interpreter symlinks; no environment is installed or modified.

Extract the manual bundle so the working directory contains examples/. Read one format at a time, inspect a few rows, then match sequence IDs.

3 FASTA lengths and GFF3 annotations

R · Example code
head(read_fasta_lengths(files = "examples/fasta/*.fna"), 4)
accver length .source_line
MT108731.1 64323 1
MT118296.1 32090 1
OQ646790.1 57367 1
OR222515.1 83080 1

FASTA supplies full lengths. GFF3 supplies intervals, types and source strands. Select CDS for plotting as needed.

R · Example code
gff <- read_gff3(files = "examples/gff3/*.gff3", unstranded = "keep")
head(gff[c("accver", "start", "end", "strand", "type")], 4)
accver start end strand type
MT108731.1 13064 14554 + CDS
MT108731.1 22920 23705 + CDS
MT108731.1 23894 24814 + CDS
MT108731.1 27115 28053 + CDS

4 Read a BLAST table

R · Example code
hits <- read_blast(file = "examples/blastn-standard/MT108731.1__MT118296.1.tsv")
head(hits[c("qaccver", "saccver", "qstart", "qend", "sstart", "send")], 3)
qaccver saccver qstart qend sstart send
MT108731.1 MT118296.1 26298 51139 7121 31959
MT108731.1 MT118296.1 21513 25922 2365 6772
MT108731.1 MT118296.1 20691 21146 1032 1495

Each row contains two intervals. Keep their endpoint order and check both sequence IDs against the FASTA records. See alignment inputs for standard BLAST output.

5 Convert Bioconductor objects directly

With GenomicRanges installed, convert one interval into a feature table. Known full lengths are supplied in seqlengths and can be extracted with as_ggchord_seq(gr).

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 +

The first GInteractions anchor is the query, and the second is the subject. This minimal example joins two intervals. It also requires InteractionSet.

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

See import and conversion for other inputs. Use the converted tables to add layers.

Search documentation

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