Contents

1 Introduction

Seqinfo is an R/Bioconductor infrastructure package that implements a simple S4 class, the Seqinfo class, for storing the following information about a collection of genomic sequences:

The sequences described in a Seqinfo object are typically, but not necessarily, the chromosomes and/or scaffolds of a specific genome assembly of a given organism.

Note that Seqinfo objects are rarely used as standalone objects. Instead, they are used as part of higher-level objects to represent their seqinfo() component. Examples of such higher-level objects are GRanges, RangedSummarizedExperiment, VCF, GAlignments, TxDb, etc… defined in other Bioconductor infrastructure packages.

2 Install and load the package

Like any Bioconductor package, Seqinfo should be installed with BiocManager::install():

if (!require("BiocManager", quietly=TRUE))
    install.packages("BiocManager")
BiocManager::install("Seqinfo")

BiocManager::install() will take care of installing the package dependencies that are missing.

Load the package:

library(Seqinfo)

3 The Seqinfo constructor

Seqinfo objects can be created with the Seqinfo() constructor function:

## Note that all the arguments (except 'genome') must have the
## same length. 'genome' can be of length 1, whatever the lengths
## of the other arguments are.
si1 <- Seqinfo(seqnames=c("chr1", "chr2", "chr3", "chrM"),
               seqlengths=c(100, 200, NA, 15),
               isCircular=c(NA, FALSE, FALSE, TRUE),
               genome="toy")
si1
## Seqinfo object with 4 sequences (1 circular) from toy genome:
##   seqnames seqnames seqlengths isCircular genome
##   1            chr1        100         NA    toy
##   2            chr2        200      FALSE    toy
##   3            chr3         NA      FALSE    toy
##   4            chrM         15       TRUE    toy

One special form of calling the Seqinfo() constructor function is to specify only the genome argument and set it to the name of an NCBI assembly (e.g. Seqinfo(genome="GRCh38.p14")) or UCSC genome (e.g. Seqinfo(genome="hg38")), in which case the sequence information is fetched from NCBI or UCSC. This requires the GenomeInfoDb package (the package only needs to be installed):

library(GenomeInfoDb)  # just making sure that the package is installed

Seqinfo(genome="GRCh38.p14")
## Seqinfo object with 709 sequences (1 circular) from GRCh38.p14 genome:
##   seqnames       seqnames seqlengths isCircular     genome
##   1                     1  248956422      FALSE GRCh38.p14
##   2                     2  242193529      FALSE GRCh38.p14
##   3                     3  198295559      FALSE GRCh38.p14
##   4                     4  190214555      FALSE GRCh38.p14
##   5                     5  181538259      FALSE GRCh38.p14
##   ...                 ...        ...        ...        ...
##   705      HSCHR22_8_CTG1     145162      FALSE GRCh38.p14
##   706       HSCHRX_3_CTG7     188004      FALSE GRCh38.p14
##   707      HSCHRX_1_CTG14     619716      FALSE GRCh38.p14
##   708      HSCHRX_2_CTG14     294119      FALSE GRCh38.p14
##   709       HSCHRX_3_CTG3     330493      FALSE GRCh38.p14
Seqinfo(genome="hg38")
## Seqinfo object with 711 sequences (1 circular) from hg38 genome:
##   seqnames             seqnames seqlengths isCircular genome
##   1                        chr1  248956422      FALSE   hg38
##   2                        chr2  242193529      FALSE   hg38
##   3                        chr3  198295559      FALSE   hg38
##   4                        chr4  190214555      FALSE   hg38
##   5                        chr5  181538259      FALSE   hg38
##   ...                       ...        ...        ...    ...
##   707      chr22_KQ759761v1_alt     145162      FALSE   hg38
##   708       chrX_KV766199v1_alt     188004      FALSE   hg38
##   709       chrX_MU273395v1_alt     619716      FALSE   hg38
##   710       chrX_MU273396v1_alt     294119      FALSE   hg38
##   711       chrX_MU273397v1_alt     330493      FALSE   hg38

