Skip to content

Commit ccec83d

Browse files
Merge pull request #85 from mastodon-sc/add_spot_counts_to_chart
Modify the command Show division counts to also show the spot counts
2 parents 365659e + 7f7b95c commit ccec83d

8 files changed

+155
-83
lines changed

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
* [Show compact lineage](#show-compact-lineage)
3636
* [Spatial track matching](#spatial-track-matching)
3737
* [Lineage analysis](#lineage-analysis)
38-
* [Show division counts over time](#show-division-counts-over-time)
38+
* [Show division counts over time](#show-spot-and-division-counts-over-time)
3939
* [Export measurements](#export-measurements)
4040
* [Export spot counts per lineage](#export-spot-counts-per-lineage)
4141
* [Export spot counts per time point](#export-spot-counts-per-time-point)
@@ -349,13 +349,13 @@ The plugin allows performing various operations based on the correspondence info
349349

350350
## Lineage analysis
351351

352-
### Show division counts over time
352+
### Show spot and division counts over time
353353

354-
* Menu Location: `Plugins > Lineage analysis > Show division counts over time`
355-
* The command shows a plot of the number of divisions over time.
354+
* Menu Location: `Plugins > Lineage analysis > Show spot and division counts over time`
355+
* The command shows a plot of the number of spots and divisions over time.
356356
* It is possible to set a window size, which is used to compute a sliding average.
357357
* A division is defined as a spot with more than one outgoing edge.
358-
* Example: ![division_counts_over_time.png](doc/lineageanalysis/division_counts_over_time.png)
358+
* Example: ![spot_and_division_counts_over_time.png](doc/lineageanalysis/spot_and_division_counts_over_time.png)
359359

360360
## Export measurements
361361

-35.9 KB
Binary file not shown.
Loading

src/main/java/org/mastodon/mamut/tomancak/TomancakPlugins.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.mastodon.mamut.model.Spot;
4646
import org.mastodon.mamut.plugin.MamutPlugin;
4747
import org.mastodon.mamut.tomancak.compact_lineage.CompactLineageFrame;
48-
import org.mastodon.mamut.tomancak.divisioncount.ShowDivisionCountsOverTimeCommand;
48+
import org.mastodon.mamut.tomancak.divisioncount.ShowSpotAndDivisionCountsOverTimeCommand;
4949
import org.mastodon.mamut.tomancak.divisiontagset.CellDivisionsTagSetCommand;
5050
import org.mastodon.mamut.tomancak.export.ExportCounts;
5151
import org.mastodon.mamut.tomancak.export.ExportDivisionCountsPerTimepointCommand;
@@ -102,7 +102,7 @@ public class TomancakPlugins extends AbstractContextual implements MamutPlugin
102102

103103
private static final String EXPORT_DIVISION_COUNTS_PER_TIMEPOINT = "[tomancak] export division counts per timepoint";
104104

105-
private static final String SHOW_DIVISION_COUNTS_OVER_TIME = "[tomancak] show division counts over time";
105+
private static final String SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME = "[tomancak] show division counts over time";
106106

107107
private static final String ADD_CENTER_SPOTS = "[tomancak] add center spots";
108108
private static final String MIRROR_SPOTS = "[tomancak] mirror spots";
@@ -132,7 +132,7 @@ public class TomancakPlugins extends AbstractContextual implements MamutPlugin
132132

133133
private static final String[] EXPORT_DIVISION_COUNTS_PER_TIMEPOINT_KEYS = { "not mapped" };
134134

135-
private static final String[] SHOW_DIVISION_COUNTS_OVER_TIME_KEYS = { "not mapped" };
135+
private static final String[] SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME_KEYS = { "not mapped" };
136136

137137
private static final String[] ADD_CENTER_SPOTS_KEYS = { "not mapped" };
138138
private static final String[] MIRROR_SPOTS_KEYS = { "not mapped" };
@@ -163,7 +163,7 @@ public class TomancakPlugins extends AbstractContextual implements MamutPlugin
163163
menuTexts.put( EXPORT_SPOTS_COUNTS_PER_LINEAGE, "Export spot counts per lineage" );
164164
menuTexts.put( EXPORT_SPOTS_COUNTS_PER_TIMEPOINT, "Export spot counts per timepoint" );
165165
menuTexts.put( EXPORT_DIVISION_COUNTS_PER_TIMEPOINT, "Export division counts per timepoint" );
166-
menuTexts.put( SHOW_DIVISION_COUNTS_OVER_TIME, "Show division counts over time" );
166+
menuTexts.put( SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME, "Show spot and division counts over time" );
167167
menuTexts.put( ADD_CENTER_SPOTS, "Add center spots" );
168168
menuTexts.put( MIRROR_SPOTS, "Mirror spots along X-axis" );
169169
menuTexts.put( CREATE_CONFLICT_TAG_SET, "Create conflict tag set" );
@@ -208,8 +208,9 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )
208208
"Exports counts of spots per timepoint into CSV-like files to be imported in data processors. One file." );
209209
descriptions.add( EXPORT_DIVISION_COUNTS_PER_TIMEPOINT, EXPORT_DIVISION_COUNTS_PER_TIMEPOINT_KEYS,
210210
"Exports counts of divisions per timepoint into CSV-like files to be imported in data processors. One file." );
211-
descriptions.add( SHOW_DIVISION_COUNTS_OVER_TIME, SHOW_DIVISION_COUNTS_OVER_TIME_KEYS,
212-
"Shows a plot of the number of divisions over time." );
211+
descriptions.add(
212+
SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME, SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME_KEYS,
213+
"Shows a plot of the number of spots and divisions over time." );
213214
descriptions.add( ADD_CENTER_SPOTS, ADD_CENTER_SPOTS_KEYS, "On each timepoint with selected spots, add a new spot that is in the center (average position)." );
214215
descriptions.add( MIRROR_SPOTS, MIRROR_SPOTS_KEYS, "Mirror spots along x-axis." );
215216
descriptions.add( CREATE_CONFLICT_TAG_SET, CREATE_CONFLICT_TAG_SET_KEYS, "Search spots that overlap and create a tag set that highlights these conflicts." );
@@ -258,7 +259,7 @@ public void getCommandDescriptions( final CommandDescriptions descriptions )
258259

259260
private final AbstractNamedAction exportDivisionCountsPerTimepointAction;
260261

261-
private final AbstractNamedAction showDivisionCountsOverTimeAction;
262+
private final AbstractNamedAction showSpotAndDivisionCountsOverTimeAction;
262263

263264
// private final AbstractNamedAction mergeProjectsAction;
264265

@@ -298,7 +299,8 @@ public TomancakPlugins()
298299
exportSpotsCountsPerTimepointAction = new RunnableAction( EXPORT_SPOTS_COUNTS_PER_TIMEPOINT, this::exportCountsPerTimepoint );
299300
exportDivisionCountsPerTimepointAction =
300301
new RunnableAction( EXPORT_DIVISION_COUNTS_PER_TIMEPOINT, this::exportDivisionCountsPerTimepoint );
301-
showDivisionCountsOverTimeAction = new RunnableAction( SHOW_DIVISION_COUNTS_OVER_TIME, this::showDivisionCountsOverTime );
302+
showSpotAndDivisionCountsOverTimeAction =
303+
new RunnableAction( SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME, this::showSpotAndDivisionCountsOverTime );
302304
addCenterSpots = new RunnableAction( ADD_CENTER_SPOTS, this::addCenterSpots );
303305
mirrorSpots = new RunnableAction( MIRROR_SPOTS, this::mirrorSpots );
304306
createConflictTagSet = new RunnableAction( CREATE_CONFLICT_TAG_SET, this::createConflictTagSet );
@@ -329,7 +331,7 @@ public List< ViewMenuBuilder.MenuItem > getMenuItems()
329331
item( EXPORT_PHYLOXML ) ) ),
330332
menu( "Plugins",
331333
menu( "Lineage analysis",
332-
item( SHOW_DIVISION_COUNTS_OVER_TIME ) ),
334+
item( SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME ) ),
333335
menu( "Tags",
334336
item( LOCATE_TAGS ),
335337
item( COPY_TAG ),
@@ -384,7 +386,7 @@ public void installGlobalActions( final Actions actions )
384386
actions.namedAction( exportSpotsCountsPerLineageAction, EXPORTS_SPOTS_COUNTS_PER_LINEAGE_KEYS );
385387
actions.namedAction( exportSpotsCountsPerTimepointAction, EXPORTS_SPOTS_COUNTS_PER_TIMEPOINT_KEYS );
386388
actions.namedAction( exportDivisionCountsPerTimepointAction, EXPORT_DIVISION_COUNTS_PER_TIMEPOINT_KEYS );
387-
actions.namedAction( showDivisionCountsOverTimeAction, SHOW_DIVISION_COUNTS_OVER_TIME_KEYS );
389+
actions.namedAction( showSpotAndDivisionCountsOverTimeAction, SHOW_SPOT_AND_DIVISION_COUNTS_OVER_TIME_KEYS );
388390
actions.namedAction( addCenterSpots, ADD_CENTER_SPOTS_KEYS );
389391
actions.namedAction( mirrorSpots, MIRROR_SPOTS_KEYS );
390392
actions.namedAction( createConflictTagSet, CREATE_CONFLICT_TAG_SET_KEYS );
@@ -484,9 +486,9 @@ private void exportDivisionCountsPerTimepoint()
484486
"context", projectModel.getContext() );
485487
}
486488

487-
private void showDivisionCountsOverTime()
489+
private void showSpotAndDivisionCountsOverTime()
488490
{
489-
commandService.run( ShowDivisionCountsOverTimeCommand.class, true, "projectModel", projectModel );
491+
commandService.run( ShowSpotAndDivisionCountsOverTimeCommand.class, true, "projectModel", projectModel );
490492
}
491493

492494
private void changeBranchLabels()

src/main/java/org/mastodon/mamut/tomancak/divisioncount/ShowDivisionCountsOverTimeCommand.java src/main/java/org/mastodon/mamut/tomancak/divisioncount/ShowSpotAndDivisionCountsOverTimeCommand.java

+12-9
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@
3232

3333
import javax.swing.SwingUtilities;
3434

35-
import org.apache.commons.lang3.tuple.Pair;
35+
import org.apache.commons.lang3.tuple.Triple;
3636
import org.mastodon.mamut.ProjectModel;
3737
import org.scijava.ItemVisibility;
3838
import org.scijava.command.Command;
3939
import org.scijava.plugin.Parameter;
4040
import org.scijava.plugin.Plugin;
4141

42-
@Plugin( type = Command.class, label = "Show division counts over time" )
43-
public class ShowDivisionCountsOverTimeCommand implements Command
42+
@Plugin( type = Command.class, label = "Show spot and division counts over time" )
43+
public class ShowSpotAndDivisionCountsOverTimeCommand implements Command
4444
{
4545

4646
@Parameter( visibility = ItemVisibility.MESSAGE, required = false, persist = false )
4747
private String documentation = "<html>\n"
4848
+ "<body width=15cm align=left>\n"
49-
+ "<h1>Show division counts over time</h1>\n"
50-
+ "<p>This command allows to set a window size and subsequently plot the number of divisions at each timepoint together with a sliding average acknowledging the given window size.</p>\n"
49+
+ "<h1>Show spot and division counts over time</h1>\n"
50+
+ "<p>This command allows to set a window size and subsequently plot the number of spots and divisions at each timepoint together with a sliding average acknowledging the given window size.</p>\n"
5151
+ "<p>A division is defined as a spot with more than one outgoing edge.</p>\n"
5252
+ "</body>\n"
5353
+ "</html>\n";
@@ -61,9 +61,12 @@ public class ShowDivisionCountsOverTimeCommand implements Command
6161
@Override
6262
public void run()
6363
{
64-
List< Pair< Integer, Integer > > divisionCounts = DivisionCount.getTimepointAndDivisions( projectModel.getModel() );
65-
double[] xValues = divisionCounts.stream().mapToDouble( Pair::getLeft ).toArray();
66-
double[] yValues = divisionCounts.stream().mapToDouble( Pair::getRight ).toArray();
67-
SwingUtilities.invokeLater( () -> new DivisionCountChart( xValues, yValues, windowSize ).setVisible( true ) );
64+
List< Triple< Integer, Integer, Integer > > divisionCounts =
65+
SpotAndDivisionCount.getSpotAndDivisionsPerTimepoint( projectModel.getModel() );
66+
double[] timepoints = divisionCounts.stream().mapToDouble( Triple::getLeft ).toArray();
67+
double[] spots = divisionCounts.stream().mapToDouble( Triple::getMiddle ).toArray();
68+
double[] divisions = divisionCounts.stream().mapToDouble( Triple::getRight ).toArray();
69+
70+
SwingUtilities.invokeLater( () -> new SpotAndDivisionCountChart( timepoints, spots, divisions, windowSize ).setVisible( true ) );
6871
}
6972
}

src/main/java/org/mastodon/mamut/tomancak/divisioncount/DivisionCount.java src/main/java/org/mastodon/mamut/tomancak/divisioncount/SpotAndDivisionCount.java

+13-6
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,29 @@
3131
import java.util.ArrayList;
3232
import java.util.List;
3333

34-
import org.apache.commons.lang3.tuple.Pair;
34+
import org.apache.commons.lang3.tuple.Triple;
3535
import org.mastodon.mamut.model.Model;
3636
import org.mastodon.mamut.model.Spot;
3737
import org.mastodon.util.TreeUtils;
3838

39-
public class DivisionCount
39+
public class SpotAndDivisionCount
4040
{
41-
private DivisionCount()
41+
private SpotAndDivisionCount()
4242
{
4343
// prevent instantiation
4444
}
4545

46-
public static List< Pair< Integer, Integer > > getTimepointAndDivisions( final Model model )
46+
/**
47+
* Calculates the number of spots and divisions per time point in the given model.
48+
*
49+
* @param model The model containing the spots and edges.
50+
* @return A list of triples, where each triple contains (in that order) the timepoint, the number of spots at that timepoint, and the number of divisions at that timepoint.
51+
*/
52+
public static List< Triple< Integer, Integer, Integer > > getSpotAndDivisionsPerTimepoint( final Model model )
4753
{
4854
int minTimepoint = TreeUtils.getMinTimepoint( model );
4955
int maxTimepoint = TreeUtils.getMaxTimepoint( model );
50-
List< Pair< Integer, Integer > > timepointAndDivisions = new ArrayList<>();
56+
List< Triple< Integer, Integer, Integer > > timepointAndDivisions = new ArrayList<>();
5157
for ( int timepoint = minTimepoint; timepoint <= maxTimepoint; timepoint++ )
5258
{
5359
int divisions = 0;
@@ -56,7 +62,8 @@ public static List< Pair< Integer, Integer > > getTimepointAndDivisions( final M
5662
if ( spot.outgoingEdges().size() > 1 )
5763
divisions++;
5864
}
59-
timepointAndDivisions.add( Pair.of( timepoint, divisions ) );
65+
int spots = model.getSpatioTemporalIndex().getSpatialIndex( timepoint ).size();
66+
timepointAndDivisions.add( Triple.of( timepoint, spots, divisions ) );
6067
}
6168
return timepointAndDivisions;
6269
}

0 commit comments

Comments
 (0)