#1 umap cluser assign

library(monocle3)
## Loading required package: Biobase
## Loading required package: BiocGenerics
## 
## Attaching package: 'BiocGenerics'
## The following objects are masked from 'package:stats':
## 
##     IQR, mad, sd, var, xtabs
## The following objects are masked from 'package:base':
## 
##     anyDuplicated, aperm, append, as.data.frame, basename, cbind,
##     colnames, dirname, do.call, duplicated, eval, evalq, Filter, Find,
##     get, grep, grepl, intersect, is.unsorted, lapply, Map, mapply,
##     match, mget, order, paste, pmax, pmax.int, pmin, pmin.int,
##     Position, rank, rbind, Reduce, rownames, sapply, setdiff, sort,
##     table, tapply, union, unique, unsplit, which.max, which.min
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## Loading required package: SingleCellExperiment
## Loading required package: SummarizedExperiment
## Loading required package: MatrixGenerics
## Loading required package: matrixStats
## 
## Attaching package: 'matrixStats'
## The following objects are masked from 'package:Biobase':
## 
##     anyMissing, rowMedians
## 
## Attaching package: 'MatrixGenerics'
## The following objects are masked from 'package:matrixStats':
## 
##     colAlls, colAnyNAs, colAnys, colAvgsPerRowSet, colCollapse,
##     colCounts, colCummaxs, colCummins, colCumprods, colCumsums,
##     colDiffs, colIQRDiffs, colIQRs, colLogSumExps, colMadDiffs,
##     colMads, colMaxs, colMeans2, colMedians, colMins, colOrderStats,
##     colProds, colQuantiles, colRanges, colRanks, colSdDiffs, colSds,
##     colSums2, colTabulates, colVarDiffs, colVars, colWeightedMads,
##     colWeightedMeans, colWeightedMedians, colWeightedSds,
##     colWeightedVars, rowAlls, rowAnyNAs, rowAnys, rowAvgsPerColSet,
##     rowCollapse, rowCounts, rowCummaxs, rowCummins, rowCumprods,
##     rowCumsums, rowDiffs, rowIQRDiffs, rowIQRs, rowLogSumExps,
##     rowMadDiffs, rowMads, rowMaxs, rowMeans2, rowMedians, rowMins,
##     rowOrderStats, rowProds, rowQuantiles, rowRanges, rowRanks,
##     rowSdDiffs, rowSds, rowSums2, rowTabulates, rowVarDiffs, rowVars,
##     rowWeightedMads, rowWeightedMeans, rowWeightedMedians,
##     rowWeightedSds, rowWeightedVars
## The following object is masked from 'package:Biobase':
## 
##     rowMedians
## Loading required package: GenomicRanges
## Loading required package: stats4
## Loading required package: S4Vectors
## 
## Attaching package: 'S4Vectors'
## The following object is masked from 'package:utils':
## 
##     findMatches
## The following objects are masked from 'package:base':
## 
##     expand.grid, I, unname
## Loading required package: IRanges
## Loading required package: GenomeInfoDb
## Warning: package 'GenomeInfoDb' was built under R version 4.3.3
## 
## Attaching package: 'monocle3'
## The following objects are masked from 'package:Biobase':
## 
##     exprs, fData, fData<-, pData, pData<-
suppressPackageStartupMessages({library(monocle3)
  library(dplyr)
  library(viridis)
  library(reshape2)
  library(ggplot2)
  library(data.table)})
DelayedArray:::set_verbose_block_processing(TRUE)
## [1] FALSE
options(DelayedArray.block.size=1000e6)

this notebook has been updated to do the analysis with the newest version of monocle 3 (v0.2.0)

Load data —————————————————————

cds = readRDS("/Users/user/Downloads/yeast_umap-master/useful_files/yeast_del_strain_monocle3_cds.RDS")

#I want to check the cds.RDS document