See ?Seqinfo for more information.

4 Seqinfo accessors

Various accessor functions are provided:

length(si1)
## [1] 4
seqnames(si1)
## [1] "chr1" "chr2" "chr3" "chrM"
names(si1)
## [1] "chr1" "chr2" "chr3" "chrM"
seqlevels(si1)
## [1] "chr1" "chr2" "chr3" "chrM"
seqlengths(si1)
## chr1 chr2 chr3 chrM 
##  100  200   NA   15
isCircular(si1)
##  chr1  chr2  chr3  chrM 
##    NA FALSE FALSE  TRUE
genome(si1)
##  chr1  chr2  chr3  chrM 
## "toy" "toy" "toy" "toy"

See ?Seqinfo for more information.

5 Operations on Seqinfo objects

5.1 Subset by seqnames

A Seqinfo object can be subsetted by seqnames:

si1[c("chrY", "chr3", "chr1")]
## Seqinfo object with 3 sequences from 2 genomes (NA, toy):
##   seqnames seqnames seqlengths isCircular genome
##   1            chrY         NA         NA   <NA>
##   2            chr3         NA      FALSE    toy
##   3            chr1        100         NA    toy

5.2 Rename, drop, add and/or reorder the sequences

Rename:

si <- si1
seqlevels(si) <- sub("chr", "ch", seqlevels(si))
si
## Seqinfo object with 4 sequences (1 circular) from toy genome:
##   seqnames seqnames seqlengths isCircular genome
##   1             ch1        100         NA    toy
##   2             ch2        200      FALSE    toy
##   3             ch3         NA      FALSE    toy
##   4             chM         15       TRUE    toy

Reorder:

seqlevels(si) <- rev(seqlevels(si))
si
## Seqinfo object with 4 sequences (1 circular) from toy genome:
##   seqnames seqnames seqlengths isCircular genome
##   1             chM         15       TRUE    toy
##   2             ch3         NA      FALSE    toy
##   3             ch2        200      FALSE    toy
##   4             ch1        100         NA    toy

Drop/add/reorder:

seqlevels(si) <- c("ch1", "ch2", "chY")
si
## Seqinfo object with 3 sequences from 2 genomes (toy, NA):
##   seqnames seqnames seqlengths isCircular genome
##   1             ch1        100         NA    toy
##   2             ch2        200      FALSE    toy
##   3             chY         NA         NA   <NA>

Rename/reorder/drop/add:

seqlevels(si) <- c(chY="Y", ch1="1", "22")
si
## Seqinfo object with 3 sequences from 2 genomes (NA, toy):
##   seqnames seqnames seqlengths isCircular genome
##   1               Y         NA         NA   <NA>
##   2               1        100         NA    toy
##   3              22         NA         NA   <NA>

See ?Seqinfo for more information.

5.3 Merge Seqinfo objects

Two Seqinfo objects can be merged if they are compatible:

si2 <- Seqinfo(seqnames=c("chr3", "chr4", "chrM"),
               seqlengths=c(300, NA, 15))
si2
## Seqinfo object with 3 sequences from an unspecified genome:
##   seqnames seqnames seqlengths isCircular genome
##   1            chr3        300         NA   <NA>
##   2            chr4         NA         NA   <NA>
##   3            chrM         15         NA   <NA>
merge(si1, si2)  # rows for chr3 and chrM are merged
## Warning in .merge_two_Seqinfo_objects(x, y): Each of the 2 combined objects has sequence levels not in the other:
##   - in 'x': chr1, chr2
##   - in 'y': chr4
##   Make sure to always combine/compare objects based on the same reference
##   genome (use suppressWarnings() to suppress this warning).
## Seqinfo object with 5 sequences (1 circular) from 2 genomes (toy, NA):
##   seqnames seqnames seqlengths isCircular genome
##   1            chr1        100         NA    toy
##   2            chr2        200      FALSE    toy
##   3            chr3        300      FALSE    toy
##   4            chrM         15       TRUE    toy
##   5            chr4         NA         NA   <NA>
suppressWarnings(merge(si1, si2))
## Seqinfo object with 5 sequences (1 circular) from 2 genomes (toy, NA):
##   seqnames seqnames seqlengths isCircular genome
##   1            chr1        100         NA    toy
##   2            chr2        200      FALSE    toy
##   3            chr3        300      FALSE    toy
##   4            chrM         15       TRUE    toy
##   5            chr4         NA         NA   <NA>

