单细胞学习

小鼠和人的同源基因对应

2021-04-27  本文已影响0人  myshu

在使用cellphoneDB和italk进行细胞通讯分析时,发现小鼠的结果很少或奇奇怪怪。查了下网上大家的一些解决办法,发现将小鼠的基因转成人的同源基因即可做。

这篇文章主要是使用biomart包的数据来进行转换的。通过下载两两物种的ID对应关系,然后写个代码替换就可以了。

1、首先打开下载页面

http://asia.ensembl.org/biomart/martview/b9f8cc0248e4714ba8e0484f0cbe4f02

2、选择对应基因组

3、选择属性

4、选择对应orthologs的物种(根据首字母)


5、最后下载


保存为mouse_human.txt,并修改文件header为human_id human_gene_name mouse_gene_name mouse_id

转换的代码:(输入的文件第一列是小鼠的gene symbol,大家根据自己的数据情况改代码~)

#!/usr/bin/python
# -*-coding:utf8 -*-
__author__ = 'myshu'
import sys
import os
import re
import argparse
sys.path.append(os.path.dirname(os.path.abspath(sys.argv[0])))

def rename_gene(ref, input_file, output_file):
    '''
        小鼠的基因name转成人的ortholog基因
    @param ref: 小鼠-人的ortholog基因对应表
    @param input_file: 输入文件,第一列为小鼠gene_name
    @param output_file: 输出替换后的文件
    @return:
    '''
    ref_file = os.path.abspath(ref)
    input_file = os.path.abspath(input_file)
    output_file = os.path.abspath(output_file)
    ref = {}
    for line in open(ref_file, "r"):
        # human_id human_gene_name mouse_gene_name mouse_id
        line = line.strip()
        line = line.split("\t")
        gene_syb = line[2]
        gene_id = line[1]
        ref[gene_syb] = gene_id

    fh = open(output_file, "w")
    num = 0
    for line0 in open(input_file, "r"):
        line = line0.strip()
        line = line.split("\t")
        # line.pop(0)
        if line0.startswith("\t") or line0.startswith("#"):
            fh.write(line0)
            fh.flush()
            continue
        result_id = line[0]
        if result_id in ref.keys():
            line.pop(0)
            fh.write(ref[result_id] + "\t" + "\t".join(line) + "\n")
            fh.flush()
            num += 1
    fh.close()
    if num == 0:
        print("all genes is pass!!!!!!!!!!!!!!!!!!!!!")
        # exit(1)


if (__name__ == "__main__"):
    parser = argparse.ArgumentParser(description=' rename mouse gene name to human orthologs gene name')
    parser.add_argument('--ref', '-r', required=False, help='biomart sub-database', default=f"mouse_human.txt")
    parser.add_argument('--input_file', '-i', required=True, help='sample.exp.txt')
    parser.add_argument('--output_file', '-p', required=True, help='"sample.exp.txt_new')
    args = parser.parse_args()
    rename_gene(**vars(args))

在R代码里面替换代码:

if (species == "Mus_musculus"){
    # 小鼠需要转ortholog基因
    ref_ortholog <- read.table("mouse_human.txt", header=T,sep="\t")
    # 筛选有的mouse基因名称
    b <- ref_ortholog[ref_ortholog$mouse_gene_name %in% colnames(iTalk_data),"mouse_gene_name"]
    data <- data[,b]
    # 替换为人的ortholog基因
    colnames(data) <- ref_ortholog[ref_ortholog$mouse_gene_name %in% colnames(data),"human_gene_name"]
}

如有任何建议欢迎评论~~

参考链接:

上一篇 下一篇

猜你喜欢

热点阅读