How can I convert a RS4 object to python data frame?

74 Views Asked by At

I am trying to perform DGE analysis with Deseq2 in python using the rpy2 package. I have currently managed to reach the step where I have my results in the RS4 object format. Ideally now I would like to save myresults in a .csv. The myresults is a type rpy2.robjects.methods.RS4.

myresults = deseq2.results(dds)
print(myresults) 
log2 fold change (MLE): treatment untreated vs treated 
Wald test p-value: treatment untreated vs treated 
DataFrame with 25958 rows and 6 columns
         baseMean log2FoldChange     lfcSE       stat    pvalue      padj
        <numeric>      <numeric> <numeric>  <numeric> <numeric> <numeric>
A1BG    140.51466      -0.832851  0.571502  -1.457303 0.1450326  0.713127
A1CF      4.14679      -0.191442  1.093415  -0.175086 0.8610119  0.966298

I tried to find my way through myresults.slots() with the purpose of retrieving the count matrix, colnames, rownames and merging them into a python data frame that can I easily save as a .csv. I am still unable to extract useful things.

items = list(result.slots.items()) 
items[0] 
keyss = list(result.slots.keys()) 
keyss[0]  

Since I am vastly unfamiliar with the structure of RS4 objects it still confuses me and takes too much time. Any help in that direction or a solution would be greatly appreciated! :)

0

There are 0 best solutions below