Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 142 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
FROM ubuntu:20.04

# Set environment variables to make the build non-interactive
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=Etc/UTC

# Update and install prerequisites for adding the PPA
RUN apt-get update && apt-get install -y \
software-properties-common \
build-essential \
libssl-dev \
libffi-dev \
curl \
lsb-release \
&& add-apt-repository -y ppa:deadsnakes/ppa \
&& apt-get update \
&& apt-get install -y \
python3.10 \
python3.10-dev \
python3.10-venv \
python3.10-distutils \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

# Install pip using the official get-pip.py script
RUN ln -sf /usr/bin/python3.10 /usr/bin/python
RUN curl -O https://bootstrap.pypa.io/get-pip.py && python get-pip.py

# Set the working directory in the container
WORKDIR /app

# Copy the requirements.txt file to the working directory
COPY requirements.txt .

RUN pip install -r requirements.txt

RUN apt-get update && \
# apt-get install -y libx11-dev libgl1-mesa-dev && \
apt-get install -y libx11-dev libgl1-mesa-dev libxcomposite-dev libxrandr-dev libxss-dev libxcursor-dev

RUN apt-get install -y libx11-xcb1 libxcb-xinerama0 libxkbcommon0 libglib2.0-0


RUN apt-get update && apt-get install -y \
libx11-xcb1 \
libxcb-util1 \
# libxcb-xinerama0 \
libxcb-icccm4 \
libxcb-image0 \
libxcb-keysyms1 \
libxcb-randr0 \
libxcb-render-util0 \
libxcb-render0 \
libxcb-shape0 \
libxcb-shm0 \
libxcb-sync1 \
libxcb-xfixes0 \
libxcb-xkb1 \
x11-utils \
libxkbcommon-x11-0

RUN export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/local/lib/python3.10/dist-packages/PyQt5/Qt5/plugins/platforms
RUN export QT_DEBUG_PLUGINS=1


# Copy Cellscanner files to the working directory
COPY cellscanner ./

# Specify the command to run the application (optional)
CMD ["python", "Cellscanner.py"]



# docker run --rm -it --entrypoint /bin/bash cellscanner
# docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v .:/media cellscanner




# # FROM DEEPSEEK AS ALTERNATIVE -- NOT WORKING MOUHAHA
# FROM ubuntu:20.04

# # Set environment variables
# ENV DEBIAN_FRONTEND=noninteractive \
# TZ=Etc/UTC \
# QT_QPA_PLATFORM_PLUGIN_PATH=/usr/local/lib/python3.10/dist-packages/PyQt5/Qt5/plugins/platforms \
# QT_DEBUG_PLUGINS=1

# # Combine all package installations into a single layer
# RUN apt-get update && apt-get install -y --no-install-recommends \
# software-properties-common \
# build-essential \
# libssl-dev \
# libffi-dev \
# curl \
# lsb-release \
# python3.10 \
# python3.10-dev \
# python3.10-venv \
# python3.10-distutils \
# libx11-dev \
# libgl1-mesa-dev \
# libxcomposite-dev \
# libxrandr-dev \
# libxss-dev \
# libxcursor-dev \
# libx11-xcb1 \
# libxcb-xinerama0 \
# libxkbcommon0 \
# libglib2.0-0 \
# libxcb-util1 \
# libxcb-icccm4 \
# libxcb-image0 \
# libxcb-keysyms1 \
# libxcb-randr0 \
# libxcb-render-util0 \
# libxcb-render0 \
# libxcb-shape0 \
# libxcb-shm0 \
# libxcb-sync1 \
# libxcb-xfixes0 \
# libxcb-xkb1 \
# x11-utils \
# libxkbcommon-x11-0 && \
# add-apt-repository -y ppa:deadsnakes/ppa && \
# apt-get clean && \
# rm -rf /var/lib/apt/lists/*

