11package org .mastodon .mamut .tomancak .lineage_registration ;
22
3+ import java .util .Collection ;
4+ import java .util .Collections ;
35import java .util .HashMap ;
6+ import java .util .List ;
47import java .util .Map ;
58import java .util .Set ;
69import java .util .stream .Collectors ;
710
8- import org .jetbrains .annotations .NotNull ;
911import org .mastodon .collection .RefCollection ;
1012import org .mastodon .collection .RefRefMap ;
1113import org .mastodon .graph .algorithm .traversal .DepthFirstSearch ;
@@ -26,26 +28,24 @@ public class LineageColoring
2628 * Creates a new tag set "lineages" in both models.
2729 * A tag is added for all the root nodes that where successfully matched using {@link RootsPairing#pairDividingRoots}.
2830 * The tags of matching roots node gets the same colors assigned.
29- * Finally the tag is applied to all the descendants of a root node.
31+ * Finally, the tag is applied to all the descendants of a root node.
3032 */
3133 public static void tagLineages ( Model embryoA , Model embryoB )
3234 {
3335 RefRefMap < Spot , Spot > roots = RootsPairing .pairDividingRoots ( embryoA .getGraph (), embryoB .getGraph () );
34- Set < String > labels = roots .keySet ().stream ().map ( Spot ::getLabel ).collect ( Collectors .toSet () );
36+ List < String > labels = roots .keySet ().stream ().map ( Spot ::getLabel ).sorted (). collect ( Collectors .toList () );
3537 Map < String , Integer > colorMap = createColorMap ( labels );
3638 tagLineages ( colorMap , roots .keySet (), embryoA );
3739 tagLineages ( colorMap , roots .values (), embryoB );
3840 }
3941
4042 private static void tagLineages ( Map < String , Integer > colorMap , RefCollection < Spot > roots , Model model )
4143 {
42- TagSetStructure .TagSet tagSet = createTagSet ( model , colorMap );
44+ TagSetStructure .TagSet tagSet = addTagSetToModel ( model , colorMap );
4345 Map < String , TagSetStructure .Tag > tags = tagSet .getTags ().stream ()
4446 .collect ( Collectors .toMap ( TagSetStructure .Tag ::label , tag -> tag ) );
4547 for ( Spot root : roots )
46- {
4748 tagLineage ( model , root , tagSet , tags .get ( root .getLabel () ) );
48- }
4949 }
5050
5151 private static void tagLineage ( Model model , Spot root , TagSetStructure .TagSet tagSet , TagSetStructure .Tag tag )
@@ -86,7 +86,7 @@ public void crossComponent( Spot spot, Spot v1, DepthFirstSearch< Spot, Link > s
8686 search .start ( root );
8787 }
8888
89- private static TagSetStructure .TagSet createTagSet ( Model model , Map < String , Integer > tagsAndColors )
89+ private static TagSetStructure .TagSet addTagSetToModel ( Model model , Map < String , Integer > tagsAndColors )
9090 {
9191 TagSetModel < Spot , Link > tagSetModel = model .getTagSetModel ();
9292 TagSetStructure tss = copy ( tagSetModel .getTagSetStructure () );
@@ -103,8 +103,11 @@ private static TagSetStructure copy( TagSetStructure original )
103103 return copy ;
104104 }
105105
106- @ NotNull
107- private static Map < String , Integer > createColorMap ( Set < String > labels )
106+ /**
107+ * For a given set of labels, create a map from label to color.
108+ * Colors are taken from the Glasbey lookup table.
109+ */
110+ private static Map < String , Integer > createColorMap ( Collection < String > labels )
108111 {
109112 Map < String , Integer > colors = new HashMap <>();
110113 int count = 4 ;
0 commit comments