有蛋白编码基因的核苷酸序列,想要转化成对应的氨基酸序列,可以利用Python的Biopython Module来实现。
- 提取核苷酸序列信息
原始的保存着核苷酸序列的fasta文件里还有着序列的id等说明信息,我们只需要核苷酸序列,可以用for循环遍历每一行,将偶数行输出到一个新的文本文档中。
# opening the file
file1 = open('D:/.../PCGs/cytb/cytb.fas', 'r')
# creating another file to store even lines
file2 = open('D:/.../PCGs/cytb/cytb_no_label.fas', 'w')
# reading content of the files and writing even lines to another file
lines = file1.readlines()
for i in range(0, len(lines)):
if (i % 2 != 0):
file2.write(lines[i])
# closing the files
file1.close()
file2.close()
- 利用Biopython将CDS转为PEP
#importing the Biopython package
from Bio.Seq import Seq
from Bio.Alphabet import IUPAC
#opening the file
file1 = open('D:/.../PCGs/atp6/atp6_no_label.fas')
file2 = open('D:/.../PCGs/atp6/atp6_aa_no_label.fas', 'w'