pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

www private pastebin - collaborative debugging tool What's a private pastebin?


Posted by Bloguero_Connor on Wed 2 Apr 12:32
download | new post

  1. # Code by Sebastian Bassi
  2. # License: GPL 3.0 (http://www.gnu.org/licenses/gpl-3.0-standalone.html)
  3.  
  4. import xml.etree.cElementTree as cET
  5.  
  6. f_in='/mnt/hda2/bio/blast-2.2.18/bin/m3x-218.xml'
  7.  
  8. i_hits={}
  9. hits={}
  10. hsps={}
  11.  
  12. for ev,x in cET.iterparse(f_in):
  13.     if 'BlastOutput_version' in x.tag:
  14.         b_version=x.text
  15.     elif 'BlastOutput_program' in x.tag:
  16.         b_prg=x.text
  17.     elif 'BlastOutput_reference' in x.tag:
  18.         b_reference=x.text[12:]
  19.     elif 'BlastOutput_query-def' in x.tag:
  20.         b_query_def=x.text
  21.     elif 'BlastOutput_query-len' in x.tag:
  22.         b_query_len=x.text
  23.     elif 'BlastOutput_db' in x.tag:
  24.         b_db=x.text
  25.     elif 'Parameters_expect' in x.tag:
  26.         p_expect=x.text
  27.     elif 'Parameters_sc-match' in x.tag:
  28.         p_sc_match=x.text
  29.     elif 'Parameters_sc-mismatch' in x.tag:
  30.         p_sc_mismatch=x.text
  31.     elif 'Parameters_gap-open' in x.tag:
  32.         p_gap_open=x.text
  33.     elif 'Parameters_gap-extend' in x.tag:
  34.         p_gap_extend=x.text
  35.     elif 'Parameters_filter' in x.tag:
  36.         p_filter=x.text
  37.     elif 'Iteration_query-def' in x.tag:
  38.         i_query_def=x.text
  39.     elif 'Iteration_iter-num' in x.tag:
  40.         i_iter_num=x.text
  41.     elif 'Iteration_query-ID' in x.tag:
  42.         i_query_id=x.text
  43.     elif 'Iteration_query-len' in x.tag:
  44.         i_query_len=x.text
  45.     elif 'Iteration'==x.tag:
  46.         i_hits[int(i_iter_num)]=(i_query_id, i_query_def,
  47.                             i_query_len, hits, stats)
  48.         hits={}
  49.     elif 'Hit_num' in x.tag:
  50.         h_num=x.text
  51.     elif 'Hit_id' in x.tag:
  52.         h_id=x.text
  53.     elif 'Hit_def' in x.tag:
  54.         h_def=x.text
  55.     elif 'Hit_accession' in x.tag:
  56.         h_accession=x.text
  57.     elif 'Hit_len' in x.tag:
  58.         h_len=x.text
  59.     elif 'Hit'==x.tag:
  60.         hits[int(h_num)]=(h_id,h_def,h_accession,h_len,hsps)
  61.         hsps={}
  62.     elif 'Hsp_num' in x.tag:
  63.         hsp_num=x.text
  64.     elif 'Hsp_bit-score' in x.tag:
  65.         hsp_bit_score=x.text
  66.     elif 'Hsp_score' in x.tag:
  67.         hsp_score=x.text
  68.     elif 'Hsp_evalue' in x.tag:
  69.         hsp_evalue=x.text
  70.     elif 'Hsp_query-from' in x.tag:
  71.         hsp_query_from=x.text
  72.     elif 'Hsp_query-to' in x.tag:
  73.         hsp_query_to=x.text
  74.     elif 'Hsp_hit-from' in x.tag:
  75.         hsp_hit_from=x.text
  76.     elif 'Hsp_hit-to' in x.tag:
  77.         hsp_hit_to=x.text
  78.     elif 'Hsp_query-frame' in x.tag:
  79.         hsp_query_frame=x.text
  80.     elif 'Hsp_hit-frame' in x.tag:
  81.         hsp_hit_frame=x.text
  82.     elif 'Hsp_identity' in x.tag:
  83.         hsp_identity=x.text
  84.     elif 'Hsp_positive' in x.tag:
  85.         hsp_positive=x.text
  86.     elif 'Hsp_align-len' in x.tag:
  87.         hsp_align_len=x.text
  88.     elif 'Hsp_qseq' in x.tag:
  89.         hsp_qseq=x.text
  90.     elif 'Hsp_hseq' in x.tag:
  91.         hsp_hseq=x.text
  92.     elif 'Hsp_midline' in x.tag:
  93.         hsp_midline=x.text
  94.     elif 'Hsp'==x.tag:
  95.         hsps[int(hsp_num)]=(hsp_bit_score,hsp_score,hsp_evalue,
  96.             hsp_query_from,hsp_query_to,hsp_hit_from,hsp_hit_to,
  97.             hsp_query_frame,hsp_hit_frame,hsp_identity,
  98.             hsp_positive,hsp_align_len,hsp_qseq,
  99.             hsp_hseq,hsp_midline)
  100.     elif 'Statistics_db-num' in x.tag:
  101.         s_db_num=x.text
  102.     elif 'Statistics_db-len' in x.tag:
  103.         s_db_len=x.text
  104.     elif 'Statistics_hsp-len' in x.tag:
  105.         s_hsp_len=x.text
  106.     elif 'Statistics_eff-space' in x.tag:
  107.         s_eff_space=x.text
  108.     elif 'Statistics_kappa' in x.tag:
  109.         s_kappa=x.text
  110.     elif 'Statistics_lambda' in x.tag:
  111.         s_lambda=x.text
  112.     elif 'Statistics_entropy' in x.tag:
  113.         s_entropy=x.text
  114.     elif 'Statistics'==x.tag:
  115.         stats=(s_db_num,s_db_len,s_hsp_len,s_eff_space,
  116.               s_kappa,s_lambda,s_entropy)
  117.  
  118.  
  119. print '''<HTML>
  120. <TITLE>BLAST Search Results</TITLE>
  121. <BODY BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#660099" ALINK="#660099">
  122. <PRE>'''
  123.  
  124. print '<b>'+b_version+'</b>\n'
  125. print '<b><a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=PubMed&cmd=Retrieve&list_uids=9254694&dopt=Citation">Reference</a>:</b>'+\
  126.               b_reference.replace('~',' ')
  127.  
  128. for x in xrange(1,len(i_hits)+1):
  129.     print '<b>Query=</b> %s' %(i_hits[x][1])
  130.     print '         (%s letters)' %(i_hits[x][2])
  131.     print '<b>Database:</b> %s' %(b_db)
  132.     print '         %s sequences; %s total letters' %(i_hits[x][4][0],i_hits[x][4][1])
  133.     print '''Searching..................................................done
  134. <PRE>
  135.                                                                  Score    E
  136. Sequences producing significant alignments:                      (bits) Value
  137. '''
  138.     for y in xrange(1,len(i_hits[x][3])+1):
  139.         k=i_hits[x][3][y][0]
  140.         m=k.index('gi|')+3
  141.         gi=k[m:k[m:].index('|')+3]
  142.         desc=i_hits[x][3][y][1]
  143.         bs=i_hits[x][3][y][4][1][0]
  144.         sc=i_hits[x][3][y][4][1][2]
  145.         print '<a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?\
  146. cmd=Retrieve&db=Nucleotide&list_uids=%s&dopt=GenBank" >\
  147. %s</a> %s <a href = #%s> %s</a>   %s' \
  148. %(gi,k.replace('gi|'+gi+'|',''),desc[:36]+'...',gi,bs,sc)
  149.     print '</PRE>\n'
  150.     for y in xrange(1,len(i_hits[x][3])+1):
  151.         print '<PRE>\n'
  152.         k=i_hits[x][3][y][0]
  153.         m=k.index('gi|')+3
  154.         gi=k[m:k[m:].index('|')+3]
  155.         desc=i_hits[x][3][y][1]
  156.         print '><a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?\
  157. cmd=Retrieve&db=Nucleotide&list_uids=%s&dopt=GenBank" >\
  158. %s</a> %s ' \
  159. %(gi,k.replace('gi|'+gi+'|',''),desc)
  160.         print ' Length = '+i_hits[x][3][y][3]+'\n'
  161.         # Walk over all the hsps
  162.         for z in xrange(1,len(i_hits[x][3][y][4])+1):
  163.             bs=i_hits[x][3][y][4][z][0]
  164.             hsc=i_hits[x][3][y][4][z][1]
  165.             sc=i_hits[x][3][y][4][z][2]
  166.             h_id=i_hits[x][3][y][4][z][10]
  167.             h_pos=i_hits[x][3][y][4][z][11]
  168.             q_frame=i_hits[x][3][y][4][z][7]
  169.             h_frame=i_hits[x][3][y][4][z][8]
  170.             q_from=i_hits[x][3][y][4][z][3]
  171.             q_to=i_hits[x][3][y][4][z][4]
  172.             h_from=i_hits[x][3][y][4][z][5]
  173.             h_to=i_hits[x][3][y][4][z][6]
  174.             qseq=i_hits[x][3][y][4][z][12]
  175.             hseq=i_hits[x][3][y][4][z][13]
  176.             medio=i_hits[x][3][y][4][z][14]
  177.             if q_frame=='1':
  178.                 qf='Plus'
  179.             else:
  180.                 qf='Minus'
  181.             if h_frame=='1':
  182.                 hf='Plus'
  183.             else:
  184.                 hf='Minus'
  185.             print 'Score = %s bits (%s), Expect = %s' %(bs,hsc,sc)
  186.             print 'Identities = %s/%s (%.0f%%)' %(h_id,
  187.                                 h_pos,float(int(h_id))/int(h_pos)*100)
  188.             print 'Strand = %s/%s\n\n' %(qf,hf)
  189.             if h_frame=='1':
  190.                 mx=max(len(q_from),len(h_from))
  191.                 print 'Query: %s %s %s' %(q_from.ljust(mx),qseq,q_to)
  192.                 print '       '+' '*mx+' '+medio
  193.                 print 'Sbjct: %s %s %s\n' %(h_from.ljust(mx),hseq,h_to)
  194.             else:
  195.                 mx=max(len(q_from),len(h_to))
  196.                 print 'Query: %s %s %s' %(q_from.ljust(mx),qseq,q_to)
  197.                 print '       '+' '*mx+' '+medio
  198.                 print 'Sbjct: %s %s %s\n' %(h_to.ljust(mx),hseq,h_from)
  199.             print '</PRE>'
  200.        
  201.  
  202.  
  203. print '''<PRE>
  204.   Database: %s
  205.   Number of letters in database: %s
  206.   Number of sequences in database:  %s
  207. Lambda     K      H
  208.     %.2f    %.3f     %.2f
  209. Matrix: %s matrix:%s %s
  210. Gap Penalties: Existence: %s, Extension: %s
  211. Number of Sequences: %s
  212. Length of database: %s
  213. </PRE>
  214. </BODY>
  215. </HTML>''' %(b_version,i_hits[1][4][1],i_hits[1][4][0],
  216.              float(i_hits[1][4][4]),
  217.              float(i_hits[1][4][5]),
  218.              float(i_hits[1][4][6]),b_prg,p_sc_match,
  219.              p_sc_mismatch,p_gap_open,p_gap_extend,
  220.              i_hits[1][4][0],i_hits[1][4][1])

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me