Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0.4.0 beamshiftnaming #94

Open
wants to merge 20 commits into
base: 0.4.0-beam-shift
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion conda-build/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: ot2rec
version: 0.3.2
version: 0.4.0_post1

source:
path: ..
Expand Down
4 changes: 2 additions & 2 deletions construct.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: Ot2Rec
version: 0.3.2
version: 0.4.0_post1
company: Rosalind Franklin Institute
channels:
- https://conda.anaconda.org/conda-forge
- file:///usr/share/miniconda3/conda-bld/
specs:
- python 3.9.*
- Ot2Rec 0.3.2
- Ot2Rec 0.4.0_post1
- conda
Binary file removed demo/raw/TS_01/TS_01_0000_-60.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0001_-57.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0002_-54.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0003_-51.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0004_-48.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0005_-45.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0006_-42.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0007_-39.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0008_-36.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0009_-33.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0010_-30.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0011_-27.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0012_-24.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0013_-21.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0014_-18.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0015_-15.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0016_-12.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0017_-9.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0018_-6.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0019_-3.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0020_0.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0021_3.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0022_6.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0023_9.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0024_12.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0025_15.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0026_18.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0027_21.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0028_24.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0029_27.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0030_30.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0031_33.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0032_36.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0033_39.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0034_42.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0035_45.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0036_48.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0037_51.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0038_54.0.tif
Binary file not shown.
Binary file removed demo/raw/TS_01/TS_01_0039_57.0.tif
Binary file not shown.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


setup(
version="0.3.2",
version="0.4.0_post1",
name="Ot2Rec",
description="Ot2Rec",
url="https://github.com/rosalindfranklininstitute/Ot2Rec",
Expand Down Expand Up @@ -70,7 +70,8 @@
"o2r.deconv.run=Ot2Rec.rlf_deconv:run",
"o2r.cleanup=Ot2Rec.main:cleanup",
"o2r.runall.imod=Ot2Rec.main:run_all_imod",
"o2r.previewer=Ot2Rec.previewer:run_previewer",
"o2r.previewer=Ot2Rec.previewer:run_previewer_with_mgui",
"o2r.rename=Ot2Rec.utils.rename:rename_all_with_mgui",
]
},
)
31 changes: 0 additions & 31 deletions src/Ot2Rec/__init__.py
Original file line number Diff line number Diff line change
@@ -1,31 +0,0 @@
# Copyright 2021 Rosalind Franklin Institute
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied. See the License for the specific
# language governing permissions and limitations under the License.


# Ot2Rec Imports
from . import params
from . import metadata
from . import motioncorr
from . import logger
from . import ctffind
from . import align
from . import recon
from . import main
from . import previewer


VERSION = "v1.0a"
"""
str : Ot2Rec version string.
"""
27 changes: 16 additions & 11 deletions src/Ot2Rec/align.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import yaml
from beautifultable import BeautifulTable as bt

