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
标签:file2,file1,python,root,PC1,fa,突变,test01,数目 From: https://www.cnblogs.com/liujiaxin2018/p/17661630.html