Skip to content

Commit fbe34e1

Browse files
authored
Helper function to replace all instances of a text string in the compute config file (#35)
1 parent 897ea95 commit fbe34e1

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

pubweb/helpers/preprocess_dataset.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,18 @@ def remove_param(self, name: str, force=False):
113113
self.logger.info("Saving parameters")
114114
self._write_json(self.params, "nextflow.json")
115115

116+
def update_compute(self, from_str, to_str, fp="nextflow.config"):
117+
"""Replace all instances of a text string in the compute config file."""
118+
119+
assert os.path.exists(fp), f"File does not exist: {fp}"
120+
with open(fp, 'r') as handle:
121+
compute = handle.read()
122+
n = len(compute.split(from_str)) - 1
123+
self.logger.info(f"Replacing {n:,} instances of {from_str} with {to_str} in {fp}")
124+
compute = compute.replace(from_str, to_str)
125+
with open(fp, 'wt') as handle:
126+
handle.write(compute)
127+
116128
def wide_samplesheet(
117129
self,
118130
index=["sampleIndex", "sample", "lane"],

0 commit comments

Comments
 (0)