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位小数

  

时间: 2025-01-18 05:40:42

05 Computing GC Content的相关文章

Tuning Java Garbage Collection for Spark Applicati

This is a guest post from our friends in the SSG STO Big Data Technology group at Intel. Join us at the Spark Summit to hear from Intel and other companies deploying Spark in production.  Use the code Databricks20 to receive a 20% discount! Spark is

edgeR之配对检验分析差异基因的使用教程

edgeR的介绍 背景 RNA-seq表达谱与生物复制的差异表达分析. 实现一系列基于负二项分布的统计方法,包括经验贝叶斯估计,精确检验,广义线性模型和准似然检验. 与RNA-seq一样,它可用于产生计数的其他类型基因组数据的差异信号分析,包括ChIP-seq,Bisulfite-seq,SAGE和CAGE. 简介 edgeR包是进行RNA-seq数据分析非常常用的一个R包.该包需要输入每个基因关于每个样本的reads数的数据,每行对应一个基因,每一列对应一个样本.edgeR作用的是真实的比对统

FastQC 测序质量

文章转载于 Original 2017-07-06 Jolvii 生信百科 介绍一下如何理解 FastQC 各模块的结果 FastQC 的使用 FastQC的安装介绍请看这里.FastQC 支持 fastq.gzip 压缩的 fastq.SAM.BAM 等格式,在不指定文件类型的情况下,FastQC 会根据文件的名字来推测文件的类型: 以 .sam 或者 .bam 结尾的文件会被当作 SAM/BAM 文件来打开,并统计 mapped 和 unmapped reads 在内的所有 reads:其它

用FastQC检查高通量测序原始数据的质量

本篇文章,主要参考了阳光1986的博文(http://www.dxy.cn/bbs/topic/31324367),自己测序的分析结果作为对比,加在其中了. 1.简介 当二代测序的原始数据拿到手之后,第一步要做的就是看一看原始reads的质量.常用的工具就是fastqc (http://www.bioinformatics.babraham.ac.uk/projects/fastqc/). fastqc的详细使用说明:http://www.bioinformatics.babraham.ac.u

HTML5和CSS3扁平化风格博客

效果: 代码: html结果 <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8" /> <link rel="stylesheet" type="text/css" href="https://necolas.github.io/normalize.css/3.0.2/norm

测序数据质量控制

基于边合成边测序(Sequencing By Synthesis,SBS)技术,Illumina HiSeq2500高通量测序平台对cDNA文库进行测序,能够产出大量的高质量Reads,测序平台产出的这些Reads或碱基称为原始数据(Raw Data),其大部分碱基质量打分能达到或超过Q30.Raw Data通常以FASTQ格式提供,每个测序样品的Raw Data包括两个FASTQ文件,分别包含所有cDNA片段两端测定的Reads. FASTQ格式文件示意图如下: FASTQ格式文件示意图 注:

pcr free library 介绍

一句话:illumina的建库方法,建库时间段,质量还好... the adapters are different in the PCR-free kit compared to the standard TruSeq kit. The standard TruSeq kit uses Y-shaped adapters that require PCR to create a library that will anneal to the flow cell--or something li

Android单元测试初探——Instrumentation(转载)

学习Android有一段时间了,虽然前段时间对软件测试有了一些了解,不过接触android的单元测试却是头一次.这几天在物流大赛上也用了不少时间,所以对于android的单元测试没有太深入的研究,所以先写个基本入门吧! 首先,我们来了解一下android的测试类的层次结构: 可以看出android中的测试方法主要有AndroidTextCase和InstrumentationTextCase.在这篇文章中,我将介绍Instrumentation这种测试方法,那么什么是Instrumentatio

C#读取并写入XML文件

XML(可扩展标记语言)文件,可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进行定义的源语言. XML与HTML的设计区别是:XML 被设计为传输和存储数据,其焦点是数据的内容.而HTML 被设计用来显示数据,其焦点是数据的外观.HTML 旨在显示信息,而 XML 旨在传输信息. XML和HTML语法区别:HTML的标记不是所有的都需要成对出现,XML则要求所有的标记必须成对出现:HTML标记不区分大小写,XML则大小敏感,即区分大小写. 在Asp.Net中我们需要通过C#来对已