Subsetting a tximport object
2
0
Entering edit mode
scanchi • 0
@scanchi-14313
Last seen 6.8 years ago

I have an tximport object with 628 files. I want to subset to remove some samples and maintain the tximport data structure.

str(txi_object)
List of 4
$ abundance          : num [1:56928, 1:628] 14.125 0 15.221 12.45 0.765 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:56928] "5S_rRNA" "5_8S_rRNA" "7SK" "A1BG" ...
  .. ..$ : chr [1:628] "20798913" "20914669" "50301125" "20149910" ...
$ counts             : num [1:56928, 1:628] 10.5 0 87.1 440 74.9 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:56928] "5S_rRNA" "5_8S_rRNA" "7SK" "A1BG" ...
  .. ..$ : chr [1:628] "20798913" "20914669" "50301125" "20149910" ...
$ length             : num [1:56928, 1:628] 15.1 24.2 116.4 718.5 1990.3 ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:56928] "5S_rRNA" "5_8S_rRNA" "7SK" "A1BG" ...
  .. ..$ : chr [1:628] "20798913" "20914669" "50301125" "20149910" ...
$ countsFromAbundance: chr "no"

Final number of desired samples is 598 and I have the sample ids in a data frame. I tried mapply and ddply without much success. 

length(clean_samples$individualID)
[1] 598

Any ideas or suggestions would be helpful

regards

scanchi

p.s - I had to post the code as text as I was running into an language '"x" not supported issue.

 

tximport • 3.5k views
ADD COMMENT
0
Entering edit mode
@james-w-macdonald-5106
Last seen 2 days ago
United States

It's just three matrices with dim (ngenes x nsamples), plus one extra list item,  so you should be able to simply subset. Using the example for tximport and removing the last sample I would do

example(tximport)
z <- lapply(txi, function(x) if(is.matrix(x)) return(x[,1:5]) else return(x))
ADD COMMENT
1
Entering edit mode

Hi James,

I was wondering if you know how I could remove samples from the tximport object which are contained in a list of outliers? Thanks!

ADD REPLY
1
Entering edit mode

If you are going to use edgeR or DESeq2 later, the easiest is to make the object and then subset that, e.g.

dds <- dds[,!colnames(dds) %in% outliers]
ADD REPLY
0
Entering edit mode

Many thanks, Michael! This is super useful, as usual!

ADD REPLY
0
Entering edit mode

Thank you James!

ADD REPLY

Login before adding your answer.

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