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:17
View followups from Bloguero_Connor | download | new post

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