filterBam using rname
1
0
Entering edit mode
rcaloger ▴ 500
@rcaloger-1888
Last seen 9.8 years ago
European Union
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 > -- ---------------------------------------- Prof. Raffaele A. Calogero Bioinformatics and Genomics Unit MBC Centro di Biotecnologie Molecolari Via Nizza 52, Torino 10126 tel. ++39 0116706457 Fax ++39 0112366457 Mobile ++39 3333827080 email: raffaele.calogero at unito.it raffaele[dot]calogero[at]gmail[dot]com www: http://www.bioinformatica.unito.it
• 1.5k views
ADD COMMENT
0
Entering edit mode
@valerie-obenchain-4275
Last seen 2.8 years ago
United States
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 > > >
ADD COMMENT

Login before adding your answer.

Traffic: 441 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6