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 (modification of post by Bloguero_Connor view diff)
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. from Bio.Blast import NCBIXML
  5.  
  6. f_in='/mnt/hda2/bio/blast-2.2.18/bin/m3x-218.xml'
  7.  
  8. fr=NCBIXML.parse(open(f_in)).next()
  9.  
  10. print '''<HTML>
  11. <TITLE>BLAST Search Results</TITLE>
  12. <BODY BGCOLOR="#FFFFFF" LINK="#0000FF" VLINK="#660099" ALINK="#660099">
  13. <PRE>'''
  14. print '<b>%s</b>' %(fr.application+' '+fr.version+' '+fr.date)
  15. print '\n<b><a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?db=PubMed&cmd=Retrieve&list_uids=9254694&dopt=Citation">Reference</a>:</b>'+\
  16.               fr.reference.replace('~',' ')
  17. for rec in NCBIXML.parse(open(f_in)):
  18.     print '<b>Query=</b> %s' %(rec.query)
  19.     print '         (%s letters)' %(rec.query_letters)
  20.     print '<b>Database:</b> %s' %(rec.database)
  21.     if fr.num_letters_in_database!=[]:
  22.         #This test is for a bug in Biopython 1.45
  23.         print '         %s sequences; %s total letters' \
  24.         %(fr.num_sequences_in_database,
  25.           fr.num_letters_in_database)
  26.     #except AttributeError:
  27.     else:
  28.         # For Biopython > 1.45
  29.         print '         %s sequences; %s total letters' \
  30.         %(fr.num_sequences_in_database,
  31.           fr._num_letters_in_database)
  32.        
  33.     print '''Searching..................................................done
  34. <PRE>
  35.                                                                  Score    E
  36. Sequences producing significant alignments:                      (bits) Value
  37. '''
  38.     for d in fr.descriptions:
  39.         k=d.accession
  40.         desc=d.title
  41.         bs=d.score
  42.         sc=d.e
  43.         if 'gi|' in k:
  44.             m=k.index('gi|')+3
  45.             gi=k[m:k[m:].index('|')+3]
  46.             print '<a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?\
  47. cmd=Retrieve&db=Nucleotide&list_uids=%s&dopt=GenBank" >\
  48. %s</a> %s <a href = #%s> %s</a>   %s' \
  49. %(gi,k.replace('gi|'+gi+'|',''),desc[:36]+'...',gi,bs,sc)
  50.         else:
  51.             print '%s <a href = #%s> %s</a>   %s' \
  52.             %(desc[:40]+'...',k,bs,sc)
  53.     print '</PRE>\n'
  54.     for alig in fr.alignments:
  55.         print '<PRE>\n'
  56.         k=alig.hit_id
  57.         desc=alig.hit_def
  58.         if 'gi|' in k:
  59.             m=k.index('gi|')+3
  60.             gi=k[m:k[m:].index('|')+3]
  61.             print '><a name=%s></a><a href="http://www.ncbi.nlm.nih.gov/entrez/query.fcgi?\
  62. cmd=Retrieve&db=Nucleotide&list_uids=%s&dopt=GenBank" >\
  63. %s</a> %s ' \
  64. %(gi,gi,k.replace('gi|'+gi+'|',''),desc)
  65.         else:
  66.             print '><a name=%s></a>%s' %(k[k.index('|')+1:],desc)
  67.         print ' Length = %s\n' %(alig.length)
  68.         # Walk over all the hsps
  69.         for hsp in alig.hsps:
  70.             bs=hsp.bits
  71.             hsc=hsp.score
  72.             sc=hsp.expect
  73.             h_id=hsp.identities
  74.             h_pos=hsp.positives
  75.             q_frame=hsp.frame[0]
  76.             h_frame=hsp.frame[1]
  77.             q_from=str(hsp.query_start)
  78.             q_to=str(hsp.query_end)
  79.             h_from=str(hsp.sbjct_start)
  80.             h_to=str(hsp.sbjct_end)
  81.             qseq=hsp.query
  82.             hseq=hsp.sbjct
  83.             medio=hsp.match
  84.             if q_frame==1:
  85.                 qf='Plus'
  86.             else:
  87.                 qf='Minus'
  88.             if h_frame==1:
  89.                 hf='Plus'
  90.             else:
  91.                 hf='Minus'
  92.             print 'Score = %s bits (%s), Expect = %s' %(bs,hsc,sc)
  93.             print 'Identities = %s/%s (%.0f%%)' %(h_id,
  94.                                 h_pos,float(int(h_id))/int(h_pos)*100)
  95.             print 'Strand = %s/%s\n\n' %(qf,hf)
  96.             if h_frame=='1':
  97.                 mx=max(len(q_from),len(h_from))
  98.                 print 'Query: %s %s %s' %(q_from.ljust(mx),qseq,q_to)
  99.                 print '       '+' '*mx+' '+medio
  100.                 print 'Sbjct: %s %s %s\n' %(h_from.ljust(mx),hseq,h_to)
  101.             else:
  102.                 mx=max(len(q_from),len(h_to))
  103.                 print 'Query: %s %s %s' %(q_from.ljust(mx),qseq,q_to)
  104.                 print '       '+' '*mx+' '+medio
  105.                 print 'Sbjct: %s %s %s\n' %(h_to.ljust(mx),hseq,h_from)
  106.             print '</PRE>'
  107. if fr.num_letters_in_database!=[]:
  108.     print '''<PRE>
  109.   Database: %s
  110.   Number of letters in database: %s
  111.   Number of sequences in database:  %s
  112. Lambda     K      H
  113.     %.2f    %.3f     %.2f
  114. Matrix: %s matrix:%s %s
  115. Gap Penalties: Existence: %s, Extension: %s
  116. Number of Sequences: %s
  117. Length of database: %s
  118. </PRE>
  119. </BODY>
  120. </HTML>''' %(rec.database,fr.num_letters_in_database,
  121.              fr.num_sequences_in_database,
  122.              fr.ka_params[0],fr.ka_params[1],
  123.              fr.ka_params[2],fr.application,
  124.              fr.sc_match,fr.sc_mismatch,
  125.              fr.gap_penalties[0],fr.gap_penalties[1],
  126.              fr.num_sequences_in_database,
  127.              fr._num_letters_in_database)
  128. else:
  129.     # Hack for Biopython 1.45 or earlier.
  130.     print '''<PRE>
  131.   Database: %s
  132.   Number of letters in database: %s
  133.   Number of sequences in database:  %s
  134. Lambda     K      H
  135.     %.2f    %.3f     %.2f
  136. Matrix: %s matrix:%s %s
  137. Gap Penalties: Existence: %s, Extension: %s
  138. Number of Sequences: %s
  139. Length of database: %s
  140. </PRE>
  141. </BODY>
  142. </HTML>''' %(rec.database,fr._num_letters_in_database,
  143.              fr.num_sequences_in_database,
  144.              fr.ka_params[0],fr.ka_params[1],
  145.              fr.ka_params[2],fr.application,
  146.              fr.sc_match,fr.sc_mismatch,
  147.              fr.gap_penalties[0],fr.gap_penalties[1],
  148.              fr.num_sequences_in_database,
  149.              fr._num_letters_in_database)

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