GPTcelltype——scRNA-seq注释


plain 复制代码
#安装包
install.packages("openai")
remotes::install_github("Winnie09/GPTCelltype")
#填写API
Sys.setenv(OPENAI_API_KEY = 'your_openai_API_key')
#加载包
#Load packages
library(GPTCelltype)
library(openai)
#准备文件
#Assume you have already run the Seurat pipeline https://satijalab.org/seurat/
#"obj" is the Seurat object; "markers" is the output from FindAllMarkers(obj)
#Cell type annotation by GPT-4
##注释
res <- gptcelltype(markers, model = 'gpt-4')
##添加到metadata
# Assign cell type annotation back to Seurat object
obj@meta.data$celltype <- as.factor(res[as.character(Idents(obj))])
##可视化
# Visualize cell type annotation on UMAP
DimPlot(obj,group.by='celltype')
markdown 复制代码
下面是代码逐行详细解释及中文翻译:

```r
#安装包
install.packages("openai")

这行代码安装openai包,这是一个与OpenAI API交互的R包。

  • 中文翻译:安装openai包,这是一个与OpenAI API交互的R包。
r 复制代码
remotes::install_github("Winnie09/GPTCelltype")

这行代码使用remotes包从GitHub安装名为GPTCelltype的包,GPTCelltype包提供了一些功能来注释细胞类型。

  • 中文翻译:使用remotes包从GitHub安装GPTCelltype包,该包提供细胞类型注释功能。
r 复制代码
#填写API
Sys.setenv(OPENAI_API_KEY = 'your_openai_API_key')

这行代码设置环境变量OPENAI_API_KEY,用于存储你的OpenAI API密钥。务必替换'your_openai_API_key'为你的实际API密钥。

  • 中文翻译:设置环境变量OPENAI_API_KEY,用于存储你的OpenAI API密钥。确保替换为你的实际API密钥。
r 复制代码
#加载包
#Load packages
library(GPTCelltype)
library(openai)

这两行代码加载之前安装的两个R包:GPTCelltypeopenai,以便可以使用它们的功能。

  • 中文翻译:加载之前安装的两个R包:GPTCelltypeopenai,以便能够使用它们的功能。
r 复制代码
#准备文件
#Assume you have already run the Seurat pipeline https://satijalab.org/seurat/

这段注释说明在运行后续代码之前,用户需要先使用Seurat分析工具对数据进行预处理。

  • 中文翻译:假设你已经运行了Seurat管道以处理数据。
r 复制代码
# "obj" 是 Seurat 对象; "markers" 是来自 FindAllMarkers(obj) 的输出

这条注释进一步说明了obj是Seurat对象,而markers是通过FindAllMarkers(obj)函数获得的标记基因数据。

  • 中文翻译:"obj" 是 Seurat 对象;"markers" 是来自FindAllMarkers(obj)的输出。
r 复制代码
#Cell type annotation by GPT-4
##注释
res <- gptcelltype(markers, model = 'gpt-4')

这里调用gptcelltype函数使用GPT-4模型对细胞标记进行注释,将结果存储在res变量中。

  • 中文翻译:使用GPT-4模型进行细胞类型注释,将结果存储在res变量中。
r 复制代码
##添加到metadata
# Assign cell type annotation back to Seurat object
obj@meta.data$celltype <- as.factor(res[as.character(Idents(obj))])

这行代码将注释结果res所对应的细胞类型赋值给Seurat对象objmeta.data属性中的celltype列。

  • 中文翻译:将细胞类型注释结果赋值回Seurat对象的meta.data中。
r 复制代码
##可视化
# Visualize cell type annotation on UMAP
DimPlot(obj, group.by='celltype')

最后这行代码使用DimPlot函数在UMAP图上可视化细胞类型注释,以celltype作为分组依据。

  • 中文翻译:在UMAP图上可视化细胞类型注释,以celltype作为分组依据。
    ``

原文中考虑到network相关问题,推荐了另外一个平替

参考:
https://mp.weixin.qq.com/s/xPQQ5v8nIWU1DwfdAxjdfw

相关推荐
LGGGGGQ2 小时前
嵌入式学习-PyTorch(4)-day21
学习
艾莉丝努力练剑3 小时前
【LeetCode&数据结构】单链表的应用——反转链表问题、链表的中间节点问题详解
c语言·开发语言·数据结构·学习·算法·leetcode·链表
人生游戏牛马NPC1号4 小时前
学习 Flutter (三):玩安卓项目实战 - 上
android·学习·flutter
深圳卢先生7 小时前
CentOS 安装jenkins笔记
笔记·centos·jenkins
u_topian7 小时前
【个人笔记】Qt使用的一些易错问题
开发语言·笔记·qt
没有羊的王K8 小时前
SSM框架学习——day1
java·学习
珊瑚里的鱼8 小时前
LeetCode 692题解 | 前K个高频单词
开发语言·c++·算法·leetcode·职场和发展·学习方法
林林要一直努力9 小时前
AOSP Settings模块问题初窥
android·学习·bug·android studio
余大侠在劈柴12 小时前
pdf.js 开发指南:在 Web 项目中集成 PDF 预览功能
前端·javascript·学习·pdf
WarPigs12 小时前
游戏框架笔记
笔记·游戏·架构