kstreet13 / slingshot

Functions for identifying and characterizing continuous developmental trajectories in single-cell data.
259 stars 42 forks source link

Error in graph.adjacency.dense: Adjacency matrix should be symmetric to produce an undirected graph. Invalid value #246

Closed erzakiev closed 3 months ago

erzakiev commented 3 months ago

Hello Kelly, I've got this error, which is most certainly related to igraph:

slingshot(sce_StartingVanillaData4PhenotypeMapping_750, clusterLabels = 'Clusteringk16_maxscore', reducedDim = 'UMAP')
## Error in graph.adjacency.dense(adjmatrix, mode = mode, weighted = weighted,  : 
## At vendor/cigraph/src/constructors/adjacency.c:538 : Adjacency matrix should be symmetric to produce an undirected graph. Invalid value

Perhaps you could point me to the file where it gets invoked? When I look up the View(slingshot::slingshot) it's giving me only the generic thingy

new("nonstandardGenericFunction", .Data = function (data, clusterLabels, 
  ...) 
{
  standardGeneric("slingshot")
}, generic = "slingshot", package = "slingshot", group = list(), 
  valueClass = character(0), signature = c("data", "clusterLabels"
  ), default = NULL, skeleton = (function (data, clusterLabels, 
    ...) 
  stop(gettextf("invalid call in method dispatch to '%s' (no default method)", 
    "slingshot"), domain = NA))(data, clusterLabels, ...))

The object i'm passing is an SCE object, if that's pertinent to the problem.

erzakiev commented 3 months ago

I think it's not worth digging it further, the problem was with singlets aka degenerate clusters (containing 1 cell). But if anyone has this same problem they can fix it by merging singlets into a 'trashy' cluster or whatever

szhorvat commented 3 months ago

igraph's graph_from_adjacency_matrix() is now stricter in checking that the adjacency matrix you pass in is consistent with the type of graph you are trying to construct. The adjacency matrix of an undirected graph should always be symmetric. If it's not, perhaps you made a mistake or there's a bug in your code? The new behaviour is meant to alert you to this. However, the previous behaviour is still available with mode="max" for cases when you are aware that the matrix is not symmetric and still want to go ahead.

kstreet13 commented 3 months ago

Thanks for these reports! I dug into it a little and the only time Slingshot would actually call graph_from_adjacency_matrix() is in the degenerate case where there is only one cluster. All other cases are handled by TrajectoryUtils::createClusterMST(), but even then, all the distance metrics are (or at least should be) symmetric, so I'm not sure how you would ever end up with a non-symmetric adjacency matrix.

erzakiev commented 3 months ago

hmm I had two or three clusters (out of 16) consisting of 1 cell each. Once I merged them with other clusters, the problem went away...

szhorvat commented 3 months ago
## At vendor/cigraph/src/constructors/adjacency.c:538 : Adjacency matrix should be symmetric to produce an undirected graph. Invalid value

Based on the line number, I can see that this error occurs when converting weighted adjacency matrices.

Could it be that the symmetry is broken due to numerical precision issues?