Learn R Programming

rbamtools (version 2.16.17)

extractRanges: extractRanges: Extraction of alignments

Description

The function extractRanges takes an opened and indexed bamReader object, a data.frame containg range data, and an ouptut filename. From the opened BAM file, aligns in the depicted ranges are transfered into a temporary BAM-file. The new file will be sorted. The sorted file will be indexed.

Usage

extractRanges(object,ranges,filename,complex=FALSE,header,idxname)

Arguments

object

bamReader. Must be opened. Index must be initialized.

ranges

data.frame. Must contain columns 'seqid','start','end'. Each line represents a range on the reference genome for which aligns are extracted.

filename

Character. Name of output BAM-file. The filename will be modified. The modified filename will have suffix '.bam'.

complex

(default=FALSE) Logical. When TRUE, only aligns with nCigar > 1 are copied. When FALSE, all aligns in the depicted ranges are copied.

header

(Optional) bamHeader. It's possible to provide a bamHeader for the new BAM file (in order to control the header entries in the new file). When no header is given, the header from the bamReader will be used. The 'SO' entry in the 'headerLine' (which gives information about the sorting status) segment will be altered. The reference sequence dictionary (RSD) of the output file will be created new inside the function. It is necessary to do that because when there are mismatches between the RSD and the contained aligns, it will be impossible to create an index for the new file (samtools will crash).

idxname

(Default='filename'.bai) character. The name for the index file.

See Also

bamReader

Examples

Run this code
# NOT RUN {
bam<-system.file("extdata","accepted_hits.bam",package="rbamtools")
reader<-bamReader(bam,idx=TRUE)
# Extract data for HLHL17 gene:
seqid<-"chr1"
start<-895967
end<-901099
gene_name<-"HLHL17" # (optional)
ranges<-data.frame(seqid=seqid,start=start,end=end,gene_name=gene_name)
# }
# NOT RUN {
extractRanges(reader,ranges=ranges,filename="new_file.bam")
# }

Run the code above in your browser using DataLab