10 Consensus and Profile
Problem
A matrix is a rectangular table of values divided into rows and columns. An m×nm×n matrix has mm rows and nn columns. Given a matrix AA, we write Ai,jAi,j to indicate the value found at the intersection of row ii and column jj.
Say that we have a collection of DNA strings, all having the same length nn. Their profile matrix is a 4×n4×n matrix PP in which P1,jP1,j represents the number of times that 'A' occurs in the jjth position of one of the strings, P2,jP2,j represents the number of times that C occurs in the jjth position, and so on (see below).
A consensus string cc is a string of length nn formed from our collection by taking the most common symbol at each position; the jjth symbol of cc therefore corresponds to the symbol having the maximum value in the jj-th column of the profile matrix. Of course, there may be more than one most common symbol, leading to multiple possible consensus strings.
A T C C A G C T | |
G G G C A A C T | |
A T G G A T C T | |
DNA Strings | A A G C A A C C |
T T G G A A C T | |
A T G C C A T T | |
A T G G C A C T | |
|
|
A 5 1 0 0 5 5 0 0 | |
Profile | C 0 0 1 4 2 0 6 1 |
G 1 1 6 3 0 1 0 0 | |
T 1 5 0 0 0 1 1 6 | |
|
|
Consensus | A T G C A A C T |
Given: A collection of at most 10 DNA strings of equal length (at most 1 kbp) in FASTA format.
Return: A consensus string and profile matrix for the collection. (If several possible consensus strings exist, then you may return any one of them.)
Sample Dataset
>Rosalind_1
ATCCAGCT
>Rosalind_2
GGGCAACT
>Rosalind_3
ATGGATCT
>Rosalind_4
AAGCAACC
>Rosalind_5
TTGGAACT
>Rosalind_6
ATGCCATT
>Rosalind_7
ATGGCACT
Sample Output
ATGCAACT
A: 5 1 0 0 5 5 0 0
C: 0 0 1 4 2 0 6 1
G: 1 1 6 3 0 1 0 0
T: 1 5 0 0 0 1 1 6 方法一:
#-*-coding:UTF-8-*-
### 10. Consensus and Profile ### from collections import Counter
from collections import OrderedDict fh = open('consesus_and_profile_output2.txt', 'wt') rosalind = OrderedDict()
seqLength = 0
with open('Sample Dataset.txt') as f:
for line in f:
line = line.rstrip()
if line.startswith('>'):
rosalindName = line
rosalind[rosalindName] = ''
continue
rosalind[rosalindName] += line
seqLength = len(rosalind[rosalindName]) #len(ATCCAGCT) A, C, G, T = [], [], [], []
consensusSeq = ''
for i in range(seqLength):
seq = ''
for k in rosalind.keys(): # rosalind.keys = Rosalind_1...Rosalind_7
seq += rosalind[k][i] # 把 Rosalind_1...Rosalind_7 相同顺序的碱基加起来
A.append(seq.count('A'))
C.append(seq.count('C'))
G.append(seq.count('G'))
T.append(seq.count('T'))
counts = Counter(seq) # 为seq计数
consensusSeq += counts.most_common()[0][0] #从多到少返回,是个list啊,只返回第一个 fh.write(consensusSeq + '\n')
fh.write('\n'.join(['A:\t' + '\t'.join(map(str, A)), 'C:\t' + '\t'.join(map(str, C)),
'G:\t' + '\t'.join(map(str, G)), 'T:\t' + '\t'.join(map(str, T))]))
#.join(map(str,A)) 把 A=[5, 1, 0, 0, 5, 5, 0, 0] 格式转化成 A:5 1 0 0 5 5 0 0
fh.close()
方法二:
# coding=utf-8
import numpy as np
import os
from collections import Counter fhand = open('Sample Dataset.txt')
t = []
for line in fhand:
if line.startswith('>'):
continue
else:
line = line.rstrip()
line_list = list(line) #变成一个list
t.append(line_list) # 再把list 放入list
a = np.array(t) # 创建一个二维数组 L1, L2, L3, L4 = [], [], [], []
comsquence = '' for i in range(a.shape[1]): # shape[0],是7 行数,shape[1]是8 项目数
l = [x[i] for x in a] # 调出二维数组的每一列
L1.append(l.count('A'))
L2.append(l.count('C'))
L3.append(l.count('T'))
L4.append(l.count('G'))
comsquence = comsquence + Counter(l).most_common()[0][0]
print comsquence
print 'A:', L1, '\n', 'T:', L2, '\n', 'C:', L3, '\n', 'G:', L4
10 Consensus and Profile的更多相关文章
- Linux bashrc和profile的用途和区别
导读 使用终端ssh登录Linux操作系统的控制台后,会出现一个提示符号(例如:#或~),在这个提示符号之后可以输入命令,Linux根据输入的命令会做回应,这一连串的动作是由一个所谓的Shell来做处 ...
- ORACLE:profile的管理
PROFILE的管理(资源文件) 当需要设置资源限制时,必须设置数据库系统启动参数RESOURCE_LIMIT,此参数默认值为FALSE 可以使用如下命令来启动当前资源限制: ...
- 四、oracle 用户管理(Profile)
oracle 用户管理 :profile + tablespace + role + user 一.使用profile管理用户口令概述:profile是口令限制,资源限制的命令集合,当建立数据库时, ...
- Maven的porfile与SpringBoot的profile结合使用详解
使用maven的profile功能,我们可以实现多环境配置文件的动态切换,可参考我的上一篇博客.但随着SpringBoot项目越来越火,越来越多人喜欢用SpringBoot的profile功能 ...
- Maven之profile实现多环境配置动态切换
一般的软件项目,在开发.测试及生产等环境下配置文件中参数是不同的.传统的做法是在项目部署的时候,手动修改或者替换这个配置文件.这样太麻烦了,我们可以用Maven的profile来解决这 ...
- 转://SQL PROFILE
我们经常会碰到一些线上的SQL问题,因为执行计划不对,可能需要添加HINT才能解决.但是添加HINT就意味着需要修改应用代码.一般一个应用代码的修改.测试及发布,可能需要两三个工作日才可完成.咱们数据 ...
- Linux /etc/profile文件详解
Linux /etc/profile文件详解 转载地址:http://linux.chinaitlab.com/administer/820910.html linux /etc/profile文 ...
- Centos7-安装Gradle4.10
1.下载 官方安装文档:https://gradle.org/install/ 官方下载地址:http://services.gradle.org/distributions/gradle-4.10- ...
- 转 sql profile 绑定 litera and move profile to another db l for spa
SQL TYPE 1:for bind value sql , first create a good plan with literal and with good profile. then u ...
随机推荐
- 【idea】如何安装jetty容器,并使用。
参考:https://www.jetbrains.com/idea/help/run-debug-configuration-jetty-server.html背景:web开发当中,我觉得服务层的代码 ...
- HDU5296 Annoying problem(LCA)
//#pragma comment(linker, "/STACK:1677721600") #include <map> #include <set> # ...
- php 自定义函数大全
1. call_user_func和call_user_func_array 以上两个函数以不同的参数形式调用函数.见如下示例: <?php class demo{ public static ...
- erlang单独配置文件
一种是erl启动的时候加参数 doudizhu.config [ {doudizhu,[ {listen_port, }, {node_caller_prefix,"ruby"}, ...
- IDEA试用期结束以后继续试用(全部失效就更新),IDEA 2018 LICENSE SERVER
IDEA是一款收费的IDE,但是新用户可以免费试用一段时间,试用期结束可以购买,也可以通过填写License server address来继续使用. 打开IDEA以后,通过Help ----- Re ...
- java之RestTemplate的访问应用
一.REST即表述性状态传递(英文:Representational State Transfer,简称REST)是Roy Fielding博士在2000年他的博士论文中提出来的一种软件架构风格.它是 ...
- 五.jQuery源码解析之jQuery.extend(),jQuery.fn.extend()
给jQuery做过扩展或者制作过jQuery插件的人这两个方法东西可能不陌生. jQuery.extend([deep],target,object1,,object2...[objectN]) jQ ...
- solr精确查询,查询关键字分词后,指定满足匹配所有
一.solr查询,查询配置了查询分词器的字段,默认会对查询关键字做分词处理 1.如查询关键字F1501ZY000011,使用solr7自带的中文分词器,默认会分词为:f,1501,zy,000011 ...
- 安装MySQL时出现黄色感叹号,提示3306已被占用
windows系统如何查看现在某个端口的应用进程id呢,命令是: 1.netstat -aon|findstr 3306 2.最后的那个数值就是进程id号,此时需要查看该id号对应的应用是哪一个,可 ...
- leetcode814
class Solution { public: TreeNode* pruneTree(TreeNode* root) { if(root==NULL) { return nullptr; } if ...