-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClusterRootNodesView.java
More file actions
160 lines (137 loc) · 6.82 KB
/
ClusterRootNodesView.java
File metadata and controls
160 lines (137 loc) · 6.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*-
* #%L
* mastodon-deep-lineage
* %%
* Copyright (C) 2022 - 2023 Stefan Hahmann
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/
package org.mastodon.mamut.clustering.ui;
import org.mastodon.mamut.clustering.ClusterRootNodesController;
import org.mastodon.mamut.clustering.config.ClusteringMethod;
import org.mastodon.mamut.clustering.config.CropCriteria;
import org.mastodon.mamut.clustering.config.SimilarityMeasure;
import org.scijava.ItemVisibility;
import org.scijava.command.InteractiveCommand;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;
import org.scijava.widget.Button;
@Plugin(type = InteractiveCommand.class, visible = false, label = "Classification of Lineage Trees")
public class ClusterRootNodesView extends InteractiveCommand
{
private static final int WIDTH = 15;
private static final int WIDTH_INPUT = 7;
@SuppressWarnings("unused")
@Parameter
private ClusterRootNodesController controller;
@SuppressWarnings("all")
@Parameter(visibility = ItemVisibility.MESSAGE, required = false, persist = false)
private String documentation = "<html>\n"
+ "<body width=" + WIDTH + "cm align=left>\n"
+ "<h1>Classification of Lineage Trees</h1>\n"
+ "<p>This plugin is capable of grouping similar lineage trees together. This is done by creating a tag set an assigning subtrees that are similar to each other with the same tag.</p>\n"
+ "<p>The similarity between two subtrees is computed based on the Zhang edit distance for unordered trees <a href=\"https://doi.org/10.1007/BF01975866\">(Zhang, K. Algorithmica 15, 205–222, 1996)</a>. The similarity measure uses the attribute the cell lifetime, which is computed as a difference of timepoints between to subsequent divisions. It is possible to apply the <i>absolute difference</i>, <i>average difference</i> or the <i>normalized difference</i> of cell lifetimes.</p>\n"
+ "<p>The similarity is computed between all possible combinations of subtrees leading to a two-dimensional similarity matrix. This matrix is then used to perform a <a href=\"https://en.wikipedia.org/wiki/Hierarchical_clustering\">agglomerative hierarchical clustering</a> into a specifiable number of classes. For the clustering three different <a href=\"https://en.wikipedia.org/wiki/Hierarchical_clustering#Cluster_Linkage\">linkage methods</a> can be chosen.</p>\n"
+ "</body>\n"
+ "</html>\n";
@SuppressWarnings("all")
@Parameter(label = "Crop criterion", callback = "update")
private CropCriteria cropCriterion = CropCriteria.TIMEPOINT;
@SuppressWarnings("unused")
@Parameter(label = "Crop start", min = "0", callback = "update")
private int start;
@SuppressWarnings("unused")
@Parameter(label = "Crop end", min = "0", callback = "update")
private int end;
@SuppressWarnings("unused")
@Parameter(label = "Number of classes", min = "2", callback = "update")
private int numberOfClasses;
@SuppressWarnings("unused")
@Parameter(label = "Minimum number of cell divisions", min = "0", description = "Only include lineage trees with at least the number of divisions specified here.", callback = "update")
private int numberOfCellDivisions;
@SuppressWarnings("all")
@Parameter(label = "Similarity measure", callback = "update")
private SimilarityMeasure similarityMeasure = SimilarityMeasure.NORMALIZED_DIFFERENCE;
@SuppressWarnings("all")
@Parameter(label = "Linkage strategy for hierarchical clustering", callback = "update")
private ClusteringMethod clusteringMethod = ClusteringMethod.AVERAGE_LINKAGE;
@SuppressWarnings("unused")
@Parameter(label = "Feature", choices = "Branch duration", callback = "update")
private String branchDuration;
// NB: dynamic choices: https://github.com/imagej/tutorials/blob/c78764438d774295d00fc8a4273e4c4f25c8ad46/maven-projects/dynamic-commands/src/main/java/DynamicCallbacks.java
@SuppressWarnings("unused")
@Parameter(label = "Show dendrogram of clustering", callback = "update")
private boolean showDendrogram;
@SuppressWarnings("unused")
@Parameter(visibility = ItemVisibility.MESSAGE, required = false, persist = false, label = " ")
private String paramFeedback;
@SuppressWarnings("unused")
@Parameter(visibility = ItemVisibility.MESSAGE, required = false, persist = false, label = " ")
private String computeFeedback;
@SuppressWarnings("unused")
@Parameter(label = "Classify lineage trees", callback = "createTagSet", persist = false)
private Button createTagSet;
/**
* This method is executed whenever a parameter changes
*/
@Override
public void run()
{
// NB: not implemented. Update method is called via callback on each parameter change.
}
@SuppressWarnings("unused")
private void update()
{
controller.setInputParams( cropCriterion, start, end, numberOfCellDivisions );
controller.setComputeParams( similarityMeasure, clusteringMethod, numberOfClasses );
controller.setShowDendrogram( showDendrogram );
paramFeedback = "<html><body width=" + WIDTH_INPUT + "cm>";
if ( controller.isValidParams() )
paramFeedback += "<font color=green>Parameters are valid.";
else
{
paramFeedback += "<font color=red>" + String.join( "<p>", controller.getFeedback() );
}
paramFeedback += "</font></body></html>";
}
@SuppressWarnings("unused")
private void createTagSet()
{
update();
if ( controller.isValidParams() )
{
String feedback;
try
{
controller.createTagSet();
feedback = "Classified lineage trees.<p>";
feedback += "Tag set created.";
}
catch ( IllegalArgumentException e )
{
feedback = e.getMessage();
}
computeFeedback = "<html><body width=" + WIDTH_INPUT + "cm><font color=\"green\">" + feedback + "</font></body></html>";
}
}
}