str(cds)
## Formal class 'cell_data_set' [package "monocle3"] with 13 slots
##   ..@ reduce_dim_aux     :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       :List of 2
##   .. .. .. ..$ PCA :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. ..@ listData       :List of 1
##   .. .. .. .. .. .. ..$ model:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. .. .. ..@ listData       :List of 8
##   .. .. .. .. .. .. .. .. .. ..$ identity     :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. .. .. .. .. .. ..@ listData       :List of 6
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_type     : chr "matrix:PCA"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_id       :List of 2
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ checksum: chr "84e677b76f6dd5ca2b0aa009308abb17"
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ dim     : int [1:2] 1484 100
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ prev_model_type: chr "none"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ prev_model_id  : chr "none"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_path     : chr "none"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_version  : num 1
##   .. .. .. .. .. .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. .. .. .. .. ..$ num_dim      : num 100
##   .. .. .. .. .. .. .. .. .. ..$ norm_method  : chr "log"
##   .. .. .. .. .. .. .. .. .. ..$ svd_v        : num [1:6170, 1:100] 0.00287 0.00465 0.00559 0.01306 0.00396 ...
##   .. .. .. .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. .. .. .. .. .. .. ..$ : chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. .. .. .. .. .. .. ..$ : chr [1:100] "PC1" "PC2" "PC3" "PC4" ...
##   .. .. .. .. .. .. .. .. .. ..$ svd_sdev     : num [1:100] 17.8 17.5 16 15.7 14.4 ...
##   .. .. .. .. .. .. .. .. .. ..$ svd_center   : Named num [1:6170] 6.81 6.88 6.76 6.83 6.81 ...
##   .. .. .. .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. .. .. .. .. ..$ svd_scale    : Named num [1:6170] 0.161 0.3 0.334 0.129 0.321 ...
##   .. .. .. .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. .. .. .. .. ..$ prop_var_expl: num [1:100] 0.0671 0.065 0.0542 0.0519 0.0439 ...
##   .. .. .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. ..$ UMAP:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. ..@ listData       :List of 1
##   .. .. .. .. .. .. ..$ model:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. .. .. ..@ listData       :List of 8
##   .. .. .. .. .. .. .. .. .. ..$ identity              :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. .. .. .. .. .. ..@ listData       :List of 6
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_type     : chr "matrix:UMAP"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_id       :List of 2
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ checksum: chr "bfa6658f9685e82a1485923faf552174"
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ dim     : int [1:2] 1484 2
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ prev_model_type: chr "matrix:PCA"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ prev_model_id  :List of 2
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ checksum: chr "84e677b76f6dd5ca2b0aa009308abb17"
##   .. .. .. .. .. .. .. .. .. .. .. .. .. ..$ dim     : int [1:2] 1484 100
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_path     : chr "none"
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ model_version  : num 1
##   .. .. .. .. .. .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. .. .. .. .. ..$ umap_preprocess_method: chr "PCA"
##   .. .. .. .. .. .. .. .. .. ..$ max_components        : num 2
##   .. .. .. .. .. .. .. .. .. ..$ umap_metric           : chr "cosine"
##   .. .. .. .. .. .. .. .. .. ..$ umap_min_dist         : num 0.05
##   .. .. .. .. .. .. .. .. .. ..$ umap_n_neighbors      : int 10
##   .. .. .. .. .. .. .. .. .. ..$ umap_fast_sgd         : logi FALSE
##   .. .. .. .. .. .. .. .. .. ..$ umap_model            :List of 25
##   .. .. .. .. .. .. .. .. .. .. ..$ embedding           : num [1:1484, 1:2] 4.328 -1.909 -3.61 -2.397 0.123 ...
##   .. .. .. .. .. .. .. .. .. .. .. ..- attr(*, "scaled:center")= num [1:2] -0.13 -2.18
##   .. .. .. .. .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ : NULL
##   .. .. .. .. .. .. .. .. .. .. ..$ scale_info          : NULL
##   .. .. .. .. .. .. .. .. .. .. ..$ search_k            : num 1000
##   .. .. .. .. .. .. .. .. .. .. ..$ local_connectivity  : num 1
##   .. .. .. .. .. .. .. .. .. .. ..$ n_epochs            : num 500
##   .. .. .. .. .. .. .. .. .. .. ..$ alpha               : num 1
##   .. .. .. .. .. .. .. .. .. .. ..$ negative_sample_rate: num 5
##   .. .. .. .. .. .. .. .. .. .. ..$ method              : chr "umap"
##   .. .. .. .. .. .. .. .. .. .. ..$ a                   : Named num 1.75
##   .. .. .. .. .. .. .. .. .. .. .. ..- attr(*, "names")= chr "a"
##   .. .. .. .. .. .. .. .. .. .. ..$ b                   : Named num 0.842
##   .. .. .. .. .. .. .. .. .. .. .. ..- attr(*, "names")= chr "b"
##   .. .. .. .. .. .. .. .. .. .. ..$ gamma               : num 1
##   .. .. .. .. .. .. .. .. .. .. ..$ approx_pow          : logi FALSE
##   .. .. .. .. .. .. .. .. .. .. ..$ metric              :List of 1
##   .. .. .. .. .. .. .. .. .. .. .. ..$ cosine:List of 1
##   .. .. .. .. .. .. .. .. .. .. .. .. ..$ ndim: int 100
##   .. .. .. .. .. .. .. .. .. .. ..$ norig_col           : int 100
##   .. .. .. .. .. .. .. .. .. .. ..$ pcg_rand            : logi TRUE
##   .. .. .. .. .. .. .. .. .. .. ..$ batch               : logi FALSE
##   .. .. .. .. .. .. .. .. .. .. ..$ opt_args            :List of 5
##   .. .. .. .. .. .. .. .. .. .. .. ..$ alpha : num 1
##   .. .. .. .. .. .. .. .. .. .. .. ..$ beta1 : num 0.5
##   .. .. .. .. .. .. .. .. .. .. .. ..$ beta2 : num 0.9
##   .. .. .. .. .. .. .. .. .. .. .. ..$ eps   : num 1e-07
##   .. .. .. .. .. .. .. .. .. .. .. ..$ method: chr "adam"
##   .. .. .. .. .. .. .. .. .. .. ..$ num_precomputed_nns : num 0
##   .. .. .. .. .. .. .. .. .. .. ..$ min_dist            : num 0.05
##   .. .. .. .. .. .. .. .. .. .. ..$ spread              : num 1
##   .. .. .. .. .. .. .. .. .. .. ..$ binary_edge_weights : logi FALSE
##   .. .. .. .. .. .. .. .. .. .. ..$ seed                : NULL
##   .. .. .. .. .. .. .. .. .. .. ..$ n_neighbors         : int 10
##   .. .. .. .. .. .. .. .. .. .. ..$ nn_index            :List of 3
##   .. .. .. .. .. .. .. .. .. .. .. ..$ ann   :Reference class 'Rcpp_AnnoyAngular' [package "RcppAnnoy"] with 0 fields
##  list()
##   .. .. .. .. .. .. .. .. .. .. .. .. ..and 33 methods, of which 19 are  possibly relevant:
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  addItem, build, finalize,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  getDistance, getItemsVector,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  getNItems, getNNsByItem,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  getNNsByItemList, getNNsByVector,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  getNNsByVectorList, getNTrees,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  initialize, load, onDiskBuild, save,
##   .. .. .. .. .. .. .. .. .. .. .. .. ..  setSeed, setVerbose, unbuild, unload
##   .. .. .. .. .. .. .. .. .. .. .. ..$ type  : chr "annoyv1"
##   .. .. .. .. .. .. .. .. .. .. .. ..$ metric: chr "cosine"
##   .. .. .. .. .. .. .. .. .. .. ..$ pca_models          : list()
##   .. .. .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   ..@ principal_graph_aux:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       : list()
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   ..@ principal_graph    :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       : list()
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   ..@ clusters           :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       :List of 1
##   .. .. .. ..$ UMAP:List of 3
##   .. .. .. .. ..$ cluster_result:List of 6
##   .. .. .. .. .. ..$ g         :Class 'igraph'  hidden list of 10
##   .. .. .. .. .. .. ..$ : num 1484
##   .. .. .. .. .. .. ..$ : logi FALSE
##   .. .. .. .. .. .. ..$ : num [1:4452] 364 1187 824 1412 770 ...
##   .. .. .. .. .. .. ..$ : num [1:4452] 0 0 0 1 1 1 2 2 2 3 ...
##   .. .. .. .. .. .. ..$ : NULL
##   .. .. .. .. .. .. ..$ : NULL
##   .. .. .. .. .. .. ..$ : NULL
##   .. .. .. .. .. .. ..$ : NULL
##   .. .. .. .. .. .. ..$ :List of 4
##   .. .. .. .. .. .. .. ..$ : num [1:3] 1 0 1
##   .. .. .. .. .. .. .. ..$ : Named list()
##   .. .. .. .. .. .. .. ..$ :List of 2
##   .. .. .. .. .. .. .. .. ..$ name : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. .. .. ..$ names: chr [1:1484] "1" "2" "3" "4" ...
##   .. .. .. .. .. .. .. ..$ :List of 1
##   .. .. .. .. .. .. .. .. ..$ weight: num [1:4452] 1 1 1 1 1 1 1 1 1 1 ...
##   .. .. .. .. .. .. ..$ :<environment: 0x172702a98> 
##   .. .. .. .. .. ..$ relations :'data.frame':    4452 obs. of  3 variables:
##   .. .. .. .. .. .. ..$ from  : chr [1:4452] "YAR003W" "YAR003W" "YAR003W" "YDL006W" ...
##   .. .. .. .. .. .. ..$ to    : chr [1:4452] "YLR015W" "YHR119W" "YBR175W" "YCR028C-A" ...
##   .. .. .. .. .. .. ..$ weight: num [1:4452] 1 1 1 1 1 1 1 1 1 1 ...
##   .. .. .. .. .. ..$ distMatrix: num [1:1484, 1:3] 0.0126 0.0457 0.0916 0.0305 0.1843 ...
##   .. .. .. .. .. ..$ coord     : NULL
##   .. .. .. .. .. ..$ edge_links: NULL
##   .. .. .. .. .. ..$ optim_res :List of 2
##   .. .. .. .. .. .. ..$ membership: Named int [1:1484] 15 3 10 5 6 14 1 22 4 4 ...
##   .. .. .. .. .. .. .. ..- attr(*, "names")= chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. ..$ modularity: num 0.91
##   .. .. .. .. ..$ partitions    : Factor w/ 28 levels "1","2","3","4",..: 15 3 10 5 6 14 1 22 4 4 ...
##   .. .. .. .. .. ..- attr(*, "names")= chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. ..$ clusters      : Factor w/ 28 levels "1","2","3","4",..: 15 3 10 5 6 14 1 22 4 4 ...
##   .. .. .. .. .. ..- attr(*, "names")= chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   ..@ int_elementMetadata:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. ..@ rownames       : NULL
##   .. .. ..@ nrows          : int 6170
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   .. .. ..@ listData       :List of 1
##   .. .. .. ..$ rowPairs:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. .. ..@ nrows          : int 6170
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ listData       : Named list()
##   ..@ int_colData        :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. ..@ rownames       : NULL
##   .. .. ..@ nrows          : int 1484
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   .. .. ..@ listData       :List of 3
##   .. .. .. ..$ reducedDims:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. .. ..@ nrows          : int 1484
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ listData       :List of 2
##   .. .. .. .. .. .. ..$ PCA : num [1:1484, 1:100] 41.2 16.8 -18.1 -47.1 21.3 ...
##   .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. .. .. ..$ : chr [1:100] "PC1" "PC2" "PC3" "PC4" ...
##   .. .. .. .. .. .. ..$ UMAP: num [1:1484, 1:2] 4.336 -1.988 -3.613 -2.491 0.135 ...
##   .. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. .. .. ..$ : NULL
##   .. .. .. ..$ altExps    :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. .. ..@ nrows          : int 1484
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ listData       : Named list()
##   .. .. .. ..$ colPairs   :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. .. ..@ nrows          : int 1484
##   .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. ..@ listData       : Named list()
##   ..@ int_metadata       :List of 4
##   .. ..$ version            :Classes 'package_version', 'numeric_version'  hidden list of 1
##   .. .. ..$ : int [1:3] 1 24 0
##   .. ..$ spike_names        : chr(0) 
##   .. ..$ size_factor_names  : chr(0) 
##   .. ..$ reduce_dim_metadata:List of 2
##   .. .. ..$ PCA :List of 1
##   .. .. .. ..$ identity:List of 6
##   .. .. .. .. ..$ matrix_type     : chr "matrix:PCA"
##   .. .. .. .. ..$ matrix_id       :List of 2
##   .. .. .. .. .. ..$ checksum: chr "84e677b76f6dd5ca2b0aa009308abb17"
##   .. .. .. .. .. ..$ dim     : int [1:2] 1484 100
##   .. .. .. .. ..$ prev_matrix_type: chr "matrix:counts"
##   .. .. .. .. ..$ prev_matrix_id  : chr "none"
##   .. .. .. .. ..$ model_type      : chr "matrix:PCA"
##   .. .. .. .. ..$ model_id        :List of 2
##   .. .. .. .. .. ..$ checksum: chr "84e677b76f6dd5ca2b0aa009308abb17"
##   .. .. .. .. .. ..$ dim     : int [1:2] 1484 100
##   .. .. ..$ UMAP:List of 1
##   .. .. .. ..$ identity:List of 6
##   .. .. .. .. ..$ matrix_type     : chr "matrix:UMAP"
##   .. .. .. .. ..$ matrix_id       :List of 2
##   .. .. .. .. .. ..$ checksum: chr "bfa6658f9685e82a1485923faf552174"
##   .. .. .. .. .. ..$ dim     : int [1:2] 1484 2
##   .. .. .. .. ..$ prev_matrix_type: chr "matrix:PCA"
##   .. .. .. .. ..$ prev_matrix_id  :List of 2
##   .. .. .. .. .. ..$ checksum: chr "84e677b76f6dd5ca2b0aa009308abb17"
##   .. .. .. .. .. ..$ dim     : int [1:2] 1484 100
##   .. .. .. .. ..$ model_type      : chr "matrix:UMAP"
##   .. .. .. .. ..$ model_id        :List of 2
##   .. .. .. .. .. ..$ checksum: chr "bfa6658f9685e82a1485923faf552174"
##   .. .. .. .. .. ..$ dim     : int [1:2] 1484 2
##   ..@ rowRanges          :Formal class 'CompressedGRangesList' [package "GenomicRanges"] with 5 slots
##   .. .. ..@ unlistData     :Formal class 'GRanges' [package "GenomicRanges"] with 7 slots
##   .. .. .. .. ..@ seqnames       :Formal class 'Rle' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. ..@ values         : Factor w/ 0 levels: 
##   .. .. .. .. .. .. ..@ lengths        : int(0) 
##   .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. ..@ ranges         :Formal class 'IRanges' [package "IRanges"] with 6 slots
##   .. .. .. .. .. .. ..@ start          : int(0) 
##   .. .. .. .. .. .. ..@ width          : int(0) 
##   .. .. .. .. .. .. ..@ NAMES          : NULL
##   .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. ..@ strand         :Formal class 'Rle' [package "S4Vectors"] with 4 slots
##   .. .. .. .. .. .. ..@ values         : Factor w/ 3 levels "+","-","*": 
##   .. .. .. .. .. .. ..@ lengths        : int(0) 
##   .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. ..@ seqinfo        :Formal class 'Seqinfo' [package "GenomeInfoDb"] with 4 slots
##   .. .. .. .. .. .. ..@ seqnames   : chr(0) 
##   .. .. .. .. .. .. ..@ seqlengths : int(0) 
##   .. .. .. .. .. .. ..@ is_circular: logi(0) 
##   .. .. .. .. .. .. ..@ genome     : chr(0) 
##   .. .. .. .. ..@ elementMetadata:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. .. .. ..@ nrows          : int 0
##   .. .. .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. .. .. ..@ listData       : Named list()
##   .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. ..@ metadata       : list()
##   .. .. ..@ elementMetadata:Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. .. .. ..@ rownames       : NULL
##   .. .. .. .. ..@ nrows          : int 6170
##   .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. ..@ metadata       : list()
##   .. .. .. .. ..@ listData       :List of 3
##   .. .. .. .. .. ..$ id                 : chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. ..$ gene_short_name    : chr [1:6170] "AAC1" "AAC3" "AAD10" "AAD14" ...
##   .. .. .. .. .. ..$ num_cells_expressed: Named int [1:6170] 1484 1484 1484 1484 1484 1484 1484 1484 1484 1484 ...
##   .. .. .. .. .. .. ..- attr(*, "names")= chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. ..@ elementType    : chr "GRanges"
##   .. .. ..@ metadata       : list()
##   .. .. ..@ partitioning   :Formal class 'PartitioningByEnd' [package "IRanges"] with 5 slots
##   .. .. .. .. ..@ end            : int [1:6170] 0 0 0 0 0 0 0 0 0 0 ...
##   .. .. .. .. ..@ NAMES          : chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. ..@ metadata       : list()
##   ..@ colData            :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. ..@ rownames       : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. ..@ nrows          : int 1484
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   .. .. ..@ listData       :List of 10
##   .. .. .. ..$ strain_systematic_name   : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. ..$ kemmeren_strain_name     : chr [1:1484] "swd1.del.matA.vs..wt.matA" "ptc1.del.vs..wt" "tlc1.del.vs..wt" "rad16.del.vs..wt" ...
##   .. .. .. ..$ strain_short_name        : chr [1:1484] "SWD1" "PTC1" "TLC1" "RAD16" ...
##   .. .. .. ..$ orig_umap1               : num [1:1484] 14.3 14.4 14 14 14.3 ...
##   .. .. .. ..$ orig_umap2               : num [1:1484] 13.9 14.3 14.8 14.5 14.2 ...
##   .. .. .. ..$ cluster_50               : Factor w/ 50 levels "1","2","3","4",..: 30 10 2 3 8 9 31 13 1 4 ...
##   .. .. .. ..$ sub_cluster              : chr [1:1484] "30" "10-2" "2-15" "3-9" ...
##   .. .. .. ..$ kemmeren_functional_group: chr [1:1484] "chromatin factor" "protein phosphatase" "DNA replication and repair" "ubiquitin(-like) modification" ...
##   .. .. .. ..$ Size_Factor              : num [1:1484] 1 1 1 1 1 1 1 1 1 1 ...
##   .. .. .. ..$ num_genes_expressed      : Named int [1:1484] 6170 6170 6170 6170 6170 6170 6170 6170 6170 6170 ...
##   .. .. .. .. ..- attr(*, "names")= chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   ..@ assays             :Formal class 'SimpleAssays' [package "SummarizedExperiment"] with 1 slot
##   .. .. ..@ data:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. .. .. ..@ listData       :List of 1
##   .. .. .. .. .. ..$ counts:Formal class 'dgCMatrix' [package "Matrix"] with 6 slots
##   .. .. .. .. .. .. .. ..@ i       : int [1:9156280] 0 1 2 3 4 5 6 7 8 9 ...
##   .. .. .. .. .. .. .. ..@ p       : int [1:1485] 0 6170 12340 18510 24680 30850 37020 43190 49360 55530 ...
##   .. .. .. .. .. .. .. ..@ Dim     : int [1:2] 6170 1484
##   .. .. .. .. .. .. .. ..@ Dimnames:List of 2
##   .. .. .. .. .. .. .. .. ..$ : chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. .. .. ..@ x       : num [1:9156280] 116 162 143 113 112 113 120 121 132 147 ...
##   .. .. .. .. .. .. .. ..@ factors : list()
##   .. .. .. .. ..@ elementType    : chr "ANY"
##   .. .. .. .. ..@ elementMetadata: NULL
##   .. .. .. .. ..@ metadata       : list()
##   ..@ NAMES              : NULL
##   ..@ elementMetadata    :Formal class 'DFrame' [package "S4Vectors"] with 6 slots
##   .. .. ..@ rownames       : NULL
##   .. .. ..@ nrows          : int 6170
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   .. .. ..@ listData       : Named list()
##   ..@ metadata           :List of 2
##   .. ..$ cds_version: chr "0.2.0"
##   .. ..$ citations  :'data.frame':   27 obs. of  2 variables:
##   .. .. ..$ method   : Factor w/ 5 levels "Monocle","UMAP",..: 1 1 1 2 3 4 5 2 3 4 ...
##   .. .. ..$ citations: Factor w/ 7 levels "Cao, J. et. al. The single-cell transcriptional landscape of mammalian organogenesis. Nature 566, 496-502 (2019"| __truncated__,..: 3 2 1 4 5 6 7 4 5 6 ...
##   ..$ preprocess_aux:Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       :List of 2
##   .. .. .. ..$ gene_loadings: num [1:6170, 1:100] 0.00287 0.00465 0.00559 0.01306 0.00396 ...
##   .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. ..$ : chr [1:6170] "YMR056C" "YBR085W" "YJR155W" "YNL331C" ...
##   .. .. .. .. .. ..$ : chr [1:100] "PC1" "PC2" "PC3" "PC4" ...
##   .. .. .. ..$ prop_var_expl: num [1:100] 0.0671 0.065 0.0542 0.0519 0.0439 ...
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
##   ..$ reducedDims   :Formal class 'SimpleList' [package "S4Vectors"] with 4 slots
##   .. .. ..@ listData       :List of 2
##   .. .. .. ..$ PCA : num [1:1484, 1:100] 41.2 16.8 -18.1 -47.1 21.3 ...
##   .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. ..$ : chr [1:100] "PC1" "PC2" "PC3" "PC4" ...
##   .. .. .. ..$ UMAP: num [1:1484, 1:2] -1.917 0.182 -3.857 -1.713 3.011 ...
##   .. .. .. .. ..- attr(*, "scaled:center")= num [1:2] 0.811 -2.733
##   .. .. .. .. ..- attr(*, "dimnames")=List of 2
##   .. .. .. .. .. ..$ : chr [1:1484] "YAR003W" "YDL006W" "TER1" "YBR114W" ...
##   .. .. .. .. .. ..$ : NULL
##   .. .. ..@ elementType    : chr "ANY"
##   .. .. ..@ elementMetadata: NULL
##   .. .. ..@ metadata       : list()
summary(cds)
## [1] "cell_data_set object of length 6170 with 3 metadata columns"

