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 ...
随机推荐
- CH2101 可达性统计
题意 给定一张N个点M条边的有向无环图,分别统计从每个点出发能够到达的点的数量.N,M≤30000. 分析 有向无环图,可以按拓扑序逆序统计答案.可以用bitset维护可达性. 时间复杂度\(O(N ...
- mysql having,group by查询去除重复记录
http://m.jb51.net/article/39302.htm 可以这样去理解group by和聚合函数 http://www.cnblogs.com/wuguanglei/p/4229938 ...
- java工具类-读配置文件
///读配置文件 import java.io.InputStream;import java.util.HashMap;import java.util.Map;import java.util.M ...
- Java中数组转为List三种情况的优劣对比,常犯的类型转换错误原因解析
一.最常见方式(未必最佳)通过 Arrays.asList(strArray) 方式,将数组转换List后,不能对List增删,只能查改,否则抛异常. 关键代码:List list = Arrays. ...
- 南京邮电大学网络攻防平台——WriteUp(持续更新)
1.签到题 右键查看源代码直接获得flag 2.MD5collision(MD5碰撞) 观察源码发现md51等于QNKCDZO通过MD5加密的结果,使用在线解密发现结果为 0e830400451993 ...
- Bootstrap-CL:列表组
ylbtech-Bootstrap-CL:列表组 1.返回顶部 1. Bootstrap 列表组 本章我们将讲解列表组.列表组件用于以列表形式呈现复杂的和自定义的内容.创建一个基本的列表组的步骤如下: ...
- Script_Notepad++如何调试VBS脚本
一.NotePad++安装 1. 下载并安装Notepad++,安装步骤一路Next就可以了. 二.NppExec插件安装和配置 1. 下载并解压 NppExec_041_dll_Unicode.zi ...
- Windows常用内容渗透命令
假设现在已经拥有一台内网[域]机器,取名X-007. 1-1.内网[域]信息收集 A.本机X-007信息收集. [+]------用户列表[Windows用户列表/邮件用户/...] ----> ...
- C#调用Oracle带输出数据集的存储过程
1.创建一个带输出数据集的Oracle存储过程 create or replace procedure PRO_test(in_top in number,cur_out out sys_refcur ...
- 六.jQuery源码分析之jQuery原型属性和方法
97 jQuery.fn = jQuery.prototype = { 98 constructor: jQuery, 99 init: function( selector, context, ro ...