1 Star 0 Fork 0

尧小飞/Cibersortx

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
convert_reference_file.py 1.03 KB
一键复制 编辑 原始数据 按行查看 历史
nina2727 提交于 2020-01-30 18:12 . edited
#!/usr/bin/env python
import pandas as pd
import sys
import subprocess
'''
20200128
python convert_reference_file.py MCA_liver_cell_expression.tsv MCA_liver_cell_class.tsv
input file 1: expression
input file 2: classes
'''
def main():
s1 = 'cat '+ str(sys.argv[1])+ ' | sed -n 1p > classes_matrix.tsv'
subprocess.call(s1,shell=True)
s2 = 'cat ' + str(sys.argv[2]) + ' >> classes_matrix.tsv'
subprocess.call(s2,shell=True)
df = pd.read_csv('classes_matrix.tsv',delimiter = '\t',index_col=0)
dct = {}
for index in df.index:
for column in df.columns:
if df.loc[index,column] == 1:
dct[column]=index
df_exp = pd.read_csv(sys.argv[1],delimiter='\t',index_col=0)
df_exp = df_exp.rename(columns=dct)
df_exp.to_csv(sys.argv[1].split('.')[0]+'_phenotype.tsv',sep='\t')
dct_count = {}
for key in dct.keys():#key:tag, value:phenotype
if dct[key] not in dct_count.keys():
dct_count[dct[key]] = 1
else:
dct_count[dct[key]] +=1
for key in dct_count.keys():
print(key + '\t' + str(dct_count[key]))
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/yao_xiao_fei2/Cibersortx.git
git@gitee.com:yao_xiao_fei2/Cibersortx.git
yao_xiao_fei2
Cibersortx
Cibersortx
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385