def find_ancestral_tags(self, node):
        ancestral_tags = []
        for pnode in timeline.reverse_iter_tree(node):
            if pnode:
                for ptag in pnode.tags:
                    if ptag.startswith('Transfer|Seed') and meta.get_field(
                            'Transfer|Seed|HarvestInstance|' +
                            exp.get_tag_instance(ptag)) is not None:
                        for tpnode in self.nodes_by_timepoint[
                                pnode.get_timepoint() - 1]:
                            if tpnode:
                                for tptag in tpnode.tags:
                                    if exp.get_tag_protocol(
                                            tptag
                                    ) == 'Transfer|Harvest|%s' % meta.get_field(
                                            'Transfer|Seed|HarvestInstance|' +
                                            exp.get_tag_instance(ptag)):
                                        for npnode in timeline.reverse_iter_tree(
                                                tpnode):
                                            if npnode:
                                                for nptag in npnode.tags:
                                                    ancestral_tags.append(
                                                        nptag)
                    else:
                        ancestral_tags.append(ptag)

        return list(reversed(ancestral_tags))
예제 #2
0
    def get_ancestral_tags(self, node):
	#ancestral_tags = []
	#for pnode in timeline.reverse_iter_tree(node):
	    #if pnode:
		#if 'CellTransfer|Seed' in node.tags:
		    #for tag in node.tags:
			##if (tag.startswith('CellTransfer|Seed') and 
			    ##meta.get_field('CellTransfer|Seed|HarvestInstance|'+exp.get_tag_instance(tag)) is not None):
			    #h_instance = meta.get_field('CellTransfer|Seed|HarvestInstance|'+exp.get_tag_instance(tag))
			    #for tpnode in self.nodes_by_timepoint[node.get_timepoint()-1]:
				#if tpnode:
				    #for tptag in tpnode.tags:	       
					#if exp.get_tag_protocol(tptag) == 'CellTransfer|Harvest|'+h_instance:
					    #for npnode in timeline.reverse_iter_tree(tpnode):
						#if npnode:
						    #for nptag in npnode.tags:
							#ancestral_tags.append(exp.get_tag_stump(nptag, 2))
		#else:
		    #for ptag in pnode.tags:
			#ancestral_tags.append(exp.get_tag_stump(ptag, 2))
	
	#return ancestral_tags

	return [exp.get_tag_stump(ptag, 2)
	        for pnode in timeline.reverse_iter_tree(node) if pnode
	        for ptag in pnode.tags]
예제 #3
0
    def get_ancestral_tags(self, node):
	#ancestral_tags = []
	#for pnode in timeline.reverse_iter_tree(node):
	    #if pnode:
		#if 'CellTransfer|Seed' in node.tags:
		    #for tag in node.tags:
			##if (tag.startswith('CellTransfer|Seed') and 
			    ##meta.get_field('CellTransfer|Seed|HarvestInstance|'+exp.get_tag_instance(tag)) is not None):
			    #h_instance = meta.get_field('CellTransfer|Seed|HarvestInstance|'+exp.get_tag_instance(tag))
			    #for tpnode in self.nodes_by_timepoint[node.get_timepoint()-1]:
				#if tpnode:
				    #for tptag in tpnode.tags:	       
					#if exp.get_tag_protocol(tptag) == 'CellTransfer|Harvest|'+h_instance:
					    #for npnode in timeline.reverse_iter_tree(tpnode):
						#if npnode:
						    #for nptag in npnode.tags:
							#ancestral_tags.append(exp.get_tag_stump(nptag, 2))
		#else:
		    #for ptag in pnode.tags:
			#ancestral_tags.append(exp.get_tag_stump(ptag, 2))
	
	#return ancestral_tags

	return [exp.get_tag_stump(ptag, 2)
	        for pnode in timeline.reverse_iter_tree(node) if pnode
	        for ptag in pnode.tags]
    def find_ancestral_tags(self, node):
	ancestral_tags = []
	for pnode in timeline.reverse_iter_tree(node):
	    if pnode: 
		for ptag in pnode.tags:
		    if ptag.startswith('Transfer|Seed')and meta.get_field('Transfer|Seed|HarvestInstance|'+exp.get_tag_instance(ptag)) is not None:
			for tpnode in self.nodes_by_timepoint[pnode.get_timepoint()-1]:
			    if tpnode:
				for tptag in tpnode.tags:
				    if exp.get_tag_protocol(tptag) == 'Transfer|Harvest|%s'%meta.get_field('Transfer|Seed|HarvestInstance|'+exp.get_tag_instance(ptag)):
					for npnode in timeline.reverse_iter_tree(tpnode):
					    if npnode:
						for nptag in npnode.tags:
						    ancestral_tags.append(nptag)	
		    else:
			ancestral_tags.append(ptag)
			
	return list(reversed(ancestral_tags))
