Reputation: 69
If anyone has any experience using the monocle package in R:
I am trying to subset my data based on a vector of sample names, but I cannot accomplish it.
I have tried:
x@phenoData$sampleNames <- example.cells
but I am getting this error:
replacement has 661 rows, data has 5809
The object I am trying to subset is a Cell Data Set (CDS) created from a Seurat object by the importCDS function.
I have also assigned a Cell Type to every sample that is called "CellType" which is part of the meta.data of the Seurat object and is listed under the varLabels slot of the phenoData after it is converted to a CDS.
I would like help subsetting based on either of these variables, thank you.
Upvotes: 1
Views: 6189
Reputation: 1453
According to the monocle tutorial low quality cells were filtered with this code (HSSM is the monocle object):
valid_cells <- row.names(subset(pData(HSMM),
Cells.in.Well == 1 &
Control == FALSE &
Clump == FALSE &
Debris == FALSE &
Mapped.Fragments > 1000000))
HSMM <- HSMM[,valid_cells]
So for your example this should work:
x = x[,example.cells]
or (directly from Seurat):
x = x[,rownames([email protected][[email protected]$CellType == "interesting_cell",])]
Upvotes: 3
Reputation: 33
This: x@phenoData$sampleNames <- example.cells
is adding new data to the dataframe representing your sample treatments, instead of subsetting.
Try using x@phenoData$sampleNames %in% example.cells
to retrieve a boolean vector (True, False) and filter using this:
x@phenoData[x@phenoData$sampleNames %in% example.cells,]
One small edit, this may mess up your CDS data structure, so be careful. It may be better to filter prior to generating the CDS or generate a new one from the old data.
Upvotes: 0