PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/Scripts/xbbtools/xbb_blast.py

https://github.com/frankkl/biopython
Python | 161 lines | 123 code | 31 blank | 7 comment | 13 complexity | 5047a8b99b63cf9048fb97572f6cf0c8 MD5 | raw file
  1. #!/usr/bin/env python
  2. # Created: Thu Jul 13 14:07:25 2000
  3. # Last changed: Time-stamp: <00/12/03 13:27:24 thomas>
  4. # thomas@cbs.dtu.dk, http://www.cbs.dtu.dk/thomas
  5. # File: xbb_blast.py
  6. import os, sys, glob
  7. from threading import *
  8. import commands
  9. from Tkinter import *
  10. import Pmw
  11. sys.path.insert(0, '.')
  12. from xbb_utils import NotePad
  13. import xbb_blastbg
  14. class BlastIt:
  15. def __init__(self, seq, parent = None):
  16. self.seq = seq
  17. self.parent = parent
  18. self.toplevel = Toplevel(parent)
  19. Pmw.initialise(parent)
  20. self.GetBlasts()
  21. self.Choices()
  22. def GetBlasts(self):
  23. pin, nin = [],[]
  24. try:
  25. pin.extend(glob.glob(os.environ['BLASTDB'] + '/*.pin'))
  26. except:
  27. pass
  28. pin.extend(glob.glob('*.pin'))
  29. try:
  30. nin.extend(glob.glob(os.environ['BLASTDB'] + '/*.nin'))
  31. except:
  32. pass
  33. nin.extend(glob.glob('*.nin'))
  34. self.pin = map(lambda x: os.path.splitext(x)[0],pin)
  35. self.nin = map(lambda x: os.path.splitext(x)[0],nin)
  36. def Choices(self):
  37. self.GetBlasts()
  38. self.cf = Frame(self.toplevel)
  39. self.cf.pack(side = TOP, expand = 1, fill = X)
  40. self.dbs = Pmw.ComboBox(self.cf,
  41. label_text = 'Blast Databases:',
  42. labelpos = 'nw',
  43. scrolledlist_items = self.nin + self.pin,
  44. selectioncommand = self.Validate
  45. )
  46. self.blasts = Pmw.ComboBox(self.cf,
  47. label_text = 'Blast Programs:',
  48. labelpos = 'nw',
  49. scrolledlist_items = ['blastn', 'blastp', 'blastx', 'tblastn', 'tblastx'],
  50. selectioncommand = self.Validate
  51. )
  52. self.dbs.pack(side = LEFT, expand = 1, fill = X)
  53. self.blasts.pack(side = LEFT, expand = 1, fill = X)
  54. self.alternative_f = Frame(self.cf)
  55. self.alternative = Entry(self.alternative_f)
  56. self.alternative_f.pack(side = TOP, fill = X, expand = 1)
  57. self.alternative.pack(side = LEFT, fill = X, expand = 1)
  58. self.ok = Button(self.alternative_f, text = 'Run',
  59. command = self._Run)
  60. self.ok.pack(side = RIGHT)
  61. self.dbs.selectitem(0)
  62. self.blasts.selectitem(0)
  63. self.Validate()
  64. def Validate(self, *args):
  65. db = self.dbs.get()
  66. prog = self.blasts.get()
  67. color = 'red'
  68. if (prog in ['blastn', 'tblastx', 'tblastn']) == (db in self.nin):
  69. color = 'green'
  70. elif (prog in ['blastp', 'blastx']) == (db in self.pin):
  71. color = 'green'
  72. self.dbs.component('entry').configure(bg = color)
  73. self.blasts.component('entry').configure(bg = color)
  74. def _Run(self):
  75. alternative_command = self.alternative.get()
  76. if len(alternative_command.strip()):
  77. self.command = alternative_command.strip()
  78. else:
  79. db = self.dbs.get()
  80. prog = self.blasts.get()
  81. self.command = 'echo %s | nice blastall -d %s -p %s' % (self.seq, db, prog)
  82. self.Run()
  83. def Update(self):
  84. self.notepad.update()
  85. #print '.',
  86. self.notepad.after(1, self.Update)
  87. def oldRun(self):
  88. self.notepad = NotePad()
  89. self.notepad.menubar.configure(bg='red')
  90. self.notepad.bind('<Destroy>', self.Exit)
  91. self.Update()
  92. print self.command
  93. self.pipe = posix.popen(self.command)
  94. while 1:
  95. try:
  96. char = self.pipe.read(1)
  97. self.notepad.insert(END,char)
  98. self.notepad.update()
  99. except:
  100. break
  101. if not char: break
  102. try:
  103. self.notepad.menubar.configure(bg='green')
  104. except:
  105. pass
  106. def Run(self):
  107. self.notepad = NotePad()
  108. tid = self.notepad.tid
  109. self.notepad.menubar.configure(bg='red')
  110. self.toplevel.destroy()
  111. blastbg = xbb_blastbg.BlastDisplayer(self.command, tid)
  112. blastbg.RunCommand()
  113. # indicate the finished run by changing color
  114. try:
  115. self.notepad.menubar.configure(bg='green4')
  116. except:
  117. pass
  118. def Exit(self, *args):
  119. try:
  120. self.pipe.close()
  121. del(pipe)
  122. except:
  123. pass
  124. self.notepad.destroy()
  125. sys.exit(0)
  126. if __name__ == '__main__':
  127. seq = sys.argv[1]
  128. win = Tk()
  129. test = BlastIt(seq)
  130. win.mainloop()