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 is the string s formed by reversing the symbols of s , then taking the complement of each symbol (e.g., the reverse complement of "GTCA" is "TGAC").
Given: A DNA string s of length at most 1000 bp.
Return: The reverse complement s of s.
Sample Dataset
AAAACCCGGT
Sample Output
ACCGGGTTTT
seq ="AAAACCCGGT"
# 方法一
from Bio.Seqimport Seq
seq1 = Seq(seq)
print(seq1.reverse_complement())
# 方法二
seq2 = seq[::-1]
seq3 = seq2.replace("A","t")
seq4 = seq3.replace("T","a")
seq5 = seq4.replace("C","g")
seq6 = seq5.replace("G","c")
print(seq6.upper())
该文描述了如何找到一个DNA字符串的反向互补序列。这涉及到将字符串反转并替换互补对,如A与T,C与G。提供了两种方法,一种使用Python的Bio.Seq模块,另一种是通过字符串操作实现。
1万+

被折叠的 条评论
为什么被折叠?



