コード例 #1
0
ファイル: main.py プロジェクト: kvarq/kvarq
    def __init__(self, testsuite_paths):
        ThemedTk.__init__(self)

        self.settings = Settings(default_config)
        self.testsuite_paths = testsuite_paths
        self.testsuites = {}

        frame = tk.Frame(self)

        self.scan = tk.Button(frame, text='scan .fastq files', command=self.do_scan)
        self.scan.pack()

        self.explore = tk.Button(frame, text='explore .json files', command=self.do_explore)
        self.explore.pack()

        dummy = tk.Label(frame)
        dummy.pack()

        self.config = tk.Button(frame, text='settings', command=self.do_config)
        self.config.pack()

        self.help = tk.Button(frame, text='help', command=open_help)
        self.help.pack()

        if logfn:
            self.showlog = tk.Button(frame, text='show log file', command=self.do_showlog)
            self.showlog.pack()

        frame.pack(side='left', padx=10)

        outer = tk.Frame(self, borderwidth=1, relief='ridge')
        outer.pack(side='left', expand=True, fill='both', padx=5, pady=5)
        label = tk.Label(outer, text='kvarq log output')
        label.pack()
        frame = tk.Frame(outer)
        frame.pack(expand=True, fill='both')
        self.text = tk.Text(frame) #, state=tk.DISABLED)
        self.text.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
        scroll = tk.Scrollbar(frame, command=self.text.yview)
        scroll.pack(side=tk.RIGHT, fill=tk.Y)
        self.text.config(yscrollcommand=scroll.set)
        self.text.yscrollbar = scroll

        def sys_exit():
            if tkMessageBox.askyesno('quit KvarQ', 'really want to exit KvarQ and close all windows?'):
                sys.exit(0)
        self.protocol("WM_DELETE_WINDOW", sys_exit)

        self.log_handler = GuiLogHandler(self.text, self.scrolldown)
        lo.addHandler(self.log_handler)
        lo.debug('GUI started')
コード例 #2
0
ファイル: explorer.py プロジェクト: kvarq/kvarq
    def __init__(self, jpath_or_analyser, testsuites, testsuite_paths):
        self.win = ThemedTk(title='json explorer', esc_closes=True,
                geometry=(-200, -200))

        if sys.platform == 'win32':
            self.win.wm_iconbitmap(bitmap = get_root_path('res', 'TPH_DNA.ico'))

        self.win.columnconfigure(0, weight=1)
        self.win.columnconfigure(1, weight=0)
        self.win.rowconfigure(0, weight=0)
        self.win.rowconfigure(1, weight=0)
        self.win.rowconfigure(2, weight=4)

        if isinstance(jpath_or_analyser, Analyser):
            self.analyser = jpath_or_analyser
            name = os.path.basename(self.analyser.fastq.fname)
        else:
            try:

                data = json.load(file(jpath_or_analyser))
                update_testsuites(testsuites, data['info']['testsuites'], testsuite_paths)

                self.analyser = Analyser()
                self.analyser.decode(testsuites, data)
                self.analyser.update_testsuites()
            except Exception, e:
                exc_info = sys.exc_info()
                self.win.destroy()
                raise exc_info[1], None, exc_info[2]
            name = os.path.basename(jpath_or_analyser)
コード例 #3
0
ファイル: explorer.py プロジェクト: kvarq/kvarq
    def __init__(self, dname, testsuites, testsuite_paths):

        self.testsuites = testsuites
        self.testsuite_paths = testsuite_paths

        if dname:
            self.dname = os.path.abspath(dname)
            self.jpaths = glob.glob(os.path.join(self.dname, '*.json'))
        else:
            jpaths = askopenfilename(
                    initialdir=os.getcwd(),
                    title='Choose .json files to explore',
                    multiple=True,
                    filetypes=[('json files', '*.json')])

            if not jpaths:
                return
            if len(jpaths) == 1:
                self.do_open_json(jpaths[0])
                return

            self.jpaths = [os.path.abspath(jpath) for jpath in jpaths]
            self.dname = os.path.dirname(self.jpaths[0])

        self.win = ThemedTk(title='explore .json files', esc_closes=True,
                geometry=(400, 800))