예제 #5
0
    def _on_paint(self, evt=None):
        '''Handler for paint events.
        '''
        if self.nodes_by_timepoint == {}:
            evt.Skip()
            return

        t0 = time()
        PAD = self.PAD + self.NODE_R
        NODE_R = self.NODE_R
        MIN_X_GAP = self.MIN_X_GAP
        MIN_Y_GAP = self.MIN_Y_GAP
        FLASK_GAP = self.FLASK_GAP
        MAX_TIMEPOINT = self.timepoints[0]
        timepoints = self.timepoints
        nodes_by_tp = self.nodes_by_timepoint
        self.current_node = None           # Node with the mouse over it
        w_win, h_win = (float(self.Size[0]), float(self.Size[1]))
                    
        if self.time_x:
            if timepoints[0] == 0:
                px_per_time = 1
            else:
                px_per_time = max((w_win - PAD * 2 - FLASK_GAP) / MAX_TIMEPOINT,
                                  MIN_X_GAP)
                
        if len(nodes_by_tp) == 2:
            x_gap = 1
        else:
            # calculate the number of pixels to separate each generation timepoint
            x_gap = max(MIN_X_GAP, 
                         (w_win - PAD * 2 - FLASK_GAP) / (len(nodes_by_tp) - 2))
            
        if len(nodes_by_tp[timepoints[0]]) == 1:
            y_gap = MIN_Y_GAP
        else:
            # calcuate the minimum number of pixels to separate nodes on the y axis
            y_gap = max(MIN_Y_GAP, 
                        (h_win - PAD * 2) / (len(nodes_by_tp[MAX_TIMEPOINT]) - 1))
                        
        nodeY = {}  # Store y coords of children so we can calculate where to draw the parents
        Y = PAD
        X = w_win - PAD
        
        dc = wx.PaintDC(self)
        dc.Clear()
        dc.BeginDrawing()
        #dc.SetPen(wx.Pen("BLACK",1))
        
        def hover(mouse_pos, node_pos, node_r):
            '''returns whether the mouse is hovering over a node
            mouse_pos - the mouse position
            node_pos - the node position
            node_r - the node radius
            '''
            if mouse_pos is None:
                return False
            MX,MY = mouse_pos
            X,Y = node_pos
            return (X - node_r < MX < X + node_r and 
                    Y - node_r < MY < Y + node_r)

        # Iterate from leaf nodes up to the root, and draw R->L, Top->Bottom
        for i, t in enumerate(timepoints):
            if t == -1:
                X = PAD
            elif self.time_x:
                X = PAD + FLASK_GAP + t * px_per_time
                x_gap = PAD + FLASK_GAP + timepoints[i-1] * px_per_time - X
            else:
                X = PAD + FLASK_GAP + (len(timepoints) - i - 2) * x_gap
            
            # NO EVENTS. JUST DRAW THE STOCK, CENTERED.
            if len(nodes_by_tp) == 1:
                X = w_win / 2
                Y = h_win / 2
                if hover(self.cursor_pos, (X,Y), self.NODE_R): 
                    dc.SetBrush(wx.Brush('#FFFFAA'))
                    self.current_node = nodes_by_tp.values()[t][0]
                else:
                    dc.SetBrush(wx.Brush('#FAF9F7'))
                    self.current_node = None
                dc.DrawRectangle(X-NODE_R, Y-NODE_R, NODE_R*2, NODE_R*2)
