Star File Utilities
- class pipeliner.starfile_handler.BodyFile(fn_in: str)
Bases:
StarFileA STAR file that lists the bodies in a multibody refinement
- class pipeliner.starfile_handler.JobStar(fn_in: str)
Bases:
StarFileA class for STAR files that define a pipeliner job parameters
- joboptions
The joboptions {name: value} all values are strings regardless of joboption type
- Type:
- all_options_as_dict() Dict[str, str]
Returns a dict of all the parameters of a job.star file
The dict contains both the job options and the running options. All values in the dict are strings.
- make_substitutions(conversions: Dict[str, str])
Substitute one job name or file name for another wherever it appears
- modify(params_to_change: dict, allow_add=False)
Change multiple values in a job.star from a dict
- Parameters:
- Raises:
ValueError – If an attempt is made to add new fields with allow_add=False
- class pipeliner.starfile_handler.StarFile(fn_in: str | PathLike[str])
Bases:
objectA superclass for all types of STAR files used by the pipeliner
- column_as_list(blockname: str | None, colname: str) List[str]
Return a single column from a block as a list
- count_block(blockname: str | None = None) int
Count the number of items in a block that only contains a single loop
This is the format in most relion data STAR files
- get_block(blockname: str | None = None) Block
Get a block from the STAR file
- Parameters:
blockname (str) – The name of the block to get. Use
Noneif the file has a single unnamed block- Returns:
The desired block or None if not found
- Return type:
- loop_as_list(block: str = '', columns: List[str] | None = None, headers: bool = False) List[List[str]]
Returns a set of columns from a STAR file loop as a list
- Parameters:
- Returns:
- The column data one row per sublist. If headers=True
the first sublist contains the headers
- Return type:
List[List[str]]
- Raises:
ValueError – If the specified block is not found
ValueError – If the specified block does not contain a loop
ValueError – If any of the specified columns are not found
- pairs_as_dict(block: str = '') Dict[str, str]
Returns paired values from a STAR file as a dict
- Parameters:
block (str) – The name of the block to get the data from
- Returns:
{parameter: value}
- Return type:
- Raises:
ValueError – If the specified block is not found
ValueError – If the specified block is a loop and not a pair-value
- pipeliner.starfile_handler.convert_old_relion_pipeline(fn_in: str)
Convert a pipeline STAR file from RELION 3 or 4 to ccpem-pipeliner format.
The file is also checked and corrected if it contains any reserved words which would cause Gemmi’s CIF parser to fail when the file is read.
Note that this function reads the whole file several times, but pipeline STAR files are never expected to be so large that this would take a significant amount of time.
- Returns:
Trueif the file was converted, orFalseotherwise.- Raises:
ValueError – if the pipeline file is invalid or its version cannot be determined
- pipeliner.starfile_handler.fix_reserved_words(fn_in)
Make sure the STAR file doesn’t contain any illegally used reserved words
Overwrites the original file if it is corrected. The old file is saved as
filename.orig.- Returns:
Trueif the file was corrected, orFalseif it contained no reserved words and did not need correcting.
- pipeliner.starfile_handler.get_particle_box_size_from_starfile(starfile: str) int
Get the image size in pixels from a starfile from the optics group(s)
assumes the images are square and all the same size
- pipeliner.starfile_handler.get_pixel_size_from_starfile(starfile: str) float
Get the pixel size from a starfile from the optics group(s)
- pipeliner.starfile_handler.get_starfile_loop_headers(in_file: str) Dict[str, List[str]]
Get the headers for each loop in each block in a STAR file
- pipeliner.starfile_handler.interconvert_box_star_coords(fn_in: str, out_name: str | None = None) str
Interconvert .box and .star coordinate files
- Parameters:
- Returns:
Name of the file written
- Return type:
- Raises:
ValueError – If the file is not .box or .star
- pipeliner.starfile_handler.quotate_starfile_line(in_line: str) str | None
Adds the necessary quotation to a line to make it compatible with gemmi
- pipeliner.starfile_handler.read_relion_optimiser_starfile(fn_in) Dict[str, str]
Special function for reading optimiser.star files written by relion
These files have issues with duplicate entries because of a Relion5 bug, which precludes use of gemmi because it raises an error if it encounters duplicate entires If a duplicate entry exists it uses the value from the last instance.
- Parameters:
fn_in (str) – Name of the optimiser file
- Returns:
The param-value pairs from the file
- Return type:
- Raises:
ValueError – If the file isn’t an optimiser file
Starfile writing utilities
Writes STAR files in the same style as RELION
- pipeliner.star_writer.star_quote(val: str) str
Quote a string value as needed for writing to a STAR file.
If the value contains only characters that can be safely written without quoting, and does not begin with a reserved word of the STAR format, it is returned unchanged.
Otherwise, the value is passed to
gemmi.cif.quote()for quoting, which handles all of the more complicated quoting logic that is sometimes required.
- pipeliner.star_writer.write(doc: Document, filename: str | PathLike[str])
Write a Gemmi CIF document to a RELION-style STAR file.
The file is written as an atomic operation. This ensures that any processes reading it will always see a valid version (old or new) and not a half-written new file.
The document is written to a temporary file first, then after the writing is complete and the file has been flushed to disk, the target file is replaced with the temporary one. The temporary file will always be removed even if the replacement is unsuccessful.
Note: it is still possible for data to be lost using this function, if two processes try to write to the file at the same time. In that case, one of the new versions of the file will be kept and the other will not.
- Parameters:
doc (
gemmi.cif.Document) – The data to write outfilename (str or pathlib.Path) – The name of the file to write the data to