tomodrgn.starfile.GenericStarfile#
- class GenericStarfile(starfile: str | None = None, *, dictionary: dict | None = None, dataframe: DataFrame | None = None)[source]#
Bases:
object
Class to parse a STAR file, a pre-existing pandas dataframe, or a pre-existing dictionary, to a dictionary of dictionaries or pandas dataframes. Simple two-column STAR blocks are parsed as dictionaries, while complex table-style blocks are parsed as pandas dataframes.
Notes:
Will ignore comments between loop_ and beginning of data block; will not be preserved if using .write()
Will raise a RuntimeError if a comment is found within a data block initiated with loop
Methods
Load particle images referenced by starfile
Attempt to identify the block_name of the data block within the star file for which rows refer to particle data (as opposed to optics or other data).
Write out the starfile dataframe(s) as a new file
- get_particles_stack(particles_block_name: str | None = None, particles_path_column: str | None = None, datadir: str | None = None, lazy: bool = False) ndarray | list[LazyImage] [source]#
Load particle images referenced by starfile
- Parameters:
particles_block_name – name of star file block containing particle path column (e.g. data_, data_particles)
particles_path_column – name of star file column containing path to particle images .mrcs (e.g. _rlnImageName)
datadir – absolute path to particle images .mrcs to override particles_path_column
lazy – whether to load particle images now in memory (False) or later on-the-fly (True)
- Returns:
np.ndarray of shape (n_ptcls * n_tilts, D, D) or list of LazyImage objects of length (n_ptcls * n_tilts)
- identify_particles_data_block(column_substring: str = 'Angle') str [source]#
Attempt to identify the block_name of the data block within the star file for which rows refer to particle data (as opposed to optics or other data).
- Parameters:
column_substring – Search pattern to identify as substring within column name for particles block
- Returns:
the block name of the particles data block (e.g. data or data_particles)
- write(outstar: str, timestamp: bool = False) None [source]#
Write out the starfile dataframe(s) as a new file
- Parameters:
outstar – name of the output star file, optionally as absolute or relative path
timestamp – whether to include the timestamp of file creation as a comment in the first line of the file
- Returns:
None