Preprocess and run UMAP dimensionality reduction ————————

cds = detect_genes(cds)
cds = preprocess_cds(cds, num_dim = 100, norm_method = "log")
cds = reduce_dimension(cds,
                       preprocess_method = "PCA",
                       reduction_method = "UMAP", 
                       max_components = 2, 
                       umap.min_dist = 0.05, 
                       umap.n_neighbors = 10L,
                       umap.metric = "cosine")

cds = cluster_cells(cds, resolution = 1e-4, k = 3)

saveRDS(cds, "/Users/user/Downloads/yeast_umap-master/useful_files/yeast_del_strain_monocle3_cds.RDS")

plot strain umap

plot_cells(cds, color_cells_by = "cluster_50", 
           cell_size = 0.75,
           label_groups_by_cluster = F,
           label_cell_groups = T, 
           group_label_size = 4)
## No trajectory to plot. Has learn_graph() been called yet?

plot functional groups

plot_cells(cds, color_cells_by = "cluster", 
           label_cell_groups = F, 
           group_label_size = 4) +
  theme(legend.position = "none") +
  facet_wrap(~kemmeren_functional_group)
## No trajectory to plot. Has learn_graph() been called yet?

plot expression of specific genes

plot_cells(cds, genes = "YCH1", 
           cell_size = 0.75, norm_method = "size_only") +
  scale_color_viridis_c()