#        self.menu = tk.Menu(self.win)
#        filemenu = tk.Menu(self.menu)
#        self.menu.add_cascade(label='KvarQ', menu=filemenu)
#        filemenu.add_command(label='Help', command=open_help)
#        self.win.config(menu=self.menu)
#
        self.win.columnconfigure(0, weight=1)
        self.win.columnconfigure(1, weight=0)
        self.win.rowconfigure(0, weight=0)
        self.win.rowconfigure(1, weight=1)
        self.win.rowconfigure(2, weight=0)

        self.dlabel = tk.Label(self.win, text='(no directory chosen)')
        self.dlabel.grid(row=0, column=0, columnspan=2, sticky='ew')

        self.yscroll = tk.Scrollbar(self.win, orient=tk.VERTICAL)
        self.yscroll.grid(row=1, column=1, sticky='ns')
        self.jlist = tk.Listbox(self.win, yscrollcommand=self.yscroll.set)
        self.jlist.grid(row=1, column=0, sticky='nsew')
        self.yscroll["command"] = self.jlist.yview
        self.jlist.bind("<Double-Button-1>", self.open_json)
        self.jlist.bind("<Return>", self.open_json)

        # convert .xls button
        self.convert = tk.Button(self.win, text='summarize...', command=self.summarize)
        self.convert.grid(row=2, column=0, sticky='ew')

        self.update()

        self.jlist.activate(0)
        self.jlist.selection_set(0)
        self.jlist.focus_set()
コード例 #4
0
ファイル: settings.py プロジェクト: kvarq/kvarq
    def show(self):
        self.win = ThemedTk(title='settings')

        self.win.rowconfigure(1, weight=1)
        self.win.columnconfigure(1, weight=1)

        row = 0

        self.win.rowconfigure(row, minsize=10)
        row += 1

        l = tk.Label(self.win, text='Engine configuration', font=self.win.boldfont)
        l.grid(row=row, column=0, columnspan=2, sticky='w')

        self.show_help = tk.Button(self.win, text='?',
                command=self.launch_help)
        self.show_help.grid(row=row, column=2, sticky='e')

        self.entries = {}
        for name in self.config.keys():
            row += 1
            l = tk.Label(self.win, text=name)
            l.grid(row=row, column=0, sticky='w')
            self.entries[name] = tk.Entry(self.win)
            self.entries[name].grid(row=row, column=1, columnspan=2, sticky='ew')
            self.entries[name].insert(0, self.config[name])

        row += 1
        self.win.rowconfigure(row, minsize=10)
        row += 1
        frame = tk.Frame(self.win)
        frame.grid(row=row, column=0, columnspan=3)
        save = tk.Button(frame, text='save', command=self.save_cb)
        save.pack(side='left')
        cancel = tk.Button(frame, text='cancel', command=self.cancel_cb)
        cancel.pack(side='left')
        self.win.bind('<Escape>', lambda x: self.win.close())
コード例 #5
0
ファイル: settings.py プロジェクト: kvarq/kvarq
class Settings:

    def __init__(self, config):
        self.config = config

    def show(self):
        self.win = ThemedTk(title='settings')

        self.win.rowconfigure(1, weight=1)
        self.win.columnconfigure(1, weight=1)

        row = 0

        self.win.rowconfigure(row, minsize=10)
        row += 1

        l = tk.Label(self.win, text='Engine configuration', font=self.win.boldfont)
        l.grid(row=row, column=0, columnspan=2, sticky='w')

        self.show_help = tk.Button(self.win, text='?',
                command=self.launch_help)
        self.show_help.grid(row=row, column=2, sticky='e')

        self.entries = {}
        for name in self.config.keys():
            row += 1
            l = tk.Label(self.win, text=name)
            l.grid(row=row, column=0, sticky='w')
            self.entries[name] = tk.Entry(self.win)
            self.entries[name].grid(row=row, column=1, columnspan=2, sticky='ew')
            self.entries[name].insert(0, self.config[name])

        row += 1
        self.win.rowconfigure(row, minsize=10)
        row += 1
        frame = tk.Frame(self.win)
        frame.grid(row=row, column=0, columnspan=3)
        save = tk.Button(frame, text='save', command=self.save_cb)
        save.pack(side='left')
        cancel = tk.Button(frame, text='cancel', command=self.cancel_cb)
        cancel.pack(side='left')
        self.win.bind('<Escape>', lambda x: self.win.close())

    def launch_help(self, e=None):
        open_help(page='gui', anchor='configuring-kvarq')

    def save_cb(self, e=None):

        # check whether parameters have correct format
        newconfig = dict(self.config)
        for name in self.config.keys():
            try:
                newconfig[name] = int(self.entries[name].get())
            except ValueError, e:
                tkMessageBox.showerror(
                        'invalid value',
                        'parameter "%s" must be an integer' % name)
                return

        # save new settings
        for name, value in newconfig.items():
            self.config[name] = value

        self.win.destroy()
