# # - eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){图书馆(VAExprs) # # #模拟差异表达基因set.seed g (1) < - 3 n < - 100 < 1000亩< - 5σ< - 5垫<矩阵(rnorm (n * m * g,μ、σ),m, n * g) rownames(垫)< - paste0(“基因”,seq_len (m)) colnames(垫)< - paste0(“细胞”,seq_len (n * g))组< -因子(酸式焦磷酸钠(seq_len (g)、功能(x){代表(paste0(“集团”,x)n)})) names(group) <- colnames(mat) mu_upreg <- 6 sigma_upreg <- 10 deg <- 100 for (i in seq_len(g)) {mat[(deg*(i-1) + 1):(deg*i), group==paste0("group", i)] <- mat[1:deg, group==paste0("group", i)] + rnorm(deg, mu_upreg, sigma_upreg)} #阳性表达式仅mat[mat < 0] <- 0 x_train <- as.matrix(t(mat))) # heatmap热图(mat, Rowv = NA, Colv = NA, col = colorRampPalette(c('green', 'red'))(100),规模= "没有 ") } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){#模型参数batch_size < - 32 original_dim intermediate_dim < < - 1000 - 512时期< - 100 # VAE vae_result < fit_vae (x_train = x_train x_val = x_train encoder_layers =列表(layer_input(形状= c (original_dim)), layer_dense(单位= intermediate_dim,激活=“relu”)),decoder_layers = list(layer_dense(units = intermediate_dim, activation = "relu"), layer_dense(units = original_dim, activation = "sigmoid")), epochs = epochs, batch_size = batch_size, use_generator = FALSE, callback = keras::callback_early_stop (monitor = "val_loss", patience = 10,restore_best_weights = TRUE )) } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){#模型架构plot_vae (vae_result $模型 ) } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){#样品代set.seed (1) gen_sample_result < - gen_exprs (vae_result,num_samples = 100) #热图的热图(cbind (t (x_train)、t (gen_sample_result x_gen美元)),坳= colorRampPalette (c(“绿色”、“红色”))(100),Rowv = NA ) } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){#情节plot_aug增广数据(gen_sample_result,“主成分分析 ") } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){库(VAExprs)库(SC3)库(SingleCellExperiment) #创建SingleCellExperiment对象sce < - SingleCellExperiment:: SingleCellExperiment(化验=列表(数量= as.matrix (yan)),colData =安)#定义功能名称构成了rowData (sce) $ feature_symbol列feature_symbol < - rownames南加州爱迪生公司(sce) #移除特性重复名称< - sce[!重复构成了rowData (sce) feature_symbol美元)(,)#删除基因不表达任何样品sce < -南加州爱迪生公司(这(rowMeans(化验(sce)) > 0),]暗(化验(sce) #模型参数batch_size < - 32 original_dim intermediate_dim < < - 19595 - 256时期< - 100 #模型cvae_result < - fit_vae(对象=,encoder_layers = list(layer_input(shape = c(original_dim)), layer_dense(units = intermediate_dim, activation = "relu")), decoder_layers = list(layer_dense(units = intermediate_dim, activation = "relu"), layer_dense(units = original_dim, activation = "sigmoid")), epochs = epochs, batch_size = batch_size, use_generator = TRUE, callback = keras:: callback_early_blocking (monitor = "loss", patience = 20,restore_best_weights = TRUE) #模型架构plot_vae (cvae_result $模型 ) } ## ---- eval = TRUE --------------------------------------------------------------- 如果(keras:: is_keras_available()和网状::py_available()){#样品代set.seed (1) gen_sample_result < - gen_exprs(100年cvae_result batch_size use_generator = TRUE)增广数据plot_aug #地块(PCA gen_sample_result。 ") } ## ---- eval = TRUE --------------------------------------------------------------- sessionInfo ()