heatmap log2foldchange values
5
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 6.5 years ago

Hi,

Is there a way to use log2foldchange values to heatmap instead of  varianceStabilizingTransformation (vd) values?

topVarGenes <- rownames(vd) %in% rownames(res[res$padj < 0.01,])
mat <- assay(vd)[ topVarGenes, ]

df <- as.data.frame(colData(dds)[,c("time","daylength")])

pheatmap(mat, color = colorRampPalette(rev(brewer.pal(n = 9, name = "RdYlGn")))(100), cluster_rows=TRUE, show_rownames=FALSE, cluster_cols=TRUE, annotation_col=df, main="Heatmap")

Thanks.

J.

deseq2 • 8.3k views
ADD COMMENT
0
Entering edit mode
@mikelove
Last seen 13 hours ago
United States

I'm sticking to my previous answer to your question 2 weeks ago about heatmap for fold changes:

"I guess, the point of the heatmap is to visualize the actual counts (normalized and transformed) across samples. There are other, perhaps better ways of visualizing fold changes"

A: DESeq heatmap based on threshold

The best way to visualize values (best in terms of our ability to discern differences) is location in the (x,y) plane. We are much better at comparing location than brightness/color. So barplots, boxplots, scatterplots are best. For the heatmap, we have 3 dimensions we want to show at once: samples on x, genes on y, and intensity as color. So the heatmap is a compromise. If you only have a vector of log fold changes, you should not use a heatmap.

ADD COMMENT
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 6.5 years ago

Thank you Michael.

I agree and I have plotted all your suggestions including the volcano plots but when your supervisor insisted what can you do :-)

Just help me here. How can I extract all Log2FoldChange with only  gene names (rownames) from the dds results? 

dds  <- dds[ddsNozero]
res<-results(dds)

> res
log2 fold change (MAP): salinity SW vs FW 
Wald test p-value: salinity SW vs FW 
DataFrame with 33120 rows and 6 columns
                   baseMean log2FoldChange     lfcSE       stat
                  <numeric>      <numeric> <numeric>  <numeric>
0:106560212        3.031134      0.1670286 0.3477488  0.4803141
10002:106603563  211.501823      0.1351472 0.1416109  0.9543557
10003:106603561 3230.822594     -0.3629763 0.1642064 -2.2104884
10008:106603558  589.836192      0.2353384 0.1451891  1.6209097
10009:100195495  746.541431      1.3967328 0.2958336  4.7213455

 

Thanks for the help. 

J.

ADD COMMENT
1
Entering edit mode

This a DataFrame, which in many ways acts like a data.frame. You can figure out what an object is with:

class(res)

Then you can look up help with:

?DataFrame

DataFrame-class           package:S4Vectors            R Documentation

DataFrame objects

Description:

     The ‘DataFrame’ class extends the DataTable virtual class and
     supports the storage of any type of object (with ‘length’ and ‘[’
     methods) as columns.

Details:

     On the whole, the ‘DataFrame’ behaves very similarly to
     ‘data.frame’, in terms of construction, subsetting, splitting,
     combining, etc. The most notable exception is that the row names
     are optional. This means calling ‘rownames(x)’ will return ‘NULL’
     if there are no row names. Of course, it could return
     ‘seq_len(nrow(x))’, but returning ‘NULL’ informs, for example,
     combination functions that no row names are desired (they are
     often a luxury when dealing with large data).

 

If you read on:

 

Subsetting:

     In the following code snippets, ‘x’ is a ‘DataFrame’.

‘x[i,j,drop]’: Behaves very similarly to the ‘[.data.frame’ method,
          except ‘i’ can be a logical ‘Rle’ object and subsetting by
          ‘matrix’ indices is not supported. Indices containing ‘NA’'s
          are also not supported.

‘x[i,j] <- value’: Behaves very similarly to the ‘[<-.data.frame’
          method.

‘x[[i]]’: Behaves very similarly to the ‘[[.data.frame’ method, except
          arguments ‘j’ and ‘exact’ are not supported. Column name
          matching is always exact. Subsetting by matrices is not
          supported.

‘x[[i]] <- value’: Behaves very similarly to the ‘[[<-.data.frame’
          method, except argument ‘j’ is not supported.

 

This is a useful website for learning basic R. Read the part about:

"There are a variety of ways to identify the elements of a data frame"

http://www.statmethods.net/input/datatypes.html

ADD REPLY
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 6.5 years ago

Yes, thanks. 

T2SPLFC <- data.frame()
T2SPLFC <- data.frame(res[,'log2FoldChange'])
colnames(T2SPLFC) <- c('T2_SP')
rownames(T2SPLFC) <- rownames(res)

 > head(T2SPLFC)
                     T2_SP
0:106560212      0.1670286
10002:106603563  0.1351472
10003:106603561 -0.3629763
10008:106603558  0.2353384
10009:100195495  1.3967328
1000:106604182  -0.5518381

and I merged the dataframes.

T2LDLFC1 <- T2LDLFC %>% add_rownames()
T2SPLFC1 <- T2SPLFC %>% add_rownames()
T2LFC <- full_join(T2LDLFC1, T2SPLFC1)


          rowname       T2_LD      T2_SP
            (chr)       (dbl)      (dbl)
1 10002:106603563  0.13508203  0.1351472
2 10003:106603561 -0.05005979 -0.3629763
3 10008:106603558  0.02584333  0.2353384
4 10010:106603557 -0.17486168  0.6236402
5 10011:100194939 -0.19421849  0.7477558
6 10012:106603555  0.05827134  1.2309237

Now pheatmap didn't like this. I have to convert the first column (rowname) to rowname.

J.

ADD COMMENT
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 6.5 years ago

Hi Michael,

I looked into vignette("DESeq2") and I couldn't understand whether log2foldcange is calculated after counts are normalised or not. 

I understand that this  "counts(dds, normalized=TRUE)" will give normalised counts. If the log2foldcahnge is not from normalised counts, what do you advice to calculate the log2foldchange after we normalised the counts.

 

Thank you Michael for the help.  

 

J.

ADD COMMENT
1
Entering edit mode
From the formula for finding beta (the LFC) in the vignette and the DESeq2 paper you can see that size factors s_j or normalization factors s_ij are taken into account.
ADD REPLY
0
Entering edit mode
John ▴ 30
@john-9676
Last seen 6.5 years ago

Thanks a lot Michael.

ADD COMMENT

Login before adding your answer.

Traffic: 645 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