JEFworks-Lab/veloviz

Error in layout_with_fr(g, dim = 2) : At core/layout/fruchterman_reingold.c:401 : Weights must be positive for Fruchterman-Reingold layout. Invalid value

Closed this issue · 12 comments

Dear developers, @LylaAtta123 @JEFworks

Hello, I am writing an issue because I have a questions.
1.

veloviz <- buildVeloviz(
  curr = curr, proj = proj,
  normalize.depth = TRUE,
  use.ods.genes = TRUE,
  alpha = 0.05,
  pca = TRUE,
  nPCs = 20,
  center = TRUE,
  scale = TRUE,
  k = 5,
  similarity.threshold = 0.25,
  distance.weight = 1,
  distance.threshold = 0.5,
  weighted = TRUE,
  verbose = FALSE
)

Error in layout_with_fr(g, dim = 2) :   At core/layout/fruchterman_reingold.c:401 : Weights must be positive for Fruchterman-Reingold layout. Invalid value

This error appears when using buildVeloviz. Can you tell me how to solve it?
2.

cell.cols <- rainbow(8)[as.numeric(clusters)]
plotEmbedding(emb.umap, groups=cell.cols, main=‘UMAP’,
              xlab = “UMAP X”, ylab = “UMAP Y”, colors = cell.cols)

Can I know the command to color the plot compared to other embeddedings (PCA, Umap, Tsne)?
이미지 2022  7  26  오후 7 20
It's generated in black and white

Thank you for your help.

Best,
EUNHA LIM

I haven't done troubleshooting yet, so if anyone knows the answer, please leave a comment.
Thank you.

Hi Eunha,

Thank you for trying out the package and for your question. Could you please provide a reproducible example for the issues you're having?

For 2., a common issue is that groups needs to be a named factor object, where the names correspond to the row names of your emb matrix. Please also note that you do not need to supply groups if you supply colors as it will default to using the supplied colors.

Best,
Lyla

Thank you very much for your quick reply. @LylaAtta123
When I run one by one with the source code of the package, the error occurs in the fdg = layout_with_fr(g,dim=2) command in graphViz function.(https://rdrr.io/github/JEFworks-Lab/veloviz/src/R/projectedNeighbors.R)

fdg = layout_with_fr(g,dim=2)
Error in layout_with_fr(g, dim = 2) : 
  At core/layout/fruchterman_reingold.c:401 : Weights must be positive for Fruchterman-Reingold
layout. Invalid value

After merging the spliced and unspliced counts from Alevin and adata, the h5ad file calculated up to velocity through scvelo was added as input file.

Hi Eunha,

From the error you included, it seems like your graph has edge weights that are non-positive. Without the specific data that you're working with, it's difficult for me to know why that could be happening.

My suggestion would be to extract the graph g, determine which cells have an edge between them that is non-positive, and go back to the curr and proj matrices to determine the source of the issue.

Happy to help further if the issue persists.

Best,
Lyla

Hi @LylaAtta123,

The error has been resolved.
Can I ask you one more question?
Do you have any recommendations of range of numbers for changing 4 parameters(k, distance.weight, distance.threshold, similarity.threshold) to change the embedding?

Thank you very much for your kindness.

Best,
EUNHA LIM

Great! Out of curiosity, what was the source of the error?

For veloviz embedding parameters, optimal parameter choices are data dependent but I generally find that the default parameters are a good starting point. For a more detailed discussion on how changing parameters can affect the embedding, please take a look at the simulation page on the veloviz website.

Let me know if anything else needs clarification

Best,
Lyla

Hi, @LylaAtta123

Thank you for your kind explanation.
The error was resolved by using a different MacBook in vain. I think it was a computer problem.

I understood everything that parameter means through the paper. However, if you look at the tutorial, the threshold has a small range of numbers, but in the case of k value or distance.weight, there is no default value and the range of numbers is too wide, so it is difficult to find any criteria.
Do you have any recommended range of values?

Thank you.

Best,
LIM EUNHA

I usually start with a k=0.1*N where N is the number of cells in your dataset and distance.weight=1 and explore variations on parameter values from there. There isn't really a recommended range of values because it depends on the features of the trajectories present in your data and which features are of interest to you. In my experience though, if there is a strong dynamic trajectory in your data, the veloviz embedding is fairly robust to parameter selection.

Let me know if this answers your question.

Best,
Lyla

Hi @galaxyeee ,
I was able to reproduce your initial error:

Error in layout_with_fr(g, dim = 2) : At core/layout/fruchterman_reingold.c:401 : Weights must be positive for Fruchterman-Reingold layout. Invalid value

The error is due to an update in the igraph package (>=1.3.4) that enforces strictly positive graph edge weights when creating 2D embeddings using the FR method. Because of the way veloviz converts composite distances to edge weights, previously edge weights could be 0. This has been addressed in the latest update.

Let me know if there are any other issues.

Lyla

Dear Lyla,

what version of igraph did you use before igraph 1.3.4?
one of my peer did not get this error when using 1.3.2, where i am still getting the same error with igraph 1.3.2.
I will try with your version too.

By the way, i have tried version 0.1.1, 0.1.2, 0.4.1, 1.0.0, 1.2.11.

Thank you!

Hi @LylaAtta123,

Thanks to you, I solved it well.
Thank you for your kind answer.

Best,
EUNHA LIM

Hi @parkjooyoung99,

I'm not sure what the latest igraph version that works is but igraph 1.2.6 works for me.

Alternatively, I have updated the package to work with the latest igraph version. The latest version on github should work (bioconductor version to be updated shortly).

Best,
Lyla