Skip to content

Commit

Permalink
Tests for tomo motioncorr and ctf
Browse files Browse the repository at this point in the history
  • Loading branch information
stephen-riggs committed Sep 12, 2024
1 parent d81961a commit f20a841
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 4 deletions.
2 changes: 0 additions & 2 deletions src/cryoemservices/util/tomo_output_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ def _ctffind_output_files(
),
str(relion_options.defocus),
str(input_file),
str(stage_tilt_angle),
str(output_file.with_suffix(".ctf")) + ":mrc",
ctf_results[1],
ctf_results[2],
Expand All @@ -299,7 +298,6 @@ def _ctffind_output_files(
"MicrographPreExposure",
"TomoNominalDefocus",
"MicrographName",
"TomoNominalTiltAxisAngle",
"CtfImage",
"DefocusU",
"DefocusV",
Expand Down
150 changes: 148 additions & 2 deletions tests/services/test_node_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1072,9 +1072,155 @@ def test_node_creator_import_tomo(mock_environment, offline_transport, tmp_path)
]


@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
def test_node_creator_motioncorr_tomo(mock_environment, offline_transport, tmp_path):
"""
Send a test message to the node creator for
relion.motioncorr.own
"""
job_dir = "MotionCorr/job002"
input_file = f"{tmp_path}/Import/job001/Movies/Position_1_2_001_1.50_fractions.tiff"
output_file = tmp_path / job_dir / "Movies/Position_1_2_001_1.50_fractions.mrc"
relion_options = RelionServiceOptions()

# .Nodes directory doesn't get made by this job
(tmp_path / ".Nodes").mkdir()

setup_and_run_node_creation(
mock_environment,
relion_options,
offline_transport,
tmp_path,
job_dir,
"relion.motioncorr.own",
input_file,
output_file,
results={"total_motion": "10", "early_motion": "4", "late_motion": "6"},
experiment_type="tomography",
)

# Check the output file structure
assert (tmp_path / job_dir / "corrected_tilt_series.star").exists()
tilt_series_file = cif.read_file(
str(tmp_path / job_dir / "corrected_tilt_series.star")
)

global_block = tilt_series_file.find_block("global")
assert list(global_block.find_loop("_rlnTomoName")) == ["Position_1_2"]
assert list(global_block.find_loop("_rlnTomoTiltSeriesStarFile")) == [
f"{job_dir}/tilt_series/Position_1_2.star"
]

assert (tmp_path / job_dir / "tilt_series/Position_1_2.star").exists()
tilts_file = cif.read_file(
str(tmp_path / job_dir / "tilt_series/Position_1_2.star")
)

tilts_block = tilts_file.sole_block()
assert list(tilts_block.find_loop("_rlnMicrographMovieName")) == [
"Import/job001/Movies/Position_1_2_001_1.50_fractions.tiff"
]
assert list(tilts_block.find_loop("_rlnTomoTiltMovieFrameCount")) == [
str(relion_options.frame_count)
]
assert list(tilts_block.find_loop("_rlnTomoNominalStageTiltAngle")) == ["1.50"]
assert list(tilts_block.find_loop("_rlnTomoNominalTiltAxisAngle")) == [
str(relion_options.tilt_axis_angle)
]
assert list(tilts_block.find_loop("_rlnMicrographPreExposure")) == ["12.77"]
assert list(tilts_block.find_loop("_rlnTomoNominalDefocus")) == [
str(relion_options.defocus)
]
assert list(tilts_block.find_loop("_rlnMicrographName")) == [
f"{job_dir}/Movies/Position_1_2_001_1.50_fractions.mrc"
]
assert list(tilts_block.find_loop("_rlnMicrographMetadata")) == [
f"{job_dir}/Movies/Position_1_2_001_1.50_fractions.star"
]
assert list(tilts_block.find_loop("_rlnAccumMotionTotal")) == ["10"]
assert list(tilts_block.find_loop("_rlnAccumMotionEarly")) == ["4"]
assert list(tilts_block.find_loop("_rlnAccumMotionLate")) == ["6"]


