-2
$\begingroup$

I have a big single-cell RNA seq data

> dput(head(new.dat[,1:10]))
structure(list(cell1 = c(0.793763840992639, 0, 1.96843530982957, 
0.461736429639991, 0.717968540649498, 0), cell2 = c(3.61741696702738, 
0.231662370550224, 0, 0, 0, 0), cell3 = c(4.14348883366621, 0.118161316317251, 
0.08074552209482, 2.27968429766934, 0.0470313356296409, 0), cell4 = c(1.34783143327084, 
0.0094666040612932, 1.14392942941128, 0.652535826921119, 0.357542816432864, 
0.149587369334621), cell5 = c(1.27104023273899, 1.55185229643731, 
0, 0, 0, 0.0117525723115277), cell6 = c(1.92307653575663, 0, 
0, 0.319156642478379, 0, 0), cell7 = c(3.9343015424917, 0.132824589520901, 
0.119679885703561, 0.772516422897241, 0.0236884909844904, 0), 
    cell8 = c(3.74969491678643, 0.103404975609384, 0.0354753982873036, 
    0, 0, 0), cell9 = c(1.19084857532713, 3.9213265721495, 0, 
    0.0341973245272891, 0.0419122921627454, 0), cell10 = c(4.1224255501566, 
    0.301871669274068, 0.0633536200981225, 0.389959552469879, 
    0, 0.0405296102106492)), row.names = c("PTPRC", "MHC-II", 
"ITGAM", "Ly6C", "Ly6G", "EMR1"), class = "data.frame")
> 

> dim(new.dat)
[1]     33 263086
> 

How I remove every columns which are zero for one gene, let's say PTPRC?

$\endgroup$
0
0
$\begingroup$

This is basic R subsetting operation. Most subset operations give you a subset of rows based on a column, while you're doing the opposite here - but the logic is the same.

This gives you a subset of rows when the expression is based on a column

df[logical_expression_that_subsets_rows,]

Why not try this - it should give you a subset of columns based on a row value. (Untested, but you should be able to build on this):

df[, logical_expression_that_subsets_columns]

The logical expression for the first could be df$cell1 < 0.5 (or the equivalent df[,"cell1"] < 0.5. You should be able to get a logical expression for the second based on this.

$\endgroup$
-4
$\begingroup$
WhichCells(seurat_object made by this matrix, slot = 'counts', expression = PTPRC > 0 )

By Seurat R package this is possible

$\endgroup$
2
  • $\begingroup$ Please accept one answer if either of them solved your problem. Thank you. $\endgroup$
    – user438383
    Jun 30 at 14:30
  • $\begingroup$ Hi there, it would be nice to write more details and an actual working code. $\endgroup$
    – Kamil S Jaron
    Jul 1 at 8:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.