Source code for biocutils.print_wrapped_table

from typing import List, Optional, Sequence

import numpy

from .subset_sequence import subset_sequence


def _get_max_width(col: List[str]):
    width = 0
    for y in col:
        if len(y) > width:
            width = len(y)
    return width






[docs] def create_floating_names( names: Optional[List[str]], indices: Sequence[int] ) -> List[str]: """Create the floating names to use in :py:meth:`~print_wrapped_table`. If no names are present, positional indices are used instead. Args: names: List of row names, or None if no row names are available. indices: Integer indices for which to obtain the names. Returns: List of strings containing floating names. """ if names is not None: return list(subset_sequence(names, indices)) else: return ["[" + str(i) + "]" for i in indices]
[docs] def truncate_strings(values: List[str], width: int = 40) -> List[str]: """Truncate long strings for printing in :py:meth:`~print_wrapped_table`. Args: values: List of strings to be printed. width: Width beyond which to truncate the string. Returns: List containing truncated strings. """ replacement = values[:] for i, y in enumerate(values): if len(y) > width: replacement[i] = y[: width - 3] + "..." return replacement