##                dc.DrawText(str(nodes_by_tp[t][0].get_timepoint()), X, Y+NODE_R)
                
            # LEAF NODES
            elif i == 0:
                for node in nodes_by_tp[t]:
                    empty_path = False # whether this path follows a harvesting
                    if len(node.get_tags()) > 0:
                        # Event occurred
                        dc.SetBrush(wx.Brush('YELLOW'))
                    else:
                        # No event
                        dc.SetBrush(wx.Brush('WHITE'))
                        if 'CellTransfer|Harvest' in [exp.get_tag_stump(ptag, 2)
                                                      for pnode in timeline.reverse_iter_tree(node) if pnode
                                                      for ptag in pnode.tags]:
                            empty_path = True

                    if hover(self.cursor_pos, (X,Y), self.NODE_R):
                        # MouseOver
                        dc.SetPen(wx.Pen('#000000', 3))
                        self.current_node = node
                    else:
                        # No MouseOver
                        dc.SetPen(wx.Pen('#000000', 1))
                    
                    if not empty_path:
                        dc.DrawCircle(X, Y, NODE_R)
##                        dc.DrawText(str(node.get_tags()), X, Y+NODE_R)
                    nodeY[node.id] = Y
                    Y += y_gap
                    
            # INTERNAL NODES
            else:
                for node in nodes_by_tp[t]:
                    empty_path = False # whether this path follows a harvesting
                    ys = []
                    for child in node.get_children():
                        ys.append(nodeY[child.id])
                    Y = (min(ys) + max(ys)) / 2

                    if len(node.get_tags()) > 0:
                        # Event occurred
                        dc.SetBrush(wx.Brush('YELLOW'))
                    else:
                        # No event
                        dc.SetBrush(wx.Brush('WHITE'))
                        if 'CellTransfer|Harvest' in [exp.get_tag_stump(ptag, 2)
                                                      for pnode in timeline.reverse_iter_tree(node) if pnode
                                                      for ptag in pnode.tags]:
                            empty_path = True

                    if hover(self.cursor_pos, (X,Y), self.NODE_R):
                        # MouseOver
                        dc.SetPen(wx.Pen(wx.BLACK, 3))
                        self.current_node = node
                    else:
                        # No MouseOver
                        dc.SetPen(wx.Pen(wx.BLACK, 1))
                    
                    if t == -1:
                        dc.DrawRectangle(X-NODE_R, Y-NODE_R, NODE_R*2, NODE_R*2)
                    else:
                        if not empty_path:
                            dc.DrawCircle(X, Y, NODE_R)
##                            dc.DrawText(str(node.get_tags()), X, Y+NODE_R)
                        
                    # DRAW LINES CONNECTING THIS NODE TO ITS CHILDREN
                    dc.SetBrush(wx.Brush('#FAF9F7'))
                    dc.SetPen(wx.Pen(wx.BLACK, 1))
                    harvest_tag = False
                    for tag in node.get_tags():
                        if tag.startswith('CellTransfer|Harvest'):
                            harvest_tag = tag
                    for child in node.get_children():
                        if t == -1:
                            if self.time_x:
                                dc.DrawLine(X + NODE_R, Y, 
                                            X + FLASK_GAP + px_per_time * timepoints[i-1] - NODE_R ,nodeY[child.id])
                            else:
                                dc.DrawLine(X + NODE_R, Y, 
                                            X + FLASK_GAP - NODE_R ,nodeY[child.id])
                        else:
                            if harvest_tag:
                                # TODO: improve performance by caching reseed 
                                #       events from the previous timepoint
                                for nn in nodes_by_tp[timepoints[i-1]]:
                                    for tag in nn.get_tags():
                                        if (tag.startswith('CellTransfer|Seed') and 
                                            meta.get_field('CellTransfer|Seed|HarvestInstance|'+exp.get_tag_instance(tag)) == exp.get_tag_instance(harvest_tag)):
                                            dc.SetPen(wx.Pen('BLACK', 1, wx.SHORT_DASH))
                                            dc.DrawLine(X + NODE_R, Y, 
                                                        X + x_gap - NODE_R ,nodeY[nn.id])
                            else:
                                if not empty_path:
                                    dc.SetPen(wx.Pen(wx.BLACK, 1))
                                    dc.DrawLine(X + NODE_R, Y, 
                                                X + x_gap - NODE_R,
                                                nodeY[child.id])
                    nodeY[node.id] = Y
        dc.EndDrawing()