Note that, strictly speaking, merging two Seqinfo objects is not a commutative operation, i.e., in general z1 <- merge(x, y) is not identical to z2 <- merge(y, x). However z1 and z2 are guaranteed to contain the same information (i.e. the same rows, but typically not in the same order):

suppressWarnings(merge(si2, si1))
## Seqinfo object with 5 sequences (1 circular) from 2 genomes (toy, NA):
##   seqnames seqnames seqlengths isCircular genome
##   1            chr3        300      FALSE    toy
##   2            chr4         NA         NA   <NA>
##   3            chrM         15       TRUE    toy
##   4            chr1        100         NA    toy
##   5            chr2        200      FALSE    toy

Trying to merge Seqinfo objects that are not compatible will raise an error:

## This contradicts what 'x' says about circularity of chr3 and chrM:
isCircular(si2)[c("chr3", "chrM")] <- c(TRUE, FALSE)
si2
## Seqinfo object with 3 sequences (1 circular) from an unspecified genome:
##   seqnames seqnames seqlengths isCircular genome
##   1            chr3        300       TRUE   <NA>
##   2            chr4         NA         NA   <NA>
##   3            chrM         15      FALSE   <NA>
merge(si1, si2)  # ERROR!
## Error in mergeNamedAtomicVectors(isCircular(x), isCircular(y), what = c("sequence",  :
##   sequences chr3, chrM have incompatible circularity flags:
##   - in 'x': FALSE, TRUE
##   - in 'y': TRUE, FALSE

See ?Seqinfo for more information.

6 Seqinfo objects as parts of higher-level objects

Seqinfo objects are typically found as part of higher-level objects to represent their seqinfo() component. For example, in TxDb objects:

