Beispiel #1
0
    def plot(
            self,
            types=None,
            clr: bool = False,
            kwargs: Dict = dict(ls="", marker=".", rasterized=True),
            line_kwargs: Dict = dict(),
    ) -> None:
        r"""Plot the :math:`k`-SFS

        Args:
            types: iterable of mutation type names to restrict plotting to
            clr: flag to normalize to total mutation intensity and display as
                 centered log ratio transform
            kwargs: key word arguments passed to data scatter plot
            line_kwargs: key word arguments passed to expectation line plot
        """
        if self.η is not None and self.r is None:
            print(
                "warning: misidentification rate is not defined, perhaps due"
                " to folded SFS inference, and will be set to 0 for plotting")
            r_vector = np.zeros(self.X.shape[1])
        else:
            r_vector = self.r_vector
        if self.μ is not None:
            Ξ = self.L @ self.μ.Z
            Ξ = Ξ * (1 - r_vector) + self.AM_freq @ Ξ @ (
                self.AM_mut * r_vector[:, np.newaxis])
        if clr:
            X = cmp.clr(self.X)
            if self.μ is not None:
                Ξ = cmp.clr(Ξ)
            plt.ylabel("variant count composition\n(CLR transformed)")
        else:
            X = self.X
            plt.ylabel("number of variants")
        if types is not None:
            idxs = [self.mutation_types.get_loc(type) for type in types]
            X = X[:, idxs]
            if self.μ is not None:
                Ξ = Ξ[:, idxs]

        plt.plot(range(1, self.n), X, **kwargs)
        if self.μ is not None:
            plt.gca().set_prop_cycle(None)
            plt.plot(range(1, self.n), Ξ, **line_kwargs)
        plt.xlabel("sample frequency")
        plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
        plt.xscale("log")
        plt.tight_layout()
Beispiel #2
0
    def plot_cumulative(self,
                        t_gen: float = None,
                        clr: bool = False,
                        **kwargs) -> None:
        r"""Plot the cumulative mutation rate, like a Muller plot

        Args:
            t_gen: generation time in years (optional)
            clr: flag to normalize to total mutation intensity and display as
                 centered log ratio transform
            kwargs: key word arguments passed to ``plt.fill_between``
        """
        t = np.concatenate((np.array([0]), self.change_points))
        if t_gen:
            t *= t_gen
            t_unit = "years ago"
        else:
            t_unit = "generations ago"
        Z = np.cumsum(self.Z, axis=1)
        if clr:
            Z = cmp.clr(Z)
        for j in range(Z.shape[1]):
            plt.fill_between(t, Z[:, j - 1] if j else 0, Z[:, j], **kwargs)
        plt.xlabel(f"$t$ ({t_unit})")
        plt.ylabel("$\\mu(t)$")
        plt.xscale("log")
        plt.tight_layout()
Beispiel #3
0
    def plot(self,
             types: List[str] = None,
             clr: bool = False,
             **kwargs) -> None:
        """Plot history.

        Args:
            types: list of mutation types to plot (default all)
            clr: flag to normalize to total mutation intensity and display as
                 centered log ratio transform
        """
        lines = super().plot(types=types, **kwargs)
        if clr:
            Z = cmp.clr(self.Z)
            if types is None:
                idxs = range(len(lines))
            else:
                idxs = [self.mutation_types.get_loc(type) for type in types]
            for idx, line in zip(idxs, lines):
                line.set_ydata(Z[:, idx])
            # recompute the ax.dataLim
            ax = plt.gca()
            ax.relim()
            # update ax.viewLim using the new dataLim
            ax.autoscale_view()
            # plt.ylabel('relative mutation intensity')
            plt.ylabel("mutation intensity composition\n(CLR transformed)")
        else:
            plt.ylabel("$\\mu(t)$")
        plt.tight_layout()
Beispiel #4
0
    def plot(
        self,
        types=None,
        clr: bool = False,
        kwargs: Dict = dict(ls='', marker='.', rasterized=True),
        line_kwargs: Dict = dict()
    ) -> None:
        r"""Plot the :math:`k`-SFS

        Args:
            types: iterable of mutation type names to restrict plotting to
            clr: flag to normalize to total mutation intensity and display as
                 centered log ratio transform
            kwargs: key word arguments passed to data scatter plot
            line_kwargs: key word arguments passed to expectation line plot
        """
        if self.μ is not None:
            Ξ = self.L @ self.μ.Z
        if clr:
            X = cmp.clr(self.X)
            if self.μ is not None:
                Ξ = cmp.clr(Ξ)
            plt.ylabel('variant count composition\n(CLR transformed)')
        else:
            X = self.X
            plt.ylabel('number of variants')
        if types is not None:
            idxs = [self.mutation_types.get_loc(type) for type in types]
            X = X[:, idxs]
            if self.μ is not None:
                Ξ = Ξ[:, idxs]

        plt.plot(range(1, self.n), X, **kwargs)
        if self.μ is not None:
            plt.gca().set_prop_cycle(None)
            plt.plot(range(1, self.n), Ξ, **line_kwargs)
        plt.xlabel('sample frequency')
        plt.xscale('log')
        plt.tight_layout()