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

相关推荐
m0_564876848 分钟前
nano-vllm学习
学习·vllm
丝斯201113 分钟前
AI学习笔记整理(76)——Python学习5
人工智能·笔记·学习
无聊大侠hello world17 分钟前
黑马大模型 RAG 与 Agent 实战学习笔记——智扫通 Agent 项目
笔记·学习
9523627 分钟前
初识多线程
java·开发语言·jvm·后端·学习·多线程
长安110829 分钟前
web后端----oatpp临时笔记
笔记
妄汐霜1 小时前
小白学习笔记(spring框架ioc)
笔记·学习
arvin_xiaoting1 小时前
OpenClaw学习总结_I_核心架构_5:Memory系统详解
学习·系统架构·学习总结·ai agent·openclaw·memory系统
_饭团1 小时前
C 语言数据存储全解析:原反补码、大小端与 IEEE 754 浮点数
c语言·数据结构·算法·leetcode·面试·蓝桥杯·学习方法
却道天凉_好个秋1 小时前
音视频学习(九十八):Profile
学习·音视频·profile
Kapibalapikapi1 小时前
操作笔记 | Ubuntu Server VMware虚拟机的文件传输
笔记·操作文档