当前位置: 首页 > news >正文

biocParallel学习

我好像做了一个愚蠢的测试

rm(list=ls())
suppressPackageStartupMessages({library(SingleCellExperiment)library(scMerge)library(scater)library(Matrix)
})setwd("/Users/yxk/Desktop/test/R_parallel/")
load("./data/exprsMat.RData")
load("./data/clust.RData")
load("./data/pseudobulk_sample_list.RData")
load("./data/pseudobulk_sample.RData")
load("./data/use_bpparm.RData")
load("./data/res.RData")#' @importFrom ruv replicate.matrix
#' @importFrom methods as isaggregate.Matrix <- function(x, groupings=NULL) {if (!methods::is(x,'Matrix')) {x <- methods::as(as.matrix(x), "CsparseMatrix")}groupings2 <- paste("A", groupings, sep = "")if (length(unique(groupings2)) > 1) {mapping <- methods::as(ruv::replicate.matrix(groupings2), "CsparseMatrix")colnames(mapping) <- substring(colnames(mapping), 2)mapping <- mapping[, levels(factor(groupings))]} else {mapping <- methods::as(matrix(rep(1, length(groupings2)), ncol = 1), "CsparseMatrix")colnames(mapping) <- unique(groupings)}result <- t(mapping) %*% xreturn(result)
}create_pseudoBulk_parallel = function (exprsMat, cell_info, k_fold = 30, use_bpparam = BiocParallel::SerialParam()) 
{#browser()k_fold <- min(ncol(exprsMat), k_fold)cv <- cvTools::cvFolds(ncol(exprsMat), K = k_fold)exprsMat_pseudo <- BiocParallel::bplapply(seq_len(k_fold), function(i) {subset_idx <- cv$subsets[cv$which == i]cellType_tab <- table(droplevels(factor(cell_info[subset_idx])))cellTypes_n_mat <- matrix(rep(cellType_tab, nrow(exprsMat)), nrow = length(cellType_tab), byrow = FALSE)rownames(cellTypes_n_mat) <- names(cellType_tab)res <- aggregate.Matrix(t(exprsMat[, subset_idx]), cell_info[subset_idx])cellTypes_n_mat <- cellTypes_n_mat[rownames(res), ]res <- res/cellTypes_n_matrownames(res) <- paste(rownames(res), i, sep = "_")res}, BPPARAM = use_bpparam)exprsMat_pseudo <- do.call(rbind, exprsMat_pseudo)return(exprsMat_pseudo)
}create_pseudoBulk_no = function (exprsMat, cell_info, k_fold = 30) 
{#browser()k_fold <- min(ncol(exprsMat), k_fold)cv <- cvTools::cvFolds(ncol(exprsMat), K = k_fold)exprsMat_pseudo =list()for (i in seq_len(k_fold)){subset_idx <- cv$subsets[cv$which == i]cellType_tab <- table(droplevels(factor(cell_info[subset_idx])))cellTypes_n_mat <- matrix(rep(cellType_tab, nrow(exprsMat)), nrow = length(cellType_tab), byrow = FALSE)rownames(cellTypes_n_mat) <- names(cellType_tab)res <- aggregate.Matrix(t(exprsMat[, subset_idx]), cell_info[subset_idx])cellTypes_n_mat <- cellTypes_n_mat[rownames(res), ]res <- res/cellTypes_n_matrownames(res) <- paste(rownames(res), i, sep = "_")exprsMat_pseudo[[i]] = res}exprsMat_pseudo <- do.call(rbind, exprsMat_pseudo)return(exprsMat_pseudo)
}set.seed(1)
i =1
res1 <- create_pseudoBulk_parallel(exprsMat[, pseudobulk_sample ==pseudobulk_sample_list[i]], clust[[i]], k_fold = 30,use_bpparam = use_bpparam)set.seed(1)
i =1
res2 <- create_pseudoBulk_no(exprsMat[, pseudobulk_sample ==pseudobulk_sample_list[i]],clust[[i]], k_fold = 30)print("done")# for (i in seq_along(pseudobulk_sample_list)) {
#     res <- create_pseudoBulk_parallel(exprsMat[, pseudobulk_sample == 
#                                         pseudobulk_sample_list[i]], clust[[i]], k_fold = 30, 
#                              use_bpparam = use_bpparam)
# }

在这里插入图片描述

首先注意一个随机种子的问题,否则这个结果就会不一样

http://www.lryc.cn/news/208325.html

相关文章:

  • AWTK实现汽车仪表Cluster/DashBoard嵌入式GUI开发(六):一个AWTK工程
  • MySQL主从复制(基于binlog日志方式)
  • 计算机网络【CN】介质访问控制
  • CDR和AI哪个软件更好用?
  • 保姆级认识AVL树【C++】(精讲:AVL Insert)
  • pinia中使用reactive声明变量,子页面使用时,值未改变,即不是响应式的(解决方法)
  • 基于springboot零食商城管理系统
  • C++程序练习
  • Golang 继承
  • 棋盘格测距-单目相机(OpenCV/C++)
  • 031-从零搭建微服务-监控中心(一)
  • vue中使用xlsx插件导出多sheet excel实现方法
  • Linux - 进程的优先级 和 如何使用优先级调度进程
  • 支持控件drag和click
  • AIR101 LuatOS LVGL 显示多个标签例程
  • Istio实战(七)- Bookinfo 部署
  • 出差学小白知识No5:|Ubuntu上关联GitLab账号并下载项目(ssh key配置)
  • FL Studio21.2中文版多少钱?值得下载吗
  • 软考系统架构师知识点集锦三:软件架构设计
  • docker - window Docker Desktop升级
  • Element UI + Vue 新增和编辑共用表单校验无法清除问题(已解决)
  • FL Studio21最新中文汉化解锁版,2024怎么激活FL Studio
  • Mac怎么清理磁盘空间?释放Mac磁盘空间有效方法
  • 论文阅读(一)城市干道分段绿波协调控制模型研究
  • k8s 部署nginx前端
  • ClickHouse UDF 官方示例Example报错解决方案
  • eval()函数的用法,计算字符串中的值,模板字符串进行计算
  • leetcode第80题:删除有序数组中的重复项 II
  • 【Docker】Docker-Compose内置DNS负载均衡失效问题
  • [Python]Selenium-自动化测试