python中截取序列的反向互补序列
001、
(base) root@PC1:/home/test3# ls test.py (base) root@PC1:/home/test3# cat test.py ## 测试程序 #!/usr/bin/python def com_trs(str): list1 = [] str = reversed(str) for i in str: if i == "a": list1.append("t") if i == "A": list1.append("T") if i == "t": list1.append("a") if i == "T": list1.append("A") if i == "c": list1.append("g") if i == "g": list1.append("c") if i == "C": list1.append("T") if i == "G": list1.append("C") if i == "n": list1.append("n") if i == "N": list1.append("N") print("".join(list1)) test_str = "gTActnGtN" ## 测试序列 com_trs(test_str) (base) root@PC1:/home/test3# python test.py ## 运行结果 NaCnagTAc
002、借助字典
(base) root@PC1:/home/test3# ls test.py (base) root@PC1:/home/test3# cat test.py ## 测试脚本 #!/usr/bin/python def com_pro(str): dict1 = {"a":"t", "t":"a", "A":"T", "T":"A", "c":"g", "g":"c", "C":"G", "G":"C", "n":"n", "N":"N"} str = reversed(str) list1 = [dict1[k] for k in str] print("".join(list1)) test_str = "aacGTNtc" ## 测试字符串 com_pro(test_str) (base) root@PC1:/home/test3# python test.py ## 运行结果 gaNACgtt
参考:https://mp.weixin.qq.com/s?__biz=MzIxNzc1Mzk3NQ==&mid=2247491504&idx=1&sn=4ac56dfb5cae9cf101b95c64b2585915&chksm=97f5afa8a08226be7ff80e8f85093295d6370dd4f014d2bc67f0302d9c794110709de7a12818&scene=178&cur_album_id=2403674812188688386#rd