Example #1
0
 def file_selected(self):
     file = self.file_listbox.curselection()
     if len(file) != 1:
         sys.stderr.write("No file selected.\n")
     else:
         file = map(int, file)
         fname = self.file_listbox.get(file[0])
         file_path = os.path.join(self.dir, fname)
         if self.GenePair_instance:
             # clean it up
             self.GenePair_instance = None
         else:
             self.GenePair_instance = GenePair(file_path)
             gene_ids = self.GenePair_instance.gene_id2expr_array.keys()
             gene_ids.sort()
             for gene_id in gene_ids:
                 self.gene_pair_listbox.insert(END, gene_id)
Example #2
0
	def liststore_gene_fill(self, filename):
		self.GenePair_instance = GenePair(filename)
		gene_ids = self.GenePair_instance.gene_id2expr_array.keys()
		gene_ids.sort()

		self.liststore = gtk.ListStore(str)
		# we'll add some data now -
		for gene_id in gene_ids:
			self.liststore.append([gene_id])
		
		# set the TreeView mode to be liststore
		self.treeview1.set_model(self.liststore)

		# make it searchable
		self.treeview1.set_search_column(0)
		# Allow sorting on the column
		self.tvcolumn.set_sort_column_id(0)
		# Allow drag and drop reordering of rows
		self.treeview1.set_reorderable(True)

		self.treeselection.set_mode(gtk.SELECTION_MULTIPLE)
Example #3
0
class GenePairGui:
	def __init__(self):
		xml = gtk.glade.XML('genepairgui.glade')
		xml.signal_autoconnect(self)
		self.window1 = xml.get_widget("window1")
		self.window1.connect("destroy", self.destroy)
		#to get gene_ids input by user
		self.textview1 = xml.get_widget("textview1")
		#to draw the plot
		self.textview2 = xml.get_widget("textview2")
		#to get gene_ids input by user
		self.treeview1 = xml.get_widget("treeview1")
		# create the TreeViewColumn to display the data
		self.tvcolumn = gtk.TreeViewColumn('Gene Id')
		# add tvcolumn to treeview
		self.treeview1.append_column(self.tvcolumn)
		# create a CellRendererText to render the data
		self.cell = gtk.CellRendererText()
		# add the cell to the tvcolumn and allow it to expand
		self.tvcolumn.pack_start(self.cell, True)
		
		# set the cell "text" attribute to column 0 - retrieve text
		# from that column in liststore
		self.tvcolumn.add_attribute(self.cell, 'text', 0)
		
		#setting the selection mode
		self.treeselection = self.treeview1.get_selection()
		
		#the backend module, non-initilized
		self.GenePair_instance = None
		
	def file_ok_sel(self, w):
		filename = self.filew.get_filename()
		self.filew.destroy()
		self.window1.set_title(filename)
		self.liststore_gene_fill(filename)
	
	def liststore_gene_fill(self, filename):
		self.GenePair_instance = GenePair(filename)
		gene_ids = self.GenePair_instance.gene_id2expr_array.keys()
		gene_ids.sort()

		self.liststore = gtk.ListStore(str)
		# we'll add some data now -
		for gene_id in gene_ids:
			self.liststore.append([gene_id])
		
		# set the TreeView mode to be liststore
		self.treeview1.set_model(self.liststore)

		# make it searchable
		self.treeview1.set_search_column(0)
		# Allow sorting on the column
		self.tvcolumn.set_sort_column_id(0)
		# Allow drag and drop reordering of rows
		self.treeview1.set_reorderable(True)

		self.treeselection.set_mode(gtk.SELECTION_MULTIPLE)

	def on_button1_clicked(self, button):
		self.filew = gtk.FileSelection("File selection")
		#self.filew.connect("destroy", self.destroy)
		# Connect the ok_button to file_ok_sel method
		self.filew.ok_button.connect("clicked", self.file_ok_sel)
		# Connect the cancel_button to destroy the widget
		self.filew.cancel_button.connect("clicked", lambda w: self.filew.destroy())
		# Lets set the filename, as if this were a save dialog,
		# and we are giving a default filename
		#self.filew.set_filename("penguin.png")
		
		self.filew.show()
	
	def on_button2_clicked(self, button):
		'''
		gene selected
		02-15-06
			use --process_gene_id_list()
		'''
		pathlist = []
		gene_id_list = []
		self.treeselection.selected_foreach(foreach_cb, pathlist)
		if len(pathlist) >0:
			for i in range(len(pathlist)):
				gene_id_list.append(self.liststore[pathlist[i][0]][0])
		self.process_gene_id_list(gene_id_list)
	
	def on_button3_clicked(self, button):
		gtk.main_quit()
		
	def on_button4_clicked(self, button):
		'''
		input gene_ids done
		02-15-06
			use --process_gene_id_list()
		'''
		textbuffer = self.textview1.get_buffer()
		startiter, enditer = textbuffer.get_bounds()
		text  = textbuffer.get_text(startiter, enditer)
		gene_id_list = text.split("\n")
		self.process_gene_id_list(gene_id_list)
	
	def process_gene_id_list(self, gene_id_list):
		"""
		02-15-06
			split from on_button2_clicked() and on_button4_clicked()
		"""
		if len(gene_id_list) >0:
			filename = self.GenePair_instance.gene_pair_analyze(gene_id_list)
			scatter_plot_fname = self.GenePair_instance.scatter_plot(gene_id_list)	#02-15-06
			if filename:
				self.show_plot(filename)
			if scatter_plot_fname:
				self.show_plot(scatter_plot_fname)
		else:
			sys.stderr.write("Have you selected a dataset?\n")
	
	def show_plot(self, filename):
		textbuffer = self.textview2.get_buffer()
		im = Image.open(filename)
		#r.postscript() gives an image with a strange direction, rotate it back
		im = im.rotate(-90)
		ar = fromimage(im)
		pixbuf = gtk.gdk.pixbuf_new_from_array(ar, gtk.gdk.COLORSPACE_RGB, 8)
		startiter = textbuffer.get_start_iter()
		textbuffer.insert_pixbuf(startiter, pixbuf)
		#cleanup the temporary files and others
		del im
		del ar
		os.remove(filename)
		
	def destroy(self, widget):
		gtk.main_quit()
