Back to index

python-biopython  1.60
xbb_blast.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # Created: Thu Jul 13 14:07:25 2000
00003 # Last changed: Time-stamp: <00/12/03 13:27:24 thomas>
00004 # thomas@cbs.dtu.dk, http://www.cbs.dtu.dk/thomas
00005 # File: xbb_blast.py
00006 
00007 import os, sys, glob
00008 from threading import *
00009 import commands
00010 from Tkinter import *
00011 import Pmw
00012 sys.path.insert(0, '.')
00013 
00014 from xbb_utils import NotePad
00015 import xbb_blastbg
00016 
00017 class BlastIt:
00018     def __init__(self, seq, parent = None):
00019         self.seq = seq
00020         self.parent = parent
00021         self.toplevel = Toplevel(parent)
00022         Pmw.initialise(parent)
00023         self.GetBlasts()
00024         self.Choices()
00025         
00026     def GetBlasts(self):
00027         pin, nin = [],[]
00028         try:
00029             pin.extend(glob.glob(os.environ['BLASTDB'] + '/*.pin'))
00030         except:
00031             pass
00032         pin.extend(glob.glob('*.pin'))
00033         
00034         try:
00035             nin.extend(glob.glob(os.environ['BLASTDB'] + '/*.nin'))
00036         except:
00037             pass
00038         nin.extend(glob.glob('*.nin'))
00039 
00040         self.pin = map(lambda x: os.path.splitext(x)[0],pin)
00041         self.nin = map(lambda x: os.path.splitext(x)[0],nin)
00042 
00043     def Choices(self):
00044         self.GetBlasts()
00045         self.cf = Frame(self.toplevel)
00046         self.cf.pack(side = TOP, expand = 1, fill = X)
00047         self.dbs = Pmw.ComboBox(self.cf,
00048                                 label_text = 'Blast Databases:',
00049                                 labelpos = 'nw',
00050                                 scrolledlist_items = self.nin + self.pin,
00051                                 selectioncommand = self.Validate
00052                                 )
00053         self.blasts = Pmw.ComboBox(self.cf,
00054                                    label_text = 'Blast Programs:',
00055                                    labelpos = 'nw',
00056                                    scrolledlist_items = ['blastn', 'blastp', 'blastx', 'tblastn', 'tblastx'],
00057                                    selectioncommand = self.Validate
00058                                    )
00059         self.dbs.pack(side = LEFT, expand = 1, fill = X)
00060         self.blasts.pack(side = LEFT, expand = 1, fill = X)
00061 
00062         self.alternative_f = Frame(self.cf)
00063         self.alternative = Entry(self.alternative_f)
00064         self.alternative_f.pack(side = TOP, fill = X, expand = 1)
00065         self.alternative.pack(side = LEFT, fill = X, expand = 1)
00066         self.ok = Button(self.alternative_f, text = 'Run',
00067                          command = self._Run)
00068         self.ok.pack(side = RIGHT)
00069         
00070         self.dbs.selectitem(0)
00071         self.blasts.selectitem(0)
00072         self.Validate()
00073         
00074     def Validate(self, *args):
00075         db = self.dbs.get()
00076         prog = self.blasts.get()
00077         color = 'red'
00078         if (prog in ['blastn', 'tblastx', 'tblastn']) == (db in self.nin):
00079             color = 'green'
00080         elif (prog in ['blastp', 'blastx']) == (db in self.pin):
00081             color = 'green'
00082 
00083         self.dbs.component('entry').configure(bg = color)
00084         self.blasts.component('entry').configure(bg = color)
00085 
00086             
00087     def _Run(self):
00088         alternative_command = self.alternative.get()
00089         if len(alternative_command.strip()):
00090             self.command = alternative_command.strip()
00091         else:
00092             db = self.dbs.get()
00093             prog = self.blasts.get()
00094             self.command = 'echo %s | nice blastall -d %s -p %s' % (self.seq, db, prog)
00095 
00096         self.Run()
00097 
00098     def Update(self):
00099         self.notepad.update()
00100         #print '.',
00101         self.notepad.after(1, self.Update)
00102         
00103     def oldRun(self):
00104         self.notepad = NotePad()
00105         self.notepad.menubar.configure(bg='red')
00106         self.notepad.bind('<Destroy>', self.Exit)
00107 
00108         self.Update()
00109         
00110         print self.command
00111         self.pipe = posix.popen(self.command)
00112         while 1:
00113             try:
00114                 char = self.pipe.read(1)
00115                 self.notepad.insert(END,char)
00116                 self.notepad.update()
00117                                 
00118             except:
00119                 break
00120             if not char: break
00121             
00122         try:
00123             self.notepad.menubar.configure(bg='green')
00124         except:
00125             pass
00126 
00127     def Run(self):
00128         self.notepad = NotePad()
00129         tid = self.notepad.tid
00130         self.notepad.menubar.configure(bg='red')
00131 
00132         self.toplevel.destroy()
00133         blastbg = xbb_blastbg.BlastDisplayer(self.command, tid)
00134         blastbg.RunCommand()
00135 
00136         # indicate the finished run by changing color
00137         try:
00138             self.notepad.menubar.configure(bg='green4')
00139         except:
00140             pass
00141         
00142         
00143     def Exit(self, *args):
00144 
00145         try:
00146             self.pipe.close()
00147             del(pipe)
00148         except:
00149             pass
00150         self.notepad.destroy()
00151 
00152         sys.exit(0)
00153         
00154 
00155 
00156 
00157 if __name__ == '__main__':
00158     seq = sys.argv[1]
00159     win = Tk()
00160     test = BlastIt(seq)
00161     win.mainloop()