人轉(zhuǎn)鼠
transformHomoloGene <- function(genes.in, inTaxID = 9606, outTaxID = 10090) {
library(homologene)
res.home <- homologene(genes.in, inTax = inTaxID, outTax = outTaxID)
res.home <- res.home[!duplicated(res.home[, 1]),]
res.home <- res.home[!duplicated(res.home[, 2]),]
genes.out <- res.home[, 1]
return(genes.out)
}
鼠轉(zhuǎn)人
transformHomoloGene <- function(genes.in, inTaxID = 10090, outTaxID = 9606) {
library(homologene)
res.home <- homologene(genes.in, inTax = inTaxID, outTax = outTaxID)
res.home <- res.home[!duplicated(res.home[, 1]),]
res.home <- res.home[!duplicated(res.home[, 2]),]
genes.out <- res.home[, 1]
return(genes.out)
}
biomaRt
# 導(dǎo)入所需的包
library(biomaRt)
# 創(chuàng)建biomaRt數(shù)據(jù)集
human_dataset <- useMart("ensembl", dataset = "hsapiens_gene_ensembl", host = "https://dec2021.archive.ensembl.org/")
mouse_dataset <- useMart("ensembl", dataset = "mmusculus_gene_ensembl", host = "https://dec2021.archive.ensembl.org/")
# 從Excel文件中讀取人的基因名列表
gene_df <- read.xlsx(excel_file_path)
# 提取人的基因名列
human_genes <- gene_df$Gene # 列名為 "Gene"准浴,你需要根據(jù)實(shí)際情況修改
# 創(chuàng)建一個(gè)空的輸出基因名向量柠座,與輸入基因名向量的長(zhǎng)度相同
mouse_genes <- character(length(human_genes))
# 進(jìn)行基因名稱的轉(zhuǎn)換
for (i in 1:length(human_genes)) {
converted_genes <- getLDS(attributes = c("external_gene_name"),
filters = "external_gene_name",
values = human_genes[i],
mart = human_dataset,
attributesL = c("external_gene_name"),
martL = mouse_dataset)
if (length(converted_genes) > 0) {
# 將多個(gè)匹配結(jié)果連接為逗號(hào)分隔的字符串
mouse_gene <- paste(converted_genes, collapse = ", ")
# 去除包含人基因的部分
mouse_gene <- gsub(paste(human_genes, collapse = "|"), "", mouse_gene)
# 移除多余的逗號(hào)和空格
mouse_gene <- gsub(",\\s+", ", ", mouse_gene)
mouse_gene <- gsub("^,\\s+|,\\s+$", "", mouse_gene)
mouse_genes[i] <- mouse_gene
} else {
mouse_genes[i] <- "" # 如果沒(méi)有匹配的小鼠基因名,使用空字符串
}
}
# 創(chuàng)建包含轉(zhuǎn)換結(jié)果的新數(shù)據(jù)框,包括人基因列和小鼠基因列
output_gene_df <- data.frame(Gene_Human = human_genes, Gene_Mouse = mouse_genes)