Analysis Engine
biopro_sdk.plugin.analysis
Analysis base classes for BioPro SDK.
Provides abstract interfaces for plugin analysis logic and background worker support for running analyses in separate threads without blocking the UI.
AnalysisBase
Bases: ABC
Abstract base for all plugin analysis logic.
Separates analysis logic from UI, enabling: - Easy unit testing of analysis algorithms - Reusable analysis in command-line scripts - Background thread execution via AnalysisWorker - State + results serialization
The plugin UI should delegate all scientific computation to a class inheriting from this, keeping the UI layer thin and testable.
Example
class MyAnalyzer(AnalysisBase): ... def run(self, state: MyState) -> dict: ... # Your analysis logic here ... results = process_image(state.image_path) ... return {"bands": results} ... ... def validate(self, state: MyState) -> tuple[bool, str]: ... if not state.image_path: ... return False, "Image path is required" ... return True, ""
Source code in src/biopro_sdk/plugin/analysis.py
__init__(plugin_id)
Initialize the analyzer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plugin_id
|
str
|
Unique identifier for the plugin |
required |
cancel()
is_cancelled()
run(state=None)
abstractmethod
Execute the analysis with the given state.
This method should contain all scientific computation and should NOT interact with PyQt6 widgets or UI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PluginState | None
|
Plugin state containing analysis parameters |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary with analysis results. Keys should match state fields |
dict[str, Any]
|
or be documented in your plugin's README. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If state is invalid or analysis fails |
Source code in src/biopro_sdk/plugin/analysis.py
validate(state)
Validate that the state has all required data for analysis.
Called before running analysis. Override to implement custom validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
PluginState
|
Plugin state to validate |
required |
Returns:
| Type | Description |
|---|---|
tuple[bool, str]
|
Tuple of (is_valid, error_message). If valid, error_message should be empty. |
Source code in src/biopro_sdk/plugin/analysis.py
AnalysisRunnable
Bases: QRunnable
Wrapper to execute an AnalysisWorker within a QThreadPool.
This adapter allows the QObject-based AnalysisWorker to run in the standard QThreadPool management system.
Source code in src/biopro_sdk/plugin/analysis.py
__init__(worker)
Initialize the runnable wrapper with a target worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
worker
|
AnalysisWorker
|
The background AnalysisWorker controller containing the job. |
required |
Source code in src/biopro_sdk/plugin/analysis.py
run()
Execution entry point for the thread pool.
Source code in src/biopro_sdk/plugin/analysis.py
AnalysisWorker
Bases: QObject
Background worker for running analysis in a separate thread.
Prevents long-running analysis from blocking the UI. Emits signals to notify the UI of progress and completion.
Example
analyzer = MyAnalyzer("my_plugin") worker = AnalysisWorker(analyzer, state) thread = QThread() worker.moveToThread(thread) worker.finished.connect(on_analysis_done) worker.error.connect(on_analysis_error) thread.started.connect(worker.run) thread.start()
Source code in src/biopro_sdk/plugin/analysis.py
__init__(analyzer, state, parent=None)
Initialize the worker.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
analyzer
|
AnalysisBase
|
AnalysisBase subclass instance |
required |
state
|
PluginState | None
|
PluginState instance with analysis parameters |
required |
parent
|
QObject | None
|
Optional parent QObject |
None
|
Source code in src/biopro_sdk/plugin/analysis.py
cancel()
run()
Execute the analysis and emit results or error signal.
This method is called when the worker is moved to a QThread and the thread is started.
Source code in src/biopro_sdk/plugin/analysis.py
biopro_sdk.plugin.managed_task
Functional Task Utilities for BioPro SDK.
Enables developers to run arbitrary functions (downloads, I/O, networking) on the global TaskScheduler without needing to subclass AnalysisBase manually.
FunctionalTask
Bases: AnalysisBase
A proxy that converts a callable into a BioPro Analysis task.
Example
def my_download(): ... return {"file": "data.fcs"} task = FunctionalTask(my_download, "my_plugin") task_scheduler.submit(task, None)
Source code in src/biopro_sdk/plugin/managed_task.py
__init__(func, plugin_id='unknown', name='Utility Task')
Initialize the task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable[[], Any]
|
The function to execute. Should return a dict or None. |
required |
plugin_id
|
str
|
The ID of the plugin owning this task (optional). |
'unknown'
|
name
|
str
|
Human-readable name for logging/UI. |
'Utility Task'
|
Source code in src/biopro_sdk/plugin/managed_task.py
run(state=None)
Executes the wrapped function and returns standardized results.