Description Objects from the Class Slots Methods Author(s) References Examples
A bamReader object encapulates functionality for reading of bamAligns from a BAM-file. It optionally contains a pointer to a bam-index structure which allows fast access to aligns that overlap a specified region (random access). The index is loaded via the loadIndex function.
Objects can be created by calls of the form
reader<-bamReader(filename)
.
filename
:Character denoting name of BAM-file.
reader
:External pointer to opened BAM-file.
startpos
:Numeric value returned by bam_tell immediately after opening BAM-file. It is used as target position for rewinding by bam_seek.
index
:External pointer to BAM index (used for retrieving bamRange objects from BAM-file.
signature(object = "bamReader")
:
Closes connection to BAM-file.
signature(object = "bamReader",
writer="bamWriter",refids,verbose)
:
Copies all aligns for given refids from reader to writer.
When no refids are given, aligns for all refids are copied.
refids refer to Reference-ID's returned by 'getRefData' (ID column).
Missing matches (from refids into Reference-ID's) will terminate
the function with an error.
signature(object = "bamReader",
writer="bamWriter")
: Copies all aligns from reader to writer.
signature(object = "bamReader", prefix="character",
byName=FALSE, maxmem=1e+9, path=dirname(filename(object)))
:
Sorting an existing BAM-file.
signature(object = "bamReader",
idx_filename="character")
: Creates an index file for opened
BAM-file.
Therefore the BAM-file must be position-sorted.
idx_filename
will be the name of the new BAM-index file.
idx_filename
is an optional argument. The standard value is
"bam_filename.bam".bai.
signature(object="bamReader",
filename="character")
: Loads index from given index file.
A loaded index is a prerequisite for random access to
a BAM file.
signature(object="bamReader")
:
Returns TRUE when a loaded BAM index is present in
bamReader
.
signature(object = "bamReader")
:
Returns filename of opened BAM-file.
signature(object = "bamReader")
:
Returns object of class bamHeader which contains binary
representation of bam-header data.
signature(object = "bamReader")
:
Returns object of class bamHeaderText which contains textual
representation of bam-header data.
signature(object = "bamReader")
:
Returns object of class bamAlign which contains data of next
Align from file.
When EOF is reached the function returns NULL.
signature(object="bamReader",
sn="character")
:
Helper function takes a sequence name and returns coordinates of
entire reference sequence for usage with bamRange, gapList or
siteList function.
The function returns a vector of length 3.
The vector elements are named "refid","start","stop".
signature(object = "bamReader")
:
Returns number of reference sequences.
signature(object = "bamReader")
:
Returns data frame which contains three columns:
For each reference sequence, the corresponding row contains the
Reference-ID (1st column, refID), the Reference name (2nd column,
refName) and the length of the Reference sequence (3rd column,
refLength).
signature(object = "bamReader")
:
Returns TRUE when file connection is open.
signature(object = "bamReader",
coords="numeric", segments="numeric", complex="logical")
:
Counts alignments for specified genomic segment regions
(genes, exons, ...)
signature(object = "bamReader")
:
Resets current file position. The subsequent call to
getNextAlign will return the first align in the BAM-file.
signature(.Object = "bamReader")
:
Initializes object and opens BAM-file for reading
Wolfgang Kaisers
The SAM Format Specification (v1.4-r985).
The SAM Format Specification Working Group. September 7, 2011.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | bam<- system.file("extdata", "accepted_hits.bam", package="rbamtools")
idx<- system.file("extdata", "accepted_hits.bam.bai", package="rbamtools")
#
# Open BAM-file for reading
reader<-bamReader(bam)
getNextAlign(reader)
rewind(reader)
getNextAlign(reader)
isOpen(reader)
#
# Create and load new index
new_idx<-"index.bam.bai"
createIndex(reader,new_idx)
loadIndex(reader,new_idx)
indexInitialized(reader)
#
# Load package provided index
loadIndex(reader,idx)
indexInitialized(reader)
#
# Read align
align<-getNextAlign(reader)
coords<-as.integer(c(0,0,249250621))
range<-bamRange(reader,coords)
align<-getNextAlign(range)
#
# Copy all aligns
writer<-bamWriter(getHeader(reader),"newFile1.bam")
bamSave(reader,writer)
bamClose(writer)
#
# reader2<-bamReader("newFile1.bam")
bamSort(reader,"newFile1s")
# Copy align for Reference-ID '0'
writer<-bamWriter(getHeader(reader),"newFile2.bam")
bamCopy(reader,writer,refid=0)
bamClose(writer)
#
# Closing reader
bamClose(reader)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.