[BioC] filterBam using rname

Valerie Obenchain vobencha at fhcrc.org
Thu Oct 18 19:02:03 CEST 2012


Hi Raffaele,

To read in only specific chromosomes (rnames) you can use 'which'.

This toy bam file has two 'chromosomes', seq1 and seq2. Here we specify 
that we want a particular range of seq1. You can also request the entire 
length of seq1.

     which <- RangesList(seq1=IRanges(0, 2000))

If you only specify 'rname' in the 'what' then only that single field 
that will be returned. Most likely you want several fields.
See ?ScanBamParam for details.

     what <- c("rname", "strand", "pos", "qwidth", "seq")

Create the param and read in the data.

     param <- ScanBamParam(which=which, what=what)
     bamFile <- system.file("extdata", "ex1.bam", package="Rsamtools")
     bam <- scanBam(bamFile, param=param)

Valerie


On 10/18/2012 06:57 AM, rcaloger wrote:
> I have the necessity to filter a Bam file,  keeping only reads 
> associated to a subset of references.
> I wanted to do it with filterBam (Rsamtools)
> but I could not manage to find a way of doing it.
> If I use the code:
> filterBam("onlymapped.bam", "filtered.bam", 
> param=ScanBamParam(which=my.rnames, what=scanBamWhat("rname")))
> I get:
> Error in function (classes, fdef, mtable)  :
>   unable to find an inherited method for function "ScanBamParam", for 
> signature "character"
>
> checking the help it seems to me that ScanBamParam(which=) only 
> support GRanges, RangesList, RangedData objects.
>
> There is any other way to filter a bam file on the basis of the rname?
> Cheers
> Raffaele
>
>
> > sessionInfo()
> R version 2.15.1 (2012-06-22)
> Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)
>
> locale:
> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods base
>
> other attached packages:
>  [1] ShortRead_1.14.4     latticeExtra_0.6-24  RColorBrewer_1.0-5 
> lattice_0.20-10      Rsamtools_1.8.6
>  [6] Biostrings_2.24.1    GenomicRanges_1.8.13 IRanges_1.14.4 
> Biobase_2.16.0       BiocGenerics_0.2.0
>
> loaded via a namespace (and not attached):
> [1] bitops_1.0-4.1 grid_2.15.1    hwriter_1.3    stats4_2.15.1 
> tools_2.15.1   zlibbioc_1.2.0
> >
>



More information about the Bioconductor mailing list