diff --git a/api/scpca_portal/models/computed_file.py b/api/scpca_portal/models/computed_file.py index 537339a1..713c0429 100644 --- a/api/scpca_portal/models/computed_file.py +++ b/api/scpca_portal/models/computed_file.py @@ -78,12 +78,6 @@ class OutputFileTypes: def __str__(self): return f"Computed file for '{self.project or self.sample}'" - @staticmethod - def get_readme_contents(readme_path: str) -> str: - with open(readme_path, "r") as readme_file: - date = utils.get_today_string() - return f"Generated on: {date}\n\n{readme_file.read()}" - @classmethod def get_project_multiplexed_file(cls, project, sample_to_file_mapping, workflow_versions): """Prepares a ready for saving single data file of project's combined multiplexed data.""" @@ -97,9 +91,9 @@ def get_project_multiplexed_file(cls, project, sample_to_file_mapping, workflow_ ) with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_MULTIPLEXED_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_MULTIPLEXED_FILE_PATH), ) zip_file.write( project.output_multiplexed_metadata_file_path, computed_file.metadata_file_name @@ -132,9 +126,9 @@ def get_project_single_cell_file(cls, project, sample_to_file_mapping, workflow_ ) with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_FILE_PATH), ) zip_file.write( project.output_single_cell_metadata_file_path, computed_file.metadata_file_name @@ -167,9 +161,9 @@ def get_project_spatial_file(cls, project, sample_to_file_mapping, workflow_vers ) with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_SPATIAL_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_SPATIAL_FILE_PATH), ) zip_file.write( project.output_spatial_metadata_file_path, computed_file.metadata_file_name @@ -211,9 +205,9 @@ def get_sample_multiplexed_file( if not os.path.exists(computed_file.zip_file_path): with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_MULTIPLEXED_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_MULTIPLEXED_FILE_PATH), ) zip_file.write( sample.output_multiplexed_metadata_file_path, @@ -242,9 +236,9 @@ def get_sample_single_cell_file(cls, sample, libraries, workflow_versions): file_paths = [] with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_FILE_PATH), ) zip_file.write( sample.output_single_cell_metadata_file_path, @@ -285,9 +279,9 @@ def get_sample_spatial_file(cls, sample, libraries, workflow_versions): file_paths = [] with ZipFile(computed_file.zip_file_path, "w") as zip_file: - zip_file.writestr( + zip_file.write( + ComputedFile.README_SPATIAL_FILE_PATH, ComputedFile.OUTPUT_README_FILE_NAME, - ComputedFile.get_readme_contents(ComputedFile.README_SPATIAL_FILE_PATH), ) zip_file.write( sample.output_spatial_metadata_file_path, diff --git a/api/scpca_portal/models/project.py b/api/scpca_portal/models/project.py index 49188f49..ad514c86 100644 --- a/api/scpca_portal/models/project.py +++ b/api/scpca_portal/models/project.py @@ -8,7 +8,7 @@ from django.db import models -from scpca_portal import common +from scpca_portal import common, utils from scpca_portal.models.base import TimestampedModel from scpca_portal.models.computed_file import ComputedFile from scpca_portal.models.contact import Contact @@ -451,7 +451,11 @@ def create_single_cell_readme_file(self): readme_template = readme_template_file.read() with open(ComputedFile.README_FILE_PATH, "w") as readme_file: readme_file.write( - readme_template.format(project_accession=self.scpca_id, project_url=self.url) + readme_template.format( + project_accession=self.scpca_id, + project_url=self.url, + date=utils.get_today_string(), + ) ) def create_multiplexed_readme_file(self): @@ -460,7 +464,11 @@ def create_multiplexed_readme_file(self): readme_template = readme_template_file.read() with open(ComputedFile.README_MULTIPLEXED_FILE_PATH, "w") as readme_file: readme_file.write( - readme_template.format(project_accession=self.scpca_id, project_url=self.url) + readme_template.format( + project_accession=self.scpca_id, + project_url=self.url, + date=utils.get_today_string(), + ) ) def create_spatial_readme_file(self): @@ -469,7 +477,11 @@ def create_spatial_readme_file(self): readme_template = readme_template_file.read() with open(ComputedFile.README_SPATIAL_FILE_PATH, "w") as readme_file: readme_file.write( - readme_template.format(project_accession=self.scpca_id, project_url=self.url) + readme_template.format( + project_accession=self.scpca_id, + project_url=self.url, + date=utils.get_today_string(), + ) ) def get_bulk_rna_seq_sample_ids(self):