from . import user_args as uaMod
from . import mgui_imod_align as mgMod
from . import metadata as mdMod
from . import params as prmMod
Expand Down Expand Up @@ -91,7 +90,7 @@ def _get_internal_metadata(self):
columns=["ts", "stack_output", "align_output"]
)
for curr_ts in self.params["System"]["process_list"]:
subfolder_name = f"{self.rootname}_{curr_ts}{self.suffix}"
subfolder_name = f"{self.rootname}_{curr_ts:03}{self.suffix}"
_to_append = pd.DataFrame(
{
"ts": [curr_ts],
Expand Down Expand Up @@ -167,8 +166,11 @@ def _check_aligned_images(self):

self._merged = self._align_images.merge(_ignored, how="left", indicator=True)
self._align_images = self._align_images[self._merged["_merge"] == "left_only"]
self._process_list = (
self._align_images["ts"].sort_values(ascending=True).unique().tolist()
# self._process_list = (
# self._align_images["ts"].sort_values(ascending=True).unique().tolist()
# )
self._process_list = sorted(
list(self._align_images["ts"].unique().astype("int"))
)

"""
Expand Down Expand Up @@ -201,7 +203,7 @@ def create_stack_folders(self, single_folder=False):
else:
for curr_ts in self._process_list:
subfolder_path = (
f"{self.basis_folder}/{self.rootname}_{curr_ts}{self.suffix}"
f"{self.basis_folder}/{self.rootname}_{curr_ts:03}{self.suffix}"
)
os.makedirs(subfolder_path, exist_ok=True)
self._path_dict[curr_ts] = subfolder_path
Expand Down Expand Up @@ -239,7 +241,7 @@ def create_rawtlt(self):
# Define path where the new rawtlt file should go
rawtlt_file = (
f"{self._path_dict[curr_ts]}/{self.params['System']['output_rootname']}_"
f"{curr_ts}{self.params['System']['output_suffix']}.rawtlt"
f"{curr_ts:03}{self.params['System']['output_suffix']}.rawtlt"
)

# Sort the filtered metadata
Expand Down Expand Up @@ -316,7 +318,9 @@ def create_stack(self):
self.export_metadata()

if error_count == 0:
self.logObj.logger.info("All Ot2Rec-align (IMOD): newstack jobs successfully finished.")
self.logObj.logger.info(
"All Ot2Rec-align (IMOD): newstack jobs successfully finished."
)
else:
self.logObj.logger.warning(
"All Ot2Rec-align (IMOD): newstack jobs finished. {error_count} of {len(tqdm_iter)} jobs failed.",
Expand Down Expand Up @@ -602,8 +606,7 @@ def update_yaml(args, logger=None):
args (Namespace): Namespace generated with user inputs
"""
if logger is None:
log_align = logMod.Logger(name="imod_align",
log_path="")
log_align = logMod.Logger(name="imod_align", log_path="")
else:
log_align = logger

Expand All @@ -616,7 +619,7 @@ def update_yaml(args, logger=None):
"Error in Ot2Rec.align.update_yaml: alignment config file not found."
)
if not os.path.isfile(mc2_yaml_name):
log_align.logger.error(message="MotionCor2 config file not found.")
log_align.logger.error("MotionCor2 config file not found.")
raise IOError(
"Error in Ot2Rec.align.update__yaml: motioncorr config file not found."
)
Expand Down Expand Up @@ -659,7 +662,9 @@ def update_yaml(args, logger=None):
project_name=args.project_name, filename=mc2_yaml_name
)

align_params.params["System"]["process_list"] = unique_ts_numbers
align_params.params["System"]["process_list"] = [
int(ts) for ts in unique_ts_numbers
]
align_params.params["BatchRunTomo"]["setup"]["pixel_size"] = (
mc2_params.params["MC2"]["desired_pixel_size"] * 0.1
)
Expand Down
50 changes: 28 additions & 22 deletions src/Ot2Rec/aretomo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
from . import align
from . import logger as logMod
from . import params as prmMod
from . import user_args as uaMod
from . import mgui_imod_align as imod_newstack_MGUI
from . import mgui_aretomo as mgMod

Expand Down Expand Up @@ -97,17 +96,18 @@ def _get_internal_metadata(self):
)
for i, curr_ts in enumerate(self.params["System"]["process_list"]):
subfolder = (
f"{self.basis_folder}/" f"{self.rootname}_{curr_ts}{self.suffix}"
f"{self.basis_folder}/" f"{self.rootname}_{curr_ts:03}{self.suffix}"
)
os.makedirs(subfolder, exist_ok=True)
# self._path_dict[curr_ts] = subfolder
if "aretomo_output_dir" not in list(self.md_out.keys()):
self.md_out["aretomo_output_dir"] = {}
self.md_out["aretomo_align_stats"] = {}
self.md_out["aretomo_output_dir"][curr_ts] = subfolder
input_img_name = os.path.splitext(
os.path.basename(self.params["AreTomo_setup"]["input_mrc"][i])
)[0]
input_img_name = os.path.basename(
self.params["AreTomo_setup"]["input_mrc"][i]
)

