A class to represent short sequences that have been aligned to a reference genome as they are typically generated in next generation sequencing experiments.
# S4 method for class 'AlignmentsTrack'
initialize(
.Object,
stackRanges = GRanges(),
stacks = numeric(),
sequences = DNAStringSet(),
referenceSequence = NULL,
...
)
# S4 method for class 'ReferenceAlignmentsTrack'
initialize(
.Object,
stream,
reference,
mapping = list(),
args = list(),
defaults = list(),
stacks = numeric(),
stackRanges = GRanges(),
sequences = Biostrings::DNAStringSet(),
referenceSequence = NULL,
...
)
AlignmentsTrack(
range = NULL,
start = NULL,
end = NULL,
width = NULL,
strand,
chromosome,
genome,
stacking = "squish",
id,
cigar,
mapq,
flag = scanBamFlag(isUnmappedQuery = FALSE),
isize,
groupid,
status,
md,
seqs,
name = "AlignmentsTrack",
isPaired = TRUE,
importFunction,
referenceSequence,
...
)
# S4 method for class 'AlignmentsTrack'
values(x)
# S4 method for class 'AlignmentsTrack'
chromosome(GdObject) <- value
# S4 method for class 'AlignmentsTrack'
stacks(GdObject)
# S4 method for class 'AlignmentsTrack'
setStacks(GdObject, ...)
# S4 method for class 'AlignmentsTrack'
subset(x, from = NULL, to = NULL, stacks = FALSE, use.defaults = TRUE, ...)
# S4 method for class 'ReferenceAlignmentsTrack'
subset(x, from, to, chromosome, ...)
# S4 method for class 'AlignmentsTrack'
drawGrid(GdObject, from, to)
# S4 method for class 'AlignmentsTrack'
drawAxis(GdObject, ...)
# S4 method for class 'AlignmentsTrack'
drawGD(GdObject, minBase, maxBase, prepare = FALSE, subset = TRUE, ...)
# S4 method for class 'AlignmentsTrack'
show(object)
# S4 method for class 'ReferenceAlignmentsTrack'
show(object)The object skeleton passed on by new() during class
instantiation, to be filled in by the initialize method.
A GRanges object with
the merged extent of each read group, i.e., the region spanned by a read and
its mate. This is what the reads are stacked on, and its names match the
groupid metadata column.
logical. Set if stacking should be preserved.
A DNAStringSet object
with the read sequences.
An optional SequenceTrack
object containing the reference sequence against which the reads have been
aligned. This is only needed when mismatch information has to be added to the
plot (i.e., the showMismatches display parameter is TRUE) because this is
normally not encoded in the BAM file. If not provided through this
argument, the plotTracks function is smart enough to detect the presence
of a SequenceTrack object in the track list and will
use that as a reference sequence.
Additional items which will all be interpreted as further
display parameters. See settings and the "Display Parameters"
section below for details.
A function to stream the data from an indexed file. It has to
accept the two arguments file and selection, and to return a
GRanges object.
A character scalar with the path to the referenced file.
A named list mapping the columns of the imported data to
the metadata columns of the track's GRanges
object.
A list of the arguments the object has been constructed with.
A list of the constructor's default arguments, used to
fill in whatever has not been provided in args.
An optional meta argument to handle the different input types.
If range is missing, all the relevant information to create the object
has to be provided as individual function arguments (see below).
The different input options for range are:
A character string: the path to a BAM file containing the read
alignments. This results in the instantiation of a
ReferenceAlignmentsTrack object, but
for the user this implementation detail should be of no concern.
A GRanges object: the genomic ranges
of the individual reads, along with the optional additional metadata
columns id, cigar, mapq, flag, isize, groupid, status, md
and seqs (see the individual function parameters below for details).
Calling the constructor on a GRanges
object without further arguments, e.g. AlignmentsTrack(range = obj), is
equivalent to calling the coerce method as(obj, "AlignmentsTrack").
An IRanges object: almost identical to the
GRanges case, except that the chromosome
and strand information, as well as all additional metadata, has to be
provided via the separate chromosome, strand, feature, group or
id arguments, since none of it can be encoded directly in an
IRanges object. None of these inputs are
mandatory; if not provided explicitly, the defaults chromosome = NA and
strand = "*" are used.
A data.frame object: must contain at least the two mandatory
columns start and end with the range coordinates. It may also
contain chromosome and strand columns; if these are absent, the
values are taken from the separate chromosome or strand arguments
instead. In addition, the id, cigar, mapq, flag, isize,
groupid, status, md and seqs data can be provided as additional
columns, with the same default-value rules as above.
Integer vectors, giving the start and the end coordinates for the individual track items, or their width. Two of the three need to be specified, and have to be of equal length or of length one, in which case this single value will be recycled. Otherwise, the usual R recycling rules for vectors do not apply here.
Character vector, the strand information for the reads. It may
be provided in the form + for the Watson strand, - for the Crick strand
or * for either one of the two. Needs to be of equal length as the provided
genomic coordinates, or of length 1. Please note that paired reads need to be
on opposite strands, and erroneous entries will result in an error.
The chromosome on which the track's genomic ranges are
defined. A valid UCSC chromosome identifier if
options(ucscChromosomeNames=TRUE). Please note that in this case only
syntactic checking takes place, i.e., the argument value needs to be an
integer, numeric character or a character of the form chrx, where x may
be any possible string. The user has to make sure that the respective
chromosome is indeed defined for the track's genome. If not provided here,
the constructor will try to construct the chromosome information based on
the available inputs, and as a last resort will fall back to the value
chrNA. Please note that by definition all objects in the Gviz package can
only have a single active chromosome at a time (although internally the
information for more than one chromosome may be present), and the user has to
call the chromosome<- replacement method in order to change to a different
active chromosome.
The genome on which the track's ranges are defined. Usually
this is a valid UCSC genome identifier, however this is not being formally
checked at this point. If not provided here, the constructor will try to
extract this information from the provided input, and eventually will fall
back to the default value of NA.
The stacking type for overlapping items of the track. One of
c(hide, dense, squish, pack, full). Currently, only squish (make best use
of the available space), dense (no stacking, collapse overlapping ranges),
and hide (do not show any track items at all) are implemented.
Character vector of read identifiers. Those identifiers have to be
unique, i.e., each range representing a read needs to have a unique id.
A character vector of valid CIGAR strings describing details of the alignment. Typically those include alignment gaps or insertions and deletions, but also hard and soft clipped read regions. If missing, a fully mapped read without gaps or indels is assumed. Needs to be of equal length as the provided genomic coordinates, or of length 1.
A numeric vector of read mapping qualities. Needs to be of equal length as the provided genomic coordinates, or of length 1.
A named integer vector of length 2, as produced by
Rsamtools::scanBamFlag(), used to filter out undesirable reads. If missing,
all mapped reads will be included.
A numeric vector of empirical insert sizes. This only applies if the reads are paired. Needs to be of equal length as the provided genomic coordinates, or of length 1. Currently not used.
A factor (or vector that can be coerced into one) defining
the read pairs. Reads with the same groupid are considered to be mates.
Please note that each read group may only have one or two members. Needs to
be of equal length as the provided genomic coordinates, or of length 1.
A factor describing the mapping status of a read. Has to be
one of mated, unmated or ambiguous. Needs to be of equal length as the
provided genomic coordinates, or of length 1.
A character vector describing the mapping details. This is effectively an alternative to the CIGAR encoding, and it removes the dependency on a reference sequence to figure out read mismatches. Needs to be of equal length as the provided genomic coordinates, or of length 1. Currently not used.
A DNAStringSet object of read
sequences.
Character scalar of the track's name used in the title panel when plotting.
A logical scalar to determine whether the reads are paired
or not. While this may be used to render paired-end data as single-end, the
opposite will typically not have any effect because the appropriate
groupid settings will not be present. Thus setting isPaired to TRUE
can usually be used to autodetect the pairing state of the input data.
A user-defined function to be used to import the data
from a file. This only applies when the range argument is a character
string with the path to the input data file. The function needs to accept an
argument x containing the file path and a second argument selection with
the desired plotting ranges. It has to return a proper
GRanges object with all the necessary
metadata columns set. A single default import function is already implemented
in the package for BAM files.
A valid track object class name, or the object itself, in which case the class is derived directly from it.
Object of class GdObject.
Value to be set.
Numeric scalar, giving the range of genomic coordinates to
limit the tracks in. Note that from cannot be larger than to.
logical. Derive the subsetting range from the track's
own defaults rather than using from and to verbatim.
Numeric scalar, the start and end coordinates of the plotting range.
logical. Run the drawing method in preparation rather than
in production mode, i.e., only compute the track's layout without rendering
anything to the device.
logical. Subset the track to the current plotting range
before drawing.
Object inheriting from
AlignmentsTrack.
The return value of the constructor function is a new object of class
AlignmentsTrack or
ReferenceAlignmentsTrack.
initialize(AlignmentsTrack): Initialize the stackRanges, stacks,
sequences and referenceSequence slots before deferring to the
StackedTrack initializer for the remaining slots.
initialize(ReferenceAlignmentsTrack): Initialize the
ReferenceTrack slots (stream, reference,
mapping, args, defaults) and the referenceSequence slot inherited
from AlignmentsTrack.
AlignmentsTrack(): Constructor for AlignmentsTrack-class.
values(AlignmentsTrack): Return all additional annotation
information except for the genomic coordinates for the track items as
a data.frame.
chromosome(AlignmentsTrack) <- value: replace the value of the track's
chromosome. This has to be a valid UCSC chromosome identifier or an integer
or character scalar that can be reasonably coerced into one.
stacks(AlignmentsTrack): return the stack indices for each track
item.
setStacks(AlignmentsTrack): recompute the stacks based on the available
space and on the object's track items and stacking settings.
subset(AlignmentsTrack): Subset an AlignmentsTrack by coordinates
and sort if necessary.
subset(ReferenceAlignmentsTrack): Subset a
ReferenceAlignmentsTrack by coordinates
and sort if necessary.
drawGrid(AlignmentsTrack): superpose a horizontal grid on the
coverage portion of the track, based on the grid, h, col.grid,
lty.grid and lwd.grid display parameters.
drawAxis(AlignmentsTrack): add a y-axis to the title panel of a track.
drawGD(AlignmentsTrack): plot the object to a graphics device.
The return value of this method is the input object, potentially updated
during the plotting operation. Internally, there are two modes in which the
method can be called. Either in 'prepare' mode, in which case no plotting is
done but the object is preprocessed based on the available space, or in
'plotting' mode, in which case the actual graphical output is created.
Since subsetting of the object can be potentially costly, this can be
switched off in case subsetting has already been performed before or
is not necessary.
show(AlignmentsTrack): Show method.
show(ReferenceAlignmentsTrack): Show method.
Objects can be created using the constructor function
AlignmentsTrack.
## Creating objects
afrom <- 2960000
ato <- 3160000
alTrack <- AlignmentsTrack(system.file(
package = "Gviz", "extdata",
"gapped.bam"
), isPaired = TRUE)
plotTracks(alTrack, from = afrom, to = ato, chromosome = "chr12")
## Omit the coverage or the pile-ups part
plotTracks(alTrack,
from = afrom, to = ato, chromosome = "chr12",
type = "coverage"
)
plotTracks(alTrack,
from = afrom, to = ato, chromosome = "chr12",
type = "pileup"
)
## Including sequence information with the constructor
if (require(BSgenome.Hsapiens.UCSC.hg38)) {
strack <- SequenceTrack(Hsapiens, chromosome = "chr21")
afrom <- 44945200
ato <- 44947200
alTrack <- AlignmentsTrack(system.file(
package = "Gviz", "extdata",
"snps.bam"
), isPaired = TRUE, referenceSequence = strack)
plotTracks(alTrack, chromosome = "chr21", from = afrom, to = ato)
## Including sequence information in the track list
alTrack <- AlignmentsTrack(system.file(
package = "Gviz", "extdata",
"snps.bam"
), isPaired = TRUE)
plotTracks(c(alTrack, strack),
chromosome = "chr21", from = 44946590,
to = 44946660
)
}
#> Loading required package: BSgenome.Hsapiens.UCSC.hg38
#> Loading required package: GenomeInfoDb
#> Loading required package: BSgenome
#> Loading required package: Biostrings
#> Loading required package: XVector
#>
#> Attaching package: 'Biostrings'
#> The following object is masked from 'package:base':
#>
#> strsplit
#> Loading required package: BiocIO
#> Loading required package: rtracklayer