2121import org .mastodon .model .tag .ObjTagMap ;
2222import org .mastodon .model .tag .TagSetStructure ;
2323
24+ /**
25+ * Utility class that implements most of the functionality
26+ * provided by the {@link LineageRegistrationPlugin}.
27+ */
2428public class LineageRegistrationUtils
2529{
2630
31+ /**
32+ * Sorts the descendants in the second {@link ModelGraph} to match the order
33+ * of the descendants in the first {@link ModelGraph}.
34+ * The sorting is based on the result of the
35+ * {@link LineageRegistrationAlgorithm}.
36+ */
2737 public static void sortSecondTrackSchemeToMatch ( Model modelA , Model modelB )
2838 {
2939 RegisteredGraphs result = LineageRegistrationAlgorithm .run ( modelA .getGraph (), modelB .getGraph () );
30- FlipDescendants .flipDescendants ( modelB , getSpotsToFlipB ( result ) );
40+ RefList < Spot > spotsToFlipB = getSpotsToFlipB ( result );
41+ FlipDescendants .flipDescendants ( modelB , spotsToFlipB );
3142 }
3243
44+ /**
45+ * Copy a tag set from modelA to modelB.
46+ * The {@link LineageRegistrationAlgorithm} is used to find the matching
47+ * between the branches in modelA and modelB. The tags are copied from
48+ * the branches in modelA to the corresponding branches in modelB.
49+ */
3350 public static TagSetStructure .TagSet copyTagSetToSecond ( Model modelA , Model modelB ,
3451 TagSetStructure .TagSet tagSetModelA , String newTagSetName )
3552 {
@@ -116,6 +133,10 @@ private static Function< TagSetStructure.Tag, TagSetStructure.Tag > getTagMap( T
116133 return map ::get ;
117134 }
118135
136+ /**
137+ * Creates a new tag set in both models. It runs the {@link LineageRegistrationAlgorithm}
138+ * and tags unmatched and flipped cells / branches.
139+ */
119140 public static void tagCells ( Model modelA , Model modelB , boolean modifyA , boolean modifyB )
120141 {
121142 RegisteredGraphs result = LineageRegistrationAlgorithm .run ( modelA .getGraph (), modelB .getGraph () );
@@ -146,6 +167,10 @@ private static RefList< Spot > getSpotsToFlipB( RegisteredGraphs result )
146167 return getSpotsToFlipA ( result .swapAB () );
147168 }
148169
170+ /**
171+ * Returns the spots in graph A that need to be flipped in order for the
172+ * descendants of graph A to match the order of the descendants in graph B.
173+ */
149174 public static RefList < Spot > getSpotsToFlipA ( RegisteredGraphs r )
150175 {
151176 Spot refA = r .graphA .vertexRef ();
@@ -172,6 +197,11 @@ public static RefList< Spot > getSpotsToFlipA( RegisteredGraphs r )
172197 }
173198 }
174199
200+ /**
201+ * Returns true if the descendants of dividingA are in the opposite order
202+ * to the descendants of dividingB. Which descendant corresponds to which
203+ * is determined by the mapping {@link RegisteredGraphs#mapAB}.
204+ */
175205 private static boolean doesRequireFlip ( RegisteredGraphs r , Spot dividingA , Spot dividingB )
176206 {
177207 Spot refA = r .graphA .vertexRef ();
@@ -195,6 +225,10 @@ private static boolean doesRequireFlip( RegisteredGraphs r, Spot dividingA, Spot
195225 }
196226 }
197227
228+ /**
229+ * Returns a list of branch starts in graph A that are not mapped to any
230+ * branch in graph B.
231+ */
198232 public static RefSet < Spot > getUnmatchSpotsA ( RegisteredGraphs r )
199233 {
200234 RefSet < Spot > branchStarts = BranchGraphUtils .getAllBranchStarts ( r .graphA );
0 commit comments