Skip to content

Commit

Permalink
Minor speed improvements for node creator
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riggs committed Nov 1, 2023
1 parent d74bfe8 commit 4b6cba8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 65 deletions.
3 changes: 2 additions & 1 deletion src/relion/zocalo/node_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,8 @@ def dummy(self, *args, **kwargs):
with open(job_dir / "run.out", "w") as f:
f.write(job_info.stdout)
with open(job_dir / "run.err", "a") as f:
f.write(f"{job_info.stderr}\n")
if job_info.stderr:
f.write(f"{job_info.stderr}\n")
with open(job_dir / "note.txt", "a") as f:
f.write(f"{job_info.command}\n")

Expand Down
117 changes: 53 additions & 64 deletions src/relion/zocalo/spa_output_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ def _import_output_files(
):
"""Import jobs save a list of all micrographs"""
star_file = job_dir / "movies.star"
added_line = [str(output_file), "1"]

# Read and append to the existing output file, or otherwise create one
if not star_file.exists():
Expand All @@ -83,13 +84,11 @@ def _import_output_files(
movies_loop = data_movies.init_loop(
"_rln", ["MicrographMovieName", "OpticsGroup"]
)
movies_loop.add_row(added_line)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
else:
output_cif = cif.read_file(str(star_file))
data_movies = output_cif.find_block("movies")
movies_loop = data_movies.find_loop("_rlnMicrographMovieName").get_loop()

movies_loop.add_row([str(output_file), "1"])
output_cif.write_file(str(star_file), style=cif.Style.Simple)
with open(star_file, "a") as output_cif:
output_cif.write(" ".join(added_line) + "\n")


def _motioncorr_output_files(
Expand All @@ -101,6 +100,14 @@ def _motioncorr_output_files(
):
"""Motion correction saves a list of micrographs and their motion"""
star_file = job_dir / "corrected_micrographs.star"
added_line = [
str(output_file),
str(output_file.with_suffix(".star")),
"1",
str(results["total_motion"]),
str(results["early_motion"]),
str(results["late_motion"]),
]

# Read and append to the existing output file, or otherwise create one
if not star_file.exists():
Expand All @@ -118,22 +125,11 @@ def _motioncorr_output_files(
"AccumMotionLate",
],
)
movies_loop.add_row(added_line)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
else:
output_cif = cif.read_file(str(star_file))
data_movies = output_cif.find_block("micrographs")
movies_loop = data_movies.find_loop("_rlnMicrographName").get_loop()

movies_loop.add_row(
[
str(output_file),
str(output_file.with_suffix(".star")),
"1",
str(results["total_motion"]),
str(results["early_motion"]),
str(results["late_motion"]),
]
)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
with open(star_file, "a") as output_cif:
output_cif.write(" ".join(added_line) + "\n")

# Logfile is expected but will not be made
(star_file.parent / "logfile.pdf").touch()
Expand All @@ -149,6 +145,21 @@ def _ctffind_output_files(
"""Ctf estimation saves a list of micrographs and their ctf parameters"""
star_file = job_dir / "micrographs_ctf.star"

# Results needed in the star file are stored in a txt file with the output
with open(output_file.with_suffix(".txt"), "r") as f:
ctf_results = f.readlines()[-1].split()
added_line = [
str(input_file),
"1",
str(output_file.with_suffix(".ctf")) + ":mrc",
ctf_results[1],
ctf_results[2],
str(abs(float(ctf_results[1]) - float(ctf_results[2]))),
ctf_results[3],
ctf_results[5],
ctf_results[6],
]

# Read and append to the existing output file, or otherwise create one
if not star_file.exists():
output_cif = get_optics_table(relion_options)
Expand All @@ -168,29 +179,11 @@ def _ctffind_output_files(
"CtfMaxResolution",
],
)
movies_loop.add_row(added_line)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
else:
output_cif = cif.read_file(str(star_file))
data_movies = output_cif.find_block("micrographs")
movies_loop = data_movies.find_loop("_rlnMicrographName").get_loop()

# Results needed in the star file are stored in a txt file with the output
with open(output_file.with_suffix(".txt"), "r") as f:
ctf_results = f.readlines()[-1].split()

movies_loop.add_row(
[
str(input_file),
"1",
str(output_file.with_suffix(".ctf")) + ":mrc",
ctf_results[1],
ctf_results[2],
str(abs(float(ctf_results[1]) - float(ctf_results[2]))),
ctf_results[3],
ctf_results[5],
ctf_results[6],
]
)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
with open(star_file, "a") as output_cif:
output_cif.write(" ".join(added_line) + "\n")

# Logfile is expected but will not be made
(star_file.parent / "logfile.pdf").touch()
Expand Down Expand Up @@ -242,6 +235,14 @@ def _icebreaker_output_files(
return

# Read and append to the existing output file, or otherwise create one
added_line = [
file_to_add,
str(input_file.with_suffix(".star")),
"1",
str(results["total_motion"]),
str(results["early_motion"]),
str(results["late_motion"]),
]
if not star_file.exists():
output_cif = cif.Document()

Expand All @@ -257,22 +258,11 @@ def _icebreaker_output_files(
"AccumMotionLate",
],
)
movies_loop.add_row(added_line)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
else:
output_cif = cif.read_file(str(star_file))
data_movies = output_cif.find_block("micrographs")
movies_loop = data_movies.find_loop("_rlnMicrographName").get_loop()

movies_loop.add_row(
[
file_to_add,
str(input_file.with_suffix(".star")),
"1",
str(results["total_motion"]),
str(results["early_motion"]),
str(results["late_motion"]),
]
)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
with open(star_file, "a") as output_cif:
output_cif.write(" ".join(added_line) + "\n")


def _cryolo_output_files(
Expand All @@ -284,6 +274,7 @@ def _cryolo_output_files(
):
"""Cryolo jobs save a list of micrographs and files with particle coordinates"""
star_file = job_dir / "autopick.star"
added_line = [str(input_file), str(output_file)]

# Read and append to the existing output file, or otherwise create one
if not star_file.exists():
Expand All @@ -297,13 +288,11 @@ def _cryolo_output_files(
"MicrographCoordinates",
],
)
movies_loop.add_row(added_line)
output_cif.write_file(str(star_file), style=cif.Style.Simple)
else:
output_cif = cif.read_file(str(star_file))
data_movies = output_cif.find_block("coordinate_files")
movies_loop = data_movies.find_loop("_rlnMicrographName").get_loop()

movies_loop.add_row([str(input_file), str(output_file)])
output_cif.write_file(str(star_file), style=cif.Style.Simple)
with open(star_file, "a") as output_cif:
output_cif.write(" ".join(added_line) + "\n")


def _extract_output_files(
Expand Down

0 comments on commit 4b6cba8

Please sign in to comment.