# NOT RUN {
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
## A) Open reader
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
bam <- system.file("extdata", "accepted_hits.bam", package="rbamtools")
idx<-paste(bam,"bai",sep=".")
# Open BAM file
reader<-bamReader(bam)
# }
# NOT RUN {
createIndex(reader,idx)
# }
# NOT RUN {
# Load BAM index file
loadIndex(reader,idx)
indexInitialized(reader) # Should return 'TRUE'
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
## B) Read range
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
# Find appropriate refid (=ID)
# Returns a data.frame with three columns:
# ID=refid, SN=Sequence Name, LN=Sequence length
rdf<-getRefData(reader)
head(rdf)
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
# The sequence length (LN) also determines valid
# range for start and stop coordinates
# Invalid refid-, start- or stop-coordinates will
# release an error.
# coords: refid=0, start=0, stop=249250621
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
coords <- as.integer(c(0, 0, 249250621))
range <- bamRange(reader, coords)
size(range)
range <- bamRange(reader, coords, complex=TRUE)
dfr <- as.data.frame(range)
size(range)
align <- getNextAlign(range)
cigarData(align)
rewind(range)
# Alterative way of reading Range
range <- readRange(reader, "chr1", c(0,249250621))
size(range)
range <- readRange(reader, "chr1", c(0,249250621), complex=TRUE)
size(range)
# Print align positions
# }
# NOT RUN {
while(!is.null(align))
{
print(position(align))
align<-getNextAlign(range)
}
# }
# NOT RUN {
bamClose(reader)
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
## C) Get print message and some other values
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
range
getCoords(range)
getSeqLen(range)
getParams(range)
getRefName(range)
getAlignRange(range)
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
## D) Rudimentary subsetting
## + + + + + + + + + + + + + + + + + + + + + + + + + + + ##
range[1:5]
# }
Run the code above in your browser using DataLab