用法:python rev_comp.py input.fa out.fa

输入文件为 fasta 格式文件,若输入文件中序列的 header 有 '+' 或 '-' 号标记正负链,则带有 '+' 的序列保持不变,带有 '-' 的序列反向互补;

若 header 没有 '+' 或 '-' 号标记, 则默认按反义链处理。

cat input.fa
>seq1 +
AGATAGATGAATT
>seq2 -
GATAGAGAATAAA
AGATATAGATAGA
>seq3
GAATATAT
>seq4 -
CCAGTGGGATCC
cat  out.fa
>seq2 -
TCTATCTATATCTTTTATTCTCTATC
>seq4 -
GGATCCCACTGG
>seq1 +
AGATAGATGAATT
>seq3
ATATATTC
import sys

complement_table = {
'A': 'T',
'B': 'V',
'C': 'G',
'D': 'H',
'G': 'C',
'H': 'D',
'M': 'K',
'N': 'N',
'R': 'Y',
'S': 'S',
'T': 'A',
'U': 'A',
'V': 'B',
'W': 'W',
'X': 'X',
'Y': 'R',
'a': 't',
'b': 'v',
'c': 'g',
'd': 'h',
'g': 'c',
'h': 'd',
'm': 'k',
'n': 'n',
'r': 'y',
's': 's',
't': 'a',
'u': 'a',
'v': 'b',
'w': 'w',
'x': 'x',
'y': 'r'
} def pqrse_fasta(seqs):
new_seqs = {}
for line in seqs:
if line.startswith(">"):
name = line.rstrip()
new_seqs[name] = ""
else:
new_seqs[name] = new_seqs[name] + line.rstrip()
return new_seqs def rev_comp(seq):
new_seq = []
line = seq.rstrip()
for letter in line:
complement_letter = complement_table[letter]
new_seq.append(complement_letter)
new_seq.reverse()
return "".join(new_seq) in_file = open(sys.argv[1])
out_file = open(sys.argv[2], 'w') seqs = pqrse_fasta(in_file) for name in seqs.keys():
if name.endswith("-"):
print >> out_file, name + '\n' + rev_comp(seqs[name])
elif name.endswith("+"):
print >> out_file, name + '\n' + seqs[name]
else:
print >> out_file, name + '\n' + rev_comp(seqs[name]) # 如果文件没有 '+' 或 '-' 号标记正负链,则默认为负链。

Reverse complement DNA的更多相关文章

  1. 3.Complementing a Strand of DNA

    Problem In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'. The r ...

  2. 03 Complementing a Strand of DNA

    Problem In DNA strings, symbols 'A' and 'T' are complements of each other, as are 'C' and 'G'. The r ...

  3. 为什么Erlang比C慢那么多倍?

    Erlang 一直以慢“著称”,本文就来看看 Erlang 慢在什么地方,为什么比实现同样功能的 C 语言程序慢那么多倍.Erlang 作为一种虚拟机解释的语言,慢是当然的.不过本文从细节上分析为什么 ...

  4. het smooth 组装高杂合度二倍体基因组前期数据处理

    http://sourceforge.net/projects/het-smooth/ equencing technologies, such as Illumina sequencing, pro ...

  5. biopython

    转载Part 2  Biopython的重头戏-生物学中序列的处理 Biopyhton的Seq和Python中标准字符串有两大重要的不同之处:首先,他们的处理方法不同.Seq适用于很多不同字符串的用的 ...

  6. 08 Translating RNA into Protein

    Problem The 20 commonly occurring amino acids are abbreviated by using 20 letters from the English a ...

  7. 05 Computing GC Content

    Problem The GC-content of a DNA string is given by the percentage of symbols in the string that are ...

  8. 安装生物信息学软件-bowtie2

    好吧,这是本周(2016.10.21-28)的学习任务之一:安装bowtie2并学习其使用方法&参数设置 所以,啃文档咯,官方文档Version 2.2.9 http://bowtie-bio ...

  9. Canu Tutorial(canu指导手册)

    链接:Canu Tutorial Canu assembles reads from PacBio RS II or Oxford Nanopore MinION instruments into u ...

随机推荐

  1. XueTr 0.45 (手工杀毒辅助工具) 绿色版

    软件名称: XueTr 0.45 (手工杀毒辅助工具)软件语言: 简体中文授权方式: 免费软件运行环境: Win7 / Vista / Win2003 / WinXP 软件大小: 3.3MB图片预览: ...

  2. 【linux shell系列--1】crontab命令

    摘自:http://www.cnblogs.com/peida/archive/2013/01/08/2850483.html 一.crond简介 crond是linux下用来周期性的执行某种任务或等 ...

  3. <meta http-equiv="X-UA-Compatible" content="IE=Edge">

    1.X-UA-Compatible X-UA-Compatible是IE8的一个专有<meta>属性,它告诉IE8采用何种IE版本去渲染网页,在html的<head>标签中使用 ...

  4. javascript 事件响应

    1.基本事件 2.点击事件 <html> <head> <script type="text/javascript"> function add ...

  5. 《LYFvs2013转vs2010》

    <LYFvs2013转vs2010>1.修改解决方案文件(**.sln) 将-------------------------------------------------------- ...

  6. Tarjan算法求解无向连通图的割点、割边、点双连通分量和边双连通分量的模板

    历时好几天,终于完工了! 支持无向图四种功能:1.割点的求解 2.割边的求解 3.点双连通分量的求解 4.边双连通分量的求解 全部支持重边!!!!全部支持重边!!!!全部支持重边!!!! 测试数据: ...

  7. git 免密码提交代码

    Linux或者Mac下方法: 创建文件,进入文件,输入内容: cd ~ touch .git-credentials vim .git-credentials https://{username}:{ ...

  8. ios ViewController的生命周期分析和基本使用逻辑

    按结构可以对iOS的所有ViewController分成两类:1.主要用于展示内容的ViewController,这种ViewController主要用于为用户展示内容,并与用户交互,如UITable ...

  9. nodejs package.json详细解读

    package.json详细内容 它是这样一个json文件(注意:json文件内是不能写注释的,复制下列内容请删除注释): JavaScript { "name": "t ...

  10. IoC容器Autofac正篇之简单实例(四)

    先上一段代码. namespace ConsoleApplication3 { class Program { static void Main(string[] args) { ContainerB ...