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

Registration of Two Lineages #10

Merged
merged 38 commits into from
Mar 13, 2023
Merged

Registration of Two Lineages #10

merged 38 commits into from
Mar 13, 2023

Conversation

maarzt
Copy link
Contributor

@maarzt maarzt commented Jan 20, 2023

Add a plugin that sorts the TrackScheme of one Mastodon project to match the order in another project.

Sorting a TrackScheme here is understood as sorting the order of child nodes for every dividing spot in the TrackScheme.

The algorithm implemented here does this by calculating the division directions for each cell division in both embryos. The division direction are compared between the two embryos in order to sort the child nodes of every dividing spot in the same way.

Requirement for the algorithm:

  • Stereotypical development
  • Root nodes need to be named in both embryos, and the names need to match pairwise between the embryos.

Steps of the algorithm:

  1. Match the root nodes in both embryos based on their name.
  2. A transformation is calculated that maps the coordinates of one embryo to the other. The coordinates of the matched nodes are used a key points to calculated the transform. The transform allows scale, rotation and translation but no sheering. (This keeps angles in both coordinate systems comparable)
  3. Pick a pair of root nodes (a, b)
  4. Calculate the division directions of both root nodes a and b: d_a, d_b. This division directions are vectors.
  5. The transformation (form step 2 to) is applied to d_a: T(d_a)
  6. The angle between the two division directions is calculated alpha = angle(T(d_a), d_b)
  7. The child nodes of root node b are flipped if the angle is larger than 90 degree.
  8. Recursively repeat step 4 to 8 for the root nodes of the subtrees of a and b.

TODOs

  • change the LineageRegistration to work on two open projects instead
  • move the code for node flipping from LineageRegistrationAlgorithm to a separate class.
  • implement plug in from copy a tagset from one mastodon project to another registered project.
  • synchronize two open mastodon projects.
  • document the fact that only the dividing spots are used to calculate transform between two embryos.
  • consider having multiple different criteria for filtering root nodes for registration.
  • consider making methods in LineageTreeUtils and RootsPairing more visible
  • Make sure undo works properly
    • after sorting a trackscheme
    • after tagging flipped / unmatched cells
    • after copying tagset from project A to project B
    • after adding tagset that colors lineages
  • properly read / write lock the graph, when performing operations
  • change the color for flipped cells to orange.
  • print to stdout or log to give the user a little more feedback.

Acceptance criteria

  • Open two of Mette's embryos (A) in Mastodon
  • In the Mastodon menu select "Plugins > Tree Management > Lineage Registration" to show the dialog for Lineage Registration.
  • Make sure that the dialog allows performing the following operations:
    • tag unmatched and flipped cells / branches
    • copy a tag set from one project to the other
    • sort the trackscheme in one project to match the order of descendants in the other project
    • color lineages -> this creates a new tag set in both projects, that have one tag per lineage
    • Activating one of the lock symbols synchronizes, focused (branch) spot & highlighted (branch) spot in both projects.

@maarzt maarzt marked this pull request as draft January 20, 2023 13:26
@maarzt maarzt requested review from tinevez, xulman and stefanhahmann and removed request for tinevez January 25, 2023 08:57
Copy link
Collaborator

@xulman xulman left a comment

Choose a reason for hiding this comment

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

Hi,
I have only a couple of minor comments that I believe could improve the readability of the code, plus a few things that might be worth double-checking .. all remarks are given in the comments to the code.

The algorithm itself is I think reasonable given its expected setting, and good that it echos the expected settings in the dialog.

I have to honestly admit that I haven't paid too much attention to the tests... and haven't yet found time to compile and test it.

Copy link
Collaborator

@stefanhahmann stefanhahmann left a comment

Choose a reason for hiding this comment

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

This pull request adds some nice functionality to register lineage trees of two projects with each other.

If the matching is successful the re-sorting of the lineage tree can be seen quite nicely in the TrackViews:

sort trackscheme

* An transformation between the two dataset is estimated from the labeled
  spots in the first time point of the two datasets
* The tree is sorted such that the spindle direction matches between
  the two datasets. Scalar product > 0.
The EstimateTransform method uses code that was probably implemented as
part of the multi-view reconstruction plugin for Fiji. But we furtunately
don't need the full multi-view reconstruction dependency.
This is a preparation step.

There is a significant difference between the LineageRegistrationPlugin
and other plugins in this repo. The lineage registration plugin will
operate on multiple open Mastodon projects. It therefor needs some
specialized MastodonPlugin.
The updated dialog supports a wider range of operations.
@maarzt maarzt force-pushed the lineage-registration branch from a040706 to 14d654b Compare February 15, 2023 15:28
@maarzt maarzt force-pushed the lineage-registration branch from 13121eb to 7fb432d Compare February 28, 2023 13:22
@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Mar 2, 2023

