用法: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. ural 1352. Mersenne Primes

    1352. Mersenne Primes Time limit: 1.0 secondMemory limit: 64 MB Definition. If the number 2N−1 is pr ...

  2. html5游戏开发框架之lufylegend开源库件学习记录

    下载地址http://lufylegend.com/lufylegend 引用 <script type="text/javascript" src="../luf ...

  3. Python 学习笔记12

    不积跬步,无以至千里.不积小流,无以成江河. 当我觉得沮丧.绝望的时候,就疯狂的敲代码,这样会好受一点. 今天和昨天敲了两天的小程序,算是对python的具体语法规则有个初步的手熟. http://w ...

  4. Understanding Neural Networks Through Deep Visualization

    当数据一层一层通过更多的卷积层时,你可以得到的特征图像代表的特征就会更加的复杂. 在网络的最后,你也许可以得到一个抽象的物体.如果你想通过可视化方法在卷积神经网络中看到更多的信息.这里有一个工具方便你 ...

  5. 【CRC校验】学习笔记

    #include<stdio.h> unsigned ]= { 0x01,0x02,0x03,0x04,0x05,0x06 }; ] = { 0x0000, 0x1021, 0x2042, ...

  6. laravel常用拓展库

    1.laravel-dompdf:pdf生成器 git地址:https://github.com/barryvdh/laravel-dompdf 2.

  7. ELK 基本搭建

    ELK是一套日志分析系统: 开发人员不能登录线上服务器查看详细日志各个系统都有日志,日志数据分散难以查找日志数据量大,查询速度慢,或者数据不够实时一个调用会设计多个系统,难以在这些系统的日志中快速定位 ...

  8. HDU 5811 Colosseo

    首先判断一下两个集合是否能够拓扑排序,顺便记录下每个节点的拓扑序. 然后看T2中每个点在T1中能够放在哪一个位置,记录下这个位置Pi. 然后T2中(按拓扑序排好),计算Pi的一个非严格递增的LIS.L ...

  9. python常用正则表达式

    匹配特定数字:^[1-9]\d*//匹配正整数−[1−9]\d∗  //匹配负整数^-?[1-9]\d*//匹配整数[1−9]\d∗|0 //匹配非负整数(正整数 + 0)^-[1-9]\d*|0// ...

  10. ECOS高可用集群

    此架构由8台PC .2台防火墙.2台24口三层交换机组成, 注意点: 1)Load Balance:Haprxoy+keepalived 实现高可用. 2)web:Nginx+php-fpm 3)DB ...