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
[email protected]$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
[email protected]$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

相关推荐
蒙奇D索大3 分钟前
【11408学习记录】考研英语写作提分秘籍:2013真题邀请信精讲+万能模板套用技巧
笔记·学习·考研·改行学it
霸王蟹1 小时前
React 项目中封装 Excel 导入导出组件:技术分享与实践
前端·笔记·学习·react.js·typescript·excel·vite
源力祁老师1 小时前
高温炉制造企业Odoo ERP实施规划与深度分析报告
开发语言·学习方法
贺函不是涵2 小时前
【沉浸式求职学习day51】【发送邮件】【javaweb结尾】
java·学习
uyeonashi2 小时前
【从零开始学习QT】快捷键、帮助文档、Qt窗口坐标体系
开发语言·c++·qt·学习
知识分享小能手3 小时前
Typescript学习教程,从入门到精通,TypeScript 配置管理与编译器详解(19)
前端·javascript·学习·typescript·前端框架·ecmascript·jquery
爱意随风起风止意难平3 小时前
002 flutter基础 初始文件讲解(1)
学习·flutter
Chef_Chen4 小时前
从0开始学习R语言--Day12--泊松分布
开发语言·学习·r语言
z人间防沉迷k4 小时前
MySQL事务和索引原理
数据库·笔记·sql·mysql
golitter.5 小时前
langchain学习 01
python·学习·langchain