コード例 #6
0
ファイル: explorer.py プロジェクト: kvarq/kvarq
class DirectoryExplorer:

    def __init__(self, dname, testsuites, testsuite_paths):

        self.testsuites = testsuites
        self.testsuite_paths = testsuite_paths

        if dname:
            self.dname = os.path.abspath(dname)
            self.jpaths = glob.glob(os.path.join(self.dname, '*.json'))
        else:
            jpaths = askopenfilename(
                    initialdir=os.getcwd(),
                    title='Choose .json files to explore',
                    multiple=True,
                    filetypes=[('json files', '*.json')])

            if not jpaths:
                return
            if len(jpaths) == 1:
                self.do_open_json(jpaths[0])
                return

            self.jpaths = [os.path.abspath(jpath) for jpath in jpaths]
            self.dname = os.path.dirname(self.jpaths[0])

        self.win = ThemedTk(title='explore .json files', esc_closes=True,
                geometry=(400, 800))

#        self.menu = tk.Menu(self.win)
#        filemenu = tk.Menu(self.menu)
#        self.menu.add_cascade(label='KvarQ', menu=filemenu)
#        filemenu.add_command(label='Help', command=open_help)
#        self.win.config(menu=self.menu)
#
        self.win.columnconfigure(0, weight=1)
        self.win.columnconfigure(1, weight=0)
        self.win.rowconfigure(0, weight=0)
        self.win.rowconfigure(1, weight=1)
        self.win.rowconfigure(2, weight=0)

        self.dlabel = tk.Label(self.win, text='(no directory chosen)')
        self.dlabel.grid(row=0, column=0, columnspan=2, sticky='ew')

        self.yscroll = tk.Scrollbar(self.win, orient=tk.VERTICAL)
        self.yscroll.grid(row=1, column=1, sticky='ns')
        self.jlist = tk.Listbox(self.win, yscrollcommand=self.yscroll.set)
        self.jlist.grid(row=1, column=0, sticky='nsew')
        self.yscroll["command"] = self.jlist.yview
        self.jlist.bind("<Double-Button-1>", self.open_json)
        self.jlist.bind("<Return>", self.open_json)

        # convert .xls button
        self.convert = tk.Button(self.win, text='summarize...', command=self.summarize)
        self.convert.grid(row=2, column=0, sticky='ew')

        self.update()

        self.jlist.activate(0)
        self.jlist.selection_set(0)
        self.jlist.focus_set()

    def update(self):
        if len(self.dname)>30:
            self.dlabel.config(text='...'+self.dname[-27:])
        else:
            self.dlabel.config(text=self.dname)

        self.jlist.delete(0, tk.END)
        for jpath in self.jpaths:
            self.jlist.insert(tk.END, os.path.basename(jpath))

    def open_json(self, x=None):
        idxs = self.jlist.curselection()
        if not idxs:
            lo.warning('cannot open JsonExplorer : idxs='+str(idxs))
            return
        jpath = self.jpaths[int(idxs[0])]
        self.do_open_json(jpath)

    def do_open_json(self, jpath):
        try:
            je = JsonExplorer(jpath, self.testsuites, self.testsuite_paths)
        except DecodingException, e:
            more = ''
            if isinstance(e, TestsuiteVersionConflictException):
                more += '\n\nYou must load compatible versions of testsuites when ' \
                        'exploring a .json file; KvarQ ships with some testsuite ' \
                        'legacy versions (in the respectevite "legacy/" directory). ' \
                        'Or you may try to find old versions online at ' + DOWNLOAD_URL
            if isinstance(e, VersionConflictException):
                more += '\n\nSome old versions of KvarQ used a file format that ' \
                        'cannot be parsed with this version; you can download older ' \
                        'versions of KvarQ at ' + DOWNLOAD_URL
            tkMessageBox.showerror(
                    'file format error',
                    'cannot load file %s : %s'%(jpath, e)
                    + more)
