首页 > 编程语言 >python中计算点突变的数目

python中计算点突变的数目

时间:2023-08-28 10:47:57浏览次数:77  
标签:file2 file1 python root PC1 fa 突变 test01 数目

 

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

相关文章

  • centos7 python3安装注意点
    1.安装,参考网上教程,不再重复赘述https://www.cnblogs.com/mindtechnist/p/17243882.html2.注意点:网上多数文章中为了方便,会直接在/usr/bin目录下重建python的软链接,指向python3,由于centos默认的python版本为2.7,2和3无法兼容,故会导致很多基础组件出现调用异常,如yum、firewall-cm......
  • Ubuntu16.04安装OpenEXR与openexr-python
    1,安装库文件sudoapt-getinstallopenexr 2,安装python接口(注意版本问题) 我使用的python3.6,安装1.3.2版本的没有问题,如果python是3.8,可以尝试选择安装1.3.9等高版本pipinstallOpenEXR==1.3.2-ihttps://pypi.tuna.tsinghua.edu.cn/simple 如果没有指定OpenEXR的......
  • Python exe文件打包神器-Nuitka! 转载
    一.pyinstaller和Nuitka使用感受1.1使用需求这次也是由于项目需要,要将python的代码转成exe的程序,在找了许久后,发现了2个都能对python项目打包的工具——pyintaller和nuitka。这2个工具同时都能满足项目的需要:隐藏源码。这里的pyinstaller是通过设置key来对源码进行加密的;而nuitka......
  • Python学习笔记
    文档中函数的参数带方括号([or])代表可选参数列表(list)基础列表是可迭代对象,列表有序矩阵#创建列表[1,2,3,4,5]#列表可以包含不同的数据类型[1,2,3,"hello"]#可以使用下表索引(从0开始)rhyme[1]rhyme[-1]#切片(不包含末尾)rhyme[0:3]rhyme[:3]rhyme[3:]r......
  • python 安装的国内镜像源
    Python镜像源是指可以用来下载Python相关软件包的在线仓库地址。Python在国内使用的比较广泛,为了提高安装包的下载速度,一般会配置国内镜像源。常见的Python镜像源包括以下几个:默认情况下pip使用的是国外的镜像,在下载的时候速度非常慢,本文我们介绍使用国内清华大学的源,......
  • 重新做人 再学一遍python
    print()input()格式化输出: 字符串:判断子串是否在父串中:  取子串:  字符串操作:  ......
  • VSCode中配置Python运行环境
    1首先需要下载相应的包可以在官网中分别下载python和anaconda的安装包,按照步骤进行下载安装即可。python安装成功的标志为cmd中输入python可以进入python的运行环境。anaconda安装成功的标志为打开anacondaprompt可以输入“condalist”来查看目前已经集成的库。2在VSCode中下载......
  • python中求DNA的反向互补序列
     001、  利用循环结构实现[root@PC1test01]#lsa.fatest.py[root@PC1test01]#cata.fa##测试DNA序列AAAACCCGGT[root@PC1test01]#cattest.py##程序#!/usr/bin/envpython#-*-coding:utf-8-*-in_file=open("a.fa","r")file=......
  • python 中实现字符串反转的几种方法
     001、利用切片实现>>>str1="abcdef"##测试字符串>>>str1[::-1]'fedcba' 002、利用for循环实现>>>str1="abcdef"##测试字符串>>>rev="">>>foriinstr1:......
  • python中实现RNA序列的翻译
     001、利用循环结构实现[root@PC1test01]#lsa.fatest.py[root@PC1test01]#cata.fa##测试RNA序列AUGGCCAUGGCGCCCAGAACUGAGAUCAAUAGUACCCGUAUUAACGGGUGA[root@PC1test01]#cattest.py##翻译程序#!/usr/bin/envpython#-*-coding:utf......