Skip to content

Commit 3bd6fbb

Browse files
committed
f strings
1 parent b86ffd9 commit 3bd6fbb

File tree

3 files changed

+37
-93
lines changed

3 files changed

+37
-93
lines changed

microSALT/utils/job_creator.py

Lines changed: 24 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -238,35 +238,15 @@ def blast_subset(self, name, search_string):
238238
batchfile.write(
239239
self._singularity_exec(
240240
"blast",
241-
"blastn -db {}/{} -query {}/assembly/{}_contigs.fasta -out {}/blast_search/{}/loci_query_{}.txt -task megablast -num_threads {} -outfmt {}".format(
242-
os.path.dirname(ref),
243-
ref_nosuf,
244-
self.finishdir,
245-
self.name,
246-
self.finishdir,
247-
name,
248-
ref_nosuf,
249-
self.config["slurm_header"]["threads"],
250-
blast_format,
251-
),
241+
f"blastn -db {os.path.dirname(ref)}/{ref_nosuf} -query {self.finishdir}/assembly/{self.name}_contigs.fasta -out {self.finishdir}/blast_search/{name}/loci_query_{ref_nosuf}.txt -task megablast -num_threads {self.config['slurm_header']['threads']} -outfmt {blast_format}",
252242
)
253243
+ "\n"
254244
)
255245
else:
256246
batchfile.write(
257247
self._singularity_exec(
258248
"blast",
259-
"blastn -db {}/{} -query {}/assembly/{}_contigs.fasta -out {}/blast_search/{}/{}.txt -task megablast -num_threads {} -outfmt {}".format(
260-
os.path.dirname(ref),
261-
ref_nosuf,
262-
self.finishdir,
263-
self.name,
264-
self.finishdir,
265-
name,
266-
ref_nosuf,
267-
self.config["slurm_header"]["threads"],
268-
blast_format,
269-
),
249+
f"blastn -db {os.path.dirname(ref)}/{ref_nosuf} -query {self.finishdir}/assembly/{self.name}_contigs.fasta -out {self.finishdir}/blast_search/{name}/{ref_nosuf}.txt -task megablast -num_threads {self.config['slurm_header']['threads']} -outfmt {blast_format}",
270250
)
271251
+ "\n"
272252
)
@@ -278,17 +258,7 @@ def blast_subset(self, name, search_string):
278258
batchfile.write(
279259
self._singularity_exec(
280260
"blast",
281-
"blastn -db {}/{} -query {}/assembly/{}_contigs.fasta -out {}/blast_search/{}/{}.txt -task megablast -num_threads {} -outfmt {}".format(
282-
os.path.dirname(search_string),
283-
ref_nosuf,
284-
self.finishdir,
285-
self.name,
286-
self.finishdir,
287-
name,
288-
ref_nosuf,
289-
self.config["slurm_header"]["threads"],
290-
blast_format,
291-
),
261+
f"blastn -db {os.path.dirname(search_string)}/{ref_nosuf} -query {self.finishdir}/assembly/{self.name}_contigs.fasta -out {self.finishdir}/blast_search/{name}/{ref_nosuf}.txt -task megablast -num_threads {self.config['slurm_header']['threads']} -outfmt {blast_format}",
292262
)
293263
+ "\n"
294264
)
@@ -310,52 +280,40 @@ def create_variantsection(self):
310280
batchfile.write(
311281
self._singularity_exec(
312282
"bwa",
313-
"bwa mem -M -t {} {} {} {} > {}.sam".format(
314-
self.config["slurm_header"]["threads"],
315-
ref,
316-
self.concat_files["f"],
317-
self.concat_files["r"],
318-
outbase,
319-
),
283+
f"bwa mem -M -t {self.config['slurm_header']['threads']} {ref} {self.concat_files['f']} {self.concat_files['r']} > {outbase}.sam",
320284
)
321285
+ "\n"
322286
)
323287
batchfile.write(
324288
self._singularity_exec(
325289
"samtools",
326-
"samtools view --threads {} -b -o {}.bam -T {} {}.sam".format(
327-
self.config["slurm_header"]["threads"], outbase, ref, outbase
328-
),
290+
f"samtools view --threads {self.config['slurm_header']['threads']} -b -o {outbase}.bam -T {ref} {outbase}.sam",
329291
)
330292
+ "\n"
331293
)
332294
batchfile.write(
333295
self._singularity_exec(
334296
"samtools",
335-
"samtools sort --threads {} -o {}.bam_sort {}.bam".format(
336-
self.config["slurm_header"]["threads"], outbase, outbase
337-
),
297+
f"samtools sort --threads {self.config['slurm_header']['threads']} -o {outbase}.bam_sort {outbase}.bam",
338298
)
339299
+ "\n"
340300
)
341301
batchfile.write(
342302
self._singularity_exec(
343303
"picard",
344-
"picard MarkDuplicates I={}.bam_sort O={}.bam_sort_rmdup M={}.stats.dup REMOVE_DUPLICATES=true".format(
345-
outbase, outbase, outbase
346-
),
304+
f"picard MarkDuplicates I={outbase}.bam_sort O={outbase}.bam_sort_rmdup M={outbase}.stats.dup REMOVE_DUPLICATES=true",
347305
)
348306
+ "\n"
349307
)
350308
batchfile.write(
351-
self._singularity_exec("samtools", "samtools index {}.bam_sort_rmdup".format(outbase))
309+
self._singularity_exec("samtools", f"samtools index {outbase}.bam_sort_rmdup")
352310
+ "\n"
353311
)
354312
batchfile.write(
355313
self._singularity_exec(
356-
"samtools", "samtools idxstats {}.bam_sort_rmdup".format(outbase)
314+
"samtools", f"samtools idxstats {outbase}.bam_sort_rmdup"
357315
)
358-
+ " &> {}.stats.ref\n".format(outbase)
316+
+ f" &> {outbase}.stats.ref\n"
359317
)
360318
# Removal of temp aligment files
361319
batchfile.write(f"rm {outbase}.bam {outbase}.sam\n")
@@ -365,28 +323,26 @@ def create_variantsection(self):
365323
batchfile.write(
366324
self._singularity_exec(
367325
"picard",
368-
"picard CollectInsertSizeMetrics I={}.bam_sort_rmdup O={}.stats.ins H={}.hist.ins".format(
369-
outbase, outbase, outbase
370-
),
326+
f"picard CollectInsertSizeMetrics I={outbase}.bam_sort_rmdup O={outbase}.stats.ins H={outbase}.hist.ins",
371327
)
372328
+ "\n"
373329
)
374330
# Coverage
375331
batchfile.write(
376332
self._singularity_exec(
377-
"samtools", "samtools stats --coverage 1,10000,1 {}.bam_sort_rmdup".format(outbase)
333+
"samtools", f"samtools stats --coverage 1,10000,1 {outbase}.bam_sort_rmdup"
378334
)
379-
+ " |grep ^COV | cut -f 2- &> {}.stats.cov\n".format(outbase)
335+
+ f" |grep ^COV | cut -f 2- &> {outbase}.stats.cov\n"
380336
)
381337
# Mapped rate, no dedup,dedup in MWGS (trimming has no effect)!
382338
batchfile.write(
383-
self._singularity_exec("samtools", "samtools flagstat {}.bam_sort".format(outbase))
384-
+ " &> {}.stats.map\n".format(outbase)
339+
self._singularity_exec("samtools", f"samtools flagstat {outbase}.bam_sort")
340+
+ f" &> {outbase}.stats.map\n"
385341
)
386342
# Total reads, no dedup,dedup in MWGS (trimming has no effect)!
387343
batchfile.write(
388-
self._singularity_exec("samtools", "samtools view -c {}.bam_sort".format(outbase))
389-
+ " &> {}.stats.raw\n".format(outbase)
344+
self._singularity_exec("samtools", f"samtools view -c {outbase}.bam_sort")
345+
+ f" &> {outbase}.stats.raw\n"
390346
)
391347

