KrishnaswamyLab / phateR

PHATE dimensionality reduction method implemented in R
GNU General Public License v2.0
77 stars 9 forks source link

error message #30

Closed kasumaz closed 5 years ago

kasumaz commented 5 years ago

HI, I am using PhateR. It looks very neat. I can get the vignette going and all working smooth. When I try with my data and run:

scex_PCA <- as.data.frame(prcomp(scex)$x) Error in colMeans(x, na.rm = TRUE) : 'x' must be numeric

With the above error message, i went back to the matrix and I cant see something wrong with it. Would it be worth while to have a look at your end? I start with a smaller bunch of cells of about 130 cells. Thanks a lot. scext.csv.zip

scottgigante commented 5 years ago

Hi @kasumaz , it looks like the file you are reading is not comprised entirely of numbers. I was able to run prcomp on the data you provided by loading it as follows:

library(tidyverse)
df <- read_csv("scext.csv", col_types =list(V1=col_character(), .default=col_double())) %>% 
  column_to_rownames("V1")
prcomp(df)
kasumaz commented 5 years ago

Hi, Thanks for your reply. We you able to proceed with any other of the commands for PhateR?
Just wondering what else I should do aside from checking the matrix thoroughly. I was using the same Matrix in seurat. But I will go over it now.

scottgigante commented 5 years ago

I just ran phateR::phate(df) after the above commands and it worked fine. Let me know if you have further problems. Passing .default=col_double() to read_csv should raise warnings if there are any other non-numeric entries.

kasumaz commented 5 years ago

Would you be able to send me over the script you used if you still have it and I try at my end? Maybe you have something slightly different from the tutorial that I give it a go. I will check out otherwise. Apologies, I am new to R but getting there. Thanks.

scottgigante commented 5 years ago

No problem.

library(phateR)
library(tidyverse)
library(viridis)
library(Rmagic)

# read data
df <- read_csv("scext.csv", col_types =list(V1=col_character(), .default=col_double())) %>% 
  column_to_rownames("V1")

# keep genes expressed in at least 10 cells
keep_cols <- colSums(df > 0) > 10
df <- df[,keep_cols]

# keep cells with at least 1000 UMIs
keep_rows <- rowSums(df) > 1000
df <- df[keep_rows,]

# normalize and transform
df <- library.size.normalize(df)
df <- sqrt(df)

# PCA
df_pca <- as.data.frame(prcomp(df)$x)
ggplot(df_pca) +
  geom_point(aes(PC1, PC2, color=df$Chd4)) +
  labs(color="Chd4") +
  scale_color_viridis(option="B")

df_phate <- phate(df)

ggplot(df_phate) +
  geom_point(aes(PHATE1, PHATE2, color=df$Chd4)) +
  labs(color="Chd4") +
  scale_color_viridis(option="B")

This worked on the sample you sent me.

kasumaz commented 5 years ago

Hi mate. Thanks soo much. This now works at my end. I will use it now. If you have any other tools in the pipeline/developing that are similar or an extension, let me know and I can implement them in. I will keep a look out otherwise. Thanks again.

scottgigante commented 5 years ago

Glad to hear it's working, and thanks very much for the offer to contribute! We always welcome PRs to our codebase if you identify somewhere you can help us improve :)