rtracklayer blocks function
1
0
Entering edit mode
Janet Young ▴ 740
@janet-young-2360
Last seen 5.0 years ago
Fred Hutchinson Cancer Research Center,…
Hi there, A quick question - I'm a little confused about how to use the "blocks" function of rtracklayer - can you help? I think perhaps I'm just not understanding the help page right and not understanding what should be possible and what should not. I'm looking at ?blocks (and ?import.bed). From those pages, it seems like the following code should work, but I get errors. I'm missing something, I think.... I think i'll be able to find another more convoluted way to do what I want to do, which is to get the total transcript size from a bed file that contains block information, but it seems like this simpler way should work - any suggestions? Thanks, Janet Young ---------- library(rtracklayer) ### read in a bed file: (this example is from the help page ?import.bed and has some block information) test_path <- system.file("tests", package = "rtracklayer") test_bed <- file.path(test_path, "test.bed") test <- import(test_bed) class(test) #[1] "UCSCData" #attr(,"package") #[1] "rtracklayer" test2 <- as(test, "RangedData") class(test2) #[1] "RangedData" #attr(,"package") #[1] "IRanges" blocks(test2) #Error in blocks(as(x, "GenomicRanges")) : # error in evaluating the argument 'x' in selecting a method for function 'blocks': Error in as(x, "GenomicRanges") : # no method or default for coercing "RangedData" to "GenomicRanges" blocks(asBED(test2)) #Error in blocks(asBED(test2)) : # error in evaluating the argument 'x' in selecting a method for function 'blocks': Error in function (classes, fdef, mtable) : # unable to find an inherited method for function "asBED", for signature "RangedData" 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] rtracklayer_1.16.3 GenomicRanges_1.8.11 IRanges_1.14.4 BiocGenerics_0.2.0 loaded via a namespace (and not attached): [1] Biostrings_2.24.1 bitops_1.0-4.1 BSgenome_1.24.0 RCurl_1.91-1 Rsamtools_1.8.6 stats4_2.15.1 tools_2.15.1 [8] XML_3.9-4 zlibbioc_1.2.0
rtracklayer rtracklayer • 1.3k views
ADD COMMENT
0
Entering edit mode
@michael-lawrence-3846
Last seen 2.9 years ago
United States
Hi Janet, Sorry, the blocks() function has fallen into disrepair. I will check- in a fix for it soon. To solve your problem, there is no need to use blocks(). Simply get the "blocks" column out, which is a RangesList, and sum up its widths. Like: sum(width(test$blocks)) Michael On Wed, Aug 8, 2012 at 7:25 PM, Janet Young <jayoung@fhcrc.org> wrote: > Hi there, > > A quick question - I'm a little confused about how to use the "blocks" > function of rtracklayer - can you help? I think perhaps I'm just not > understanding the help page right and not understanding what should be > possible and what should not. I'm looking at ?blocks (and ?import.bed). > From those pages, it seems like the following code should work, but I get > errors. I'm missing something, I think.... > > I think i'll be able to find another more convoluted way to do what I want > to do, which is to get the total transcript size from a bed file that > contains block information, but it seems like this simpler way should work > - any suggestions? > > Thanks, > > Janet Young > > ---------- > > library(rtracklayer) > > ### read in a bed file: (this example is from the help page ?import.bed > and has some block information) > > test_path <- system.file("tests", package = "rtracklayer") > test_bed <- file.path(test_path, "test.bed") > > test <- import(test_bed) > class(test) > #[1] "UCSCData" > #attr(,"package") > #[1] "rtracklayer" > > test2 <- as(test, "RangedData") > class(test2) > #[1] "RangedData" > #attr(,"package") > #[1] "IRanges" > > blocks(test2) > #Error in blocks(as(x, "GenomicRanges")) : > # error in evaluating the argument 'x' in selecting a method for function > 'blocks': Error in as(x, "GenomicRanges") : > # no method or default for coercing "RangedData" to "GenomicRanges" > > blocks(asBED(test2)) > #Error in blocks(asBED(test2)) : > # error in evaluating the argument 'x' in selecting a method for function > 'blocks': Error in function (classes, fdef, mtable) : > # unable to find an inherited method for function "asBED", for signature > "RangedData" > > > 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] rtracklayer_1.16.3 GenomicRanges_1.8.11 IRanges_1.14.4 > BiocGenerics_0.2.0 > > loaded via a namespace (and not attached): > [1] Biostrings_2.24.1 bitops_1.0-4.1 BSgenome_1.24.0 RCurl_1.91-1 > Rsamtools_1.8.6 stats4_2.15.1 tools_2.15.1 > [8] XML_3.9-4 zlibbioc_1.2.0 > > _______________________________________________ > 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]]
ADD COMMENT
0
Entering edit mode
Hi, Thanks, Michael. I ended up with a different and less elegant solution: geneInfo <- import.bed(myBedFileThreeGenes, asRangedData=FALSE) geneLengths <- sapply( values(geneInfo)$blocks, function(x) { sum(width(x)) } ) names(geneLengths) <- values(geneInfo)$name Interestingly, test$blocks works but values(test)$blocks gives NULL. That seems a little non-intuitive, but I kinda see why. (my first thought was along the lines of your solution, but I got caught by values(test)$blocks not working - I think the difference between RangedData and GRanges is confusing me once again). Janet On Aug 10, 2012, at 6:16 AM, Michael Lawrence wrote: > Hi Janet, > > Sorry, the blocks() function has fallen into disrepair. I will check-in a fix for it soon. > > To solve your problem, there is no need to use blocks(). Simply get the "blocks" column out, which is a RangesList, and sum up its widths. > > Like: > > sum(width(test$blocks)) > > Michael > > On Wed, Aug 8, 2012 at 7:25 PM, Janet Young <jayoung@fhcrc.org> wrote: > Hi there, > > A quick question - I'm a little confused about how to use the "blocks" function of rtracklayer - can you help? I think perhaps I'm just not understanding the help page right and not understanding what should be possible and what should not. I'm looking at ?blocks (and ?import.bed). From those pages, it seems like the following code should work, but I get errors. I'm missing something, I think.... > > I think i'll be able to find another more convoluted way to do what I want to do, which is to get the total transcript size from a bed file that contains block information, but it seems like this simpler way should work - any suggestions? > > Thanks, > > Janet Young > > ---------- > > library(rtracklayer) > > ### read in a bed file: (this example is from the help page ?import.bed and has some block information) > > test_path <- system.file("tests", package = "rtracklayer") > test_bed <- file.path(test_path, "test.bed") > > test <- import(test_bed) > class(test) > #[1] "UCSCData" > #attr(,"package") > #[1] "rtracklayer" > > test2 <- as(test, "RangedData") > class(test2) > #[1] "RangedData" > #attr(,"package") > #[1] "IRanges" > > blocks(test2) > #Error in blocks(as(x, "GenomicRanges")) : > # error in evaluating the argument 'x' in selecting a method for function 'blocks': Error in as(x, "GenomicRanges") : > # no method or default for coercing "RangedData" to "GenomicRanges" > > blocks(asBED(test2)) > #Error in blocks(asBED(test2)) : > # error in evaluating the argument 'x' in selecting a method for function 'blocks': Error in function (classes, fdef, mtable) : > # unable to find an inherited method for function "asBED", for signature "RangedData" > > > 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] rtracklayer_1.16.3 GenomicRanges_1.8.11 IRanges_1.14.4 BiocGenerics_0.2.0 > > loaded via a namespace (and not attached): > [1] Biostrings_2.24.1 bitops_1.0-4.1 BSgenome_1.24.0 RCurl_1.91-1 Rsamtools_1.8.6 stats4_2.15.1 tools_2.15.1 > [8] XML_3.9-4 zlibbioc_1.2.0 > > _______________________________________________ > 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]]
ADD REPLY
0
Entering edit mode
On Fri, Aug 10, 2012 at 11:07 AM, Janet Young <jayoung@fhcrc.org> wrote: > Hi, > > Thanks, Michael. > > I ended up with a different and less elegant solution: > geneInfo <- import.bed(myBedFileThreeGenes, asRangedData=FALSE) > geneLengths <- sapply( values(geneInfo)$blocks, function(x) { > sum(width(x)) } ) > names(geneLengths) <- values(geneInfo)$name > > Interestingly, test$blocks works but values(test)$blocks gives > NULL. That seems a little non-intuitive, but I kinda see why. (my first > thought was along the lines of your solution, but I got caught by > values(test)$blocks not working - I think the difference between RangedData > and GRanges is confusing me once again). > > Yea, it's confusing. The values() function on RangedData returns a DataFrameList that is indexed by e.g. chromosome. You could do a values(test)[,"blocks"] I think. > Janet > > > On Aug 10, 2012, at 6:16 AM, Michael Lawrence wrote: > > Hi Janet, > > Sorry, the blocks() function has fallen into disrepair. I will check-in a > fix for it soon. > > To solve your problem, there is no need to use blocks(). Simply get the > "blocks" column out, which is a RangesList, and sum up its widths. > > Like: > > sum(width(test$blocks)) > > Michael > > On Wed, Aug 8, 2012 at 7:25 PM, Janet Young <jayoung@fhcrc.org> wrote: > >> Hi there, >> >> A quick question - I'm a little confused about how to use the "blocks" >> function of rtracklayer - can you help? I think perhaps I'm just not >> understanding the help page right and not understanding what should be >> possible and what should not. I'm looking at ?blocks (and ?import.bed). >> From those pages, it seems like the following code should work, but I get >> errors. I'm missing something, I think.... >> >> I think i'll be able to find another more convoluted way to do what I >> want to do, which is to get the total transcript size from a bed file that >> contains block information, but it seems like this simpler way should work >> - any suggestions? >> >> Thanks, >> >> Janet Young >> >> ---------- >> >> library(rtracklayer) >> >> ### read in a bed file: (this example is from the help page ?import.bed >> and has some block information) >> >> test_path <- system.file("tests", package = "rtracklayer") >> test_bed <- file.path(test_path, "test.bed") >> >> test <- import(test_bed) >> class(test) >> #[1] "UCSCData" >> #attr(,"package") >> #[1] "rtracklayer" >> >> test2 <- as(test, "RangedData") >> class(test2) >> #[1] "RangedData" >> #attr(,"package") >> #[1] "IRanges" >> >> blocks(test2) >> #Error in blocks(as(x, "GenomicRanges")) : >> # error in evaluating the argument 'x' in selecting a method for >> function 'blocks': Error in as(x, "GenomicRanges") : >> # no method or default for coercing "RangedData" to "GenomicRanges" >> >> blocks(asBED(test2)) >> #Error in blocks(asBED(test2)) : >> # error in evaluating the argument 'x' in selecting a method for >> function 'blocks': Error in function (classes, fdef, mtable) : >> # unable to find an inherited method for function "asBED", for signature >> "RangedData" >> >> >> 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] rtracklayer_1.16.3 GenomicRanges_1.8.11 IRanges_1.14.4 >> BiocGenerics_0.2.0 >> >> loaded via a namespace (and not attached): >> [1] Biostrings_2.24.1 bitops_1.0-4.1 BSgenome_1.24.0 RCurl_1.91-1 >> Rsamtools_1.8.6 stats4_2.15.1 tools_2.15.1 >> [8] XML_3.9-4 zlibbioc_1.2.0 >> >> _______________________________________________ >> 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]]
ADD REPLY

Login before adding your answer.

Traffic: 736 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