def plotTransformations(self, plot_filename="transformations.png"):

        log = self.log(inplace=False)
        vst = self.transform(inplace=False, method="vst")
        rlog = self.transform(inplace=False, method="rlog")

        def counts2meanSdPlot(df):
            ''' takes a counts object and returns a dataframe with standard
            deviation vs. average expression'''

            mean_sd_df = pd.DataFrame({"mean": df.table.apply(np.mean, axis=1),
                                       "std": df.table.apply(np.std, axis=1)})

            mean_sd_df = mean_sd_df[mean_sd_df["mean"] > 0]

            mean_sd_df.sort("mean", inplace=True)
            return mean_sd_df

        plotTransformations = R('''
        function(log_df, rlog_df, vst_df, plot_outfile){

          library(ggplot2)
          library("gridExtra")

          plotMeanSd = function(df, ymax, title){
            df$index <- as.numeric(row.names(df))
            df$bin = .bincode(df$index, seq(1,max(df$index),1000))

            l_txt = element_text(size=20)
            m_txt = element_text(size=15)

            p = ggplot(df, aes(x=index, y=std)) +
                geom_point(alpha=0.1)  +
                stat_summary(mapping=aes(x=bin*1000, y=std),
                             col="red", geom = "point",
                             fun.y = "median", size=5) +
            theme_minimal() +
            ylim(0, ymax) +
            xlab("index") + ylab("sd") +
            theme(axis.text.x=element_text(size=15, angle=90,
                                           hjust=1, vjust=0.5),
                  axis.text.y=m_txt,
                  axis.title.y=m_txt,
                  title=m_txt) +
            ggtitle(title)

            return (p)
        }

        max_sd = max(log_df$std, rlog_df$std, vst_df$std)

        p1 = plotMeanSd(log_df, max_sd, "log")
        p2 = plotMeanSd(rlog_df, max_sd, "rlog")
        p3 = plotMeanSd(vst_df, max_sd, "vst")

        png("%(plot_filename)s",
            width=10, height=10, units="in", res=400, pointsize=1)
        grid.arrange(p1, p2, p3, ncol=3)
        dev.off()
        }''' % locals())

        mean_sd_log_df = counts2meanSdPlot(log)
        mean_sd_vst_df = counts2meanSdPlot(vst)
        mean_sd_rlog_df = counts2meanSdPlot(rlog)

        plotTransformations(mean_sd_log_df, mean_sd_rlog_df, mean_sd_vst_df)
Run the test suite
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Counts.py/Counts.plotTransformations--crossover with--dataset/ETHPy150Open sahana/eden/modules/unit_tests/modules/s3layouts.py/run_suite