本篇内容主要讲解“python怎么实现CDS序列”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“python怎么实现CDS序列”吧!
筛选编码蛋白的CDS序列
#!python # coding:utf-8 ''' ############################################################################################# #北京组学生物科技有限公司 #author huangls #date 2021.01.26 #version 1.2 #学习python课程推荐: #python 入门到精通(生物信息): #https://study.163.com/course/introduction/1209531837.htm?share=1&shareId=1030291076 ############################################################################################### ''' from Bio.Seq import Seq from Bio import SeqIO #from Bio.Alphabet import IUPAC from Bio.SeqRecord import SeqRecord import os, argparse, os.path,re parser = argparse.ArgumentParser(description='This script is used to get coding sequence from fasta file.') parser.add_argument('-f','--fasta',help='Please input fasta file. [REQUIRED]',required=True) parser.add_argument('-l','--len',type=int,default=300,help='seq length filter, default 300. [OPTIONAL]',required=False) parser.add_argument('-p','--prefix',default ='demo_seq',required=False,help='Please specify the output file prefix, default demo_seq. [OPTIONAL]') parser.add_argument('-o','--out_dir',help='Please input output directory path default cwd. [OPTIONAL]',default = os.getcwd(),required=False) ################################################################################ args = parser.parse_args() dout='' if os.path.exists(args.out_dir): dout=os.path.abspath(args.out_dir) else: os.mkdir(args.out_dir) dout=os.path.abspath(args.out_dir) count=0 total=0 output_handle = open(dout+'/'+args.prefix+'.fa', "w") for rec in SeqIO.parse(args.fasta, "fasta"): seq=str(rec.seq) #seq=seq.upper() total+=1 if(len(seq)>=args.len and re.search("^ATG",seq,re.I) and len(seq)%3==0): if re.search('TAG$',seq,re.I) or re.search('TGA$',seq,re.I) or re.search('TAA$',seq,re.I): seq = seq[:-3] f=re.finditer('TAG|TGA|TAA',seq,re.I) if not f: SeqIO.write(rec, output_handle, "fasta") count+=1 else: isstop=False for i in f: index=i.start() if index%3 ==0: isstop=True break if not isstop: SeqIO.write(rec, output_handle, "fasta") count+=1 print("Total input seqs: %s"%total) print("Coding seqs: %s"%count) print("Output file: %s"%dout+'/'+args.prefix+'.fa') output_handle.close()
到此,相信大家对“python怎么实现CDS序列”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。