【Rosalind】Complementing a Strand of DNA

原题链接

题目描述

Problem

In DNA strings, symbols ‘A’ and ‘T’ are complements of each other, as are ‘C’ and ‘G’.

The reverse complement of a DNA string s s s is the string s c s^{\textrm{c}} sc formed by reversing the symbols of s s s, then taking the complement of each symbol (e.g., the reverse complement of “GTCA” is “TGAC”).

Given: A DNA string s s s of length at most 1000 bp.

Return: The reverse complement s c s^{\textrm{c}} sc of s s s.

Sample Dataset

AAAACCCGGT

Sample Output

ACCGGGTTTT

题目大意

输出给定DNA序列的互补序列(均为按5’到3’顺序)

题解

利用Python sting.maketrans()和string.translate()方法,使用maketrans()方法创建字符映射转换表,之后translate()方法映射即可
也可使用BioPython库:使用Bio.Seq.reserve_complement()直接获取反向互补链

参考代码

直接用Python求解

with open("rosalind_revc.txt", "r") as f:
	s = f.read()
	s = s[::-1]
	transtab = s.maketrans("ATCG", "TAGC")
	with open("out.txt", "w") as fo:
		fo.write(s.translate(transtab))
		fo.close()
	f.close()

使用BioPython

from Bio.Seq import Seq
from Bio.Alphabet import IUPAC

with open("rosalind_revc.txt", "r") as f:
	s = f.read()
	my_seq = Seq(s, IUPAC.unambiguous_dna)
	ans = my_seq.reverse_complement()
	with open("out_bp.txt", "w") as fo:
		fo.write(str(ans))
		fo.close()
	f.close()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值