Пример #1
0
    def MAF_comparison_boxplot(self):
        long_format_mafs = self._generate_maf_long_df()

        populations_to_plot = {
            "superpopulation": ['AFR', 'EUR', 'AMR'],
            "population": Dataset.used_populations(),
        }
        for population_level, long_df in long_format_mafs.items():
            population_list = populations_to_plot[population_level]
            mask = long_df["population"].isin(population_list)
            long_df = long_df[mask]
            fig_width = 13 if population_level == "population" else 7
            fig = plt.figure(figsize=(fig_width, 4))
            ax = fig.add_subplot(1, 1, 1)

            panel_labels = long_df["panel"].unique()
            colors = [v for k, v in panel_colors().items() if k in panel_labels]

            sns.boxplot(data=long_df, x="population", y="MAF", hue="panel",
                        ax=ax, linewidth=0.3, showcaps=False, showfliers=False,
                        palette=sns.color_palette(colors), width=0.70)

            self._boxplot_aesthetics(ax)

            filename = "MAF_comparison__{}".format(population_level)
            plt.savefig(join(self.PLOTS_DIR, filename), bbox_inches="tight")
            plt.show()
    def plot(self, filename, panel_list, ancestries_df):
        dataset_label, _ = self._unique_dataset_and_K_check(ancestries_df)
        dataset = Dataset(dataset_label)
        population_order = Dataset.used_populations()

        rows, cols = 1, len(panel_list)
        width, height = self.PLOT_SIZE
        fig = plt.figure(figsize=(cols * width, rows * height), dpi=30)
        fig.set_size_inches((cols*width), (rows*height))
        ax_ids = (np.arange(rows * cols) + 1).tolist()[::-1]

        # One subplot per panel
        for panel in panel_list:
            df_lite = ancestries_df.xs(panel.label, level="panel")
            df_lite = df_lite.reset_index(drop=True).set_index("population")
            plot_title = "Dataset: {}\n{}".format(dataset.name, panel.name)

            ax = fig.add_subplot(rows, cols, ax_ids.pop())
            fig, tax = ternary.figure(scale=1, ax=ax)

            df_lite = df_lite.loc[population_order]
            df_lite = df_lite[["EUR", "AFR", "AMR"]].dropna()
            df_grouped = df_lite.groupby(level="population", sort=False)

            for population, df_pop_group in df_grouped:
                tax.scatter(
                    df_pop_group.values, label=population, s=45,
                    alpha=0.75, color=population_colors(population),
                    marker=population_markers(population)
                )

            self._ternary_plot_aesthetics(tax, plot_title, df_lite)

        makedirs(self.PLOTS_DIR, exist_ok=True)
        plt.savefig(join(self.PLOTS_DIR, filename), bbox_inches="tight")