General Utilities
These utilites are used by the pipeliner for basic tasks such as nice looking on-screen display, checking file names, and getting directory and file names
- pipeliner.utils.check_for_illegal_symbols(check_string: str, string_name: str = 'input', exclude: str = '')
Check a text string doesn’t have any of the disallowed symbols.
Illegal symbols are !*?()^/#<>&%{}$.”’ and @.
- Parameters
- Raises
ValueError – If illegal symbols are present in the test string
- pipeliner.utils.clean_jobname(jobname: str) str
Makes sure job names are in the correct format
Job names must have a trailing slash, cannot begin with a slash, and have no illegal characters
- pipeliner.utils.date_time_tag(compact: bool = False) str
Get a current date and time tag
If can return a compact version or one that is easier to read
- pipeliner.utils.decompose_pipeline_filename(fn_in: str) Tuple[str, Optional[int], str]
Breaks a job name into usable pieces
Returns everything before the job number, the job number as an int and everything after the job number setup for up to 20 dirs deep. The 20 directory limit is from the relion code but no really necessary anymore
- Parameters
fn_in (str) – The job or file name to be broken down in the format: <jobtype>/jobxxx/<filename>
- Returns
- Return type
- Raises
ValueError – If the input file name is more than 20 directories deep
- pipeliner.utils.find_common_string(input_strings: List[str]) str
Find the common part of a list of strings starting from the beginning
- Parameters
input_strings (list) – List of strings to compare
- Returns
The common portion of the strings
- Return type
- Raises
ValueError – If input_list is shorter than 2
- pipeliner.utils.fix_newlines(file_path: str)
Replace LF+CR new lines in files with LF, because RELION doesn’t like them
- Parameters
file_path (str) – The file to fix
- pipeliner.utils.get_pipeliner_root() pathlib.Path
Get the directory of the main pipeliner module
- Returns
The path of the pipeliner
- Return type
path
- pipeliner.utils.print_nice_columns(list_in: List[str], err_msg: str = 'ERROR: No items in input list')
Takes a list of items and makes three columns for nicer on-screen display
- pipeliner.utils.quotate_command_list(commands: List[list]) List[list]
Adds quotation marks to commands arguments that need them
If a command is to be run in terminal some args need to be quotated. Quotation marks are not needed if the command list is run with subprocess.run but they are if the command is run as a string in a qsub script or in the terminal
Any arg that contains a space or the set of characters !*?()^#<>&%{}$@ will be quotated
- pipeliner.utils.smart_strip_quotes(in_string: str) str
Strip the quotes from a string in a intellegant manner
Remove leading and ending ‘ and ” but don’t remove them internally
- pipeliner.utils.touch(filename: str)
Create an empty file
- Parameters
filename (str) – The name for the file to create
- pipeliner.utils.truncate_number(number: float, maxlength: int) str
Return a number with no more than x decimal places but no trailing 0s
This is used to format numbers in the exact same way that RELION does it. IE: with maxlength 3; 1.2000 = 1.2, 1.0 = 1, 1.23 = 1.23. RELION commands are happy to accept numbers with any number of decimal places or trailing 0s. This function is just to maintain continuity between RELION and pipeliner commands