Skip to content
Merged
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
4 changes: 4 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import bfabric_web_apps

# Initialize the Dash app
app = bfabric_web_apps.create_app()
2 changes: 2 additions & 0 deletions backend/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from .app_state import AppState
from .models import Plate, PlateWell, Sample, Measurement, AppSpecificFile
55 changes: 55 additions & 0 deletions backend/app_state.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from pydantic import BaseModel, Field
from typing import List, Dict, Any
from .models import Plate, PlateWell, Sample


class AppState(BaseModel):

plate_registry: List[Plate] = Field(default_factory=list)
sample_registry: List[Sample] = Field(default_factory=list)
uploaded_files_base64: Dict[str, str] = Field(default_factory=dict) # dict key is filename/id, value is base64 encoded content


# to and from json need to respect the model structure
def to_json(self) -> str:
return self.model_dump_json()


@classmethod
def from_json(cls, json_str: str) -> "AppState":
return cls.model_validate_json(json_str)


@property
def plate_well_by_id(self) -> Dict[str, Dict[str, PlateWell]]:
out = {}
for plate in self.plate_registry:
out[plate.plate_id] = {well.well_position_id: well for well in plate.plate_wells}
return out


@property
def plate_by_id(self) -> Dict[str, Plate]:
return {plate.plate_id: plate for plate in self.plate_registry}


@property
def sample_by_id(self) -> Dict[str, Sample]:
return {sample.file_sample_identifier: sample for sample in self.sample_registry}


@property
def all_samples_by_bfabric_id(self) -> Dict[str, List[Sample]]:
return {sample.sample_id: sample for sample in self.sample_registry if sample.sample_id}


@property
def platewells_by_sample_id(self) -> Dict[str, List[PlateWell]]:
result = {}
for plate in self.plate_registry:
for well in plate.plate_wells:
sid = well.get_sample(self).file_sample_identifier
if sid:
result.setdefault(sid, []).append(well)
return result

Loading
Loading