Question: pheatmap in R - Error: logical subscript contains NAs
0
gravatar for Rob
4 months ago by
Rob20
Rob20 wrote:

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
pheatmap rna-seq deseq2 R • 480 views
ADD COMMENTlink modified 4 months ago by ATpoint44k • written 4 months ago by Rob20

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

ADD REPLYlink modified 4 months ago • written 4 months ago by newbio17320

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 REPLYlink written 4 months ago by Rob20
2
gravatar for ATpoint
4 months ago by
ATpoint44k
ATpoint44k wrote:

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 COMMENTlink modified 4 months ago • written 4 months ago by ATpoint44k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1375 users visited in the last hour
_