I want to plot heatmap with the DESeq2 result. the heatmap will be for differentially expressed genes with FDR<0.05. but the data coming from DESeq2 includes NA which create problem when sub setting them for heatmap.
how can I deal with these NAs? this is the code:
## Differential abundance
alpha <- 0.05 #set the cutoff value
## subset only significant genes
sig <- res[res$padj < alpha, ]
sig_genes <- rownames(sig)
subset <- rdata[sig_genes,]
## log transform data for visualization
tdata <- log2(subset + 0.5)
mat <- as(tdata, "matrix")
## Set colours
my_colour = list(
Group = c("0" = "blue", "1" = "yellow"))
#################
pheatmap(symbreaks = FALSE,cluster_cols = FALSE,
cluster_rows = TRUE,color = colorRampPalette(c("#f71616","#f71616","white",
"#1919d4", "#1919d4"))(100),annotation_col = sample_org,
annotation_colors = my_colour, mat, scale = "row")
Error is created here :
sig <- res[res$padj < alpha, ]
error:
Error: logical subscript contains NAs
1 answer
You have to remove NAs first from the results as these were produced by the independent filtering.
Spending time on R basics is recommended. All these functions like is.na() do not directly alter the object you give it. They produce logical lists (TRUE/FALSE) when the argument they test (in this case whether each entry is NA or not) are met or not. This you can then use to filter the original object. The ! below reverses the logical list, reads as "remove from res all those rows where the column padj is NOT NA):
res <- res[!is.na(res$padj),]
Log in to answer this question.
Have you tried dropping the rows with NAs as p-values with
na.omit(res)before applying the filter?Hi newbio17 Thanks I tried
na.omit(res)this doesnot work my code was like then I get error again:
error message is: in this line Im get error: