python中实现提取碱基序列的互补序列

发布时间 2023-06-07 00:00:11作者: 小鲨鱼2018

 

001、

[root@PC1 test03]# ls
a.fa  test.py
[root@PC1 test03]# cat a.fa           ## 测试fasta文件
ATCGATGC
[root@PC1 test03]# cat test.py        ## python程序
#!/usr/bin/env python
# -*- coding: utf-8 -*-
in_file = open("a.fa", "r")
str1 = ""
for i in in_file:
        i = i.strip()
        for j in i:
                if j == "A":
                        str1 += "T"
                if j == "T":
                        str1 += "A"
                if j == "C":
                        str1 += "G"
                if j == "G":
                        str1 += "C"
print(str1)
[root@PC1 test03]# python test.py         ## 执行程序
TAGCTACG