@pytest.mark.skipif(sys.platform == "win32", reason="does not run on windows")
def test_node_creator_ctffind_tomo(mock_environment, offline_transport, tmp_path):
"""
Send a test message to the node creator for
relion.ctffind.ctffind4
"""
job_dir = "CtfFind/job003"
input_file = (
f"{tmp_path}/MotionCorr/job002/Movies/Position_1_2_001_1.50_fractions.mrc"
)
output_file = tmp_path / job_dir / "Movies/Position_1_2_001_1.50_fractions.ctf"
relion_options = RelionServiceOptions()

output_file.parent.mkdir(parents=True)
with open(output_file.with_suffix(".txt"), "w") as f:
f.write("0.0 1.0 2.0 3.0 4.0 5.0 6.0")
with open(f"{output_file.with_suffix('')}_avrot.txt", "w") as f:
f.write(
"header\nheader\nheader\nheader\nheader\n0.24 0.26 0.27 0.29\n1 2 3 4\n"
)

# .Nodes directory doesn't get made by this job
(tmp_path / ".Nodes").mkdir()

setup_and_run_node_creation(
mock_environment,
relion_options,
offline_transport,
tmp_path,
job_dir,
"relion.ctffind.ctffind4",
input_file,
output_file,
experiment_type="tomography",
)

# Check the output file structure
assert (tmp_path / job_dir / "tilt_series_ctf.star").exists()
tilt_series_file = cif.read_file(str(tmp_path / job_dir / "tilt_series_ctf.star"))

global_block = tilt_series_file.find_block("global")
assert list(global_block.find_loop("_rlnTomoName")) == ["Position_1_2"]
assert list(global_block.find_loop("_rlnTomoTiltSeriesStarFile")) == [
f"{job_dir}/tilt_series/Position_1_2.star"
]

assert (tmp_path / job_dir / "tilt_series/Position_1_2.star").exists()
tilts_file = cif.read_file(
str(tmp_path / job_dir / "tilt_series/Position_1_2.star")
)

tilts_block = tilts_file.sole_block()
assert list(tilts_block.find_loop("_rlnTomoTiltMovieFrameCount")) == [
str(relion_options.frame_count)
]
assert list(tilts_block.find_loop("_rlnTomoNominalStageTiltAngle")) == ["1.50"]
assert list(tilts_block.find_loop("_rlnTomoNominalTiltAxisAngle")) == [
str(relion_options.tilt_axis_angle)
]
assert list(tilts_block.find_loop("_rlnMicrographPreExposure")) == ["12.77"]
assert list(tilts_block.find_loop("_rlnTomoNominalDefocus")) == [
str(relion_options.defocus)
]
assert list(tilts_block.find_loop("_rlnMicrographName")) == [
"MotionCorr/job002/Movies/Position_1_2_001_1.50_fractions.mrc"
]
assert list(tilts_block.find_loop("_rlnCtfImage")) == [
f"{job_dir}/Movies/Position_1_2_001_1.50_fractions.ctf:mrc"
]
assert list(tilts_block.find_loop("_rlnDefocusU")) == ["1.0"]
assert list(tilts_block.find_loop("_rlnDefocusV")) == ["2.0"]
assert list(tilts_block.find_loop("_rlnCtfAstigmatism")) == ["1.0"]
assert list(tilts_block.find_loop("_rlnDefocusAngle")) == ["3.0"]
assert list(tilts_block.find_loop("_rlnCtfFigureOfMerit")) == ["5.0"]
assert list(tilts_block.find_loop("_rlnCtfMaxResolution")) == ["6.0"]
assert list(tilts_block.find_loop("_rlnCtfIceRingDensity")) == ["5.0"]


# Still to do:
# "relion.motioncorr.own"
# "relion.ctffind.ctffind4"
# "relion.excludetilts"
# "relion.aligntiltseries"
# "relion.reconstructtomograms"
Expand Down

0 comments on commit f20a841

Please sign in to comment.