## No trajectory to plot. Has learn_graph() been called yet?
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.

Visualize sub-clusters ———————————————————

extract large main cluster (clusters 1 - 10) and re-analyze

cds_sub = cds[,colData(cds)$cluster_50 == 3,]
cds_sub = detect_genes(cds_sub)
cds_sub = preprocess_cds(cds_sub, num_dim = 20, norm_method = "log")
cds_sub = reduce_dimension(cds_sub,
                       preprocess_method = "PCA",
                       reduction_method = "UMAP", 
                       max_components = 2, 
                       umap.min_dist = 0.05, 
                       umap.n_neighbors = 10L,
                       umap.metric = "cosine")

cds_sub = cluster_cells(cds_sub, resolution = 1e-4, k = 3)

plot UMAP with sub-cluster designations from paper

plot_cells(cds_sub, color_cells_by = "sub_cluster", 
           cell_size = 1,
           label_groups_by_cluster = F,
           label_cell_groups = T, 
           group_label_size = 4)
## No trajectory to plot. Has learn_graph() been called yet?

plot specific gene expression

plot_cells(cds_sub, genes = "ATP8", 
           cell_size = 1.25, norm_method = "size_only") +
  scale_color_viridis_c()
## No trajectory to plot. Has learn_graph() been called yet?
## Scale for colour is already present.
## Adding another scale for colour, which will replace the existing scale.