Skip to content

Commit

Permalink
ensure rlnTomoName is correctly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
EuanPyle authored and Euan William Pyle committed May 7, 2024
1 parent 6d5addd commit feab197
Show file tree
Hide file tree
Showing 11 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ class Config:

@classmethod
def from_star_file(cls, filename: os.PathLike):
star = starfile.read(filename, always_dict=True)
star = starfile.read(filename, always_dict=True, parse_as_string=['rlnTomoName'])
tilt_series_id = list(star.keys())[0]
return cls(name=tilt_series_id, data=starfile.read(filename))
return cls(name=tilt_series_id, data=starfile.read(filename, parse_as_string=['rlnTomoName']))

def write_star_file(self, filename: os.PathLike):
starfile.write({self.name: self.data}, filename, overwrite=True)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def from_star_file(
filename: os.PathLike,
tilt_series_id: Optional[str] = None
):
star = starfile.read(filename, always_dict=True)
star = starfile.read(filename, always_dict=True, parse_as_string=['rlnTomoName'])
global_df = star['global'].set_index('rlnTomoName', drop=False)
if tilt_series_id is not None: # get single tilt-series
global_df = global_df.loc[tilt_series_id]
Expand Down
2 changes: 1 addition & 1 deletion src/tomography_python_programs/denoise/cryoCARE/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def cryoCARE_predict(
else:
predict_executable = "cryoCARE_predict.py"

global_star = starfile.read(tomogram_star_file, always_dict=True)['global']
global_star = starfile.read(tomogram_star_file, always_dict=True, parse_as_string=['rlnTomoName'])['global']

if not model_file.exists():
e = f'Could not find denoise model'
Expand Down
2 changes: 1 addition & 1 deletion src/tomography_python_programs/denoise/cryoCARE/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def cryoCARE_train(
extract_train_data_executable = "cryoCARE_extract_train_data.py"


global_star = starfile.read(tomogram_star_file, always_dict=True)['global']
global_star = starfile.read(tomogram_star_file, always_dict=True, parse_as_string=['rlnTomoName'])['global']

if not 'rlnTomoReconstructedTomogramHalf1' in global_star.columns:
e = 'Could not find rlnTomoReconstructedTomogramHalf1 in tomogram star file.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ def get_poses_along_filament_backbones(
"during refinement."
)
):
global_df = starfile.read(tilt_series_star_file)
global_df = starfile.read(tilt_series_star_file, parse_as_string=['rlnTomoName'])
global_df = global_df.set_index('rlnTomoName')
annotation_files = annotations_directory.glob('*_filaments.star')
dfs = []
for file in annotation_files:
filament_df = starfile.read(file)
filament_df = starfile.read(file, parse_as_string=['rlnTomoName'])
tilt_series_id = '_'.join(file.name.split('_')[:-1])
pixel_size = float(
global_df.loc[tilt_series_id, 'rlnTomoTiltSeriesPixelSize']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ def combine_particle_annotations(
):
console.log("Running get_particle_poses particles.")

global_df = starfile.read(tilt_series_star_file)
global_df = starfile.read(tilt_series_star_file, parse_as_string=['rlnTomoName'])
global_df = global_df.set_index('rlnTomoName')
annotation_files = annotations_directory.glob('*_particles.star')
dfs = []
for file in annotation_files:
df = starfile.read(file)
df = starfile.read(file, parse_as_string=['rlnTomoName'])
tilt_series_id = '_'.join(file.name.split('_')[:-1])
pixel_size = float(
global_df.loc[tilt_series_id, 'rlnTomoTiltSeriesPixelSize'])
Expand Down Expand Up @@ -89,8 +89,8 @@ def create_annotations_from_previous_star_file(

annotations_directory.mkdir(parents=True, exist_ok=True)

star_data = starfile.read(in_star_file)
tomo_data = starfile.read(tomograms_file)
star_data = starfile.read(in_star_file, parse_as_string=['rlnTomoName'])
tomo_data = starfile.read(tomograms_file, parse_as_string=['rlnTomoName'])
tomo_data = tomo_data.set_index('rlnTomoName')

if isinstance(star_data, pd.DataFrame):
Expand Down
4 changes: 2 additions & 2 deletions src/tomography_python_programs/get_particle_poses/spheres.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ def derive_poses_on_spheres(
..., help="target spacing between particle poses on spheres in angstroms."
),
):
global_df = starfile.read(tilt_series_star_file)
global_df = starfile.read(tilt_series_star_file, parse_as_string=['rlnTomoName'])
global_df = global_df.set_index('rlnTomoName')
annotation_files = annotations_directory.glob('*_spheres.star')
dfs = []
for file in annotation_files:
sphere_df = starfile.read(file)
sphere_df = starfile.read(file, parse_as_string=['rlnTomoName'])
tilt_series_id = '_'.join(file.name.split('_')[:-1])
pixel_size = float(
global_df.loc[tilt_series_id, 'rlnTomoTiltSeriesPixelSize'])
Expand Down
2 changes: 1 addition & 1 deletion src/tomography_python_programs/pick/filaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def save_particles(self):
def load_particles(self) -> N3dPaths:
if not self.current_particle_star_file.exists():
raise FileNotFoundError
df = starfile.read(self.current_particle_star_file)
df = starfile.read(self.current_particle_star_file, parse_as_string=['rlnTomoName'])
paths = []
for _, _df in df.groupby('rlnTomoManifoldIndex'):
zyx = _df[['rlnCoordinateZ', 'rlnCoordinateY', 'rlnCoordinateX']].to_numpy()
Expand Down
2 changes: 1 addition & 1 deletion src/tomography_python_programs/pick/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def save_particles(self):
def load_particles(self) -> N3dPoints:
if not self.current_particle_star_file.exists():
raise FileNotFoundError
df = starfile.read(self.current_particle_star_file)
df = starfile.read(self.current_particle_star_file, parse_as_string=['rlnTomoName'])
zyx = df[['rlnCoordinateZ', 'rlnCoordinateY', 'rlnCoordinateX']].to_numpy()

return N3dPoints(data=zyx)
Expand Down
2 changes: 1 addition & 1 deletion src/tomography_python_programs/pick/spheres.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def save_particles(self):
def load_particles(self) -> N3dSpheres:
if not self.current_particle_star_file.exists():
raise FileNotFoundError
df = starfile.read(self.current_particle_star_file)
df = starfile.read(self.current_particle_star_file, parse_as_string=['rlnTomoName'])
zyx = df[['rlnCoordinateZ', 'rlnCoordinateY', 'rlnCoordinateX']].to_numpy()
radii = df['rlnSphereRadius'].to_numpy()
return N3dSpheres(centers=zyx, radii=radii)
Expand Down
4 changes: 2 additions & 2 deletions src/tomography_python_programs/view/particles.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,15 +174,15 @@ def view_particles(
)
):
# read in particle STAR file and get particle dataframe per tomogram
star = starfile.read(particle_star_file, always_dict=True)
star = starfile.read(particle_star_file, always_dict=True, parse_as_string=['rlnTomoName'])
particle_df = star['particles']
if 'optics' in star:
particle_df = particle_df.merge(star['optics'], on='rlnOpticsGroup')
particle_df_grouped = particle_df.groupby('rlnTomoName')

# if requested, read in tomogram STAR file and get dataframe per tomogram
if tilt_series_star_file is not None:
tomogram_df = starfile.read(tilt_series_star_file)
tomogram_df = starfile.read(tilt_series_star_file, parse_as_string=['rlnTomoName'])
tomogram_df_grouped = tomogram_df.groupby('rlnTomoName')

# construct a widget for switching between different tomograms
Expand Down

0 comments on commit feab197

Please sign in to comment.