Skip to content

Commit

Permalink
updated particle picking plotting to handle multiple metadata files a…
Browse files Browse the repository at this point in the history
…nd added example scripts
  • Loading branch information
MJoosten committed Jul 4, 2024
1 parent ad491a1 commit 34da066
Show file tree
Hide file tree
Showing 7 changed files with 681 additions and 712 deletions.
10 changes: 5 additions & 5 deletions scripts/plot_ctf_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
EXECUTABLE=$"roodmus"
SUBROUTINE=$" plot_ctf"

CONFIG_DIR=/path/to/config/files/dir
NUM_UGRAPHS=5
META_FILE=/path/to/metafile
PLOT_DIR=/path/to/output/files/dir
CONFIG_DIR=path/to/config/files
META_FILE=path/to/meta/file
JOB_TYPES="job019_extraction"
PLOT_DIR=path/to/plot/directory
PLOT_TYPES="scatter" # "scatter" or "per-particle-scatter"
DPI=300

$EXECUTABLE $SUBROUTINE \
--verbose \
--tqdm \
--config_dir $CONFIG_DIR \
--num_ugraphs $NUM_UGRAPHS \
--meta_file $META_FILE \
--job_types $JOB_TYPES \
--plot_dir $PLOT_DIR \
--plot_types $PLOT_TYPES \
--dpi $DPI
Expand Down
27 changes: 27 additions & 0 deletions scripts/plot_picking_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

EXECUTABLE=$"roodmus"
SUBROUTINE=$" plot_picking"

CONFIG_DIR=path/to/config/files
NUM_UGRAPHS=1
META_FILE="path/to/meta/file1 \
path/to/meta/file2 "
JOB_TYPES="job012_extraction job020_selection"
PLOT_DIR=path/to/plot/directory
PLOT_TYPES="label_truth label_picked label_truth_and_picked label_matched_and_unmatched precision boundary overlap"
BOX_WIDTH=16
BOX_HEIGHT=16
PARTICLE_DIAMETER=100
DPI=300

$EXECUTABLE $SUBROUTINE \
--verbose \
--tqdm \
--config_dir $CONFIG_DIR \
--num_ugraphs $NUM_UGRAPHS \
--meta_file $META_FILE \
--job_types $JOB_TYPES \
--plot_dir $PLOT_DIR \
--plot_types $PLOT_TYPES \
--dpi $DPI
58 changes: 58 additions & 0 deletions scripts/write_starfile_example.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/bin/bash

EXECUTABLE=$"roodmus"
SUBROUTINE=$" write_starfile"

INPUT_CSV=path/to/input/csv/file
TYPE=coordinate_star
OUTPUT_DIR=path/to/output/directory
UGRAPH_DIR=Micrographs
PIXEL_SIZE=1

$EXECUTABLE $SUBROUTINE \
--verbose \
--tqdm \
--input_csv $INPUT_CSV \
--type $TYPE \
--output_dir $OUTPUT_DIR \
--ugraph_dir $UGRAPH_DIR \
--pixel_size $PIXEL_SIZE

INPUT_CSV=path/to/input/csv/file
TYPE=data_star
OUTPUT_DIR=path/to/output/directory
UGRAPH_DIR=Micrographs
PIXEL_SIZE=1
OPTICS_GROUP_NAME=opticsGroup1
OPTICS_GROUP=1
MTF_FILENAME=mtf_300kV.star
MICROGRAPH_ORIGINAL_PIXEL_SIZE=1.0
VOLTAGE=300.0
SPHERICAL_ABERRATION=2.7
AMPLITUDE_CONTRAST=0.1
IMAGE_PIXEL_SIZE=1.0
IMAGE_SIZE=128
IMAGE_DIMENSIONALITY=2
CTF_DATA_ARE_CTF_PREMULTIPLIED=0

$EXECUTABLE $SUBROUTINE \
--verbose \
--tqdm \
--input_csv $INPUT_CSV \
--type $TYPE \
--output_dir $OUTPUT_DIR \
--ugraph_dir $UGRAPH_DIR \
--pixel_size $PIXEL_SIZE \
--optics_group_name $OPTICS_GROUP_NAME \
--optics_group $OPTICS_GROUP \
--mtf_filename $MTF_FILENAME \
--micrograph_original_pixel_size $MICROGRAPH_ORIGINAL_PIXEL_SIZE \
--voltage $VOLTAGE \
--spherical_aberration $SPHERICAL_ABERRATION \
--amplitude_contrast $AMPLITUDE_CONTRAST \
--image_pixel_size $IMAGE_PIXEL_SIZE \
--image_size $IMAGE_SIZE \
--image_dimensionality $IMAGE_DIMENSIONALITY \
--ctf_data_are_ctf_premultiplied $CTF_DATA_ARE_CTF_PREMULTIPLIED


37 changes: 26 additions & 11 deletions src/roodmus/analysis/extract_particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ def add_arguments(parser):
type=str,
default="particles",
)
parser.add_argument(
"--file_type",
help="File type of the micrographs. Default 'mrcs'",
type=str,
default="mrcs",
)
parser.add_argument(
"--tqdm",
help="Use tqdm progress bar. Default False",
Expand Down Expand Up @@ -100,6 +106,24 @@ def get_particle(
return particle


def save_particle_stack(
particle_stack: np.ndarray, particle_dir: str, file_type: str
):
particle_file = os.path.join(
args.particle_dir,
"particle_stack." + file_type,
)

if file_type == "mrcs" or file_type == "mrc":
with mrcfile.new(particle_file, overwrite=True) as mrc:
mrc.set_data(np.float32(particle_stack))
mrc.set_image_stack()
mrc.update_header_from_data()

elif file_type == "tif" or file_type == "tiff":
tifffile.imwrite(particle_file.replace(".mrc", ".tif"), particle_stack)


def main(args):
if args.mrc_dir is None:
args.mrc_dir = args.config_dir
Expand Down Expand Up @@ -152,17 +176,8 @@ def main(args):
print(f"particle stack shape: {particle_stack.shape}")

# save the particle stack
particle_file = os.path.join(
args.particle_dir,
"particle_stack.mrc",
)

with mrcfile.new(particle_file, overwrite=True) as mrc:
mrc.set_data(np.float32(particle_stack))
mrc.set_image_stack()
mrc.update_header_from_data()
tifffile.imwrite(
particle_file.replace(".mrc", ".tif"), particle_stack
save_particle_stack(
particle_stack, args.particle_dir, args.file_type
)


Expand Down
Loading

0 comments on commit 34da066

Please sign in to comment.