Title: | Wrappers to Save Common File Formats |
---|---|
Description: | Save common bioinformatics file formats within the alabaster framework. This includes BAM, BED, VCF, bigWig, bigBed, FASTQ, FASTA and so on. We save and load additional metadata for each file, and we support linkage between each file and its corresponding index. |
Authors: | Aaron Lun [aut, cre] |
Maintainer: | Aaron Lun <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.3.0 |
Built: | 2024-07-23 05:31:01 UTC |
Source: | https://github.com/bioc/alabaster.files |
Reference to a BAM file, for saving and reading in the alabaster framework.
BamFileReference(path, index = NULL)
BamFileReference(path, index = NULL)
path |
String containing the path to a BAM file. |
index |
String specifying the path to a BAI or CSI index file, or |
A BamFileReference instance that can be used in saveObject
.
Aaron Lun
# Using a BAM file from Rsamtools. fl <- system.file("extdata", "ex1.bam", package="Rsamtools", mustWork=TRUE) # Creating a BamFileReference. wrapped <- BamFileReference(fl) wrapped # Fetching the path information: path(wrapped) wrapped$index # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Reading it back again: readObject(dir)
# Using a BAM file from Rsamtools. fl <- system.file("extdata", "ex1.bam", package="Rsamtools", mustWork=TRUE) # Creating a BamFileReference. wrapped <- BamFileReference(fl) wrapped # Fetching the path information: path(wrapped) wrapped$index # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Reading it back again: readObject(dir)
Reference to a BCF file, for saving and loading in the alabaster framework.
BcfFileReference(path, index = NULL)
BcfFileReference(path, index = NULL)
path |
String containing the path to a BCF file. |
index |
String specifying the path to an index file in tabix or CSI format, or |
A BcfFileReference instance that can be used in saveObject
.
Aaron Lun
# Using Rsamtools's example file. fl <- system.file("extdata", "ex1.bcf.gz", package="Rsamtools") # Creating a BcfFileReference. wrapped <- BcfFileReference(fl) wrapped # Fetching the path information: path(wrapped) wrapped$index # Staging the BcfFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Using Rsamtools's example file. fl <- system.file("extdata", "ex1.bcf.gz", package="Rsamtools") # Creating a BcfFileReference. wrapped <- BcfFileReference(fl) wrapped # Fetching the path information: path(wrapped) wrapped$index # Staging the BcfFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
Reference to a BED file, for saving and loading in the alabaster framework.
BedFileReference(path, index = NULL)
BedFileReference(path, index = NULL)
path |
String containing the path to a Gzip- or BGZF-compressed BED file. |
index |
String containing a path to a tabix file.
If supplied, |
A BedFileReference instance that can be used in saveObject
.
Aaron Lun
# Mocking up a BED file. raw <- tempfile(fileext=".bed") bed <- write("chr1\t2222\t33333", file=raw) tmp <- tempfile(fileext=".bed.bgz") Rsamtools::bgzip(raw, tmp) # Creating a BedFileReference. wrapped <- BedFileReference(tmp) wrapped # Extracting the paths: path(wrapped) wrapped$index # Saving it to disk. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Mocking up a BED file. raw <- tempfile(fileext=".bed") bed <- write("chr1\t2222\t33333", file=raw) tmp <- tempfile(fileext=".bed.bgz") Rsamtools::bgzip(raw, tmp) # Creating a BedFileReference. wrapped <- BedFileReference(tmp) wrapped # Extracting the paths: path(wrapped) wrapped$index # Saving it to disk. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
This class is deprecated and only listed here for back-compatibility purposes.
BgzipIndexWrapper(path)
BgzipIndexWrapper(path)
path |
String containing the path to a Bgzip index file. |
The BgzipIndexWrapper class is a subclass of a Wrapper,
so all of the methods of the latter can also be used here, e.g., path
.
A BgzipIndexWrapper instance that can be used in stageObject
.
Aaron Lun
# Mocking up a FASTA index file. input <- system.file("extdata", "ce2dict1.fa", package="Rsamtools") temp <- tempfile(fileext=".fa.bgz") copy <- Rsamtools::bgzip(input, dest=temp) Rsamtools::indexFa(copy) # Creating a BgzipIndexWrapper. wrapped <- BgzipIndexWrapper(paste0(copy, ".gzi")) wrapped # Staging the BgzipIndexWrapper. dir <- tempfile() library(alabaster.base) info <- stageObject(wrapped, dir, "tab") invisible(.writeMetadata(info, dir)) list.files(dir, recursive=TRUE) # Loading it back again: meta <- acquireMetadata(dir, "tab/file.fa.bgz.gzi") loadObject(meta, dir)
# Mocking up a FASTA index file. input <- system.file("extdata", "ce2dict1.fa", package="Rsamtools") temp <- tempfile(fileext=".fa.bgz") copy <- Rsamtools::bgzip(input, dest=temp) Rsamtools::indexFa(copy) # Creating a BgzipIndexWrapper. wrapped <- BgzipIndexWrapper(paste0(copy, ".gzi")) wrapped # Staging the BgzipIndexWrapper. dir <- tempfile() library(alabaster.base) info <- stageObject(wrapped, dir, "tab") invisible(.writeMetadata(info, dir)) list.files(dir, recursive=TRUE) # Loading it back again: meta <- acquireMetadata(dir, "tab/file.fa.bgz.gzi") loadObject(meta, dir)
Reference to a bigBed file, for saving and loading in the alabaster framework.
BigBedFileReference(path)
BigBedFileReference(path)
path |
String containing the path to a bigBed file. |
A BigBedFileReference instance that can be used in stageObject
.
Aaron Lun
# Mocking up a bigBed file. test_path <- system.file("tests", "test.bb", package = "rtracklayer") # Creating a BigBedFileReference. wrapped <- BigBedFileReference(test_path) wrapped # Staging the BigBedFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Mocking up a bigBed file. test_path <- system.file("tests", "test.bb", package = "rtracklayer") # Creating a BigBedFileReference. wrapped <- BigBedFileReference(test_path) wrapped # Staging the BigBedFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
Reference to a bigWig file, for saving and loading in the alabaster framework.
BigWigFileReference(path)
BigWigFileReference(path)
path |
String containing the path to a bigWig file. |
A BigWigFileReference instance that can be used in stageObject
.
Aaron Lun
# Mocking up a bigWig file. test_path <- system.file("tests", "test.bw", package = "rtracklayer") # Creating a BigWigFileReference. wrapped <- BigWigFileReference(test_path) wrapped # Staging the BigWigFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Mocking up a bigWig file. test_path <- system.file("tests", "test.bw", package = "rtracklayer") # Creating a BigWigFileReference. wrapped <- BigWigFileReference(test_path) wrapped # Staging the BigWigFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
Reference to a FASTA file, for saving and loading in the alabaster framework.
FastaFileReference(path, seqtype = "DNA", faindex = NULL, gzindex = NULL)
FastaFileReference(path, seqtype = "DNA", faindex = NULL, gzindex = NULL)
path |
String containing the path to a Gzip- or BGZF-compressed FASTA file. |
seqtype |
String specifying the sequence type.
This should be one of |
faindex |
String specifying the path to an FASTA index file, or |
gzindex |
String specifying the path to a BGZF index file, or |
A FastaFileReference instance that can be used in saveObject
.
Aaron Lun
# Mocking up a FASTA file. tmp <- tempfile(fileext=".fa.gz") write(">FOOBAR\nacgtacgt", gzfile(tmp)) # Creating a FastaFileReference. wrapped <- FastaFileReference(tmp) wrapped # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Mocking up a FASTA file. tmp <- tempfile(fileext=".fa.gz") write(">FOOBAR\nacgtacgt", gzfile(tmp)) # Creating a FastaFileReference. wrapped <- FastaFileReference(tmp) wrapped # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
Reference to a FASTQ file, for saving and loading in the alabaster framework.
FastqFileReference( path, seqtype = "DNA", qualtype = "phred", qualoffset = 33, faindex = NULL, gzindex = NULL )
FastqFileReference( path, seqtype = "DNA", qualtype = "phred", qualoffset = 33, faindex = NULL, gzindex = NULL )
path |
String containing the path to a Gzip- or BGZF-compressed FASTQ file. |
seqtype |
String specifying the sequence type.
This should be one of |
qualtype |
String specifying the type of the quality strings.
This should be one of |
qualoffset |
Integer specifying the encoding offset for the quality strings.
This is only used when |
faindex |
String specifying the path to an FASTA index file, or |
gzindex |
String specifying the path to a BGZF index file, or |
A FastqFileReference instance that can be used in saveObject
.
Aaron Lun
# Mocking up a FASTQ file. tmp <- tempfile(fileext=".fq.gz") write("@FOOBAR\nacgtacgt\n+134987382", gzfile(tmp)) # Creating a FastqFileReference. wrapped <- FastqFileReference(tmp) wrapped # Staging the FastqFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Mocking up a FASTQ file. tmp <- tempfile(fileext=".fq.gz") write("@FOOBAR\nacgtacgt\n+134987382", gzfile(tmp)) # Creating a FastqFileReference. wrapped <- FastqFileReference(tmp) wrapped # Staging the FastqFileReference. dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
A virtual class for file reference objects.
This implements common methods for path
, [[
and $
.
Aaron Lun
Reference to a GFF2/3 file, for saving and loading in the alabaster framework.
GffFileReference(path, index = NULL)
GffFileReference(path, index = NULL)
path |
String containing the path to a Gzip- or BGZF-compressed GFF file.
The format is automatically detected from the file extension ( |
index |
String specifying the path to a tabix file in tabix format, or |
A GffFileReference instance that can be used in saveObject
.
Aaron Lun
# Using rtracklayer's example GFF file. src <- system.file("tests", "genes.gff3", package = "rtracklayer") fl <- tempfile(fileext=".gff3.gz") writeLines(con=gzfile(fl), readLines(src)) # Creating a GffFileReference. wrapped <- GffFileReference(fl) wrapped # Saving it: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
# Using rtracklayer's example GFF file. src <- system.file("tests", "genes.gff3", package = "rtracklayer") fl <- tempfile(fileext=".gff3.gz") writeLines(con=gzfile(fl), readLines(src)) # Creating a GffFileReference. wrapped <- GffFileReference(fl) wrapped # Saving it: dir <- tempfile() saveObject(wrapped, dir) list.files(dir, recursive=TRUE) # Loading it back again: readObject(dir)
Reference to a GMT file, for saving and loading in the alabaster framework.
GmtFileReference(path)
GmtFileReference(path)
path |
String containing the path to a Gzip-compressed GMT file. |
A GmtFileReference instance that can be used in stageObject
.
Aaron Lun
# Mocking up a GMT file. tmp <- tempfile(fileext=".gmt.gz") write("SET1\tdescription\tgene1\tgene2\tgene3", file=gzfile(tmp)) # Creating a GmtFileReference. wrapped <- GmtFileReference(tmp) wrapped # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) # Loading it back again: readObject(dir)
# Mocking up a GMT file. tmp <- tempfile(fileext=".gmt.gz") write("SET1\tdescription\tgene1\tgene2\tgene3", file=gzfile(tmp)) # Creating a GmtFileReference. wrapped <- GmtFileReference(tmp) wrapped # Saving to disk: dir <- tempfile() saveObject(wrapped, dir) # Loading it back again: readObject(dir)
This class is deprecated and only listed here for back-compatibility purposes.
TabixIndexWrapper(path)
TabixIndexWrapper(path)
path |
String containing the path to a Tabix file. |
The TabixIndexWrapper class is a subclass of a Wrapper,
so all of the methods of the latter can also be used here, e.g., path
.
A TabixIndexWrapper instance that can be used in stageObject
.
Aaron Lun
# Mocking up a Tabix file. test_tbx <- system.file("extdata", "example.gtf.gz.tbi", package="Rsamtools") # Creating a TabixIndexWrapper. wrapped <- TabixIndexWrapper(test_tbx) wrapped # Staging the TabixIndexWrapper. dir <- tempfile() library(alabaster.base) info <- stageObject(wrapped, dir, "tab") invisible(.writeMetadata(info, dir)) list.files(dir, recursive=TRUE) # Loading it back again: meta <- acquireMetadata(dir, "tab/file.tbi") loadObject(meta, dir)
# Mocking up a Tabix file. test_tbx <- system.file("extdata", "example.gtf.gz.tbi", package="Rsamtools") # Creating a TabixIndexWrapper. wrapped <- TabixIndexWrapper(test_tbx) wrapped # Staging the TabixIndexWrapper. dir <- tempfile() library(alabaster.base) info <- stageObject(wrapped, dir, "tab") invisible(.writeMetadata(info, dir)) list.files(dir, recursive=TRUE) # Loading it back again: meta <- acquireMetadata(dir, "tab/file.tbi") loadObject(meta, dir)
Defines some base classes for the concrete wrappers for specific file formats. This provides a standard set of methods that can be applied to all Wrapper instances.
Any instance x
of a base Wrapper class can be used with the path(x)
method,
which returns a string containing the path to the file on the current file system.
The Wrapper class inherits from the Annotated class,
so users can also get and set metadata via metadata(x)
.
The IndexedWrapper class inherits from the Wrapper class and can be used with all its methods.
It additionally implements the index(x)
method, which returns another Wrapper object for the associated index file
(or NULL
, if no index file exists).
The CompressedWrapper class inherits from the Wrapper class and can be used with all its methods.
It additionally implements the compression(x)
method, which returns a string specifying the compression strategy.
The CompressedIndexedWrapper class inherits from both the IndexedWrapper and CompressedWrapper classes and can be used with all their methods.
Aaron Lun