[BioC] BAM files to Genomic Ranges object

Hervé Pagès hpages at fhcrc.org
Mon Jan 14 20:47:46 CET 2013


Hi JL,

On 01/14/2013 08:27 AM, Steve Lianoglou wrote:
> Hi,
>
> On Mon, Jan 14, 2013 at 5:20 AM,  <jluis.lavin at unavarra.es> wrote:
>> First of all I want to thank Herve Pages and Martin Morgan for their kind
>> answers. And I want to apologize for this delay answering back, but I was
>> offline for a few days...
>>
>> I used Herve code to read my BAM files into GRanges objects, but I don't
>> seem to be able to use that Granges object into the cpgDensityCalc
>> function.
>> This is how I try to do it:
>>
>> -(My files are in the working directory already)
>>
>> library(Mus.musculus)
>> library(Repitools)
>> library(GenomicRanges)
>> library(Rsamtools)
>>
>>   bam_files <- list.files(pattern="*.bam")
>>     gr_list <- lapply(bam_files,
>>                       function(bam_file)
>>                         as(readGappedAlignments(bam_file), "GRanges"))
>>     names(gr_list) <- bam_files
>>
>> require(BSgenome.Mmusculus.UCSC.mm9)
>>
>> cpdens <- cpgDensityCalc(gr_list, organism=Mmusculus, window =600)
>>
>> -And I get the following error:
>>
>> Error in function (classes, fdef, mtable)  :
>> unable to find an inherited method for function "cpgDensityCalc", for
>> signature "character", "BSgenome"
>>
>> What does this error mean?
>
> It means that your `gr_list` isn't what you think it is -- it's a
> character, perhaps "try-error"?

When running your code, I get:

   > cpdens <- cpgDensityCalc(gr_list, organism=Mmusculus, window =600)
   Error in function (classes, fdef, mtable)  :
     unable to find an inherited method for function ‘cpgDensityCalc’ 
for signature ‘"list", "BSgenome"’

Not exactly the same error you get: see "list" in the error message
I get, versus "character" in the error message you get? Not sure why
your 'gr_list' ends up being a character vector instead of a list.

Anyway, having it being a list (an ordinary list) doesn't seem to work
either. The reason the call to cpgDensityCalc() fails is because this
is a generic function and there are no "cpgDensityCalc" methods that
will accept the first argument to be a list:

   > cpgDensityCalc
   standardGeneric for "cpgDensityCalc" defined from package "Repitools"

function (x, organism, ...)
   standardGeneric("cpgDensityCalc")
   <environment: 0x717c2a0>
   Methods may be defined for arguments: x, organism
   Use  showMethods("cpgDensityCalc")  for currently available ones.

   > showMethods("cpgDensityCalc")
   Function: cpgDensityCalc (package Repitools)
   x="data.frame", organism="BSgenome"
   x="GRanges", organism="BSgenome"
   x="GRangesList", organism="BSgenome"

Note that the type of input expected by the function is explained in
its man page (?cpgDensityCalc):

        x: A ‘data.frame’, with columns ‘chr’ and ‘position’, or columns
           ‘chr’, ‘start’, ‘end’, and ‘strand’.  Also may be a
           ‘GRangesList’ object, or ‘GRanges’.

So once you've sorted out the reasons why you get a character instead of
a list of GRanges (I've no clue how this could happen), you'll need to
turn that ordinary list into a GRangesList object with:

   gr_list <- GRangesList(gr_list)

before calling cpgDensityCalc().

Hope this helps,
H.

>
> Look at `head(gr_list)` ... what do you see?
>
>> *I'm awfully sorry for my lack of intermediate-advance R scripting
>> knowledge, I'm trying to fix that...
>
> Reading through an Introduction to R might be helpful, if you haven't
> done so already.
>
> Bioconductor uses the S4 class system in R, and it would be helpful to
> understand some parts of that too. If you look. If you look at
> previous bioc courses online, you will often find that Martin does a
> quick intro to these things at the beginning of many sessions:
>
> http://bioconductor.org/help/course-materials/
>
> Look for courses that were run at The Hutch (in Seattle)
>
> Perhaps the intro slides here will bear fruit:
>
> http://bioconductor.org/help/course-materials/2010/SeattleIntro/
>
> -steve
>

-- 
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpages at fhcrc.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



More information about the Bioconductor mailing list