def transform(self, method="vst", design=None, inplace=True, blind=True):

        assert method in ["vst", "rlog"], ("method must be one of"
                                           "[vst, rlog]")

        method2function = {"vst": "varianceStabilizingTransformation",
                           "rlog": "rlog"}

        t_function = method2function[method]

        r_counts = pandas2ri.py2ri(self.table)

        if not blind:
            assert design, ("if not using blind must supply a design table "
                            "(a CGAT.Expression.ExperimentalDesign object")

            # currently this only accepts "~group" design
            transform = R('''
            function(df, design){

            suppressMessages(library('DESeq2'))

            dds <- suppressMessages(DESeqDataSetFromMatrix(
                     countData= df, colData = design, design = ~group))

            transformed <- suppressMessages(%(t_function)s(dds, blind=FALSE))
            transformed_df <- as.data.frame(assay(transformed))

            return(transformed_df)
            }''' % locals())

            r_design = pandas2ri.py2ri(design.table)
            df = pandas2ri.ri2py(transform(r_counts, r_design))

        else:

            transform = R('''
            function(df){

            suppressMessages(library('DESeq2'))

            design = data.frame(row.names = colnames(df),
                                group = seq(1, length(colnames(df))))

            dds <- suppressMessages(DESeqDataSetFromMatrix(
                     countData= df, colData = design, design = ~group))

            transformed <- suppressMessages(%(t_function)s(dds, blind=TRUE))
            transformed_df <- as.data.frame(assay(transformed))

            return(transformed_df)
            }''' % locals())

            df = pandas2ri.ri2py(transform(r_counts))

        # losing rownames for some reason during the conversion?!
        df.index = self.table.index

        if inplace:
            self.table = df
            # R replaces "-" in column names with ".". Revert back!
            self.table.columns = [x.replace(".", "-")
                                  for x in self.table.columns]
        else:
            tmp_counts = self.clone()
            tmp_counts.table = df
            tmp_counts.table.columns = [x.replace(".", "-")
                                        for x in tmp_counts.table.columns]
            return tmp_counts
perform transformation on counts table
dataset/ETHPy150Open CGATOxford/cgat/CGAT/Counts.py/Counts.transform