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
复制代码

 

 

posted @   小鲨鱼2018  阅读(70)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 震惊!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编程练习
点击右上角即可分享
微信分享提示