Pick some clusters to run trajectory and pseudotime analysis on Monocle3
0
0
Entering edit mode
@f7281b41
Last seen 20 months ago
United Kingdom

Hi there,

I have a normalized Seurat object converted to a cell_data_set as an input for Monocle3. My cell_data_set object has 27 clusters, same as my seurat object. I have 2 problems: 1st: I got an error when I'm tryint to order my cells as a pseudotime function: Error in Y[, root_pr_nodes, drop = F] : subscript out of bounds 2nd: I would like to analyse trajectory and pseudotime on only 3 clusters out of the 27. I'm stucked there as I'm not finding any resource that help me with this. Please find below my code since the beginning.

Thank you so much in advance! Marta

MONOCLE WORKFLOW

monocle3 require cell_data_set object

1. convert Seurat object to a cell_data_set as monocle3 input

> cds<- as.cell_data_set(seu.rna)

to get cell metada

colData(cds)

colData(cds) DataFrame with 33459 rows and 13 columns orig.ident nCount_RNA nFeature_RNA percent.mito UMAP_1 UMAP_2 seurat_clusters integrated_snn_res.0.8 integrated_snn_res.0.5 <character> <numeric> <integer> <numeric> <numeric> <numeric> <factor> <factor> <factor> C21_AAACCCACACCCTCTA-1 C21 4409 1837 4.76298 8.14349 -1.418249 T cell 2 1 C21_AAACCCAGTCACTCAA-1 C21 825 449 1.45455 -9.32482 -4.767177 DC 24 11 C21_AAACCCAGTGTCTTCC-1 C21 3201 1485 5.77944 7.58707 0.679149 T regulatory cell 12 12 C21_AAACCCATCAAGCCTA-1 C21 4698 1894 6.23670 -4.08939 3.162478 Cd21h B cell 9 5 C21_AAACCCATCCGGCAAC-1 C21 4200 1810 4.45238 2.67093 -7.562114 Macrophage 18 17 ... ... ... ... ... ... ... ... ... ... Exp_TTTGTTGAGCTCGAAG-1 Exp 2310 1074 8.13853 -2.85803 -3.18452 GCB-Centrocytes 3 2 Exp_TTTGTTGTCACCTACC-1 Exp 3020 1289 2.74834 7.18867 -2.80873 T cell 2 1 Exp_TTTGTTGTCAGATGCT-1 Exp 3785 1700 5.17834 -3.02914 -5.50020 GCB-Centroblasts 14 4 Exp_TTTGTTGTCCACAAGT-1 Exp 2652 1304 2.75264 6.35676 8.92432 Macrophage 11 13 Exp_TTTGTTGTCTTGCAAG-1 Exp 1339 506 2.98730 -3.13572 -11.78153 Neutrophil 19 18 integrated_snn_res.0.3 ident Size_Factor my_colour <factor> <factor> <numeric> <logical> C21_AAACCCACACCCTCTA-1 2 T cell 4409 FALSE C21_AAACCCAGTCACTCAA-1 8 DC 825 FALSE C21_AAACCCAGTGTCTTCC-1 10 T regulatory cell 3201 FALSE C21_AAACCCATCAAGCCTA-1 4 Cd21h B cell 4698 FALSE C21_AAACCCATCCGGCAAC-1 13 Macrophage 4200 FALSE ... ... ... ... ... Exp_TTTGTTGAGCTCGAAG-1 1 GCB-Centrocytes 2310 FALSE Exp_TTTGTTGTCACCTACC-1 2 T cell 3020 FALSE Exp_TTTGTTGTCAGATGCT-1 1 GCB-Centroblasts 3785 FALSE Exp_TTTGTTGTCCACAAGT-1 11 Macrophage 2652 FALSE Exp_TTTGTTGTCTTGCAAG-1 12 Neutrophil 1339 FALSE*

get gene metadata

fData(cds)
rownames(fData(cds))[1:10]
fData(cds)$gene_short_name<-rownames(fData(cds))

get counts

counts(cds)

2. CLuster cells (using clustering info from Seurat's UMAP)

assigning partitions

reacreate.partition<-c(rep(1,length(cds@colData@rownames)))
reacreate.partition
names(reacreate.partition)<-cds@colData@rownames
reacreate.partition<-as.factor(reacreate.partition)
reacreate.partition

cds@clusters$UMAP$partitions<-reacreate.partition
cds

Assign the cluster information

list_cluster<-seu.rna@active.ident
cds@clusters$UMAP$clusters<-list_cluster

Assign UMAP coordinate-cell embeddings

cds@int_colData@listData$reducedDims$UMAP<-seu.rna@reductions$umap@cell.embeddings

plot

cluster.before.trajectory<-plot_cells(cds,
           color_cells_by = 'cluster',
           label_groups_by_cluster = FALSE,
           group_label_size = 3)+
  theme(legend.position = "none")

cluster.names<-plot_cells(cds,
           color_cells_by = "cluster",
           label_groups_by_cluster = FALSE,
           group_label_size = 3)+
  theme(legend.position = "none")


cluster.before.trajectory|cluster.names

3. Learn the trajectory graph

cds<-learn_graph(cds,use_partition = TRUE)

plot_cells(cds,
           color_cells_by='cluster',
           label_groups_by_cluster=FALSE,
           label_branch_points = FALSE,
           label_roots = FALSE,
           label_leaves = FALSE,
           group_label_size = 3)

31 Learn trajectory graph for specific clusters

??????????

4. Order cells in pseudotime

cds<-order_cells(cds, reduction_method = 'UMAP', root_cells = colnames(cds[,clusters(cds)==4]))

Error in Y[, root_pr_nodes, drop = F] : subscript out of bounds

SpecificClusters TrajectoryAnalysis PseudotimeAnalysis Monocle3 • 2.1k views
ADD COMMENT
0
Entering edit mode

@martacrespi7 might be a little late but I also ran into that problem and found a solution. Apparently, in that case "root_cells = colnames(cds[,clusters(cds)==4])" does not correctly define a starting point for the ordering. If you leave this argument out, a window opens in which you can manually select a root point to use as a starting point.

cds<-order_cells(cds, reduction_method = 'UMAP', root_cells = NULL)

After manually selecting a starting point you can continue with the normal workflow.

ADD REPLY

Login before adding your answer.

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