用法: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. Smarty练习增删改

    <?php //将题目表显示在页面 include("../init.inc.php"); include("../DBDA.php"); $db = n ...

  2. C#第八天

    ArrayList ArrayList list=new ArrayList(): list.Add()           //添加单个元素 list.AddRange()   //添加集合元素 l ...

  3. linux命令英文缩写的含义(方便记忆)

    命令缩写: ls:list(列出目录内容) cd:Change Directory(改变目录) su:switch user 切换用户 rpm:redhat package manager 红帽子打包 ...

  4. Confluence搭建

    参见 https://confluence.atlassian.com/display/CONF54/Installing+the+Confluence+EAR-WAR+Edition 下载5.4.4 ...

  5. 工作中用到的简单linux命令

    1.rpm包查询.卸载.安装: rpm包查询 rpm -q 包名(不带版本号.后缀等)  q----query rpm包卸载 rpm -e 包名(不带版本号.后缀等)e----erase rpm包安装 ...

  6. KVM 命令行启动第一台虚拟机

    KVM创建第一台虚拟机 1 创建一个镜像 [root@kvm ~]# qemu-img create -f raw /opt/CentOS6.-x86_64.raw 5G Formatting [ro ...

  7. Elasticsearch Java虚拟机配置详解(转)

    引言: 今天,事情终于发生了.Java6(Mustang),是2006年早些时候出来的,至今仍然应用在众多生产环境中,现在终于走到了尽头.已经没有什么理由阻止迁移到Java7(Dolphin)上了. ...

  8. Redis简介三

    目录 一.Key 二.String 三.Hash 四.List 五.Set 六.SortedSet 七.Pub/Sub 八.Transaction 九.Script 十.Connection 十一.S ...

  9. VBS调用windows api函数(postmessage)实现后台发送按键脚本

    '=========================================================================='' VBScript Source File - ...

  10. sql 在将 nvarchar 值 转换成数据类型 int 时失败。

    假设有存储过程:proc_test2 create proc proc_test2 @Id int begin as declare @sql varchar(max) @sql = 'select ...