Error when running pheatmap
0
0
Entering edit mode
5.0 years ago
luzglongoria ▴ 50

Hi there,

I would like to do a heat map by using pheatmap. The problem is that when I tried to run it (with a very basic command) I get this error message:

head(dataset)
# A tibble: 6 x 11
 ID                         s21      s22     s23      s24       s25     s31     s32     s33    s34    s35
 <chr>                    <dbl>    <dbl>   <dbl>    <dbl>     <dbl>   <dbl>   <dbl>   <dbl>  <dbl>  <dbl>
1 TRINITY_DN31277_c0_…    7.80    2.65e+0  2.12e0  1.93e+0   6.35e+0  0.0258 0.00541 0.00004 0.0132 0.0182
2 TRINITY_DN38059_c1_… 2671.      1.13e+4  1.62e4  1.64e+4   3.13e+4 19.0    4.38    1.61    3.07   7.69  
3 TRINITY_DN29156_c0_…    0.960   2.56e+0  2.81e0  2.56e+0   6.93e+0  0.156  0.180   0.0934  0.156  0.0568
4 TRINITY_DN36493_c2_…    0.468   1.10e+0  1.75e0  1.70e+0   4.36e+0  0.0587 0.0907  0.0523  0.0483 0.0928
5 TRINITY_DN22456_c0_…    0.428   1.17e+0  1.71e0  1.42e+0   4.26e+0  0.0862 0.149   0.0845  0.0904 0.0545
6 TRINITY_DN24468_c0_…    0.0965  1.93e-1  0.      1.23e-1   8.12e-2  0      0       0       0      0     

pheatmap(as.matrix(dataset))
Error in hclust(d, method = method) : 
 NA/NaN/Inf in foreign function call (arg 11)
In addition: Warning messages:
1: In dist(mat, method = distance) : NAs introduced by coercion
2: In dist(mat, method = distance) : NAs introduced by coercion

I have been reading and apparently is a problem with removing the zero variance columns in my matrix. but I don't know how to do it.

Any help will be appreciate!

pheatmap Error in hclust • 16k views
ADD COMMENT
0
Entering edit mode

There are some strange entries like 0. and 2671. Can you confirm this is indeed in your data or is this a copy/paste error when you made the post?

ADD REPLY
0
Entering edit mode

It appears like this when I do head() but the dataset appears like this in R:

https://ibb.co/w01P34W

ADD REPLY
0
Entering edit mode

I have also imported the data by using a .txt file by:

data <- read.table("Genes_with_function.txt", header = TRUE, sep = "\t", dec = ".")

and then if I do:

head(data)
                  ID          s21          s22          s23          s24          s25         s31         s32     s33       s34        s35
1    TRINITY_DN31277_c0_g1_i1 7.795158e+00 2.647286e+00     2.115808 1.933543e+00 6.350756e+00  0.02582418 0.005407407 0.00004 0.0132500 0.01820809
2    TRINITY_DN38059_c1_g1_i1 2.670699e+03 1.131360e+04 16209.190000 1.642066e+04 3.127527e+04 18.96368000 4.375704000 1.61464 3.0683130 7.69485500
3    TRINITY_DN29156_c0_g1_i1 9.597895e-01 2.562030e+00     2.810692 2.559634e+00 6.926222e+00  0.15565930 0.180370400 0.09336 0.1556250 0.05676301
4    TRINITY_DN36493_c2_g1_i1 4.683158e-01 1.099098e+00     1.746231 1.704085e+00 4.361867e+00  0.05868132 0.090740740 0.05228 0.0483125 0.09277457
5    TRINITY_DN22456_c0_g1_i1 4.275263e-01 1.168571e+00     1.711769 1.419817e+00 4.256356e+00  0.08620879 0.149481500 0.08448 0.0904375 0.05450867
6 TRINITY_DN24468_c0_g1_i7.p2 9.647368e-02 1.931579e-01     0.000000 1.231707e-01 8.124444e-02  0.00000000 0.000000000 0.00000 0.0000000 0.00000000

But it didn't solve the problem:

