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 ...
随机推荐
- 关于 ThinkPHP5 使用 getBy 字段名方式获取数据
关于 ThinkPHP5 使用 getBy 字段名方式获取数据 有小伙半说怎么全文搜索都没有搜索到 getByName 之类的函数. 其实是在这里.
- docker基于Dockerfile命令创建支持ssh服务的镜像
首先,创建一个sshd_centos工作目录: [root@localhost ~]# mkdir sshd_centos [root@localhost ~]# cd sshd_centos [ro ...
- [C++ Primer] 第9章: 顺序容器
顺序容器概述 顺序容器的类型有: 类型 说明 vector 可变长度数组. 支持快速随机访问. deque 双端队列. 支持快速随机访问. list 双向链表. 只支持双向顺序访问. forward_ ...
- [C++ Primer] 第8章: IO库
IO类 iostream定义了读写流的基本类型 istream, wistream 从流读取数据 ostream, wostream 向流写入数据 iostream, wiostream 读写流 fs ...
- 不同复制模式下,如何忽略某些binlog事件
在MySQL复制中,如果slave节点上遇到错误,比如数据不存在或者主键冲突等错误时,想要忽略这些错误,可以采用以下几种方法: 1.未启用GTID模式时 只需通过设定 SQL_SLAVE_SKIP_C ...
- Thinkphp 联表查询 表名要全名
我有2个表 表1. 表2 已知表2的user_id 查询满足 表2.wb_id=表1.id 表1的内容 最佳答案 i 2013年11月15日 $result = M()->table(array ...
- javascript使用bind指定接收者
var json = { jArray: [], jPush: function (c) { this.jArray.push(c); } } var examp = ["123" ...
- web.xml中配置spring.xml的三种方式
我们知道spring在web.xml中可以有三种方式来配置其xml路径:org.springframework.web.servlet.DispatcherServletorg.springframe ...
- git_基本使用
1.默认你已经安装了,git的客户端,这里我们使用git bash操作. 2.执行git init命令: git ini 3.在本地创建ssh key: ssh-keygen -t rsa - ...
- ACM Dance Recital(dfs+剪枝)
The Production Manager of a dance company has been tasked with determining the cost for the seasonal ...