Mercurial > repos > charles_s_test > seqsero2
comparison libs/special_gene_test_assemblies.py @ 0:6895de35a263 draft
planemo upload commit 844a891e4eaf732830043204ac636907eefb011d-dirty
| author | charles_s_test |
|---|---|
| date | Thu, 19 Oct 2017 18:16:51 -0400 |
| parents | |
| children | 3d6680af0bec |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:6895de35a263 |
|---|---|
| 1 #just an possible use, we can use it to replace H**.py, treat fliC and fljB as the target genes? | |
| 2 | |
| 3 from __future__ import division | |
| 4 import sys | |
| 5 import os | |
| 6 from Bio.Blast import NCBIXML | |
| 7 from Bio import SeqIO | |
| 8 | |
| 9 Makebltdb="/nfs/sw/apps/blast/ncbi-blast-2.6.0+/bin/makeblastdb" | |
| 10 Blastnpth="/nfs/sw/apps/blast/ncbi-blast-2.6.0+/bin/blastn" | |
| 11 | |
| 12 def special_gene(target_fie,database,gene_list): | |
| 13 database=database.split("/")[-1]##########1/27/2015 | |
| 14 os.system(Makebltdb+' -in database/'+database+' -out '+database+'_db -dbtype nucl')##########1/28/2015 | |
| 15 os.system(Blastnpth+' -query '+target_file+' -db '+database+'_db -out '+database+'_vs_'+target_file+'.xml '+'-outfmt 5')##########1/28/2015 | |
| 16 xml_file=database+'_vs_'+target_file+'.xml' | |
| 17 result_handle=open(xml_file) | |
| 18 blast_record=NCBIXML.parse(result_handle) | |
| 19 records=list(blast_record) | |
| 20 E_thresh=1e-10 | |
| 21 for x in gene_list: | |
| 22 handle=SeqIO.parse("database/"+database,"fasta")##########1/28/2015 | |
| 23 length_list=[] | |
| 24 for y in handle: | |
| 25 if x in y.description: | |
| 26 length_x=len(y.seq) | |
| 27 length_list.append(length_x) | |
| 28 aver_len=float(sum(length_list))/len(length_list) | |
| 29 hspbit=[] | |
| 30 alignmentlist=[] | |
| 31 for record in records: | |
| 32 for alignment in record.alignments: | |
| 33 if x in alignment.hit_def: #multi gene database, so... | |
| 34 print x,"got a hit, evaluating the hit quality..." | |
| 35 score=0 | |
| 36 for hsp in alignment.hsps: | |
| 37 if hsp.expect<E_thresh: | |
| 38 score+=hsp.bits | |
| 39 alignment=alignment.hit_def+':'+str(score) | |
| 40 hspbit.append(score) | |
| 41 alignmentlist.append(alignment) | |
| 42 scorelist=dict(zip(alignmentlist,hspbit)) | |
| 43 score=0 | |
| 44 for Htype in scorelist: | |
| 45 if scorelist[Htype]>score: | |
| 46 First_Choice=Htype | |
| 47 score=scorelist[Htype] | |
| 48 if float(score)>=0.1*aver_len: | |
| 49 print "$$$",First_Choice,"got a hit, score:",score | |
| 50 else: | |
| 51 print "$$$No ",x,"exists" | |
| 52 os.system("rm "+database+"_db.*")##########1/28/2015 | |
| 53 os.system("rm "+xml_file)##########1/28/2015 | |
| 54 | |
| 55 database=sys.argv[1] | |
| 56 target_file=sys.argv[2] | |
| 57 gene_list=[] | |
| 58 a=1 | |
| 59 i=3 | |
| 60 while a==1: | |
| 61 try: | |
| 62 gene_list.append(sys.argv[i]) | |
| 63 i+=1 | |
| 64 except: | |
| 65 a=0 | |
| 66 special_gene(target_file,database,gene_list) |