コード例 #7
0
ファイル: explorer.py プロジェクト: kvarq/kvarq
class JsonExplorer:

    # whishlist
    #   - file info
    #     - version, size, scantime
    #     - readlengths_hist=f(Amin), fastq_type
    #   - lineage
    #     - scores
    #   - resistances
    #     - analyse : (non) synonymous

    def __init__(self, jpath_or_analyser, testsuites, testsuite_paths):
        self.win = ThemedTk(title='json explorer', esc_closes=True,
                geometry=(-200, -200))

        if sys.platform == 'win32':
            self.win.wm_iconbitmap(bitmap = get_root_path('res', 'TPH_DNA.ico'))

        self.win.columnconfigure(0, weight=1)
        self.win.columnconfigure(1, weight=0)
        self.win.rowconfigure(0, weight=0)
        self.win.rowconfigure(1, weight=0)
        self.win.rowconfigure(2, weight=4)

        if isinstance(jpath_or_analyser, Analyser):
            self.analyser = jpath_or_analyser
            name = os.path.basename(self.analyser.fastq.fname)
        else:
            try:

                data = json.load(file(jpath_or_analyser))
                update_testsuites(testsuites, data['info']['testsuites'], testsuite_paths)

                self.analyser = Analyser()
                self.analyser.decode(testsuites, data)
                self.analyser.update_testsuites()
            except Exception, e:
                exc_info = sys.exc_info()
                self.win.destroy()
                raise exc_info[1], None, exc_info[2]
            name = os.path.basename(jpath_or_analyser)

        self.dlabel = tk.Label(self.win, text=name)
        self.dlabel.grid(row=0, column=0, columnspan=2, sticky='ew')

        self.menu = tk.Menu(self.win)
        filemenu = tk.Menu(self.menu)
        self.menu.add_cascade(label='KvarQ', menu=filemenu)
        filemenu.add_command(label='Help', command=open_help)
        self.win.config(menu=self.menu)

        # list of analyses
        self.yscroll1 = tk.Scrollbar(self.win, orient=tk.VERTICAL)
        self.yscroll1.grid(row=1, column=1, sticky='ns')
        self.alist = tk.Listbox(self.win, height=len(self.analyser.testsuites)+1, yscrollcommand=self.yscroll1.set)
        self.alist.grid(row=1, column=0, sticky='nsew')
        self.yscroll1["command"]  =  self.alist.yview
        self.alist.bind("<Double-Button-1>", self.show_analyses)
        self.alist.bind("<Return>", self.show_analyses)

        # fill in list of analyses, prepare dict of coverages
        self.anames = ['info']
        self.alist.insert(tk.END, 'info')
        for aname, testsuite in self.analyser.testsuites.items():
            self.anames.append(aname)
            result = self.analyser.results[aname]
            if type(result)==list:
                result = '; '.join(result)
            self.alist.insert(tk.END, aname + ': ' + result)

        # list of coverages
        self.yscroll2 = tk.Scrollbar(self.win, orient=tk.VERTICAL)
        self.yscroll2.grid(row=2, column=1, sticky='ns')
        self.clist = tk.Listbox(self.win, yscrollcommand=self.yscroll2.set)
        self.clist.grid(row=2, column=0, sticky='nsew')
        self.yscroll2["command"]  =  self.clist.yview
        self.clist.bind("<Double-Button-1>", self.show_coverage)
        self.clist.bind("<Return>", self.show_coverage)

        self.current = None
        self.alist.activate(0)
        self.alist.selection_set(0)
        self.alist.focus_set()

        self.after_id = None
        def close_win(a=None):
            if self.after_id:
                self.win.after_cancel(self.after_id)
            self.win.destroy()
        self.win.close = close_win
        self.win.protocol('WM_DELETE_WINDOW', close_win)
        self.poll()