File size: 2,306 Bytes
5ad11ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
from qtpy.QtWidgets import QMainWindow, QLabel,QGridLayout
import napari
from qtpy import uic
from pathlib import Path
import pandas as pd
import dask.array as da
# Define the main window class
class FancyGUI(QMainWindow):
def __init__(self, napari_viewer:napari.Viewer,codebook:pd.DataFrame,fovs,x_loc,y_loc,img_scale): # include napari_viewer as argument (it has to have this name)
super().__init__()
self.viewer = napari_viewer
self.fovs = fovs
self.x_loc = x_loc
self.y_loc = y_loc
self.img_scale=img_scale
self.codebook = codebook
self.UI_FILE = str(Path(__file__).parent / "barcode_viewer.ui") # path to .ui file
uic.loadUi(self.UI_FILE, self) # load QtDesigner .ui file
# self.widgetArrangement = QGridLayout()
# self.widgetArrangement.addWidget(self.geneName)
# self.widgetArrangement.addWidget(self.barcode)
# self.setLayout(self.widgetArrangement)
self.btnMakeLayer.clicked.connect(self.makeGeneLayer)
self.viewer.dims.events.connect(self.updateBarcode)
def updateBarcode(self):
current_slice = self.viewer.dims.current_step
self.lblDecodedBarcode.setText(self.codebook.iloc[current_slice[0]]['barcode'])
self.lbDecodedGeneName.setText(self.codebook.iloc[current_slice[0]]['name'])
def makeGeneLayer(self):
current_slice = self.viewer.dims.current_step
for idx,fov in enumerate(self.fovs):
if idx==0:
l = self.viewer.layers[f"decoded"]
else:
try:
l = self.viewer.layers[f"decoded [{idx}]"]
except KeyError:
continue
self.viewer.add_image(
da.repeat(
da.stack([l.data[current_slice[0],:,:,:,:]],axis=0),
repeats = len(self.codebook),
axis=0),
name=f"Gene: {current_slice[0]} decoded [{idx}]",
translate=(self.x_loc[idx],-self.y_loc[idx]),
scale=self.img_scale,
)
print("Layers added")
|