From fc14800f4ac409486d9d5ed125b99f01578dd327 Mon Sep 17 00:00:00 2001 From: glrs <5999366+glrs@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:38:58 +0100 Subject: [PATCH 1/2] Remove variables that are now part of the AbstractProject class | rearrange/clean methods --- lib/realms/smartseq3/ss3_project.py | 68 ++++++++++++----------------- 1 file changed, 29 insertions(+), 39 deletions(-) diff --git a/lib/realms/smartseq3/ss3_project.py b/lib/realms/smartseq3/ss3_project.py index e15f8dc..c6b55e9 100644 --- a/lib/realms/smartseq3/ss3_project.py +++ b/lib/realms/smartseq3/ss3_project.py @@ -35,45 +35,13 @@ def __init__(self, doc, yggdrasil_db_manager): 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() - # 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 - self.samples = [] - - def _extract_project_info(self): - """ - Extracts project information from the provided document. - - Returns: - dict: A dictionary containing selected project information or an empty dictionary in case of an error. - """ - try: - project_info = { - "project_name": self.doc.get("project_name", ""), - "project_id": self.doc.get("project_id", "Unknown_Project"), - "escg_id": self.doc.get("customer_project_reference"), - "library_prep_option": self.doc.get("details", {}).get( - "library_prep_option" - ), - "contact": self.doc.get("contact"), # Is this an email or a name? - "ref_genome": self.doc.get("reference_genome"), - "organism": self.doc.get("details", {}).get("organism"), - "sequencing_setup": self.doc.get("details", {}).get("sequencing_setup"), - } - - return project_info - except Exception as e: - logging.error(f"Error occurred while extracting project information: {e}") - return ( - {} - ) # Return an empty dict or some default values to allow continuation def check_required_fields(self): """ @@ -123,6 +91,34 @@ def _is_field(self, field_path, data): return False return True + def _extract_project_info(self): + """ + Extracts project information from the provided document. + + Returns: + dict: A dictionary containing selected project information or an empty dictionary in case of an error. + """ + try: + project_info = { + "project_name": self.doc.get("project_name", ""), + "project_id": self.doc.get("project_id", "Unknown_Project"), + "escg_id": self.doc.get("customer_project_reference"), + "library_prep_option": self.doc.get("details", {}).get( + "library_prep_option" + ), + "contact": self.doc.get("contact"), # Is this an email or a name? + "ref_genome": self.doc.get("reference_genome"), + "organism": self.doc.get("details", {}).get("organism"), + "sequencing_setup": self.doc.get("details", {}).get("sequencing_setup"), + } + + return project_info + except Exception as e: + logging.error(f"Error occurred while extracting project information: {e}") + return ( + {} + ) # Return an empty dict or some default values to allow continuation + # TODO: Check whether this would be better fit in the sample_file_handler def ensure_project_directory(self): """ @@ -242,14 +238,8 @@ def _generate_ngi_report(self): def create_slurm_job(self, sample): """ Placeholder for creating a Slurm job on the project level. - Not used in the current implementation, but demanded by the RealmTemplate (perhaps reconsider template). + Not used in the current implementation, but demanded by the template class (perhaps reconsider template). """ - # try: - # output_file = f"sim_out/10x/{sample['scilife_name']}_slurm_script.sh" - # # Use your method to generate the Slurm script here - # generate_slurm_script(sample, "sim_out/10x/slurm_template.sh", output_file) - # except Exception as e: - # logging.warning(f"Error in creating Slurm job for sample {sample['scilife_name']}: {e}") pass # def submit_job(self, script): From 6c719cd07228d7233f87d1a3d1e83eb2715e90d2 Mon Sep 17 00:00:00 2001 From: glrs <5999366+glrs@users.noreply.github.com> Date: Fri, 22 Nov 2024 16:39:21 +0100 Subject: [PATCH 2/2] Rearrange methods --- lib/realms/smartseq3/ss3_sample.py | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/realms/smartseq3/ss3_sample.py b/lib/realms/smartseq3/ss3_sample.py index 1a33cd9..d861381 100644 --- a/lib/realms/smartseq3/ss3_sample.py +++ b/lib/realms/smartseq3/ss3_sample.py @@ -126,25 +126,6 @@ async def pre_process(self): # If all pre-processing steps succeeded self.status = "pre_processed" - async def process(self): - """Process the sample by submitting its job.""" - logging.info("\n") - logging.info(f"[{self.id}] Processing...") - logging.debug(f"[{self.id}] Submitting job...") - self.status = "processing" - self.job_id = await self.sjob_manager.submit_job( - self.file_handler.slurm_script_path - ) - - if self.job_id: - logging.debug(f"[{self.id}] Job submitted with ID: {self.job_id}") - # Wait here for the monitoring to complete before exiting the process method - await self.sjob_manager.monitor_job(self.job_id, self) - logging.debug(f"[{self.id}] Job {self.job_id} monitoring complete.") - else: - logging.error(f"[{self.id}] Failed to submit job.") - self.status = "processing_failed" - def get_barcode(self): """ Retrieve and validate the barcode from sample data. @@ -338,6 +319,25 @@ def create_yaml_file(self, metadata) -> bool: """ return write_yaml(self.config, metadata) + async def process(self): + """Process the sample by submitting its job.""" + logging.info("\n") + logging.info(f"[{self.id}] Processing...") + logging.debug(f"[{self.id}] Submitting job...") + self.status = "processing" + self.job_id = await self.sjob_manager.submit_job( + self.file_handler.slurm_script_path + ) + + if self.job_id: + logging.debug(f"[{self.id}] Job submitted with ID: {self.job_id}") + # Wait here for the monitoring to complete before exiting the process method + await self.sjob_manager.monitor_job(self.job_id, self) + logging.debug(f"[{self.id}] Job {self.job_id} monitoring complete.") + else: + logging.error(f"[{self.id}] Failed to submit job.") + self.status = "processing_failed" + def post_process(self): """ Post-process the sample after job completion.