Skip to content

Commit

Permalink
Merge pull request #24 from glrs/feature/ss3-dev
Browse files Browse the repository at this point in the history
Update to interact with YggDB and follow AbstractProject changes
  • Loading branch information
glrs authored Nov 20, 2024
2 parents 3d68887 + 73d438a commit 68759a9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
15 changes: 10 additions & 5 deletions lib/realms/smartseq3/ss3_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
from lib.base.abstract_project import AbstractProject
from lib.core_utils.config_loader import ConfigLoader
from lib.core_utils.logging_utils import custom_logger
from lib.module_utils.ngi_report_generator import generate_ngi_report

# from datetime import datetime
# from lib.couchdb.manager import YggdrasilDBManager
from lib.module_utils.ngi_report_generator import generate_ngi_report
from lib.realms.smartseq3.ss3_sample import SS3Sample

logging = custom_logger("SS3 Project")
Expand Down Expand Up @@ -35,12 +34,14 @@ def __init__(self, doc, yggdrasil_db_manager):
Args:
doc (dict): Document containing project metadata.
"""
super().__init__(doc, yggdrasil_db_manager)
self.doc = doc
self.ydm = yggdrasil_db_manager
self.proceed = self._check_required_fields()
self.proceed = self.check_required_fields()

# TODO: What if I return None if not self.proceed?
if self.proceed:
self.initialize_project_in_db()
self.project_info = self._extract_project_info()
self.project_dir = self.ensure_project_directory()
self.project_info["project_dir"] = self.project_dir
Expand Down Expand Up @@ -74,7 +75,7 @@ def _extract_project_info(self):
{}
) # Return an empty dict or some default values to allow continuation

def _check_required_fields(self):
def check_required_fields(self):
"""
Checks if the document contains all required fields.
Expand Down Expand Up @@ -154,6 +155,8 @@ async def launch(self):
logging.warning("No samples found for processing. Returning...")
return

self.add_samples_to_project_in_db()

# Pre-process samples
pre_tasks = [sample.pre_process() for sample in self.samples]
await asyncio.gather(*pre_tasks)
Expand Down Expand Up @@ -201,7 +204,9 @@ def extract_samples(self):
samples = []

for sample_id, sample_data in self.doc.get("samples", {}).items():
sample = SS3Sample(sample_id, sample_data, self.project_info, self.config)
sample = SS3Sample(
sample_id, sample_data, self.project_info, self.config, self.ydm
)

if sample.flowcell_id:
samples.append(sample)
Expand Down
9 changes: 8 additions & 1 deletion lib/realms/smartseq3/ss3_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class SS3Sample(AbstractSample):
file_handler (SampleFileHandler): Handler for sample files.
"""

def __init__(self, sample_id, sample_data, project_info, config):
def __init__(
self, sample_id, sample_data, project_info, config, yggdrasil_db_manager
):
"""
Initialize a SmartSeq3 sample instance.
Expand All @@ -44,6 +46,8 @@ def __init__(self, sample_id, sample_data, project_info, config):
self._id = sample_id
self.sample_data = sample_data
self.project_info = project_info
# TODO: ensure project_id is always available
self.project_id = self.project_info.get("project_id", "")

# Initialize barcode
self.barcode = self.get_barcode()
Expand All @@ -52,6 +56,7 @@ def __init__(self, sample_id, sample_data, project_info, config):
self.flowcell_id = self._get_latest_flowcell()

self.config = config
self.ydm = yggdrasil_db_manager
# self.job_id = None

# TODO: Currently not used much, but should be used if we write to a database
Expand Down Expand Up @@ -79,6 +84,8 @@ def status(self):
@status.setter
def status(self, value):
self._status = value
# Update the status in the database
self.ydm.update_sample_status(self.project_id, self.id, value)

async def pre_process(self):
"""Pre-process the sample by collecting metadata and creating YAML files."""
Expand Down

0 comments on commit 68759a9

Please sign in to comment.