【编程练习】获得反向互补序列
题目:
给定:一条DNA序列
任务:得到这条DNA序列的反向互补序列
解题:
complement = {'A': 'T', 'C': 'G', 'G': 'C', 'T': 'A'}seq = 'ATGCTTAGGGATTACG'# 方法一:使用列表推导式seq_list = [complement[base] for base in seq]seq_complement = ''.join(seq_list)print(seq_complement)# 方法二:使用map函数seq_complement = ''.join(map(complement.get, seq))print(seq_complement)# 方法三:使用字符串的translate方法seq_complement = seq.translate(str.maketrans(complement))print(seq_complement)# 方法四:使用字符串的maketrans方法seq_complement = seq.translate(str.maketrans('ATCG', 'TAGC'))print(seq_complement)# 方法五:使用字符串的replace方法seq_complement = seq.replace('A', 't').replace('T', 'a').replace('C', 'g').replace('G', 'c').upper()print(seq_complement)
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
