pheatmap in R - Error: logical subscript contains NAs
1
0
Entering edit mode
7 months ago
Rob ▴ 40

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
RNA-Seq DESeq2 R pheatmap • 837 views
ADD COMMENT
0
Entering edit mode

Have you tried dropping the rows with NAs as p-values with na.omit(res) before applying the filter?

ADD REPLY
0
Entering edit mode

Hi newbio17 Thanks I tried na.omit(res)
this doesnot work my code was like then I get error again:

## Create metadata 

    sample_org <- data.frame(row.names = colnames(rdata), c(rep("0", 66), rep("1", 93)))
    colnames(sample_org) <- c("Group")

    dds <- DESeqDataSetFromMatrix(countData = rdata,
                                  colData = sample_org,
                                  design = ~Group)

    dd <- DESeq(dds)
    dd2 <- na.omit(dd)
    alpha <- 0.05

    res <- results(dd2)
    #Saving results
    write.csv(res,"res.csv")

    ## subset only significant genes
    sig <- res[res$padj < alpha,]
    sig_genes <- rownames(sig)
    subset <- rdata[sig_genes,]

error message is: in this line Im get error:

sig <- res[res$padj < alpha,]

Error: logical subscript contains NAs
ADD REPLY
2
Entering edit mode
7 months ago
ATpoint 48k

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),]
ADD COMMENT

Login before adding your answer.

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