首页 > 编程语言 >python 中实现DNA一致性序列计算

python 中实现DNA一致性序列计算

时间:2022-08-18 19:23:40浏览次数:59  
标签:DNA dict3 python test Rosalind file 一致性 home append

 

001、

root@PC1:/home/test# ls
a.fasta  test.py
root@PC1:/home/test# cat a.fasta              ## 测试数据
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
root@PC1:/home/test# cat test.py                     ## 测试程序
#!/usr/bin/python

in_file = open("a.fasta", "r")
out_file = open("result.txt", "w")
dict1 = dict()
dict2 = dict()

for i in in_file:
    i = i.strip()
    if i[0] == ">":
        key = i
        dict1[key] = []
    else:
        dict1[key].append(i)

list1 = list()

for i in dict1.values():
    i = "".join(i)
    list1.append(i)

length = len(list1[0])
for i in range(length):
    dict2[i] = []

for i in list1:
    for j in range(length):
        dict2[j].append(i[j])

dict3 = dict()
for i in "ATCG":
    dict3[i] = []

for i in dict2.values():
    i = "".join(i)
    dict3["A"].append(str(i.count("A")))
    dict3["C"].append(str(i.count("C")))
    dict3["G"].append(str(i.count("G")))
    dict3["T"].append(str(i.count("T")))

for i,j in dict3.items():
    print(i, " ".join(j), file = out_file)

in_file.close()
out_file.close()
root@PC1:/home/test# python test.py                    ## 执行程序
root@PC1:/home/test# ls
a.fasta  result.txt  test.py
root@PC1:/home/test# cat result.txt                    ## 程序结果
A 5 1 0 0 5 5 0 0
T 1 5 0 0 0 1 1 6
C 0 0 1 4 2 0 6 1
G 1 1 6 3 0 1 0 0

 

参考:https://mp.weixin.qq.com/s?__biz=MzIxMjQxMDYxNA==&mid=2247484219&idx=1&sn=45fe0f337db0c2bb078bbbac0c0a3b77&chksm=9747caa2a03043b4e348e7d4a3946a2dcfdbc0dd33f533aa5a615d74da2571f52729f3ae86bd&scene=178&cur_album_id=1635727573621997580#rd

 

标签:DNA,dict3,python,test,Rosalind,file,一致性,home,append
From: https://www.cnblogs.com/liujiaxin2018/p/16599824.html

相关文章

  • Python list methods All In One
    PythonlistmethodsAllInOnePython3#!/usr/bin/envpython3#coding=utf-8__author__='xgqfrms'__editor__='vscode'__version__='1.0.1'__copyrigh......
  • python菜鸟学习: 9. 文件操作
    #-*-coding:utf-8-*-importsys,time#读文件:一次性读取所有内容#r=readf=open("singe.txt",'r',encoding="utf-8").read()print(f)#写文件,覆盖原来的文件#w=wr......
  • python 读取.pkl.gz文件
    1importpandasaspd2importsix.moves.cPickleascPickle3importgzip45filePath='./a/data.pkl.gz'6f=gzip.open(filePath,'rb')7df=pd.D......
  • Python进阶篇02-函数
    一、常规函数的定义函数函数就是一段组织好的、可以重复使用的代码块。比如在你写的某个.py文件中,需要频繁的计算面积,这样我们会有很多相似、重复的代码,在这种情况下,我......
  • Python 创建虚拟环境
    桌面建立一个文件夹,假设为tor打开cmdcddesktopcdtor假设python没有  pipenv包,则pip3installpipenv假设tor文件夹内没有虚拟环境,即没有pipfiel及p......
  • python中输出两条长度一致序列碱基不同的个数
     001、方法1root@PC1:/home/test#lstest.pyroot@PC1:/home/test#cattest.py##测试程序#!/usr/bin/pythonstr1="GAGCCTACTAACGGGAT"......
  • Python报错:ImportError cannot import name 'imresize'
    原文链接Python出现错误:ImportError:cannotimportname'imresize'解决方案首先安装pillow:pipinstallpillow然后安装scipy早期版本。高级版scipy本不再......
  • Python 数据类型及转换
    Python数据类型及转换说明:Python每一个变量在使用前都要赋值,每个变量都有一个数据类型,之前说的type()函数可以查看变量的类型。Python常见的数据类型有:Number(数字)、Strin......
  • python 执行shell 日志 输出
    一、python执行shell实时打印到屏幕上fromsubprocessimportPopen,PIPE,STDOUTmove_data="cmd_val"defexec_command(command):move_path=Popen(com......
  • 发现一个舔狗神器,Python真的太厉害了,自动下载妹子视频...
    兄弟们,现在短视频主播好看的妹子太多了,有时候遇到自己喜欢的,虽然点了赞或者收藏了,但是万一主播把视频隐藏下架了呢?所以今天咱们就用Python来把这些好看的视频统统保存......