Skip to content

Commit

Permalink
use date as a template
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsmejia committed Nov 2, 2023
1 parent 4cfb3e2 commit b42420e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 22 deletions.
30 changes: 12 additions & 18 deletions api/scpca_portal/models/computed_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
20 changes: 16 additions & 4 deletions api/scpca_portal/models/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand Down

0 comments on commit b42420e

Please sign in to comment.