self.md_out["aretomo_align_stats"][
curr_ts
] = f"{subfolder}/{input_img_name}.aln"
Expand Down Expand Up @@ -261,7 +261,9 @@ def export_metadata(self):
for ts in list(self.sta.keys()):
sta_ts_folder = f"{self.sta_folder}/{self.sta[ts].split(os.sep)[-2]}"
if os.path.exists(sta_ts_folder):
self.logObj.logger.warning(f"STA folder {sta_ts_folder} not empty, overwriting.")
self.logObj.logger.warning(
f"STA folder {sta_ts_folder} not empty, overwriting."
)
shutil.rmtree(sta_ts_folder)
shutil.move(
src=self.sta[ts],
Expand Down Expand Up @@ -303,15 +305,18 @@ def _update_volz(args, aretomo_params):
def _create_stacks_with_imod(args):
# Uses align to create the InMrc and AngFile in correct form
try:
args_in_align = imod_newstack_MGUI.get_args_align
args_in_align.project_name.value = args["project_name"]
args_in_align.rot_angle.value = args["rot_angle"]
args_in_align.output_folder.value = args["output_path"]
align.create_yaml(args_in=args_in_align)
align.run(newstack=True, do_align=False, args_pass=[args["project_name"]])
args_in_align = asObject(imod_newstack_MGUI.get_args_align(return_only=True))
args_in_align.project_name = args["project_name"]
args_in_align.rot_angle = args["rot_angle"]
args_in_align.output_folder = args["output_path"]
args_in_align.pixel_size = args["pixel_size"]
args_in_align.file_ext = "st"
prmMod.new_align_yaml(args_in_align)
align.update_yaml(args_in_align, None)
align.run(newstack=True, do_align=False, args_in=args_in_align, exclusive=False)
print("Created stacks for input to AreTomo")
except:
warnings.warn("Stacks could not be created, IMOD might not be loaded")
raise ImportError("Stacks could not be created, IMOD might not be loaded")


def _find_files_with_ext(ext, rootname, suffix, directory):
Expand All @@ -337,13 +342,14 @@ def _get_yaml_filename(aretomo_mode, project_name):
def _get_process_list(file_list, rootname, suffix, ext):
ts_list = []
for st in file_list:
st_bn = os.path.basename(st)
if suffix != "":
ts_list.append(
st_bn.split(f"{rootname}_")[1].split(f"_{suffix}{ext}")[0][:-1]
)
else:
ts_list.append(st_bn.split(f"{rootname}_")[1].split(ext)[0][:-1])
st_bn = os.path.splitext(os.path.basename(st))[0]
# if suffix != "":
# ts_list.append(
# # int(st_bn.split(f"{rootname}_")[1].split(f"_{suffix}{ext}")[0][:-1])
# )
# else:
# ts_list.append(int(st_bn.split(f"{rootname}_")[1].split(ext)[0][:-1]))
ts_list.append(int(st_bn.split("_")[-1]))
return ts_list


Expand Down Expand Up @@ -426,8 +432,8 @@ def update_yaml(args):
out_file_list = [
(
f"{aretomo_params.params['System']['output_path']}/"
f"{rootname}_{curr_ts}{suffix}/"
f"{rootname}_{curr_ts}{suffix}{ext}"
f"{rootname}_{curr_ts:03}{suffix}/"
f"{rootname}_{curr_ts:03}{suffix}{ext}"
)
for curr_ts in ts_list
]
Expand Down
1 change: 0 additions & 1 deletion src/Ot2Rec/ctffind.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import pandas as pd
from icecream import ic

from . import user_args as uaMod
from . import mgui_ctffind as mgMod
from . import metadata as mdMod
from . import logger as logMod
Expand Down
1 change: 0 additions & 1 deletion src/Ot2Rec/ctfsim.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from icecream import ic

from . import user_args as uaMod
from . import magicgui as mgMod
from . import metadata as mdMod
from . import logger as logMod
Expand Down
Loading