Skip to content

Commit

Permalink
LineageRegistrationPlugin: add copy spot labels functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
maarzt committed Jun 14, 2024
1 parent 9c03ba2 commit 413b471
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,31 @@ public void onColorLineagesClicked()
} );
}

@Override
public void onCopyLabelsAtoB()
{
copyLabelsFromTo( dialog.getProjectA(), dialog.getProjectB() );
}

@Override
public void onCopyLabelsBtoA()
{
copyLabelsFromTo( dialog.getProjectB(), dialog.getProjectA() );
}

private void copyLabelsFromTo( SelectedProject fromProject, SelectedProject toProject )
{
executeTask( true, fromProject, toProject, () -> {
dialog.clearLog();
dialog.log( "Copy labels from project \"%s\" to project \"%s\"...",
fromProject.getName(), toProject.getName() );
RegisteredGraphs registration = runRegistrationAlgorithm( fromProject, toProject );
LineageRegistrationUtils.copySpotLabelsFromAtoB( registration );
toProject.getModel().setUndoPoint();
dialog.log( "done." );
} );
}

@Override
public void onCopyTagSetAtoB()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ public class LineageRegistrationFrame extends JFrame
+ "</ul>"
+ "</body></html>";

private static final String COPY_LABELS_TOOLTIP = "<html><body>"
+ "Use the found correspondences to copy spot labels from one project to the other.<br>"
+ "<br>"
+ "The correspondences are on a level of cells / branches.<br>"
+ "That is why the all the spots that belong to a cell / branch will get the same label.<br>"
+ "Labels on individual spot can not copied."
+ "</body></html>";

private static final String COPY_TAGSET_TOOLTIP = "<html><body>"
+ "Use the found correspondences to copy a tag set from one project to the other.<br>"
+ "<br>"
Expand Down Expand Up @@ -176,6 +184,9 @@ public LineageRegistrationFrame( Listener listener )
add( new JLabel( "Sort TrackScheme:" ) );
add( newOperationButton( "project A", SORT_TRACKSCHEME_TOOLTIP, listener::onSortTrackSchemeAClicked ), "split 2" );
add( newOperationButton( "project B", SORT_TRACKSCHEME_TOOLTIP, listener::onSortTrackSchemeBClicked ), "wrap" );
add( new JLabel( "Copy spot labels:" ) );
add( newOperationButton( "from A to B ...", COPY_LABELS_TOOLTIP, listener::onCopyLabelsAtoB ), "split 2" );
add( newOperationButton( "from B to A ...", COPY_LABELS_TOOLTIP, listener::onCopyLabelsBtoA ), "wrap" );
add( new JLabel( "Copy tag set:" ) );
add( newOperationButton( "from A to B ...", COPY_TAGSET_TOOLTIP, listener::onCopyTagSetAtoB ), "split 2" );
add( newOperationButton( "from B to A ...", COPY_TAGSET_TOOLTIP, listener::onCopyTagSetBtoA ), "wrap" );
Expand Down Expand Up @@ -408,6 +419,10 @@ public interface Listener

void onColorLineagesClicked();

void onCopyLabelsAtoB();

void onCopyLabelsBtoA();

void onCopyTagSetAtoB();

void onCopyTagSetBtoA();
Expand Down Expand Up @@ -446,6 +461,18 @@ public void onColorLineagesClicked()

}

@Override
public void onCopyLabelsAtoB()
{

}

@Override
public void onCopyLabelsBtoA()
{

}

@Override
public void onCopyTagSetAtoB()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,4 +318,28 @@ public static void plotAngleAgainstTimepoint( RefDoubleMap< Spot > angles )
frame.pack();
frame.setVisible( true );
}

public static void copySpotLabelsFromAtoB( final RegisteredGraphs registration )
{
final ModelGraph graphB = registration.graphB;
final Spot refB = graphB.vertexRef();
try
{
for ( final Spot spotA : registration.mapAB.keySet() )
{
boolean hasLabel = !Integer.toString( spotA.getInternalPoolIndex() ).equals( spotA.getLabel() );
if ( hasLabel )
{
final Spot spotB = registration.mapAB.get( spotA, refB );
final RefList< Spot > spotsOfBranchB = BranchGraphUtils.getBranchSpotsAndLinks( graphB, spotB ).getA();
for ( final Spot spot : spotsOfBranchB )
spot.setLabel( spotA.getLabel() );
}
}
}
finally
{
graphB.releaseRef( refB );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,27 @@ public void testCopyTagSet()
assertEquals( set( "B~2 -> B2" ), getTaggedEdges( barB ) );
}

@Test
public void testCopyLabels()
{
// setup: labels for embryoA
for ( Spot spot : embryoA.graph.vertices() )
spot.setLabel( spot.getLabel() + "_test" );
// process
LineageRegistrationUtils.copySpotLabelsFromAtoB( registration );
// test: labels for embryoB
assertEquals( "A_test", embryoB.a.getLabel() );
assertEquals( "A_test", embryoB.a.outgoingEdges().get( 0 ).getTarget().getLabel() );
assertEquals( "A1_test", embryoB.a1.getLabel() );
assertEquals( "A2_test", embryoB.a2.getLabel() );
assertEquals( "B_test", embryoB.b.getLabel() );
assertEquals( "B2_test", embryoB.b1.getLabel() );
assertEquals( "B1_test", embryoB.b2.getLabel() );
assertEquals( "C_test", embryoB.c.getLabel() );
assertEquals( "C1_test", embryoB.c1.getLabel() );
assertEquals( "C2_test", embryoB.c2.getLabel() );
}

private static < T > Set< T > set( T... values )
{
return new HashSet<>( Arrays.asList( values ) );
Expand Down

0 comments on commit 413b471

Please sign in to comment.