-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(starrynight): integrate starrynightmodules and massive refactor
- Loading branch information
Showing
27 changed files
with
628 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,17 @@ | ||
"""Job domain related validators.""" | ||
|
||
from pydantic import BaseModel | ||
|
||
from conductor.constants import JobInputSchema, JobOutputSchema, JobType | ||
from starrynight.modules.schema import Container | ||
|
||
|
||
class Job(BaseModel): | ||
"""Job create schema.""" | ||
|
||
id: int | None = None | ||
module_id: str | ||
step_id: int | ||
name: str | ||
description: str | ||
type: JobType | ||
outputs: dict[str, JobOutputSchema] | ||
inputs: dict[str, JobInputSchema] | ||
spec: Container | ||
|
||
model_config: dict = {"from_attributes": True} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""Create index for a project.""" | ||
|
||
from pathlib import Path | ||
|
||
from pipecraft.backend.snakemake import SnakeMakeBackend, SnakeMakeConfig | ||
|
||
from starrynight.experiments.common import DummyExperiment | ||
from starrynight.modules.gen_inv import GenInvModule | ||
from starrynight.pipelines.index import create_index_pipeline | ||
from starrynight.schema import DataConfig | ||
|
||
# Setup experiment | ||
data = DataConfig( | ||
dataset_path=Path("/datastore/cpg0999-merck-asma"), | ||
storage_path=Path("./run001/workspace"), | ||
workspace_path=Path("./run001/workspace"), | ||
) | ||
experiment = DummyExperiment(dataset_id="cpg0999-merck-asma") | ||
|
||
# Create the pipeline | ||
pipeline = create_index_pipeline(experiment, data) | ||
|
||
|
||
# Configure execution backend | ||
config = SnakeMakeConfig() | ||
exec_backend = SnakeMakeBackend( | ||
pipeline, config, data.storage_path, data.workspace_path | ||
) | ||
|
||
# Compile to get the generated snakemake file if | ||
# manual execution or inspection is required. | ||
# exec_backend.compile() | ||
|
||
# or execute directly | ||
# exec_backend.run() | ||
|
||
# ------------------------------------------------------------------- | ||
# Changing default module specs | ||
# ------------------------------------------------------------------- | ||
|
||
# Iniialize module with experiment and data | ||
gen_inv_module = GenInvModule.from_config(experiment, data) | ||
|
||
# Inspect current specification and make changes | ||
print(gen_inv_module.spec) | ||
gen_inv_module.spec.inputs[0].path = Path("path/to/my/parser.lark").resolve().__str__() | ||
|
||
# Add the configured module back to pipeline | ||
pipeline = create_index_pipeline( | ||
experiment, data, {GenInvModule.uid(): gen_inv_module.spec} | ||
) |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Starrynight experiments.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
"""Common experiment schemas.""" | ||
|
||
from abc import ABC, abstractstaticmethod | ||
from enum import Enum | ||
from pathlib import Path | ||
from typing import Unpack | ||
|
||
# Use a try block for backwards compatibility | ||
try: | ||
from typing import Self | ||
except ImportError: | ||
from typing_extensions import Self | ||
|
||
from pydantic import BaseModel | ||
|
||
|
||
class Experiment(BaseModel, ABC): | ||
"""Experiment configuration.""" | ||
|
||
dataset_id: str | ||
data_production_contact: str | None = None | ||
data_processing_contact: str | None = None | ||
|
||
@abstractstaticmethod | ||
def from_index(index_path: Path, **kwargs: Unpack) -> Self: | ||
"""Create experiment schema from index.""" | ||
pass | ||
|
||
|
||
class DummyExperiment(Experiment): | ||
"""DummyExperiment to bootstrap pipeline configuration.""" | ||
|
||
@staticmethod | ||
def from_index(index_path: Path) -> Self: | ||
"""Configure experiment with index.""" | ||
raise NotImplementedError | ||
|
||
|
||
class ImageMetadataGeneric(BaseModel): | ||
"""Generic metadata for an image.""" | ||
|
||
name: str | ||
batch_id: str | ||
plate_id: str | ||
site_id: str | ||
img_format: str | ||
assay_type: str | ||
channel_dict: dict | ||
|
||
|
||
class ImageFrameType(Enum): | ||
"""Frame type for image.""" | ||
|
||
ROUND = "round" | ||
SQUARE = "square" | ||
|
||
|
||
class AcquisitionOrderType(Enum): | ||
"""Acquisition order for image.""" | ||
|
||
SNAKE = "snake" | ||
ROWS = "rows" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
"""PCP Experiment.""" | ||
|
||
from collections.abc import Callable | ||
from pathlib import Path | ||
from typing import Self | ||
|
||
import polars as pl | ||
from pydantic import BaseModel, Field | ||
|
||
from starrynight.experiments.common import ( | ||
AcquisitionOrderType, | ||
Experiment, | ||
ImageFrameType, | ||
) | ||
from starrynight.schema import MeasuredInventory | ||
|
||
|
||
class SBSConfig(BaseModel): | ||
"""SBS experiment configuration.""" | ||
|
||
im_per_well: int = Field(320) | ||
n_cycles: int = Field(12) | ||
img_overlap_pct: int = Field(10) | ||
img_frame_type: ImageFrameType = Field(ImageFrameType.ROUND) | ||
channel_dict: dict | ||
acquisition_order: AcquisitionOrderType = Field(AcquisitionOrderType.SNAKE) | ||
|
||
|
||
class CPConfig(BaseModel): | ||
"""CP Experiment configuration.""" | ||
|
||
im_per_well: int = Field(1364) | ||
img_overlap_pct: int = Field(10) | ||
img_frame_type: ImageFrameType = Field(ImageFrameType.ROUND) | ||
channel_dict: dict | ||
acquisition_order: AcquisitionOrderType = Field(AcquisitionOrderType.SNAKE) | ||
|
||
|
||
class PCPGeneric(Experiment): | ||
"""PCP experiment configuration.""" | ||
|
||
path_parser: Callable[[str], MeasuredInventory] | ||
sbs_config: SBSConfig | ||
cp_config: CPConfig | ||
|
||
@staticmethod | ||
def from_index(index_path: Path) -> Self: | ||
if index_path.name.endswith(".csv"): | ||
index_df = pl.scan_csv(index_path) | ||
else: | ||
index_df = pl.scan_parquet(index_path) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.