05 Computing GC Content
Problem
The GC-content of a DNA string is given by the percentage of symbols in the string that are 'C' or 'G'. For example, the GC-content of "AGCTATAG" is 37.5%. Note that the reverse complement of any DNA string has the same GC-content.
DNA strings must be labeled when they are consolidated into a database. A commonly used method of string labeling is called FASTA format. In this format, the string is introduced by a line that begins with '>', followed by some labeling information. Subsequent lines contain the string itself; the first line to begin with '>' indicates the label of the next string.
In Rosalind's implementation, a string in FASTA format will be labeled by the ID "Rosalind_xxxx", where "xxxx" denotes a four-digit code between 0000 and 9999.
Given: At most 10 DNA strings in FASTA format (of length at most 1 kbp each).
Return: The ID of the string having the highest GC-content, followed by the GC-content of that string. Rosalind allows for a default error of 0.001 in all decimal answers unless otherwise stated; please see the note on absolute error below.
Sample Dataset
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
Sample Output
Rosalind_0808
60.919540 方法一:
# -*- coding: utf-8 -*- # to open FASTA format sequence file:
s=open('Computing_GC_Content.txt','r').readlines() # to create two lists, one for names, one for sequences
name_list=[]
seq_list=[] data='' # to put the sequence from several lines together for line in s:
line=line.strip()
for i in line:
if i == '>':
name_list.append(line[1:])
if data:
seq_list.append(data) #将每一行的的核苷酸字符串连接起来
data='' # 合完后data 清零
break
else:
line=line.upper()
if all([k==k.upper() for k in line]): #验证是不是所有的都是大写
data=data+line
seq_list.append(data) # is there a way to include the last sequence in the for loop?
GC_list=[]
for seq in seq_list:
i=0
for k in seq:
if k=="G" or k=='C':
i+=1
GC_cont=float(i)/len(seq)*100.0
GC_list.append(GC_cont) m=max(GC_list)
print name_list[GC_list.index(m)] # to find the index of max GC
print "{:0.6f}".format(m) # 保留6位小数
方法二:
# -*- coding: utf-8 -*- def parse_fasta(s):
results = {}
strings = s.strip().split('>')
# Python split()通过指定分隔符对字符串进行切片,如果参数num 有指定值,则仅分隔 num 个子字符串 for s in strings:
if len(s) == 0:
continue
# 如果字符串长度为0,就跳出循环。 parts = s.split()
label = parts[0]
bases = ''.join(parts[1:]) results[label] = bases return results def gc_content(s):
n = len(s)
m = 0 for c in s:
if c == 'G' or c == 'C':
m += 1 return 100 * (float(m) / n) if __name__ == "__main__": small_dataset = """
>Rosalind_6404
CCTGCGGAAGATCGGCACTAGAATAGCCAGAACCGTTTCTCTGAGGCTTCCGGCCTTCCC
TCCCACTAATAATTCTGAGG
>Rosalind_5959
CCATCGGTAGCGCATCCTTAGTCCAATTAAGTCCCTATCCAGGCGCTCCGCCGAAGGTCT
ATATCCATTTGTCAGCAGACACGC
>Rosalind_0808
CCACCCTCGTGGTATGGCTAGGCATTCAGGAACCGGAGAACGCTTCAGACCAGCCCGGAC
TGGGAACCTGCGGGCAGTAGGTGGAAT
""" #large_dataset = open('datasets/rosalind_gc.txt').read() results = parse_fasta(small_dataset)
results = dict([(k, gc_content(v)) for k, v in results.iteritems()])
# 这里iteritem()和item()功能是一样的
# 前一个results输出,名称+序列,后一个results输出,名称+百分比 highest_k = None
highest_v = 0 for k, v in results.iteritems():
if v > highest_v:
highest_k = k
highest_v = v
# 输出GC含量高的
print highest_k
print '%f%%' % highest_v
方法三:
# -*- coding: utf-8 -*- ### 5. Computing GC Content ###
from operator import itemgetter
from collections import OrderedDict seqTest = OrderedDict()
gcContent = OrderedDict() with open('Computing_GC_Content.txt', 'rt') as f:
for line in f:
line = line.rstrip()
if line.startswith('>'):
seqName = line[1:]
seqTest[seqName] = ''
continue
seqTest[seqName] += line.upper() for ke, val in seqTest.items():
totalLength = len(val)
gcNumber = val.count('G') + val.count('C')
gcContent[ke] = (float(gcNumber) / totalLength)*100 sortedGCContent = sorted(gcContent.items(), key=itemgetter(1))
largeName = sortedGCContent[-1][0]
largeGCContent = sortedGCContent[-1][1] print ('most GC ratio gene is %s and it is %s ' % (largeName, largeGCContent))
05 Computing GC Content的更多相关文章
- Evaluate|GC content|Phred|BAC|heterozygous single nucleotide polymorphisms|estimate genome size|
(Evaluate):检查reads,可使用比对软件:使用SOAPaligner重新排列:采用massively parallel next-generation sequencing technol ...
- GC偏好的校正与偏好程度的评估
在二代测序仪上测出的数据,通常都会表现出测序深度与GC 含量的相关性,称为GC bias. GC bias校正 为了后续生物信息分析更加准确,通常需要做GC bias的校正. 2010 年 steve ...
- GC偏好
GC偏好 测序中的GC偏好指的是基因组上GC含量在50%左右的区域更容易被测到,产生的reads更多,这些区域的覆盖度更高, 在高GC或者低GC区域,不容易被测到,产生较少的reads,这些区域的覆盖 ...
- Physicoochemical|CG content|
NCBI存在的问题: 数据用户的增长 软件开发受限 数据分析缺乏 有些传统束缚,仅用底层语言书写 Pangenome Open gene是随菌株数量增大而增大的gene,Closed gene是随菌株 ...
- 【Python小试】判断一条序列GC含量高低
题目: 随便给定一条序列,如果GC含量超过65%,则认为高. 编程: from __future__ import division #整数除法 def is_gc_rich(dna): length ...
- ODOO-10.0 错误 Could not execute command 'lessc'
2017-01-05 20:24:12,473 4652 INFO None odoo.service.db: Create database `hello`. 2017-01-05 20:24:16 ...
- 《深入理解Java虚拟机》内存分配策略
上节学习回顾 1.判断对象存活算法:引用计数法和可行性分析算法 2.垃圾收集算法:标记-清除算法.复制算法.标记-整理算法 3.垃圾收集器: Serial:新生代收集器,采用复制算法,单线程. Par ...
- MongoDB和Redis-NoSQL数据库-文档型-内存型
1NoSQL简述 CAP(Consistency,Availabiity,Partitiontolerance)理论告诉我们,一个分布式系统不可能满足一致性,可用性和分区容错性这三个需求,最多只能同时 ...
- 生物信息大数据&数据库(NCBI、EBI、UCSC、TCGA)
想系统的学习生信数据库可以先看一下北大的公开课,有一章专门讲的数据库与软件: -生物信息学:导论与方法 北大\ 生物信息数据库及软件资源 一个优秀的生信开发者能够解决如下问题: 如何鉴定一个重要的且没 ...
随机推荐
- Hibernate学习3—映射对象标识符(OID)
一.Hibernate 用对象标识符(OID)来区分对象 作如下代码的实验: public class StudentTest { public static void main(String[] a ...
- 1、Window.document对象
1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个: var a =docunmen ...
- [知识整理]Linux系统WIFI知识的一些整理
前段时间接触了wifi,主要是在linux系统下做预研.开发.本文根据个人收集资料及研究经验做了一些基本入门级别的引子,旨在对wifi有一个很基础的入门的认知,比如知道wifi模块硬件接口有哪些,了解 ...
- Centos7 可执行程序自定义为系统服务
systemctl的使用相比以往系统服务的/etc/init.d的启动脚本的方式变动也比较大,但变的更简单更易用了,同firewalld一样,运行原理一目了然,对于初学者来说,只要做过一两次练习,就能 ...
- ListView下拉刷新,上拉自动加载更多
下拉刷新,Android中非常普遍的功能.为了方便便重写的ListView来实现下拉刷新,同时添加了上拉自动加载更多的功能.设计最初是参考开源中国的Android客户端源码.先看示例图. ...
- 1.Linux下生成密钥
1.Linux下生成密钥 ssh-keygen的命令手册,通过”man ssh-keygen“命令: 通过命令”ssh-keygen -t rsa“ 生成之后会在用户的根目录生成一个 “.ssh”的文 ...
- FastDFS:搭建文件管理系统
文章转自:https://www.cnblogs.com/chiangchou/p/fastdfs.html#_label1 一.FastDFS介绍 FastDFS开源地址:https://githu ...
- awk查看接口耗时情况
+1:LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Ag ...
- ORA-00600: 内部错误代码, 参数: [qctcte1]
[情景再现] 生产环境,JAVA程序某功能报错: ORA-00600: 内部错误代码, 参数: [qctcte1], [0], [], [], [], [], [], [] [问题排查] 1.检查Or ...
- Android 4 学习(19):Services
参考<Professional Android 4 Development> Services Service是invisible的,因此其优先级不高于visible的Activity,之 ...