treetoclust 988 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /* Convert a rooted tree to a hierarchy of clusters for patchwork.
  2. * ARGV[0] is desired root
  3. */
  4. BEG_G {
  5. node_t rt;
  6. node_t n;
  7. graph_t cg;
  8. graph_t sg;
  9. int depth;
  10. int mark[node_t];
  11. graph_t stk[int];
  12. if (! $.directed) {
  13. printf(2,"Input graph is not directed\n");
  14. exit (1);
  15. }
  16. rt = isNode($,ARGV[0]);
  17. if (rt == NULL) {
  18. printf(2,"Root node \"%s\" not found\n", ARGV[0]);
  19. exit (1);
  20. }
  21. $tvroot = rt;
  22. $tvtype = TV_prepostfwd;
  23. cg = graph(rt.name,"U");
  24. }
  25. N {
  26. if (mark[$]) {
  27. depth--;
  28. }
  29. else {
  30. mark[$] = 1;
  31. if (depth > 0) {
  32. if (fstout($)) {
  33. sg = subg(stk[depth-1], "cluster_" + $.name);
  34. if (($.style == "filled") && ($.fillcolor != ""))
  35. sg.bgcolor = $.fillcolor;
  36. }
  37. else {
  38. sg = NULL;
  39. n = node(stk[depth-1], $.name);
  40. n.style = "filled";
  41. n.fillcolor = $.fillcolor;
  42. }
  43. }
  44. else sg = cg;
  45. stk[depth] = sg;
  46. depth++;
  47. }
  48. }
  49. END_G {
  50. write(cg);
  51. }