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 ...
随机推荐
- 【java基础】ThreadLocal的实现原理
[一]:ThreadLocal对象的大体实现原理===>当前线程对象有一个ThreadLocal.ThreadLocalMap属性.===>声明的ThreadLocal对象最终存储在当前线 ...
- python print 控制台输出中文
在pycharm里面的控制台用print输出信息, 本意想输出中文, 但是实际上是u\xxxx. 可以用这种方式: print("%s " % cn_string)
- Git Flow分支策略
就像代码需要代码规范一样,代码管理同样需要一个清晰的流程和规范 Vincent Driessen 同学为了解决这个问题提出了 A Successful Git Branching Model 下面是G ...
- windows7安装django并创建第一个应用
1.安装django 1.1.下载Django包 https://www.djangoproject.com/download/https://www.djangoproject.com/m/rele ...
- Ubuntu各种indicator汇总
1. indicator-multiload: 可视化图形显示 sudo apt-get install indicator-multiload 2. indicator-sysmonitor: 以 ...
- emacs之切换h/cpp配置
emacsConfig/switch-file-setting.el (defun switch-c () (global-set-key (kbd "<C-return>&qu ...
- [html][LigerUI]使用示例
<link href="Source/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet&quo ...
- 最小化安装CentOS7,没有ifconfig命令---yum search command_name搜索未知包名
新安装的CentOS7系统,想查询ip的时候,发现没有ifconfig这个命令: -bash: ifconfig: 未找到命令 yum安装: 没有可用软件包 ifconfig 既然知道命令,搜索一下命 ...
- 030:Cetus中间件和MHA读写分离
030:Cetus中间件和MHA读写分离 line:V1.1 mail: gczheng@139.com date: 2018-08-30 一.主机环境 虚拟机配置 CPU 内存 硬盘 OS版本 My ...
- SSH: sshd dead but subsys locked
问题: 查看SSH的状态时,提示错误如下: /etc/init.d/sshd status error: sshd dead but subsys locked 解决方法: sshd -d rm -r ...