392348
batchfile.write("\n\n")
@@ -433,16 +389,12 @@ def create_preprocsection(self):
433389
batchfile.write(
434390
self._singularity_exec(
435391
"trimmomatic",
436-
"trimmomatic PE -threads {} -phred33 {} {} {} {} {} {}\
437-
ILLUMINACLIP:{}/NexteraPE-PE.fa:2:30:10 LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36".format(
438-
self.config["slurm_header"]["threads"],
439-
self.concat_files.get("f"),
440-
self.concat_files.get("r"),
441-
fp,
442-
fu,
443-
rp,
444-
ru,
445-
self.config["singularity"]["trimmomatic_adapters"],
392+
(
393+
f"trimmomatic PE -threads {self.config['slurm_header']['threads']}"
394+
f" -phred33 {self.concat_files.get('f')} {self.concat_files.get('r')}"
395+
f" {fp} {fu} {rp} {ru}"
396+
f" ILLUMINACLIP:{self.config['singularity']['trimmomatic_adapters']}/NexteraPE-PE.fa:2:30:10"
397+
" LEADING:3 TRAILING:3 SLIDINGWINDOW:4:15 MINLEN:36"
446398
),
447399
)
448400
+ "\n"
@@ -464,9 +416,7 @@ def create_assemblystats_section(self):
464416
batchfile.write(
465417
self._singularity_exec(
466418
"quast",
467-
"quast.py {}/assembly/{}_contigs.fasta -o {}/assembly/quast".format(
468-
self.finishdir, self.name, self.finishdir
469-
),
419+
f"quast.py {self.finishdir}/assembly/{self.name}_contigs.fasta -o {self.finishdir}/assembly/quast",
470420
)
471421
+ "\n"
472422
)

microSALT/utils/referencer.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,16 +128,12 @@ def index_db(self, full_dir, suffix):
128128
# Resistence files
129129
if ".fsa" in suffix:
130130
bash_cmd = self._singularity_exec('blast',
131-
"makeblastdb -in {}/{} -dbtype nucl -out {}".format(
132-
full_dir, os.path.basename(file), os.path.basename(base)
133-
)
131+
f"makeblastdb -in {full_dir}/{os.path.basename(file)} -dbtype nucl -out {os.path.basename(base)}"
134132
)
135133
# MLST locis
136134
else:
137135
bash_cmd = self._singularity_exec('blast',
138-
"makeblastdb -in {}/{} -dbtype nucl -parse_seqids -out {}".format(
139-
full_dir, os.path.basename(file), os.path.basename(base)
140-
)
136+
f"makeblastdb -in {full_dir}/{os.path.basename(file)} -dbtype nucl -parse_seqids -out {os.path.basename(base)}"
141137
)
142138
proc = subprocess.Popen(bash_cmd.split(), cwd=full_dir, stdout=subprocess.PIPE)
143139
proc.communicate()
@@ -423,15 +419,15 @@ def download_ncbi(self, reference):
423419
output = f"{self.config['folders']['genomes']}/{reference}.fasta"
424420
with open(output, "w") as f:
425421
f.write(sequence)
426-
bwaindex = self._singularity_exec('bwa', "bwa index {}".format(output))
422+
bwaindex = self._singularity_exec('bwa', f"bwa index {output}")
427423
proc = subprocess.Popen(
428424
bwaindex.split(),
429425
cwd=self.config["folders"]["genomes"],
430426
stdout=DEVNULL,
431427
stderr=DEVNULL,
432428
)
433429
out, err = proc.communicate()
434-
samindex = self._singularity_exec('samtools', "samtools faidx {}".format(output))
430+
samindex = self._singularity_exec('samtools', f"samtools faidx {output}")
435431
proc = subprocess.Popen(
436432
samindex.split(),
437433
cwd=self.config["folders"]["genomes"],

microSALT/utils/reporter.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def gen_STtracker(self, customer="all", silent=False):
108108
self.name = "Sequence Type Update"
109109
try:
110110
content = STtracker_page(customer)
111-
outname = "{}/ST_updates_{}.html".format(self.output, self.now)
111+
outname = f"{self.output}/ST_updates_{self.now}.html"
112112
outfile = open(outname, "wb")
113113
outfile.write(content.encode("utf8"))
114114
outfile.close()
@@ -123,13 +123,13 @@ def gen_qc(self, silent=False):
123123
try:
124124
last_version = self.db_pusher.get_report(self.name).version
125125
except Exception:
126-
self.logger.error("Project {} does not exist".format(self.name))
126+
self.logger.error(f"Project {self.name} does not exist")
127127
sys.exit(-1)
128128
try:
129129
content = alignment_page(self.name)
130-
outfile = "{}_QC_{}.html".format(self.sample.get("Customer_ID_project"), last_version)
131-
local = "{}/{}".format(self.output, outfile)
132-
output = "{}/analysis/{}".format(self.config["folders"]["reports"], outfile)
130+
outfile = f"{self.sample.get('Customer_ID_project')}_QC_{last_version}.html"
131+
local = f"{self.output}/{outfile}"
132+
output = f"{self.config['folders']['reports']}/analysis/{outfile}"
133133

134134
with open(output, "wb") as f:
135135
f.write(content.encode("utf8"))
@@ -146,15 +146,13 @@ def gen_typing(self, silent=False):
146146
try:
147147
last_version = self.db_pusher.get_report(self.name).version
148148
except Exception:
149-
self.logger.error("Project {} does not exist".format(self.name))
149+
self.logger.error(f"Project {self.name} does not exist")
150150
sys.exit(-1)
151151
try:
152152
content = typing_page(self.name, "all")
153-
outfile = "{}_Typing_{}.html".format(
154-
self.sample.get("Customer_ID_project"), last_version
155-
)
156-
local = "{}/{}".format(self.output, outfile)
157-
output = "{}/analysis/{}".format(self.config["folders"]["reports"], outfile)
153+
outfile = f"{self.sample.get('Customer_ID_project')}_Typing_{last_version}.html"
154+
local = f"{self.output}/{outfile}"
155+
output = f"{self.config['folders']['reports']}/analysis/{outfile}"
158156

159157
with open(output, "wb") as f:
160158
f.write(content.encode("utf8"))

0 commit comments

Comments
 (0)