Subset SummarizedExperiment/GRangesList by seqnames
2
1
Entering edit mode
@mikelove
Last seen 2 days ago
United States

I should really know this by now, but I can't recall how to cleanly subset a SummarizedExperiment/GRangesList by seqnames. 

Here I gave some bad example code just now, though I know there is something better:

C: remove X and Y chromosome genes in RNA-seq data using DESeq2 pipeline

I searched here first and found:

A: GRangesList filtering

But using Valerie's code there gives:

> grl[seqnames(grl) == "chr2"]

GRangesList object of length 3:
$gr1
GRanges object with 1 range and 0 metadata columns:
      seqnames    ranges strand
         <Rle> <IRanges>  <Rle>
  [1]     chr2    [3, 6]      *

$gr2
GRanges object with 0 ranges and 0 metadata columns:
     seqnames ranges strand

$gr3
GRanges object with 1 range and 0 metadata columns:
      seqnames ranges strand
  [1]     chr2 [4, 9]      *

Already, a better solution than my as.character() hack is to throw a elementLengths on top:

> elementLengths(grl[seqnames(grl) == "chr2"]) > 0
  gr1   gr2   gr3
 TRUE FALSE  TRUE

But there must be a better way I'm forgetting.

> sessionInfo()
R version 3.2.0 Patched (2015-04-26 r68264)
Platform: x86_64-apple-darwin10.8.0 (64-bit)
Running under: OS X 10.8.5 (Mountain Lion)

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] stats4    parallel  stats     graphics  grDevices datasets  utils     methods   base

other attached packages:
[1] GenomicRanges_1.20.3 GenomeInfoDb_1.4.0   IRanges_2.2.1        S4Vectors_0.6.0
[5] BiocGenerics_0.14.0  testthat_0.9.1       devtools_1.7.0       knitr_1.10
[9] BiocInstaller_1.18.1

loaded via a namespace (and not attached):
[1] XVector_0.8.0 tools_3.2.0
genomicranges • 2.0k views
ADD COMMENT
1
Entering edit mode
@mikelove
Last seen 2 days ago
United States

Martin already answered this here:

C: remove X and Y chromosome genes in RNA-seq data using DESeq2 pipeline

ADD COMMENT
1
Entering edit mode
anpham ▴ 60
@anpham-7402
Last seen 7.2 years ago

Thanks very much Michael and Martin.  I used the codes below to subset the dds object and it worked without any problem.

seqnames(dds)
dds.sub <- dds[ all(! seqnames(dds) %in%  c("chrX", "chrY"))]

ADD COMMENT

Login before adding your answer.

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