federicomarini / GeneTonic

Enjoy your transcriptomic data and analysis responsibly - like sipping a cocktail
https://federicomarini.github.io/GeneTonic
Other
76 stars 8 forks source link

error with gs_scores() #49

Open DaniBlumstein opened 1 year ago

DaniBlumstein commented 1 year ago

Hello! I am having issues creating the heatmap that comes with the gs_scoresheat() function and this is because when I run gs_scores() I get the error:

Error in colMeans(thisset_zs) : 'x' must be an array of at least two dimensions

here is the code I'm using:

vst_macrophage <- varianceStabilizingTransformation(kid_dds_trt) scores_mat <- gs_scores( se = vst_macrophage, res_de = kid_res_trt, res_enrich = res_enrich, annotation_obj = anno_df ) gs_scoresheat(scores_mat, n_gs = 30)

I know this is not the most reproducible problem as you don't have any of the other objects so let me know what else you might need!! Thank you!

federicomarini commented 1 year ago

Hi, as you said, since I cannot access those objects it is pretty hard to make a guess.

One thing you could check with running the function in debug mode: Are the names of the genes correctly carried out in the computations?

DaniBlumstein commented 1 year ago

Ah I should have added that all other graphs and outputs work as expected. I am able to create the enhancement table, mds plot, the dendro plot, volcano plot, ect so I think the genes are being correctly carried out in the computations. Can you clarify what you mean by debug mode? Is there any way for me to add objects or code to the open issue? Sory I'm not very github savvy.

federicomarini commented 1 year ago

In debug mode, that would simply mean to call

# this
debug(gs_scores)
# before this
scores_mat <- gs_scores(
se = vst_macrophage,
res_de = kid_res_trt,
res_enrich = res_enrich,
annotation_obj = anno_df
)

Maybe it is some kind of edge case we could not consider on the "standard" datasets we used while developing this functionality. If you want, you can send an email to marinif at uni-mainz dot de with an RData object/workspace containing the objects needed? Or if it is too large, send me at that email a link to retrieve them (of course, handled confidentially)? F

fishmatt commented 1 year ago

Hi, Hope you are well. I was wondering if you found a solution to this error code? When using the debug mode it appear to be related to colMeans(thisset_zs). Was it do do with the annotations and naming of genes?

Thanks, Matt

federicomarini commented 1 year ago

Likely an NA value for some of the members for that vector? That is the first thing I can think of, but it is hard to pinpoint without a concrete example. Can you provide me one where I can reproduce the error locally?

UdoUnnoetig commented 1 year ago

Hello there,

I ran into the same problem yesterday. I dug into the gs_scores() function and believe to have found a likely cause. In gs_heatmap.R starting at line 399 there is:

thisset_zs <- mydata_z[thisset_members_ids, ] 
thisset_mean_zs <- colMeans(thisset_zs)

The expected case here is for mydata_z[thisset_members_ids, ] to return a dataframe, which is the case, when there is >1 element in thisset_members_ids. Then, colMeans() will work. However, when thisset_members_ids contains only one element (i.e. there is only one gene belonging to the current gene set), R "drops the data frame complexity", returning a vector instead of a df. colMeans does not work on vectors and produces the error stated above.

My fix: Add drop = FALSE in the indexing function of mydata_z. This will force returning a data frame.

thisset_zs <- mydata_z[thisset_members_ids, , drop = FALSE] 

As testing data you can use the GeneTonic macrophage example data, grab one row of res_enrich and replace the gs_genes field with just a single gene from the annotation.

library(macrophage)
example("GeneTonic", ask = F) #close Shiny App

test <- res_enrich[1,]
test$gs_genes <- "C1R"
gs_scores(vst(dds_macrophage),res_de,test,annotation_obj = anno_df)
# --> Error

test <- res_enrich[1,]
test$gs_genes <- "C1R,B2M"
gs_scores(vst(dds_macrophage),res_de,test,annotation_obj = anno_df)
# --> Works

I hope this helps! Also, I just started looking into GeneTonic and it seems to be a very cool tool :D Thanks!

federicomarini commented 1 year ago

Good catch. Fix is coming in soon! Thanks for the kind words too - and for the suggestion 😉