Skip to content

Commit 14d654b

Browse files
committed
Add functionality for the coloring of lineages
1 parent 2a9ae00 commit 14d654b

3 files changed

Lines changed: 15 additions & 10 deletions

File tree

src/test/java/org/mastodon/mamut/tomancak/lineage_registration/Glasbey.java renamed to src/main/java/org/mastodon/mamut/tomancak/lineage_registration/Glasbey.java

File renamed without changes.

src/test/java/org/mastodon/mamut/tomancak/lineage_registration/LineageColoring.java renamed to src/main/java/org/mastodon/mamut/tomancak/lineage_registration/LineageColoring.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package org.mastodon.mamut.tomancak.lineage_registration;
22

3+
import java.util.Collection;
4+
import java.util.Collections;
35
import java.util.HashMap;
6+
import java.util.List;
47
import java.util.Map;
58
import java.util.Set;
69
import java.util.stream.Collectors;
710

8-
import org.jetbrains.annotations.NotNull;
911
import org.mastodon.collection.RefCollection;
1012
import org.mastodon.collection.RefRefMap;
1113
import 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;

src/main/java/org/mastodon/mamut/tomancak/lineage_registration/LineageRegistrationControlService.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ public void onSortTrackSchemeBClicked()
8383
@Override
8484
public void onColorLineagesClicked()
8585
{
86-
// TODO
86+
Model modelA = dialog.getProjectA().getAppModel().getModel();
87+
Model modelB = dialog.getProjectB().getAppModel().getModel();
88+
LineageColoring.tagLineages( modelA, modelB );
8789
}
8890

8991
@Override

0 commit comments

Comments
 (0)