用法: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. linux ssh连接不自动断开

    修改linux服务器ssh配置文件: vim /etc/ssh/ssh_config 修改两处的值为: ClientAliveInterval ClientAliveCountMax 使修改的ssh配 ...

  2. NSURL访问项目中的文件

    最近在研究视频处理,具体为:将一个mp4文件,拖入项目工程中,通过url访问文件. 开始代码如下: NSString *path = [[NSBundle mainBundle]pathForReso ...

  3. C/C++语言的标准库函数malloc/free与运算符new/delete的区别

    概括地说 1.malloc与free是C++/C的标准库函数,new/delete是C++的运算符,它们都可用于申请动态内存和释放内存. 2.对于非内部数据类型的对象而言,只用malloc/free无 ...

  4. angular中重要指令介绍($eval,$parse和$compile)

    在angular的服务中,有一些服务你不得不去了解,因为他可以说是ng的核心,而今天,我要介绍的就是ng的两个核心服务,$parse和$compile.其实这两个服务讲的人已经很多了,但是100个读者 ...

  5. Nginx 安装(CentOS )

    一.安装编译工具及库文件 yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel 二.首先要安装 PCRE ...

  6. A框架第一步,传递不同参数.主程序执行对应方法

    访问: www.test.com/admin 1============后台目录:admin (确保单一入口) --有入口文件index.php <?phprequire '../A/a.php ...

  7. device-mapper: multipath: Failing path recovery【转载】

      digoal 2016-04-05 10:09:42 浏览180 评论0 摘要: 由于扇区损坏导致多路径设备failed. 现象如下 :  # dmesg : device-mapper: mul ...

  8. PHP上传文件详解

    1.上传文件使用的提交方式和请求Content-type POST提交方式,原始的form表单提交请加上enctype="multipart/form-data" 2.MAX_FI ...

  9. python 邮件报警

    为了以后方便使用邮件报警 我这边直接写入一推报警模板 方便以后使用 加入模块 import smtplib from email.mime.text import MIMEText from emai ...

  10. linux 文件系统操作()

    1. 用Xshell 客户端连上远程主机. 2.ll 或 ls 查看当前目录下的文件或目录, cd / 切换到根目录, cd **切换到某个目录(或者叫进入某个文件夹) 3.文件的压缩命令:zip - ...