吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 371|回复: 1
收起左侧

[Python 原创] 密码子偏好性筛选序列代码

[复制链接]
yy951010 发表于 2024-4-4 12:20
本帖最后由 苏紫方璇 于 2024-4-8 01:03 编辑

[Python] 纯文本查看 复制代码
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[i:i+3]
        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)

免费评分

参与人数 1吾爱币 +1 收起 理由
lymanxin + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

苏紫方璇 发表于 2024-4-8 01:03
插入代码的方法可以看这个帖子
【公告】发帖代码插入以及添加链接教程(有福利)
https://www.52pojie.cn/thread-713042-1-1.html
(出处: 吾爱破解论坛)
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-5-5 18:18

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表