Example #4
0
class GenePairGui:
    def __init__(self, master, dir):
        self.dir = dir
        frame = Frame(master)
        frame.pack()
        self.scrollbar_file = Scrollbar(frame, orient=VERTICAL)
        self.scrollbar_gene_pair = Scrollbar(frame, orient=VERTICAL)

        self.file_listbox = Listbox(frame, yscrollcommand=self.scrollbar_file.set)
        self.gene_pair_listbox = Listbox(frame, selectmode=EXTENDED, yscrollcommand=self.scrollbar_gene_pair.set)

        self.button_file = Button(frame, text="select file", command=self.file_selected)
        self.button_gene_pair = Button(frame, text="select gene pair", command=self.gene_pair_selected)
        self.button_quit = Button(frame, text="QUIT", fg="red", command=frame.quit)

        # geometry arrangement
        self.scrollbar_file.config(command=self.file_listbox.yview)
        self.scrollbar_gene_pair.config(command=self.gene_pair_listbox.yview)
        self.scrollbar_file.pack(fill=Y, expand=1)
        self.scrollbar_gene_pair.pack(fill=Y, expand=1)

        self.file_listbox.grid(row=0, column=0)
        self.scrollbar_file.grid(row=0, column=1)
        self.gene_pair_listbox.grid(row=0, column=2)
        self.scrollbar_gene_pair.grid(row=0, column=3)

        self.button_file.grid(row=1, column=0, columnspan=2)
        self.button_gene_pair.grid(row=1, column=2, columnspan=2)
        self.button_quit.grid(row=2, column=1, columnspan=2)

        # fill the list box
        self.file_listbox_fill()
        # GenePair handler
        self.GenePair_instance = None

    def file_listbox_fill(self):
        files = os.listdir(self.dir)
        for item in files:
            self.file_listbox.insert(END, item)

    def file_selected(self):
        file = self.file_listbox.curselection()
        if len(file) != 1:
            sys.stderr.write("No file selected.\n")
        else:
            file = map(int, file)
            fname = self.file_listbox.get(file[0])
            file_path = os.path.join(self.dir, fname)
            if self.GenePair_instance:
                # clean it up
                self.GenePair_instance = None
            else:
                self.GenePair_instance = GenePair(file_path)
                gene_ids = self.GenePair_instance.gene_id2expr_array.keys()
                gene_ids.sort()
                for gene_id in gene_ids:
                    self.gene_pair_listbox.insert(END, gene_id)

    def gene_pair_selected(self):
        gene_pair = self.gene_pair_listbox.curselection()
        if len(gene_pair) != 2:
            sys.stderr.write("Did you select two genes?\n")
        else:
            gene_pair = map(int, gene_pair)
            gene_id1 = self.gene_pair_listbox.get(gene_pair[0])
            gene_id2 = self.gene_pair_listbox.get(gene_pair[1])
            print gene_id1
            print gene_id2
            self.GenePair_instance.gene_pair_analyze(gene_id1, gene_id2)