def load():
        DeconRNASeq.load_r()
        rpy2.robjects.r("data(rat_liver_brain)")
        x = rpy2.robjects.r('all.datasets')
        df = rpy2.robjects.pandas2ri.ri2py(x)
        df.index = rpy2.robjects.r('rownames')(x)

        sample_info = {
            'd15282bm': 'liver',
            'd15283bm': 'liver',
            'd15284bm': 'liver',
            'd15285bm': 'mix',
            'd15286bm': 'mix',
            'd15287bm': 'mix',
            'd15288bm': 'mix',
            'd15289bm': 'mix',
            'd15290bm': 'mix',
            'd15291bm': 'mix',
            'd15292bm': 'mix',
            'd15293bm': 'mix',
            'd15294bm': 'brain',
            'd15295bm': 'brain',
            'd15296bm': 'brain',
        }
        return sample_info, df
 def select_genes(df_tpm, reference_information):
     DeconRNASeq.load_r()
     rpy2.robjects.r("data(liver_kidney)")
     x = rpy2.robjects.r('signatures')
     xdf = rpy2.robjects.pandas2ri.ri2py(x)
     xdf.index = rpy2.robjects.r("rownames")(x)
     xdf = xdf[xdf.kidney > xdf.liver]
     return xdf  # gg.convert_dataframe_to_r(x, True)
    def load():
        DeconRNASeq.load_r()
        rpy2.robjects.r("data(liver_kidney)")
        x = rpy2.robjects.r('datasets')
        df = rpy2.robjects.pandas2ri.ri2py(x)
        df.index = rpy2.robjects.r('rownames')(x)

        sample_info = {}
        for x in df.columns:
            sample_info[x] = np.nan
        return sample_info, df
def Percentage_DeconRNASeq():
    DeconRNASeq.load_r()

    def calc(df_tpm, genes_for_estimation):
        if isinstance(genes_for_estimation, list):
            signature_df = df_tpm.ix[genes_for_estimation, [
                'reference_sample', 'reference_contamination']]
        else:
            signature_df = genes_for_estimation
        if not isinstance(signature_df, rpy2.robjects.vectors.DataFrame):
            signature_df = gg.convert_dataframe_to_r(signature_df, True)
        if signature_df is None:
            print genes_for_estimation
            print type(genes_for_estimation)
            raise ValueError("Here it is")

        mixture_df = df_tpm[['observed']]
        # for some arcane reason it won't work if you run it with one sample
        # only...
        mixture_df.insert(1, 'duplicate', mixture_df['observed'])
        mixture_df = gg.convert_dataframe_to_r(mixture_df, True)
        result = rpy2.robjects.r('DeconRNASeq')(
            mixture_df,
            signature_df,
        )
        calc_percentage = result[0][1]  # the contamination percentage
        calc_percentage_std = np.nan
        percentage, corrected = correct_with_percentage(
            df_tpm,
            'observed',
            ['reference_sample'],
            ['reference_contamination'],
            calc_percentage)
        return {
            'percentage': calc_percentage,
            'percentage_std': calc_percentage_std,
            'corrected': corrected,
        }
    return 'DeconRNAseq', calc
 def select_genes(df_tpm, reference_information):
     DeconRNASeq.load_r()
     rpy2.robjects.r("data(rat_liver_brain)")
     x = rpy2.robjects.r('array.signatures')
     return list(rpy2.robjects.r('rownames')(x))
 def select_genes(df_tpm, reference_information):
     DeconRNASeq.load_r()
     rpy2.robjects.r("data(liver_kidney)")
     x = rpy2.robjects.r('signatures')
     return x