pheatmap(as.matrix(data))
Error in hclust(d, method = method) : 
 NA/NaN/Inf in foreign function call (arg 11)
In addition: Warning messages:
1: In dist(mat, method = distance) : NAs introduced by coercion
2: In dist(mat, method = distance) : NAs introduced by coercion
ADD REPLY
1
Entering edit mode

Well, you obviously cannot cluster the first column, ID; so, you will have to set that as the rownames and then remove that column from the object before you convert it to a data matrix.

ADD REPLY
0
Entering edit mode

Thank you Kevin.

I have tried to do what you have said:

tbl_ready <- as.matrix(data[,2:11])
mode(tbl_ready)<-"numeric"

I have checked:

sum(is.infinite(tbl_ready))
[1] 0

And then I try to do the heatmap by:

pheatmap(tbl_ready)

And now R doesn't do anything. No error message, no warnings messages.

What I am doing wrongly?

ADD REPLY
0
Entering edit mode

Do you have a plot window or some output stream open? Try running dev.off() multiple times until that shows an error, and then try the pheatmap() command.

Also, what is the output of str(data)? It will help to see how your columns are encoded.

I am not sure that you need these lines:

tbl_ready <- as.matrix(data[,2:11])
mode(tbl_ready)<-"numeric"

Usually, data.matrix() suffices.

ADD REPLY
0
Entering edit mode
str(data)
'data.frame':   45 obs. of  11 variables:
 $ ID : Factor w/ 44 levels "TRINITY_DN119101_c0_g1_i1",..: 23 37 20 29 5 12 11 40 31 13 ...
 $ s21: num  7.795 2670.699 0.96 0.468 0.428 ...
 $ s22: num  2.65 11313.6 2.56 1.1 1.17 ...
 $ s23: num  2.12 16209.19 2.81 1.75 1.71 ...
 $ s24: num  1.93 16420.66 2.56 1.7 1.42 ...
 $ s25: num  6.35 31275.27 6.93 4.36 4.26 ...
 $ s31: num  0.0258 18.9637 0.1557 0.0587 0.0862 ...
 $ s32: num  0.00541 4.3757 0.18037 0.09074 0.14948 ...
 $ s33: num  0.00004 1.61464 0.09336 0.05228 0.08448 ...
 $ s34: num  0.0132 3.0683 0.1556 0.0483 0.0904 ...
 $ s35: num  0.0182 7.6949 0.0568 0.0928 0.0545 ...

I have also done the dev.off() and now I get a plot!

The problem is that it doesn't seem to be very informative since I have some very high values and other quite low. but I know that there is significant differences between the two species (s21,22,23,24,25) and (s31,32,33,34,35)

pheatmap(data.matrix(data))

image of the heatmap: https://ibb.co/9qy7xW4

ADD REPLY
2
Entering edit mode

I see, you could try to scale the data (transform to Z-scores) and then set custom breaks:

# transform to Z-scale
mat <- t(scale(t(data.matrix(data))))

# set colour
require(RColorBrewer)
myCol <- colorRampPalette(c("dodgerblue", "black", "yellow"))(100)
myBreaks <- seq(-2, 2, length.out=100)

hmap <- pheatmap(mat,
  cluster_rows = TRUE,
  cluster_cols = TRUE,
  scale = 'none',
  breaks = myBreaks,
  col = myCol,
  show_colnames = TRUE,
  #gaps_col = c(5,10,15,20,25,30),
  #gaps_row = c(2),
  fontsize = 14,
  annotation_col = annot_col,
  annotation_colors = list(Day = c(
    "Day 0"="#4098B6",
    "Day 1"="#8DD1A4",
    "Day 2"="#DDF199",
    "Day 4"="#FDD885",
    "Day 6"="#F99254",
    "Day 8"="#DD4B4B",
    "Day 10"="#9E0142")))

That is just copied from another example that I did. Please edit as per your needs.

-------------------------

Edit: using my t(scale(t(x))) code with pheatmap(..., scale = 'none',... ) is actually the same as using pheatmap(..., scale = 'row',... ) on its own

ADD REPLY

Login before adding your answer.

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