python 中实现统计基因缺失率

 

001、

复制代码
[b20223040323@admin1 test2]$ ls
dat.txt  test.py
[b20223040323@admin1 test2]$ cat dat.txt    ## 测试数据
gene1   gene2   gene3
0       1       0
0       1       1
1       0       0
0       1       1
[b20223040323@admin1 test2]$ cat test.py     ## python程序
## calculate the absent percent.

in_file = open("dat.txt", "r")
out_file = open("result.txt", "w")
lines = in_file.readlines()
temp = lines[0].strip().split("\t")
list1 = [0] * len(temp)
lines = lines[1::]

for i in lines:
        i = i.strip().split("\t")
        for j in range(len(temp)):
                if int(i[j]) == 0:
                        list1[j] = list1[j] + 1

for i in range(len(list1)):
        list1[i] = 1.0*list1[i]/len(temp)
        out_file.write(str(1.0*list1[i]/len(temp)) + " ")

out_file.write("\n")

in_file.close()
out_file.close()
[b20223040323@admin1 test2]$ python test.py    ## 执行程序
[b20223040323@admin1 test2]$ ls
dat.txt  result.txt  test.py
[b20223040323@admin1 test2]$ cat result.txt     ## 运行结果
0.333333333333 0.111111111111 0.222222222222
复制代码

 

posted @   小鲨鱼2018  阅读(44)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
历史上的今天:
2021-02-26 python中实现字典的逆向排列
2021-02-26 python中字典的复制
2021-02-26 python中删除字典的指定键值对
2021-02-26 python中如何清空字典
点击右上角即可分享
微信分享提示