Skip to content

ColumnMapper

Abstract superclass for all Column Mapper classes, each of which applies a specific strategy to extracting HPO terms from columns of tables (e.g., supplemental files) representing cohorts of individuals with a given disease.

Source code in pyphetools/creation/column_mapper.py
class ColumnMapper(metaclass=abc.ABCMeta):
    """
    Abstract superclass for all Column Mapper classes, each of which applies a specific strategy to extracting HPO terms
    from columns of tables (e.g., supplemental files) representing cohorts of individuals with a given disease.
    """
    def __init__(self, column_name:str) -> None:
        """Constructor

        :param column_name: name of the column in the pandas DataFrame
        :type column_name: str
        """
        self._column_name = column_name

    @abc.abstractmethod
    def map_cell(self, cell_contents) -> List:
        """
        Map a cell to HPO Terms or other data
        """
        pass

    @abc.abstractmethod
    def preview_column(self, df:pd.DataFrame):
        """
        Show a preview of the entire column for review purposes

        :param df: the pandas DataFrame that contains the column (self._column_name)
        :type df: pd.DataFrame
        """
        pass

    @staticmethod
    def is_valid_iso8601(cell_contents):
        """Check for a match with iso8601 age (period)

        returns true for strings such as P6Y, P2M, P42Y1M2W1D etc.

        :returns: true iff the cell_contents represent an iso8601 age
        :rtype: bool
        """
        m = re.match(r"^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?$", cell_contents)
        if m:
            return True
        else:
            return False

    def get_column_name(self):
        return self._column_name

__init__(column_name)

Constructor

Parameters:

Name Type Description Default
column_name str

name of the column in the pandas DataFrame

required
Source code in pyphetools/creation/column_mapper.py
def __init__(self, column_name:str) -> None:
    """Constructor

    :param column_name: name of the column in the pandas DataFrame
    :type column_name: str
    """
    self._column_name = column_name

is_valid_iso8601(cell_contents) staticmethod

Check for a match with iso8601 age (period)

returns true for strings such as P6Y, P2M, P42Y1M2W1D etc.

Returns:

Type Description
bool

true iff the cell_contents represent an iso8601 age

Source code in pyphetools/creation/column_mapper.py
@staticmethod
def is_valid_iso8601(cell_contents):
    """Check for a match with iso8601 age (period)

    returns true for strings such as P6Y, P2M, P42Y1M2W1D etc.

    :returns: true iff the cell_contents represent an iso8601 age
    :rtype: bool
    """
    m = re.match(r"^P(?!$)(\d+Y)?(\d+M)?(\d+W)?(\d+D)?$", cell_contents)
    if m:
        return True
    else:
        return False

map_cell(cell_contents) abstractmethod

Map a cell to HPO Terms or other data

Source code in pyphetools/creation/column_mapper.py
@abc.abstractmethod
def map_cell(self, cell_contents) -> List:
    """
    Map a cell to HPO Terms or other data
    """
    pass

preview_column(df) abstractmethod

Show a preview of the entire column for review purposes

Parameters:

Name Type Description Default
df DataFrame

the pandas DataFrame that contains the column (self._column_name)

required
Source code in pyphetools/creation/column_mapper.py
@abc.abstractmethod
def preview_column(self, df:pd.DataFrame):
    """
    Show a preview of the entire column for review purposes

    :param df: the pandas DataFrame that contains the column (self._column_name)
    :type df: pd.DataFrame
    """
    pass