Giter Site home page Giter Site logo

Comments (2)

VPetukhov avatar VPetukhov commented on June 14, 2024 1

Just found that it was implemented in Palo

from conos.

VPetukhov avatar VPetukhov commented on June 14, 2024
graph_cl <- sccore::getClusterGraph(con_v1$graph, groups=ann_by_level$annotation$l6, method="paga")
nns_per_clust <- as.matrix(graph_cl) %>% apply(1, order, decreasing=T) #%>% .[1:2,]
sims_per_clust <- 1:ncol(nns_per_clust) %>% lapply(function(i) graph_cl[nns_per_clust[, i], i]) %>% 
  setNames(colnames(nns_per_clust)) %>% lapply(function(x) x[x > 0])

color_set <- (RColorBrewer::brewer.pal(9, "Set1") %>% colorRampPalette())(100)
color_set_dists <- col2rgb(color_set) %>% apply(2, convertColor, "sRGB", "Lab") %>% t() %>%
  dist(method="minkowski", p=1) %>% as.matrix() %>% set_rownames(color_set) %>% set_colnames(color_set)

cl_colors <- rep(NA, length(sims_per_clust)) %>% setNames(names(sims_per_clust)) %>% 
  factor(levels=color_set)

col_queue <- names(cl_colors)[1]
while(length(col_queue) > 0) {
  n <- col_queue[1]
  # n
  cur.sims <- sims_per_clust[[n]]
  cur.neighbs <- names(cur.sims)
  col_queue <- c(col_queue[-1], cur.neighbs[is.na(cl_colors[cur.neighbs])] %>% .[!(.%in% col_queue[-1])])

  if (all(is.na(cl_colors[cur.neighbs]))) {
    cl_colors[[n]] <- table(cl_colors) %>% which.max() %>% names()
    next
  }
  cur.assigned.neighbs <- cl_colors[cur.neighbs] %>% .[!is.na(.)]
  cl_colors[[n]] <- apply(color_set_dists[cur.assigned.neighbs,,drop=F] * cur.sims[names(cur.assigned.neighbs)], 2, median) %>% 
    which.max() %>% names()
}

cl_colors %<>% as.character() %>% setNames(names(cl_colors))

Works somehow, but needs penalty for assigning distant clusters to exactly the same color

from conos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.