Skip to content

Commit

Permalink
allow writing tbl files (#160)
Browse files Browse the repository at this point in the history
  • Loading branch information
brisvag authored Jan 24, 2024
1 parent afd2168 commit 34db573
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ dependencies = [
"pandas",
"scipy",
"magicgui>=0.4.0",
"cryohub>=0.6.3",
"cryohub>=0.6.4",
"cryotypes>=0.2.0",
"einops",
"morphosamplers>=0.0.10",
Expand Down
7 changes: 7 additions & 0 deletions src/blik/napari.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ contributions:
- id: blik.write_particles_relion_40
python_name: blik.writer:write_particles_relion_40
title: Save particles data with blik (relion 4.0)
- id: blik.write_particles_dynamo
python_name: blik.writer:write_particles_dynamo
title: Save particles data with blik (relion 4.0)
- id: blik.write_surface_picks
python_name: blik.writer:write_surface_picks
title: Save surface picks data with blik
Expand Down Expand Up @@ -84,6 +87,10 @@ contributions:
display_name: particles (relion 4.0)
layer_types: ["points+", "vectors*"]
filename_extensions: [".star"]
- command: blik.write_particles_dynamo
display_name: particles (dynamo tbl)
layer_types: ["points+", "vectors*"]
filename_extensions: [".tbl"]
- command: blik.write_surface_picks
display_name: surface picks
layer_types: ["shapes"]
Expand Down
19 changes: 15 additions & 4 deletions src/blik/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from cryohub.utils.types import PoseSet
from cryohub.writing.mrc import write_mrc
from cryohub.writing.star import write_star
from cryohub.writing.tbl import write_tbl
from cryotypes.image import Image
from scipy.spatial.transform import Rotation

Expand All @@ -25,7 +26,7 @@ def write_image(path, data, attributes):
return [path]


def _write_particles(path, layer_data, relion_version):
def _generate_particle_set(layer_data):
particles = []
for data, attributes, layer_type in layer_data:
if layer_type == "vectors":
Expand Down Expand Up @@ -62,21 +63,31 @@ def _write_particles(path, layer_data, relion_version):
raise ValueError(
"cannot write a layer that does not have blik metadata. Add it to an experiment!"
)
return particles


def _write_particles_star(path, layer_data, relion_version):
particles = _generate_particle_set(layer_data)
write_star(particles, path, overwrite=True, version=relion_version)
return [path]


def write_particles_relion_30(path, layer_data):
return _write_particles(path, layer_data, relion_version="3.0")
return _write_particles_star(path, layer_data, relion_version="3.0")


def write_particles_relion_31(path, layer_data):
return _write_particles(path, layer_data, relion_version="3.1")
return _write_particles_star(path, layer_data, relion_version="3.1")


def write_particles_relion_40(path, layer_data):
return _write_particles(path, layer_data, relion_version="4.0")
return _write_particles_star(path, layer_data, relion_version="4.0")


def write_particles_dynamo(path, layer_data):
particles = _generate_particle_set(layer_data)
write_tbl(particles, path, overwrite=True)
return [path]


def write_surface_picks(path, data, attributes):
Expand Down

0 comments on commit 34db573

Please sign in to comment.