Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LineageRegistrationPlugin: add copy spot labels functionality #61

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>"
stefanhahmann marked this conversation as resolved.
Show resolved Hide resolved
+ "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."
stefanhahmann marked this conversation as resolved.
Show resolved Hide resolved
+ "</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,9 +184,12 @@ 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:" ) );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering, if Copy spot labels is the best term here.

The tool tip says that the function works on cell / branch level. I thus ask myself, if copy cell or branch label would be a better choice here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The text says now "copy spot labels"

add( newOperationButton( "labels from A to B ...", COPY_LABELS_TOOLTIP, listener::onCopyLabelsAtoB ), "split 2" );
add( newOperationButton( "labels 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" );
add( newOperationButton( "tags from A to B ...", COPY_TAGSET_TOOLTIP, listener::onCopyTagSetAtoB ), "split 2" );
add( newOperationButton( "tags from B to A ...", COPY_TAGSET_TOOLTIP, listener::onCopyTagSetBtoA ), "wrap" );
add( new JLabel( "Cell division angles:") );
add( newOperationButton( "plot angles", PLOT_ANGLES_TOOLTIP, listener::onPlotAnglesClicked ), "split 2" );
add( newOperationButton( "add angles to table", ANGLES_FEATURE_TOOLTIP, listener::onAddAnglesFeatureClicked ), "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() );
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, it would be a good idea, if there was a method in the Spot class, which can be used to test, if a label different to the internal pool index exists.

This could maybe even be part of the HasLabel interface.

public boolean isLabelSet()
	{
		return pool.label.isSet( this ); // preferable?
		// return !Integer.toString( getInternalPoolIndex() ).equals( getLabel() );
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened a PR mastodon-sc/mastodon#318 that addresses this suggestion.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maarzt mastodon-sc/mastodon#318 has been merged in the meantime. Thus you could update here.

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
Loading