# # Install pip and setup Python
# RUN ln -sf /usr/bin/python3.10 /usr/bin/python && \
# curl -sS https://bootstrap.pypa.io/get-pip.py | python -

# WORKDIR /app

# # Install Python dependencies first (better layer caching)
# COPY requirements.txt .
# RUN pip install --no-cache-dir -r requirements.txt

# # Copy application files
# COPY cellscanner ./

# CMD ["python", "Cellscanner.py"]
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ To run CellScanner with its GUI, you may now run:
# Always remember to activate your conda environment, if you set one for CellScanner
conda activate cellscanner
# If `python` returns an error message that is not there, try with `python3` instead
python Cellscanner.py
python cellscanner/Cellscanner.py
```

This will pop-up CellScanner where you can now import your data, fill in your training parameters and
Expand Down Expand Up @@ -90,7 +90,7 @@ Once your configuration file is ready, you may run CellScanner CLI :

```bash
conda activate cellscanner
python CellscannerCLI.py --config config.yml
python cellscanner/CellscannerCLI.py --config config.yml
```


Expand All @@ -107,5 +107,22 @@ For the new features that have been added, a manuscript is in process. :pencil:



## Docker

In linux, remember to disable access control for local connections first:

```bash
xhost +local:
```

then, you need to run something line:

```bash
docker run -e DISPLAY=$DISPLAY -v /tmp/.X11-unix:/tmp/.X11-unix -v ./Testfiles:/csFiles hariszaf/cell_scanner
```

where `Testfiles` is the directory where you have you input data, and also, where CellScanner will return its findings, on your local machine.

`csFiles` is the output directory of CellScanner within the container, so make sure you always keep it like that in your command.


Binary file removed Tutorial/Images/GUI.png
Binary file not shown.
Binary file removed Tutorial/Images/Import_data_step.png
Binary file not shown.
Binary file removed Tutorial/Images/Run_prediction_step.png
Binary file not shown.
Binary file removed Tutorial/Images/Train_model_step.png
Binary file not shown.
Binary file removed Tutorial/Images/growthcurves.png
Binary file not shown.
65 changes: 0 additions & 65 deletions Tutorial/README.md

This file was deleted.

94 changes: 26 additions & 68 deletions Cellscanner.py → cellscanner/Cellscanner.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,5 @@
# CellScanner.py
import os
import sys

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QFont
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,\
QPushButton, QWidget, QLabel, QScrollArea

from scripts.helpers import button_style, get_app_dir
from scripts.ImportFiles import ImportFilePanel
from scripts.TrainingModel import TrainModelPanel
from scripts.Prediction import PredictionPanel


#!/usr/bin/env python
"""
CellScanner - A Comprehensive Flow Cytometry Data Analysis Tool

==========================================
Overview
==========================================
Expand All @@ -36,78 +20,52 @@
- **Heterogeneity Analysis**: Perform heterogeneity assessments using both simple range-based methods and MiniBatchKMeans clustering.
- **Interactive Visualizations**: Generate and save interactive 3D scatter plots, pie charts, and bar charts to visualize predictions, gating results, and heterogeneity measures.


==========================================
Modules and Functions
Cellscanner.py
==========================================

1. **get_app_dir()**:
- **Description**: Determines the base path of the application, accommodating both development and bundled executable environments (e.g., PyInstaller).
- **Returns**: Absolute path to the directory where the script or executable is located.

2. **get_abs_path(relative_path)**:
- **Description**: Converts a relative file path to an absolute path based on the application's base directory.
- **Parameters**:
- `relative_path` (str): The relative path of the resource.
- **Returns**: Absolute path to the specified resource.

3. **NeuralNetworkGUI (class)**:
- **Description**: The primary GUI class inheriting from `QMainWindow`. It orchestrates the layout, user interactions, and integrates various panels for data importation, model training, prediction, and analysis.
- **Attributes**:
- `model`: Trained neural network model.
- `scaler`: Scaler object for data preprocessing.
- `label_encoder`: Encoder for translating model predictions into readable labels.
- **Methods**:
- `__init__()`: Initializes the GUI components, including title, logo, buttons, and panels.
- `init_predict_panel()`: Configures the prediction panel with options for selecting coculture files, axis channels, gating parameters, and initiating predictions.
- `toggle_file_panel()`: Shows or hides the data import panel based on user interaction.
- `toggle_train_panel()`: Shows or hides the model training panel.
- `toggle_gating_options()`: Displays or conceals gating options contingent on the gating checkbox state.
- `toggle_predict_panel()`: Shows or hides the prediction panel.
- `choose_coculture_file()`: Facilitates the selection of coculture files and populates axis selection dropdowns with appropriate channels.
- `run_prediction()`: Executes the prediction workflow, including loading models, predicting species, applying gating, performing heterogeneity analysis, and generating visualizations.
- `open_documentation()`: Opens the application's documentation webpage in the user's default web browser.

4. **Main Application Loop**:
- **Description**: Initializes the QApplication, instantiates the main GUI window, and executes the application loop to render the GUI.
Initializes the QApplication, instantiates the main GUI window, and executes the application loop to render the GUI.

Usage:
- Import Files: Allows users to import monoculture and blank files for analysis.
- Train Neural Network: Provides an interface to train a neural network model on the imported data.
- Predict Coculture: Allows users to select a coculture file, predict species within the sample, and optionally apply gating and heterogeneity analysis.
"""
import os
import sys

Dependencies:
- Python 3.x
- PyQt5
- TensorFlow
- fcsparser
- joblib
- numpy
- shutil
- atexit
from PyQt5.QtCore import Qt
from PyQt5.QtGui import QPixmap, QFont
from PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QHBoxLayout,\
QPushButton, QWidget, QLabel, QScrollArea

from scripts.helpers import get_app_dir
from scripts.GUIhelpers import button_style
from scripts.ImportFiles import ImportFilePanel
from scripts.TrainingModel import TrainModelPanel
from scripts.Prediction import PredictionPanel

"""
Authors:
- Ermis Ioannis Michail Delopoulos
- Haris Zafeiropoulos

Date: 2024-2025

"""

class NeuralNetworkGUI(QMainWindow):
"""
Main class of the CellScanner GUI.
It builds a PyQT app with 3 main panels:
- Importing files
- Training
- Prediction

NOTE: The Training panel is delivered thanks to the TrainModelPanel class of the TrainingModel.py
The Importing files and the Predictions panels though, they are described as features of the NeuralNetworkGUI class.
- Importing files (:class:`scripts.ImportFiles.ImportFilePanel`)
- Training (:class:`scripts.TrainingModel.TrainModelPanel`)
- Prediction (:class:`scripts.Prediction.PredictionPanel`)
"""
def __init__(self):
super().__init__()
self.setWindowTitle("CellScanner")
self.setGeometry(100, 100, 850, 1800)
# setGeometry(x, y, width, height) x, y stand for top-left corner
self.setGeometry(100, 100, 950, 2100)

# Initialize model-related attributes
self.model = None
Expand Down Expand Up @@ -207,21 +165,21 @@ def __init__(self):
self.setCentralWidget(scroll_area)

def toggle_file_panel(self):
# Toggle the visibility of the file import panel
"""Shows or hides the data import panel based on user interaction."""
if self.file_panel.isVisible():
self.file_panel.hide()
else:
self.file_panel.show()

def toggle_train_panel(self):
# Toggle the visibility of the train model panel
"""Shows or hides the model training panel."""
if self.train_panel.isVisible():
self.train_panel.hide()
else:
self.train_panel.show()

def toggle_predict_panel(self):
# Toggle the visibility of the predict panel
"""Shows or hides the predict panel"""
if self.predict_panel.isVisible():
self.predict_panel.hide()
else:
Expand Down
Loading