MA plot from my data frame
1
0
Entering edit mode
9.5 years ago
bgraphit ▴ 20

Hello! I am trying to figure out how I can make an MA plot from the following my data frame dar

I am currently using DESeq2 but I extracted the information from data frame dr which is the results (dds) I saved this as a csv.

Opened another R session and loaded dr where I can have the column with gene name. I changed the header of that column to "gene" then merged dr by "gene" it to my list of genes of interest to make my data frame dim.

So dim at the moment isnt seen as a DESeq2 object data frame.

dim(dar)
[1] 13348     6

head(dar)
                           baseMean log2FoldChange     lfcSE          stat
A1BG                   7.278775e-02    0.140265235 1.6670434   0.084140124
A1CF                   4.130988e-02   -1.102589688 1.6676373  -0.661168755
AAAS                   1.657182e+01    1.173655704 0.5986687   1.960442661
AACS                   6.373922e+00   -0.653331952 0.8046976  -0.811897466
AADAC                  3.251195e+00    0.736454731 0.7014096   1.049963935
                            pvalue                    padj
A1BG                   9.329450e-01           NA
A1CF                   5.085041e-01           NA
AAAS                   4.994407e-02 1.377416e-01
AACS                   4.168505e-01 6.001605e-01
AADAC                  2.937347e-01 4.793114e-01

I want to make an MA plot with the plotMA function where x axis is mean expression("baseMean") and y axis is log2FoldChange

plotMA(Merged_H3K27me3_not_inforMAplot_nocols, ylim=c(-5,5))

How can I get this data frame back into DESeq2 format? and make my MA plot?

plotMA R • 5.5k views
ADD COMMENT
1
Entering edit mode
9.5 years ago
Steven Lakin ★ 1.8k

Based on the way your dataframe is formatted, I'm guessing you're using DESeq2. Make sure DESeq2 was the last package you loaded that has a plotMA function; there are many other packages with a function of the same name, so whichever you loaded last would be the one you're using. Can you confirm that you're using the DESeq2 plotMA function and report back if you have further problems?

Try the following:

library(DESeq2)
plotMA(dar, main="DESeq2", ylim=c(-2,2))

Or:

DESeq2::plotMA(dar, main="DESeq2", ylim=c(-2,2))
ADD COMMENT
0
Entering edit mode

Hi Steven

I am using DESeq2 but I extracted the information from "dr" which is the results (dds) I saved this as a csv.

Opened another R session and loaded "dr" where I can have the column with gene name. I changed the header of that column to "gene"

then merged "dr" by "gene" it to my list of genes of interest to make my data frame dim.

So dim at the moment isn't seen as a DESeq2 object data frame.

ADD REPLY
1
Entering edit mode

To use the DESeq plotMA, you need to maintain the original architecture of the dds result object. Try the following in the same R environment as your processed dds object:

res <- results(dds)
myGenesOfInterest <- c("Gene1", "Gene2")   # place all genes of interest in this vector
dar <- res[rownames(res) %in% myGenesOfInterest, ]
plotMA(dar, main="DESeq2", ylim=c(-2,2))

Keep in mind your gene names should be your row names, and row names is just another column you can manipulate using rownames().

ADD REPLY
0
Entering edit mode

My genesofInterest list looks like this:

Merged_Genes_notin_H3K27
                        gene                      samplex     ......
2                       A1BG                      0.000000
3                       A1CF                      0.000000
4                       AAAS                      0.000000
5                       AACS                      4.247928
6                      AADAC                      0.000000
7                AADACL2-AS1                      0.000000
8                    AADACP1                      6.554589
9                      AADAT                      2.584963

Is there a way to use this instead of the vector your describe?

ADD REPLY
1
Entering edit mode

Yep, assuming row 1 is also in the data and "gene" is the column name, this should work:

res <- results(dds)
dar <- res[rownames(res) %in% Merged_Genes_notin_H3K27$gene, ]
plotMA(dar, main="DESeq2", ylim=c(-2,2))

If row 1 is not needed, then this should work:

res <- results(dds)
genesOfInterest <- as.character(Merged_Genes_notin_H3K27[2:nrow(Merged_Genes_notin_H3K27), 1])

dar <- res[rownames(res) %in% genesOfInterest, ]
plotMA(dar, main="DESeq2", ylim=c(-2,2))
ADD REPLY
0
Entering edit mode

OK so I did

res2 <- results(dds)
> dim(res2)
[1] 25369     7
dar <- res2[rownames(res2) %in% Merged_Genes_notin_H3K9me3$gene, ]

> names(Merged_Genes_in_H3K9me3)
  [1] "gene"

and the problem is that dar

> dar
[1] gene           baseMean       log2FoldChange lfcSE          stat          
[6] pvalue         padj          
<0 rows> (or 0-length row.names)

plotMA(dar, main="DESeq2", ylim=c(-2,2))

This is odd because there are genes that match in both lists.

ADD REPLY
0
Entering edit mode

Try recopying the second block of code, where I explicitly converted it to character. Sometimes these column types can be tricky and convert to factors.

ADD REPLY
0
Entering edit mode
> genesOfInterest <- as.character(Merged_Genes_in_H3K9me3[1:nrow(Merged_Genes_in_H3K9me3), 1])

> genesOfInterest
  [1] "ABCA11P"       "ABCA13"        "ABI3BP"        "ADCY2"        
  [5] "AMN1"          "ANKMY1"        "ANKRD20A12P"   "ANKRD20A9P"   
  [9] "ANKRD30BP2"    "ANKRD36BP1"    "APMAP"         "ARHGAP39"     
 [1

> dar <- res2[rownames(res2) %in% genesOfInterest, ]

> dar
[1] gene           baseMean       log2FoldChange lfcSE          stat          
[6] pvalue         padj          
<0 rows> (or 0-length row.names)

> dim(dar)
[1] 0 7

no still not working well

ADD REPLY
0
Entering edit mode

That is strange. It worked for me on a test dataset from DESeq2 vignette. Did you make sure to recall the results(dds) from your analyzed dds object?

What is the output of:

str(res2)
ADD REPLY
0
Entering edit mode

Actually yes it worked. It was my mistake that when I loaded the rdata file that had my list of genes of interest it had a res2 object derived from a .csv file that overwrote over the res2 I needed.

Thanks!

ADD REPLY

Login before adding your answer.

Traffic: 2481 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6