bamReader-class: Class '"bamReader"'

Description Objects from the Class Slots Methods Author(s) References Examples

Description

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 load.index function.

Objects from the Class

Objects can be created by calls of the form reader<-bamReader(filename).

Slots

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.

Methods

bamClose

signature(object = "bamReader"): Closes connection to BAM-file.

bamCopy

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.

bamSave

signature(object = "bamReader",writer="bamWriter"): Copies all aligns from reader to writer.

create.index

signature(object = "bamReader", filename="character"): Creates an index file for opened BAM-file. Therfore the BAM-file must be position-sorted. filename determines the name of the new BAM-Index-file (usually bam_filename.bam.idx)

filename

signature(object = "bamReader"): Returns filename of opened BAM-file.

getHeader

signature(object = "bamReader"): Returns object of class bamHeader which contains binary representation of bam-header data.

getHeaderText

signature(object = "bamReader"): Returns object of class bamHeaderText which contains textual representation of bam-header data.

getNextAlign

signature(object = "bamReader"): Returns object of class bamAlign which contains data of next Align from file. When EOF is reached the function returns NULL.

getNextChunk

signature(object = "bamReader", n="integer"): Returns object of class bamRange which contains data of next 'n' Aligns from file. When EOF is reached the function returns a range of size zero.

getRefCoords

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".

getRefCount

signature(object = "bamReader"): Returns number of reference sequences.

getRefData

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).

isOpen

signature(object = "bamReader"): Returns TRUE when file connection is open.

rewind

signature(object = "bamReader"): Resets current file position. The subsequent call to getNextAlign will return the first align in the BAM-file.

bamSort

signature(object = "bamReader",prefix="character",byName=FALSE,maxmem=1e+9): BAM-files must be sorted before an index can be created. During this routine, some content of the source file is copied into the working memory, sorted and written into temporary files. Finally, the sorted files are merged into a single target. The name of the sorted BAM-file will be [prefix].bam. Number and size of temporary files depend on source file size and used working memory (maxmem). Small maxmem values result in large numbers of temporary files. The minimum maxmem value is 100000000. Smaller maxmem values cause an error.

initialize

signature(.Object = "bamReader"): Initializes object and opens BAM-file for reading.

Author(s)

Wolfgang Kaisers

References

The SAM Format Specification (v1.4-r985). The SAM Format Specification Working Group. September 7, 2011. http://www.samtools.sourceforge.net/SAM1.pdf

Examples

 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
library(rbamtools)
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
idx<-"index.bam.bai"
create.index(reader,idx)
load.index(reader,idx)
index.initialized(reader)
# Load package provided index
load.index(reader,idx)
index.initialized(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,0)
bamClose(writer)
# Closing reader
bamClose(reader)

robertdouglasmorrison/DuffyNGS documentation built on Dec. 7, 2018, 8:01 a.m.