密码子偏好性筛选序列代码
本帖最后由 苏紫方璇 于 2024-4-8 01:03 编辑import os
from Bio import SeqIO
def is_valid_cds(cds):
if len(cds) <= 300:
return False
if not (cds.startswith("ATG") and (cds.endswith("TAG") or cds.endswith("TGA") or cds.endswith("TAA"))):
return False
if len(cds) % 3 != 0:
return False
# 检查中间是否有终止密码子或错误碱基
for i in range(0, len(cds) - 3, 3):
codon = cds
if codon in ["TAG", "TGA", "TAA"] or not all(base in "ATGC" for base in codon):
return False
return True
def filter_fasta_files(input_folder, output_folder):
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for filename in os.listdir(input_folder):
if filename.endswith(".fasta"):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
valid_cds_records = []
for record in SeqIO.parse(input_path, "fasta"):
cds = str(record.seq).upper()
if is_valid_cds(cds):
valid_cds_records.append(record)
SeqIO.write(valid_cds_records, output_path, "fasta")
print(f"Filtered {len(valid_cds_records)} valid CDS sequences to {output_path}")
# 请根据你的实际情况修改这些路径
input_folder = "C:/Users/Administrator/Desktop/cds-before"# 输入文件夹的路径
output_folder = "C:/Users/Administrator/Desktop/cds-after"# 输出文件夹的路径
filter_fasta_files(input_folder, output_folder) 插入代码的方法可以看这个帖子
【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
(出处: 吾爱破解论坛)
页:
[1]