On Tue, Nov 26, 2013 at 10:00 AM, Prashantha Hebbar <
prashantha.hebbar@yahoo.com> wrote:

> Hello friends,
>
> I am trying to get genome cordinate information for list of genes using
> sapply function. I find an error saying "
> Error in c(values, x) :  all arguments in '...' must be CompressedList
> objects
>
> "
>
> Following is the code I am using.
>
> library(VariantAnnotation)
> library(TxDb.Hsapiens.UCSC.hg19.knownGene)
> txdb = TxDb.Hsapiens.UCSC.hg19.knownGene
> txg = transcriptsBy(txdb,by="gene")
> allGeneRange <- GRanges()
> genes<-c("47","4067","2017")
> gRangeFun <- function(i){
>       geneRange <- reduce(txg[i])
>       allGeneRange<-append(allGeneRange, geneRange)
>       return(allGeneRange)
> }
> x<-sapply(genes, gRangeFun )
> print(x)
>
> I wanted to have coordination of all genes in one GRange object to process
> it further. when I print x following error appears. Can somebody tell me
> what is going wrong with sapply() usage?
>
>
When using *apply() to iterate, you're calling a function on each element,
and the return values from the function calls are automatically
concatenated into a list, with the same order as the input. In the case of
sapply, there is an attempt to simplify the list. But the bottom-line is
that function calls should not (and will not without special effort) have
side-effects outside of their scope.

So one way to do this would be:
gRangeFun <- function(i){
  reduce(txg[i])
}
x<-sapply(genes, gRangeFun)

But 'x' will be a list, because sapply does not know how to simplify the
list of S4 objects. So to concatenate the list elements into a GRanges, we
can do: do.call(c, unname(x)).

However, it is often not necessary to explicitly iterate in R, and this is
also true of the GenomicRanges API. Operations like reduce() are implicitly
vectorized over GRangesList, so the above code simplifies to:

geneRange <- unlist(reduce(txg[genes]))

However, I think what you really want here is to call range(), not reduce(),

geneRange <- unlist(range(txg[genes]))

Hope that helps,
Michael

Here is sessionInfo()
>
> > sessionInfo() R version 2.15.2 (2012-10-26)
> Platform: i686-pc-linux-gnu (32-bit) locale: [1] LC_CTYPE=en_US.UTF-8
> LC_NUMERIC=C         LC_TIME=C            LC_COLLATE=C         [5]
> LC_MONETARY=C        LC_MESSAGES=C        LC_PAPER=C           LC_NAME=C
>          [9] LC_ADDRESS=C         LC_TELEPHONE=C       LC_MEASUREMENT=C
> LC_IDENTIFICATION=C  attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>  other attached packages: [1] VariantAnnotation_1.4.12
>  Rsamtools_1.10.2                        [3] Biostrings_2.26.3
>           TxDb.Hsapiens.UCSC.hg19.knownGene_2.8.0 [5]
> GenomicFeatures_1.10.2                  AnnotationDbi_1.20.7
>      [7] Biobase_2.18.0                          GenomicRanges_1.10.7
>              [9] IRanges_1.16.6                          BiocGenerics_0.4.0
>                      loaded via a namespace (and not attached): [1]
> BSgenome_1.26.1    DBI_0.2-7          RCurl_1.95-4.1     RSQLite_0.11.4
> [5] XML_3.98-1.1       biomaRt_2.14.0     bitops_1.0-5
> parallel_2.15.2    [9] rtracklayer_1.18.2 stats4_2.15.2      tools_2.15.2
>     zlibbioc_1.4.0
>
> Regards,
> Prashantha
>         [[alternative HTML version deleted]]
>
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>

	[[alternative HTML version deleted]]

