Exemplo n.º 1
0
    def percent(dataframe: hint.dataframe) -> None:
        """
        Add percent resist column

        Args:
            dataframe: dataframe to process

        Effects:
            add percent column
        """
        def resist(row) -> float:
            """
            Percent resistant of row value

            Args:
                row: row of dataframe

            Returns:
                percent resistant
            """

            ss = row['genotype_susceptible']
            sr = row['genotype_heterozygous']
            rr = row['genotype_resistant']

            total = 2 * (ss + sr + rr)

            if total == 0:
                return np.nan
            else:
                r = 2 * rr + sr

                return r / total

        dataframe['percent'] = dataframe.apply(lambda row: resist(row), axis=1)
Exemplo n.º 2
0
    def _cut_dataframe(dataframe: hint.dataframe) -> hint.dataframe:
        """
        Cut the dataframe to start at the new point

        Args:
            dataframe: dataframe to cut

        Returns:
            the cut dataframe
        """

        new = dataframe.copy()
        new = new.iloc[start_point:]
        new.reset_index(inplace=True, drop=True)

        return new
    def cut_dataframe(self, dataframe: hint.dataframe) -> hint.dataframe:
        """
        Cut dataframe to start at new point

        Args:
            dataframe: dataframe to cut

        Returns:
            the cut dataframe
        """

        new = dataframe.copy()
        new = new.iloc[self.cut_point:]
        new.reset_index(inplace=True, drop=True)
        new['index'] = range(len(new.index))

        return new
def percent_dataframe(dataframe: hint.dataframe) -> None:
    """
    Add percent resist column

    Args:
        dataframe: dataframe to process

    Effects:
        add percent column
    """

    def resist(row) -> float:
        """
        Percent resistant of row value

        Args:
            row: row of dataframe

        Returns:
            percent resistant
        """

        ss = row[runs.columns[2]]
        sr = row[runs.columns[1]]
        rr = row[runs.columns[0]]

        total = 2 * (ss + sr + rr)

        if total == 0:
            return np.nan
        else:
            r = 2 * rr + sr

            return r / total

    dataframe['new'] \
        = dataframe.apply(lambda row: resist(row), axis=1)
Exemplo n.º 5
0
    def ratios(dataframe: hint.dataframe) -> None:
        """
        Add ratio of genotype columns

        Args:
            dataframe: dataframe to process

        Effects:
            add ratio columns
        """
        def resist(row) -> float:
            """
            Percent resistant of row value

            Args:
                row: row of dataframe

            Returns:
                percent resistant
            """

            ss = row['genotype_susceptible']
            sr = row['genotype_heterozygous']
            rr = row['genotype_resistant']

            total = ss + sr + rr

            if total == 0:
                return 0
            else:
                return rr / total

        def suscept(row) -> float:
            """
            Percent susceptible of row value

            Args:
                row: row of dataframe

            Returns:
                percent resistant
            """

            ss = row['genotype_susceptible']
            sr = row['genotype_heterozygous']
            rr = row['genotype_resistant']

            total = ss + sr + rr

            if total == 0:
                return 0
            else:
                return ss / total

        def hetero(row) -> float:
            """
            Percent hetero of row value

            Args:
                row: row of dataframe

            Returns:
                percent resistant
            """

            ss = row['genotype_susceptible']
            sr = row['genotype_heterozygous']
            rr = row['genotype_resistant']

            total = ss + sr + rr

            if total == 0:
                return 0
            else:
                return sr / total

        dataframe['percent_resist'] = \
            dataframe.apply(lambda row: resist(row), axis=1)

        dataframe['percent_suscept'] = \
            dataframe.apply(lambda row: suscept(row), axis=1)

        dataframe['percent_hetero'] = \
            dataframe.apply(lambda row: hetero(row), axis=1)