Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/ss3 dev #25

Merged
merged 2 commits into from
Nov 29, 2024
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
68 changes: 29 additions & 39 deletions lib/realms/smartseq3/ss3_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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):
Expand Down
38 changes: 19 additions & 19 deletions lib/realms/smartseq3/ss3_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down