repic.utils.coord_converter =========================== .. py:module:: repic.utils.coord_converter .. autoapi-nested-parse:: Converts particle bounding box coordinates between different formats (STAR, BOX, dat, coord, etc.) Attributes ---------- .. autoapisummary:: repic.utils.coord_converter.STAR_COL_X repic.utils.coord_converter.STAR_COL_Y repic.utils.coord_converter.STAR_COL_C repic.utils.coord_converter.STAR_COL_N repic.utils.coord_converter.DF_COL_NAMES repic.utils.coord_converter.STAR_HEADER_MAP repic.utils.coord_converter.BOX_HEADER_MAP repic.utils.coord_converter.CBOX_HEADER_MAP repic.utils.coord_converter.TSV_HEADER_MAP repic.utils.coord_converter.CS_HEADER_MAP repic.utils.coord_converter.AUTO repic.utils.coord_converter.parser Classes ------- .. autoapisummary:: repic.utils.coord_converter.Box Functions --------- .. autoapisummary:: repic.utils.coord_converter._log repic.utils.coord_converter._is_int repic.utils.coord_converter._row_is_all_nonnumeric repic.utils.coord_converter._has_numbers repic.utils.coord_converter._make_parent_dir repic.utils.coord_converter._path_occupied repic.utils.coord_converter.cs_to_df repic.utils.coord_converter.star_to_df repic.utils.coord_converter.tsv_to_df repic.utils.coord_converter.df_to_star repic.utils.coord_converter.df_to_tsv repic.utils.coord_converter.process_conversion Module Contents --------------- .. py:class:: Box Bases: :py:obj:`tuple` .. py:attribute:: x .. py:attribute:: y .. py:attribute:: w .. py:attribute:: h .. py:attribute:: conf .. py:data:: STAR_COL_X :value: '_rlnCoordinateX' STAR file column name for x-coordinate of particle bounding box .. py:data:: STAR_COL_Y :value: '_rlnCoordinateY' STAR file column name for y-coordinate of particle bounding box .. py:data:: STAR_COL_C :value: '_rlnAutopickFigureOfMerit' STAR file column name for figure of merit .. py:data:: STAR_COL_N :value: '_rlnMicrographName' STAR file column name for micrograph name .. py:data:: DF_COL_NAMES :value: ['x', 'y', 'w', 'h', 'conf', 'name'] default column names for Pandas data frame .. py:data:: STAR_HEADER_MAP dictionary of header mappings for STAR file .. py:data:: BOX_HEADER_MAP dictionary of header mappings for BOX file .. py:data:: CBOX_HEADER_MAP dictionary of header mappings for cBOX file .. py:data:: TSV_HEADER_MAP dictionary of header mappings for TSV file .. py:data:: CS_HEADER_MAP dictionary of header mappings for CryoSparc file .. py:data:: AUTO :value: 'auto' flag for automatically processing columns of certain file types .. py:function:: _log(msg, lvl=0, quiet=False) Formats and prints message to console with one of the following logging levels: 0: info (print and continue execution; ignore if quiet=True), 1: warning (print and continue execution), 2: error (print and exit with code 1) :param msg: message text :type msg: str :keyword lvl: logging level :kwtype lvl: int, default=0 :keyword quiet: suppress log printing :kwtype quiet: bool, default=False :returns: None .. py:function:: _is_int(val) Checks if Python object can be converted to int datatype :param val: Python object :type val: obj :returns: True if string can be converted (False otherwise) :rtype: bool .. py:function:: _row_is_all_nonnumeric(x) Checks if all elements of Pandas dataframe row are numeric values :param x: Pandas dataframe row object :type x: obj :returns: True if all elements are numeric values (False otherwise) :rtype: bool .. py:function:: _has_numbers(s) Checks if string s contains an integer :param s: string :type s: str :returns: True if string contains integer (False otherwise) :rtype: bool .. py:function:: _make_parent_dir(path_str) Creates parent directory if it does not exist :param path_str: filepath to subdirectory :type path_str: str :returns: None .. py:function:: _path_occupied(path_str) Checks if file path is a file :param path_str: filepath :type path_str: str :returns: True if filepath is a file (False otherwise) :rtype: bool .. py:function:: cs_to_df(path) Converts particle bounding box coordinate file (in CryoSparc format) into a Pandas dataframe with the correct column headers :param path: filepath to particle bounding box file :type path: str :returns: Pandas dataframe of particle bounding box coordinates :rtype: obj .. py:function:: star_to_df(path) Converts particle bounding box coordinate file (in STAR file format) into a Pandas dataframe with the correct column headers :param path: filepath to particle bounding box file :type path: str :returns: Pandas dataframe of particle bounding box coordinates :rtype: obj .. py:function:: tsv_to_df(path, header_mode=None) Converts particle bounding box coordinate file (in TSV-like file format) into a Pandas dataframe, skipping any non-numeric header rows :param path: filepath to particle bounding box file :type path: str :keyword header_mode: One of None, "infer" or an int (row index). If None, any non-numeric rows at the top of the file are skipped and column names are not set. Otherwise, manual column skipping is not performed, and header_mode is passed directly to the header argument of pandas.read_csv :kwtype header_mode: int, str, or None :returns: Pandas dataframe of particle bounding box coordinates :rtype: obj .. py:function:: df_to_star(df, out_path, force=False) Writes Panda dataframe of particle bounding box coordinates (generated from one of the *_to_df methods) to storage in STAR file format :param df: Pandas dataframe of particle bounding box coordinates :type df: object :param out_path: filepath to output file :type out_path: str :keyword force: overwrite output file if it exists :kwtype force: bool, default=False :returns: None .. py:function:: df_to_tsv(df, col_order, out_path, include_header=False, force=False) Writes Panda dataframe of particle bounding box coordinates (generated from one of the *_to_df methods) to storage, optionally writing out [x, y, w, h, conf] labels as a header :param df: Pandas dataframe of particle bounding box coordinates :type df: object :param col_order: list of ordered file columns :type col_order: list :param out_path: filepath to output file :type out_path: str :keyword include_header: include header in output file :kwtype include_header: bool, default=False :keyword force: overwrite output file if it exists :kwtype force: bool, default=False :returns: None .. py:function:: process_conversion(paths, in_fmt, out_fmt, boxsize=None, out_dir=None, in_cols=('auto', 'auto', 'auto', 'auto', 'auto', 'auto'), out_col_order=('x', 'y', 'w', 'h', 'conf', 'name'), suffix='', include_header=False, single_out=False, multi_out=False, round_to=None, norm_conf=None, require_conf=None, force=False, quiet=False) Converts between different particle bounding box formats :param paths: filepaths of particle bounding box coordinate files :type paths: list :param in_fmt: input file format :type in_fmt: str :param out_fmt: output file format :type out_fmt: str :keyword boxsize: particle bounding box height/width :kwtype boxsize: int or None :keyword out_dir: filepath to output file :kwtype out_dir: str or None :keyword in_cols: tuple of column determination (default=auto) :kwtype in_cols: tuple :keyword out_col_order: output column order :kwtype out_col_order: tuple :keyword suffix: additional suffix for output files (default='') :kwtype suffix: str :keyword include_header: include header in output file :kwtype include_header: bool, default=False :keyword single_out: output particle bounding box coordinates in a single file :kwtype single_out: bool, default=False :keyword multi_out: output particle bounding box coordinates in multiple files (one per micrograph) :kwtype multi_out: bool, default=False :keyword round_to: round coordinates to the specified number of decimal places :kwtype round_to: int or None :keyword norm_conf: list of min and max confidence values to be used to normalize observed confidence scores :kwtype norm_conf: list or None :keyword require_conf: model confidence score to assign to particle bounding boxes without a score :kwtype require_conf: float or None :keyword force: overwrite output file if it exists :kwtype force: bool, default=False :keyword quiet: suppress log printing :kwtype quiet: bool, default=False :returns: None .. py:data:: parser argparse parse_args() object :type: obj