(fixed) It would be good, if the Lineage Registration Dialog would always come to front, when "Plugins" > "Lineage Registration" is selected. Otherwise, the user may have forgotten that the dialog is already open and just not visible anymore, because other Windows are in front of it. Consider e.g. the following workflow:

GIF 02 03 2023 16-18-02

@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Mar 2, 2023

(fixed) It would be good, if the Lineage Registration Dialog disappears, if the last Mastodon related Window has been closed. The dialog is then not needed anymore and the user would need to close it manually.

GIF 02 03 2023 16-23-41

However, an argument against this may be that all other Mastodon related windows also have to be closed one by one.

But all other windows that have to be closed manually actually appear in the task manager:
grafik

If the dialog remains to be closed manually, the latter should be consistent. Also, if the dialog would appear in the task manager, it would be easier to bring to the front again, if disappears under other windows.

@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Mar 3, 2023

The lineage registration dialog shows Mastodon projects that are not open anymore:

grafik

Before this screenshot, I did the following:

  1. Open Project "Mastodon" (a folder project)
  2. Open Project "e2-complete-3" (a file project)
  3. Open the Lineage Registration Dialog
  4. Close the Lineage Registration Dialog
  5. Close Project "Mastodon"
  6. Close Project "e2-complete-3"
  7. Open Project "e1-Mastodon"
  8. Open Project "e2-complete-3"
  9. Open the Lineage Registration Dialog again

Result: four project are shown in selection dialog, while only two projects are open.

The function "Update list of projects" does not seem to change anything in list of available projects, even though the name of that function would indicate that.

Also the lists of tag sets in the "copy tag set function" does not seem to be correctly updated (shows tag sets of projects that are not open anymore).

@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Mar 3, 2023

This tooltip disappears rather quickly, at least more quickly than I was able to read / understand it:

grafik

Consider making it appear a bit longer. The same also applies to other tooltips in this dialog (some of them are even longer and require even more time to read)

@stefanhahmann
Copy link
Collaborator

Would it be possible to automatically, regenerate the branch graph after sorting the TrackScheme via the Lineage Registration dialog.

GIF 03 03 2023 09-55-16

At the moment, if you are not an experienced user, it may be easily overseen that the icon to regenerate the branch graph in the sorted project changed and that only after pressing this button the actual sorting visually happens.

@stefanhahmann
Copy link
Collaborator

stefanhahmann commented Mar 3, 2023

(fixed) In this tooltip the user learns, how the tag sets are not created (i.e. not making use of the correspondences). It would at least be as interesting how the tag sets are then actually created (I assume using the root cell names?)

grafik

@stefanhahmann
Copy link
Collaborator

One may consider naming the buttons "project A", "project B" the same as the selected project.

grafik

Probably, this could go into a new Pull Request / Issue

@stefanhahmann
Copy link
Collaborator

I am not sure, if the function "Tag unmatched & flipped cells" work as expected:

grafik

After pressing all the buttons, I could not find any new tag set in both projects.

Also the tooltips should not be all the same for all three of the buttons.

maarzt added 2 commits March 7, 2023 14:54
Microsoft Windows treats JDialog and JFrame differently. A JDialog does
not show up in the task manager. Extending JFrame therefore improves
usability.

There are also other reasons for this change. The LineageRegistrationDialog
does not behave like a dialog: It is not modal. There are no Ok or Cancel
buttons. There's only a close button. It's meant to stay open for a longer
duration, while interacting with other windows. It therefor behaves more
like a JFrame.
@maarzt
Copy link
Contributor Author

maarzt commented Mar 7, 2023

The lineage registration dialog shows Mastodon projects that are not open anymore:

Well spotted. I'm aware of this problem. But I don't know no way for this plugin to get informed when the Mastodon project is closed. The plugin API has no unregister method MastodonPlugin. I tried to use WeakReferences but this didn't work. Mastodon projects are never garbage collected (on linux). So there is also garbage collection bug in Mastodon.

The function "Update list of projects" does not seem to change anything in list of available projects, even though the name of that function would indicate that.

The button adds newly opened projects to the list. It doesn't remove the already existing entries. I would like to get rid of this button but it's required for stupid reasons. When initializing a plugin the project path is not yet set, so it's not possible to update this list, as the project name cannot yet be deduced. This means I cannot reliably update this list when a new mastodon project is opened. This button is a workaround for that problem.

Also the lists of tag sets in the "copy tag set function" does not seem to be correctly updated (shows tag sets of projects that are not open anymore).

I cannot reproduce this problem. The list behave correctly as far as I can tell. Please provide a more detailed problem description.
(Also the Mastodon garbage collection bug means that projects are basically never closed. There is nothing like a Mastodon project being "not open".)

@maarzt
Copy link
Contributor Author

maarzt commented Mar 7, 2023

This tooltip disappears rather quickly, at least more quickly than I was able to read / understand it:

There are only hacky ways in java swing to show a tooltip longer.

Please keep in mind that there are currently only two intended users for this plugin. Too much time invested here is time wasted!

@maarzt
Copy link
Contributor Author

maarzt commented Mar 7, 2023

One may consider naming the buttons "project A", "project B" the same as the selected project.

I also had this idea. But no, we shouldn't do this. I learned from some provided datasets that projects name tend to become very long. So having only the short letters is best for readability.

@maarzt
Copy link
Contributor Author

maarzt commented Mar 7, 2023

I am not sure, if the function "Tag unmatched & flipped cells" work as expected:

grafik

After pressing all the buttons, I could not find any new tag set in both projects.

Also the tooltips should not be all the same for all three of the buttons.

This should work. The projects should get a tag set called "lineage registration" added. Could you verify if this problem persists. Please tell me how to reproduce the problem. For me the functionality works as expected.

@maarzt
Copy link
Contributor Author

maarzt commented Mar 7, 2023

@stefanhahmann & @xulman when reviewing this, please keep in mind that I currently only expect two users for this plugin: Johannes and Mette. Tell me if you see significant problems with the functionality or code. There is no need to polish all the little details. I want to make this algorithm available for now. Let's see if the algorithm works at all, it probably still need a lot off improvement and the UI will need to change with it. This plugin needs to be considered a prototype!

This drastically improves the feedback to the user if the sorting the
TrackScheme is used together with the "TrackScheme Branch" or "TrackScheme
Hierarchy" window. As the user no longer needs to klick. The tiny "regen."
button.
@stefanhahmann
Copy link
Collaborator

One may consider naming the buttons "project A", "project B" the same as the selected project.

I also had this idea. But no, we shouldn't do this. I learned from some provided datasets that projects name tend to become very long. So having only the short letters is best for readability.

I agree. Hadn't thought of long filenames.

This tooltip disappears rather quickly, at least more quickly than I was able to read / understand it:

There are only hacky ways in java swing to show a tooltip longer.

Please keep in mind that there are currently only two intended users for this plugin. Too much time invested here is time wasted!

I agree. Thanks for clarification.

The lineage registration dialog shows Mastodon projects that are not open anymore:

Well spotted. I'm aware of this problem. But I don't know no way for this plugin to get informed when the Mastodon project is closed. The plugin API has no unregister method MastodonPlugin. I tried to use WeakReferences but this didn't work. Mastodon projects are never garbage collected (on linux). So there is also garbage collection bug in Mastodon.

I did not know this. Thanks for making that clear.

The function "Update list of projects" does not seem to change anything in list of available projects, even though the name of that function would indicate that.

The button adds newly opened projects to the list. It doesn't remove the already existing entries. I would like to get rid of this button but it's required for stupid reasons. When initializing a plugin the project path is not yet set, so it's not possible to update this list, as the project name cannot yet be deduced. This means I cannot reliably update this list when a new mastodon project is opened. This button is a workaround for that problem.

That was unclear to me. Thanks for making that clear.

Also the lists of tag sets in the "copy tag set function" does not seem to be correctly updated (shows tag sets of projects that are not open anymore).

I cannot reproduce this problem. The list behave correctly as far as I can tell. Please provide a more detailed problem description. (Also the Mastodon garbage collection bug means that projects are basically never closed. There is nothing like a Mastodon project being "not open".)

I am not sure, if the function "Tag unmatched & flipped cells" work as expected:
grafik
After pressing all the buttons, I could not find any new tag set in both projects.
Also the tooltips should not be all the same for all three of the buttons.

This should work. The projects should get a tag set called "lineage registration" added. Could you verify if this problem persists. Please tell me how to reproduce the problem. For me the functionality works as expected.

It works as intended. It did not understand that expected result are 2 tag sets, but this is actually said in the tooltip.

Copy link
Collaborator

@stefanhahmann stefanhahmann left a comment

Choose a reason for hiding this comment

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

All the acceptance criteria seem to work now. This is very good.
Thanks also for the UI improvements. Especially that the Dialog is now a JFrame is an usability improvement.

There are some minor comments leave. Can you please have a look on them?

The coupling mechanism may deserve a more detailed code review. I did only a coarse one for the sake of the getting this to the user.

maarzt added 3 commits March 12, 2023 21:32
Previously those cells that had differently sorted child cells where
tagged. This commit changes the code such that the child cells themselves
get tagged. Which is hopefully more intuitively to understand.

Incoming edges are tagged too.

The order of the buttons in the LineageRegistrationFrame is changed.
Tagging cells is usually the first action a user would want the use.
The buttons for tagging cells are therefor now in the top row.
@maarzt maarzt marked this pull request as ready for review March 13, 2023 13:32
@maarzt maarzt merged commit 7b7d154 into master Mar 13, 2023
@maarzt maarzt deleted the lineage-registration branch August 1, 2023 08:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants