Skip to content

Commit

Permalink
Merge pull request #253 from CovertLab/special-char
Browse files Browse the repository at this point in the history
Do not allow special characters in experiment ID
  • Loading branch information
thalassemia authored Nov 29, 2024
2 parents 78aa2f4 + 6acb308 commit a857d48
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 20 deletions.
7 changes: 3 additions & 4 deletions doc/experiments.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,11 @@ documented in :ref:`/workflows.rst`.
# chains if possible.
"inherit_from": [],
# String that uniquely identifies simulation (or workflow if passed
# as input to runscripts/workflow.py). Avoid special characters as we
# quote experiment IDs using urlparse.parse.quote_plus, which may make
# experiment IDs with special characters hard to deciphe later.
# as input to runscripts/workflow.py). Special characters and spaces
# are not allowed (hyphens are OK).
"experiment_id": "experiment_id_one"
# Whether to append date and time to experiment ID in the following format
# experiment_id_%d-%m-%Y_%H-%M-%S.
# experiment_id_%Y%m%d-%H%M%S.
"suffix_time": true,
# Optional string description of simulation
"description": "",
Expand Down
9 changes: 7 additions & 2 deletions ecoli/experiments/ecoli_master_sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,13 @@ def run(self):
self.experiment_id = datetime.now().strftime(
f"{self.experiment_id_base}_%Y%m%d-%H%M%S"
)
# Special characters can break Hive partitioning so quote them
self.experiment_id = parse.quote_plus(self.experiment_id)
# Special characters can break Hive partitioning so do not allow them
if self.experiment_id != parse.quote_plus(self.experiment_id):
raise TypeError(
"Experiment ID cannot contain special characters"
f"that change the string when URL quoted: {self.experiment_id}"
f" != {parse.quote_plus(self.experiment_id)}"
)
experiment_config["experiment_id"] = self.experiment_id
experiment_config["profile"] = self.profile

Expand Down
10 changes: 6 additions & 4 deletions ecoli/processes/polypeptide_elongation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,10 +1139,12 @@ def request(self, states, aasInSequences):
request_ppgpp_metabolites = -delta_metabolites
ppgpp_request = counts(states["bulk"], self.process.ppgpp_idx)
bulk_request.append((self.process.ppgpp_idx, ppgpp_request))
bulk_request.append((
self.process.ppgpp_rxn_metabolites_idx,
request_ppgpp_metabolites.astype(int),
))
bulk_request.append(
(
self.process.ppgpp_rxn_metabolites_idx,
request_ppgpp_metabolites.astype(int),
)
)

return (
fraction_charged,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-anaerobic.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily anaerobic",
"experiment_id": "daily-anaerobic",
"single_daughters": true,
"generations": 8,
"fail_at_total_time": true,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-glucose-minimal.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily build",
"experiment_id": "daily-build",
"single_daughters": true,
"generations": 16,
"fail_at_total_time": true,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-new-gene-gfp.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily new gene GFP",
"experiment_id": "daily-new-gene-gfp",
"single_daughters": true,
"generations": 4,
"fail_at_total_time": true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily no growth rate control",
"experiment_id": "daily-no-growth-rate-control",
"single_daughters": true,
"generations": 4,
"fail_at_total_time": true,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-no-operons.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily no operons",
"experiment_id": "daily-no-operons",
"single_daughters": true,
"generations": 4,
"fail_at_total_time": true,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-superhelical-density.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily superhelical density",
"experiment_id": "daily-superhelical-density",
"single_daughters": true,
"generations": 4,
"fail_at_total_time": true,
Expand Down
2 changes: 1 addition & 1 deletion runscripts/jenkins/configs/ecoli-with-aa.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"experiment_id": "Daily with AA",
"experiment_id": "daily-with-aa",
"single_daughters": true,
"generations": 8,
"fail_at_total_time": true,
Expand Down
12 changes: 9 additions & 3 deletions runscripts/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import subprocess
import warnings
from datetime import datetime
from urllib import parse

from pyarrow import fs

Expand Down Expand Up @@ -202,7 +203,7 @@ def generate_code(config):
kb_dir = os.path.dirname(sim_data_path)
run_parca = [
f"\tfile('{kb_dir}').copyTo(\"${{params.publishDir}}/${{params.experimentId}}/parca/kb\")",
f"\tChannel.fromPath('{kb_dir}').toList().set {{ kb }}"
f"\tChannel.fromPath('{kb_dir}').toList().set {{ kb }}",
]
else:
run_parca = ["\trunParca(params.config)", "\trunParca.out.toList().set {kb}"]
Expand Down Expand Up @@ -294,8 +295,13 @@ def main():
if config["suffix_time"]:
current_time = datetime.now().strftime("%Y%m%d-%H%M%S")
experiment_id = experiment_id + "_" + current_time
config["suffix_time"] = False

# Special characters are messy so do not allow them
if experiment_id != parse.quote_plus(experiment_id):
raise TypeError(
"Experiment ID cannot contain special characters"
f"that change the string when URL quoted: {experiment_id}"
f" != {parse.quote_plus(experiment_id)}"
)
# Resolve output directory
if "out_uri" not in config["emitter_arg"]:
out_uri = os.path.abspath(config["emitter_arg"]["out_dir"])
Expand Down

0 comments on commit a857d48

Please sign in to comment.