library(TxDb.Hsapiens.UCSC.hg38.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene
class(txdb)
## [1] "TxDb"
## attr(,"package")
## [1] "GenomicFeatures"
seqinfo(txdb)
## Seqinfo object with 711 sequences (1 circular) from hg38 genome:
##   seqnames             seqnames seqlengths isCircular genome
##   1                        chr1  248956422      FALSE   hg38
##   2                        chr2  242193529      FALSE   hg38
##   3                        chr3  198295559      FALSE   hg38
##   4                        chr4  190214555      FALSE   hg38
##   5                        chr5  181538259      FALSE   hg38
##   ...                       ...        ...        ...    ...
##   707      chr22_KQ759761v1_alt     145162      FALSE   hg38
##   708       chrX_KV766199v1_alt     188004      FALSE   hg38
##   709       chrX_MU273395v1_alt     619716      FALSE   hg38
##   710       chrX_MU273396v1_alt     294119      FALSE   hg38
##   711       chrX_MU273397v1_alt     330493      FALSE   hg38

and in BSgenome objects:

library(BSgenome.Hsapiens.UCSC.hg38)
bsg <- BSgenome.Hsapiens.UCSC.hg38
class(bsg)
## [1] "BSgenome"
## attr(,"package")
## [1] "BSgenome"
seqinfo(bsg)
## Seqinfo object with 711 sequences (1 circular) from hg38 genome:
##   seqnames             seqnames seqlengths isCircular genome
##   1                        chr1  248956422      FALSE   hg38
##   2                        chr2  242193529      FALSE   hg38
##   3                        chr3  198295559      FALSE   hg38
##   4                        chr4  190214555      FALSE   hg38
##   5                        chr5  181538259      FALSE   hg38
##   ...                       ...        ...        ...    ...
##   707      chr22_KQ759761v1_alt     145162      FALSE   hg38
##   708       chrX_KV766199v1_alt     188004      FALSE   hg38
##   709       chrX_MU273395v1_alt     619716      FALSE   hg38
##   710       chrX_MU273396v1_alt     294119      FALSE   hg38
##   711       chrX_MU273397v1_alt     330493      FALSE   hg38

Sanity checks:

stopifnot(identical(seqinfo(txdb), Seqinfo(genome="hg38")))
stopifnot(identical(seqinfo(bsg), Seqinfo(genome="hg38")))

7 Session information

Here is the output of sessionInfo() on the system on which this document was compiled:

sessionInfo()
## R version 4.6.1 (2026-06-24)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 24.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.24-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0  LAPACK version 3.12.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] BSgenome.Hsapiens.UCSC.hg38_1.4.5       
##  [2] TxDb.Hsapiens.UCSC.hg38.knownGene_3.22.0
##  [3] BSgenome_1.81.1                         
##  [4] rtracklayer_1.73.0                      
##  [5] BiocIO_1.23.3                           
##  [6] Biostrings_2.81.7                       
##  [7] XVector_0.53.0                          
##  [8] GenomicFeatures_1.65.0                  
##  [9] AnnotationDbi_1.75.2                    
## [10] Biobase_2.73.2                          
## [11] GenomicRanges_1.65.3                    
## [12] GenomeInfoDb_1.49.1                     
## [13] IRanges_2.47.5                          
## [14] S4Vectors_0.51.9                        
## [15] Seqinfo_1.3.2                           
## [16] BiocGenerics_0.59.12                    
## [17] generics_0.1.4                          
## [18] BiocStyle_2.41.0                        
## 
## loaded via a namespace (and not attached):
##  [1] KEGGREST_1.53.6             SummarizedExperiment_1.43.0
##  [3] rjson_0.2.23                xfun_0.60                  
##  [5] bslib_0.12.0                lattice_0.23-1             
##  [7] vctrs_0.7.3                 tools_4.6.1                
##  [9] bitops_1.1-0                curl_8.0.0                 
## [11] parallel_4.6.1              RSQLite_3.53.3             
## [13] blob_1.3.0                  pkgconfig_2.0.3            
## [15] BiocBaseUtils_1.15.1        Matrix_1.7-6               
## [17] cigarillo_1.3.1             lifecycle_1.0.5            
## [19] compiler_4.6.1              Rsamtools_2.29.0           
## [21] codetools_0.2-20            htmltools_0.5.9            
## [23] sass_0.4.10                 RCurl_1.98-1.20            
## [25] yaml_2.3.12                 crayon_1.5.3               
## [27] jquerylib_0.1.4             BiocParallel_1.47.0        
## [29] DelayedArray_0.39.6         cachem_1.1.0               
## [31] abind_1.4-8                 digest_0.6.39              
## [33] restfulr_0.0.17             bookdown_0.47              
## [35] fastmap_1.2.0               grid_4.6.1                 
## [37] SparseArray_1.13.2          cli_3.6.6                  
## [39] S4Arrays_1.13.0             XML_3.99-0.24              
## [41] UCSC.utils_1.9.0            bit64_4.8.4                
## [43] rmarkdown_2.31              httr_1.4.8                 
## [45] matrixStats_1.5.0           bit_4.6.0                  
## [47] otel_0.2.0                  png_0.1-9                  
## [49] memoise_2.0.1               evaluate_1.0.5             
## [51] knitr_1.51                  rlang_1.3.0                
## [53] DBI_1.3.0                   BiocManager_1.30.27        
## [55] jsonlite_2.0.0              R6_2.6.1                   
## [57] MatrixGenerics_1.25.0       GenomicAlignments_1.49.1