예제 #6
0
    def _on_mouse_click(self, evt):
        if self.current_node is None:
            return
        
        # --- Update the Bench view ---
        try:
            bench = wx.GetApp().get_bench()
        except: 
            return
	
        bench.set_timepoint(self.current_node.get_timepoint())
        bench.taglistctrl.set_selected_protocols(
            [exp.get_tag_protocol(tag) for tag in self.current_node.get_tags()])
        bench.group_checklist.SetCheckedStrings(
            [exp.PlateDesign.get_plate_group(well[0]) 
             for well in self.current_node.get_well_ids()])
        bench.update_plate_groups()
        bench.update_well_selections()
	bench.del_evt_button.Enable()
	
        # -- Update the expt setting/metadata view --#
        try:
            exptsettings = wx.GetApp().get_exptsettings()
        except:
            return
	
        exptsettings.OnLeafSelect()
        if self.current_node.get_tags():
            exptsettings.ShowInstance(self.current_node.get_tags()[0])
            
        ancestors = [exp.get_tag_stump(ptag, 2)
                     for pnode in timeline.reverse_iter_tree(self.current_node) if pnode
                     for ptag in pnode.tags]   
	
	# -- show the data url list --- #
        data_acquis = False

        for tag in self.current_node.get_tags():
	    if tag.startswith('DataAcquis'):
		data_acquis = True
		break
	    
	if data_acquis:
	    dia = DataLinkListDialog(self, self.current_node.get_well_ids())
	    if dia.ShowModal() == wx.ID_OK:
		if dia.output_options.GetSelection() == 0:
		    file_dlg = wx.FileDialog(None, message='Exporting Data URL...', 
		                             defaultDir=os.getcwd(), defaultFile='data urls', 
		                             wildcard='.csv', 
		                             style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
		    if file_dlg.ShowModal() == wx.ID_OK:
			os.chdir(os.path.split(file_dlg.GetPath())[0])
			myfile = open(file_dlg.GetPath(), 'wb')
			wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
			for row in dia.listctrl.get_selected_urls():
			    wr.writerow(row)
			myfile.close()	
			file_dlg.Destroy()
		if dia.output_options.GetSelection() == 1:
		    file_dlg = wx.FileDialog(None, message='Exporting Data URL...', 
		                            defaultDir=os.getcwd(), defaultFile='data urls', 
		                            wildcard='.csv', 
		                            style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
		    if file_dlg.ShowModal() == wx.ID_OK:
			os.chdir(os.path.split(file_dlg.GetPath())[0])
			myfile = open(file_dlg.GetPath(), 'wb')
			wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
			for row in dia.listctrl.get_all_urls():
			    wr.writerow(row)
			myfile.close()	
			file_dlg.Destroy()
		
		if dia.output_options.GetSelection() == 2:
		    image_urls = []
		    for row in dia.listctrl.get_selected_urls():
			image_urls.append(row[2])
		    if os.path.isfile('C:\Program Files\ImageJ\ImageJ.exe') is False:
			#err_dlg = wx.lib.dialogs.ScrolledMessageDialog(self, str("\n".join(urls)), "ERROR!! ImageJ was not found in C\Program Files directory to show following images")
			err_dlg = wx.MessageDialog(None, 'ImageJ was not found in C\Program Files directory to show images!!', 'Error', wx.OK | wx.ICON_ERROR)
			err_dlg.ShowModal()			 
			return 			
		    else:
			#TO DO: check the image format to be shown in ImageJ    
			ImageJPath = 'C:\Program Files\ImageJ\ImageJ.exe'
			subprocess.Popen("%s %s" % (ImageJPath, ' '.join(image_urls)))		    
			
	    dia.Destroy()	
예제 #7
0
    def _on_mouse_click(self, evt):
        if self.current_node is None:
            return
        for tag in self.current_node.get_tags():
            if tag.startswith("DataAcquis|TLM") or tag.startswith("DataAcquis|HCS"):
                for well in self.current_node.get_well_ids():
                    image_tag = "%s|Images|%s|%s|%s" % (
                        exp.get_tag_stump(tag, 2),
                        exp.get_tag_instance(tag),
                        exp.get_tag_timepoint(tag),
                        well,
                    )
                    urls = meta.get_field(image_tag, [])
                    image_viewer_path = ""
                    if os.path.isfile("C:\Program Files\ImageJ\ImageJ.exe"):
                        ImageJPath = "C:\Program Files\ImageJ\ImageJ.exe"
                        subprocess.Popen("%s %s" % (ImageJPath, " ".join(urls)))
                    else:
                        dlg = wx.lib.dialogs.ScrolledMessageDialog(
                            self,
                            str("\n".join(urls)),
                            "ERROR!! ImageJ was not found in C\Program Files directory to show following images",
                        )
                        dlg.ShowModal()
                        return
                        # for url in urls:
                        # im = Image.open(url)
                        # im.show()
                        ##TODO: make it Try with ImageJ first then Exception is Image.open(url)
                        # ImageJPath = r'C:\Program Files\ImageJ\ImageJ'
                        # subprocess.Popen("%s %s" % (ImageJPath, url))

            elif tag.startswith("DataAcquis|FCS"):
                for well in self.current_node.get_well_ids():
                    image_tag = "%s|Images|%s|%s|%s" % (
                        exp.get_tag_stump(tag, 2),
                        exp.get_tag_instance(tag),
                        exp.get_tag_timepoint(tag),
                        well,
                    )
                    urls = meta.get_field(image_tag, [])
                    for url in urls:
                        os.startfile(url)

        # print self.current_node.get_well_ids()
        # print self.current_node.get_parent()

        ##        message = ''
        ##        for well in sorted(self.current_node.get_well_ids()):
        ##            message += ', '.join(well)
        ##            message += '\n'
        ##        msg = wx.MessageDialog(self, message, caption='Info', style=wx.OK | wx.ICON_INFORMATION | wx.STAY_ON_TOP, pos=(200,200))
        ##        msg.ShowModal()
        ##        msg.Destroy()

        try:
            bench = wx.GetApp().get_bench()
        except:
            return

        # --- Update the Bench view ---
        bench.set_timepoint(self.current_node.get_timepoint())
        bench.taglistctrl.set_selected_protocols([exp.get_tag_protocol(tag) for tag in self.current_node.get_tags()])
        bench.group_checklist.SetCheckedStrings(
            [exp.PlateDesign.get_plate_group(well[0]) for well in self.current_node.get_well_ids()]
        )
        bench.update_plate_groups()
        bench.update_well_selections()

        try:
            exptsettings = wx.GetApp().get_exptsettings()
        except:
            return
        # -- Update the expt setting/metadata view --#
        exptsettings.OnLeafSelect()
        if self.current_node.get_tags():
            exptsettings.ShowInstance(self.current_node.get_tags()[0])

        ancestors = [
            exp.get_tag_stump(ptag, 2)
            for pnode in timeline.reverse_iter_tree(self.current_node)
            if pnode
            for ptag in pnode.tags
        ]
예제 #8
0
    def _on_mouse_click(self, evt):
        if self.current_node is None:
            return
        
        # --- Update the Bench view ---
        try:
            bench = wx.GetApp().get_bench()
        except: 
            return
	
        bench.set_timepoint(self.current_node.get_timepoint())
        bench.taglistctrl.set_selected_protocols(
            [exp.get_tag_protocol(tag) for tag in self.current_node.get_tags()])
        bench.group_checklist.SetCheckedStrings(
            [exp.PlateDesign.get_plate_group(well[0]) 
             for well in self.current_node.get_well_ids()])
        bench.update_plate_groups()
        bench.update_well_selections()
	bench.del_evt_button.Enable()
	
        # -- Update the expt setting/metadata view --#
        try:
            exptsettings = wx.GetApp().get_exptsettings()
        except:
            return
	
        exptsettings.OnLeafSelect()
        if self.current_node.get_tags():
            exptsettings.ShowInstance(self.current_node.get_tags()[0])
            
        ancestors = [exp.get_tag_stump(ptag, 2)
                     for pnode in timeline.reverse_iter_tree(self.current_node) if pnode
                     for ptag in pnode.tags]   
	
	# -- show the data url list --- #
        data_acquis = False

        for tag in self.current_node.get_tags():
	    if tag.startswith('DataAcquis'):
		data_acquis = True
		break
	    
	if data_acquis:
	    dia = DataLinkListDialog(self, self.current_node.get_well_ids())
	    if dia.ShowModal() == wx.ID_OK:
		if dia.output_options.GetSelection() == 0:
		    file_dlg = wx.FileDialog(None, message='Exporting Data URL...', 
		                             defaultDir=os.getcwd(), defaultFile='data urls', 
		                             wildcard='.csv', 
		                             style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
		    if file_dlg.ShowModal() == wx.ID_OK:
			os.chdir(os.path.split(file_dlg.GetPath())[0])
			myfile = open(file_dlg.GetPath(), 'wb')
			wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
			for row in dia.listctrl.get_selected_urls():
			    wr.writerow(row)
			myfile.close()	
			file_dlg.Destroy()
		if dia.output_options.GetSelection() == 1:
		    file_dlg = wx.FileDialog(None, message='Exporting Data URL...', 
		                            defaultDir=os.getcwd(), defaultFile='data urls', 
		                            wildcard='.csv', 
		                            style=wx.SAVE|wx.FD_OVERWRITE_PROMPT)
		    if file_dlg.ShowModal() == wx.ID_OK:
			os.chdir(os.path.split(file_dlg.GetPath())[0])
			myfile = open(file_dlg.GetPath(), 'wb')
			wr = csv.writer(myfile, quoting=csv.QUOTE_ALL)
			for row in dia.listctrl.get_all_urls():
			    wr.writerow(row)
			myfile.close()	
			file_dlg.Destroy()
		
		if dia.output_options.GetSelection() == 2:
		    image_urls = []
		    for row in dia.listctrl.get_selected_urls():
			image_urls.append(row[2])
		    if os.path.isfile('C:\Program Files\ImageJ\ImageJ.exe') is False:
			#err_dlg = wx.lib.dialogs.ScrolledMessageDialog(self, str("\n".join(urls)), "ERROR!! ImageJ was not found in C\Program Files directory to show following images")
			err_dlg = wx.MessageDialog(None, 'ImageJ was not found in C\Program Files directory to show images!!', 'Error', wx.OK | wx.ICON_ERROR)
			err_dlg.ShowModal()			 
			return 			
		    else:
			#TO DO: check the image format to be shown in ImageJ    
			ImageJPath = 'C:\Program Files\ImageJ\ImageJ.exe'
			subprocess.Popen("%s %s" % (ImageJPath, ' '.join(image_urls)))		    
			
	    dia.Destroy()	
    def get_ancestral_tags(self, node):
	return [exp.get_tag_stump(ptag, 2)
	        for pnode in timeline.reverse_iter_tree(node) if pnode
	        for ptag in pnode.tags]
 def get_ancestral_tags(self, node):
     return [
         exp.get_tag_stump(ptag, 2)
         for pnode in timeline.reverse_iter_tree(node) if pnode
         for ptag in pnode.tags
     ]