python中计算点突变的数目
001、直接比较计算
[root@PC1 test01]# ls a.fa b.fa test.py [root@PC1 test01]# cat a.fa ## 测试dna序列 GAGCCTACTAACGGGAT [root@PC1 test01]# cat b.fa ## 测试dna序列 CATCGTAATGACGGCCT [root@PC1 test01]# cat test.py ## 计算程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file1 = open("a.fa", "r") in_file2 = open("b.fa", "r") file1 = in_file1.read().strip() file2 = in_file2.read().strip() in_file1.close() in_file2.close() count = 0 for i in range(len(file1)): if file1[i] != file2[i]: count += 1 print(count) [root@PC1 test01]# python3 test.py ## 计算结果 7
002、利用函数结构计算
[root@PC1 test01]# ls a.fa b.fa test.py [root@PC1 test01]# cat a.fa ## 测试dna序列 GAGCCTACTAACGGGAT [root@PC1 test01]# cat b.fa ## 测试dna序列 CATCGTAATGACGGCCT [root@PC1 test01]# cat test.py ## 计算程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file1 = open("a.fa", "r") in_file2 = open("b.fa", "r") file1 = in_file1.read().strip() file2 = in_file2.read().strip() def count(seq1, seq2): count = 0 if len(seq1) != len(seq2): print("anomalous length!") exit else: for i in range(len(seq1)): if seq1[i] != seq2[i]: count += 1 return count print(count(file1, file2)) [root@PC1 test01]# python test.py ## 计算结果 7
003、借助zip实现
[root@PC1 test01]# ls a.fa b.fa test.py [root@PC1 test01]# cat a.fa GAGCCTACTAACGGGAT [root@PC1 test01]# cat b.fa CATCGTAATGACGGCCT [root@PC1 test01]# cat test.py ## 计数程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file1 = open("a.fa", "r") in_file2 = open("b.fa", "r") file1 = in_file1.read().strip() file2 = in_file2.read().strip() in_file1.close() in_file2.close() count = 0 for i,j in zip(file1,file2): if i != j: count += 1 print(count) [root@PC1 test01]# python test.py ## 点突变结果 7
004、函数实现
[root@PC1 test01]# ls a.fa b.fa test.py [root@PC1 test01]# cat a.fa GAGCCTACTAACGGGAT [root@PC1 test01]# cat b.fa CATCGTAATGACGGCCT [root@PC1 test01]# cat test.py ## 计数程序 #!/usr/bin/env python # -*- coding: utf-8 -*- in_file1 = open("a.fa", "r") in_file2 = open("b.fa", "r") file1 = in_file1.read().strip() file2 = in_file2.read().strip() in_file1.close() in_file2.close() def count(dna1, dna2): count = 0 for i,j in zip(dna1, dna2): if i != j: count += 1 return count print(count(file1, file2)) [root@PC1 test01]# python test.py ## 计数结果 7
。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 单元测试从入门到精通
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
2022-08-28 R语言中快捷键 选中光标的文件头的所有内容、及选种光标到文件尾的所有内容
2022-08-28 R语言中快捷键 选中光标所在行
2022-08-28 R语言中删除光标到行首、光标到行末的快捷键
2022-08-28 seurat 单细胞数据分析中MinMax函数
2022-08-28 R语言中依据数据框元素筛选元素
2021-08-28 c primer plus 8编程练习