From 6a37cfd8d5e49750c899966d7e1f93e93734d03a Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 12:59:39 +0200 Subject: [PATCH 1/6] Add a short name to enum CropCriteria --- .../mamut/clustering/config/CropCriteria.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/clustering/config/CropCriteria.java b/src/main/java/org/mastodon/mamut/clustering/config/CropCriteria.java index e30432243..30c658f0a 100644 --- a/src/main/java/org/mastodon/mamut/clustering/config/CropCriteria.java +++ b/src/main/java/org/mastodon/mamut/clustering/config/CropCriteria.java @@ -4,14 +4,17 @@ public enum CropCriteria { - TIMEPOINT( "Timepoint" ), - NUMBER_OF_CELLS( "Number of cells" ); + TIMEPOINT( "Timepoint", "time" ), + NUMBER_OF_CELLS( "Number of cells", "cells" ); private final String name; - CropCriteria( String name ) + private final String nameShort; + + CropCriteria( String name, String nameShort ) { this.name = name; + this.nameShort = nameShort; } public static CropCriteria getByName( final String name ) @@ -27,4 +30,9 @@ public String getName() { return name; } + + public String getNameShort() + { + return nameShort; + } } From 7755273cdfb5bd2ac024afe1a3e4e7d28e6dd2b0 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 13:07:42 +0200 Subject: [PATCH 2/6] Rename visual name of Plugin to "Classification of Lineage Trees" --- .../org/mastodon/mamut/clustering/ClusterRootNodesPlugin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesPlugin.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesPlugin.java index 46bb65cea..4a0e6ef50 100644 --- a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesPlugin.java +++ b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesPlugin.java @@ -22,7 +22,7 @@ @Plugin( type = MamutPlugin.class ) public class ClusterRootNodesPlugin implements MamutPlugin { - private static final String CLUSTER_ROOT_NODES = "Cluster root nodes"; + private static final String CLUSTER_ROOT_NODES = "Classification of Lineage Trees"; private static final String[] CLUSTER_ROOT_NODES_KEYS = { "not mapped" }; From 6b0fffa6e38c5a29cce536d69b06f55d61009cca Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 13:14:28 +0200 Subject: [PATCH 3/6] Add separate parameters for crop start/end and crop star/end time * Add cropCriterion as class variable * This change allows to handle crop start and end independent of resulting crop start/end time --- .../ClusterRootNodesController.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java index ba7d9d715..1212748f2 100644 --- a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java +++ b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java @@ -45,10 +45,16 @@ public class ClusterRootNodesController private ClusteringMethod clusteringMethod = ClusteringMethod.AVERAGE_LINKAGE; + private CropCriteria cropCriterion; + private int cropStart; private int cropEnd; + private int cropStartTime; + + private int cropEndTime; + private int numberOfClasses; private int minCellDivisions; @@ -99,6 +105,7 @@ private void runClassification() private String getParameters() { StringJoiner joiner = new StringJoiner( ", " ); + joiner.add( "Crop criterion: " + cropCriterion.getName() ); joiner.add( "Crop start: " + cropStart ); joiner.add( "Crop end: " + cropEnd ); joiner.add( "Number of classes: " + numberOfClasses ); @@ -167,14 +174,14 @@ private List< BranchSpotTree > getRoots() { if ( !synchronizer.isUptodate() ) model.getBranchGraph().graphRebuilt(); - RefSet< Spot > roots = LineageTreeUtils.getRoots( model.getGraph(), cropStart ); + RefSet< Spot > roots = LineageTreeUtils.getRoots( model.getGraph(), cropStartTime ); List< BranchSpotTree > trees = new ArrayList<>(); for ( Spot root : roots ) { BranchSpot rootBranchSpot = model.getBranchGraph().getBranchVertex( root, model.getBranchGraph().vertexRef() ); try { - BranchSpotTree branchSpotTree = new BranchSpotTree( rootBranchSpot, cropEnd ); + BranchSpotTree branchSpotTree = new BranchSpotTree( rootBranchSpot, cropEndTime ); int minTreeSize = 2 * minCellDivisions + 1; if ( TreeUtils.size( branchSpotTree ) < minTreeSize ) continue; @@ -190,16 +197,19 @@ private List< BranchSpotTree > getRoots() public void setInputParams( CropCriteria cropCriterion, int cropStart, int cropEnd, int minCellDivisions ) { + this.cropCriterion = cropCriterion; this.cropStart = cropStart; this.cropEnd = cropEnd; - this.minCellDivisions = minCellDivisions; + this.cropStartTime = cropStart; + this.cropEndTime = cropEnd; if ( cropCriterion.equals( CropCriteria.NUMBER_OF_CELLS ) ) { - logger.debug( "Crop criterion cells, crop start cells: {}, crop end cells: {}", cropStart, cropEnd ); - this.cropStart = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropStart ); - this.cropEnd = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropEnd ); + this.cropStartTime = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropStart ); + this.cropEndTime = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropEnd ); } - logger.debug( "Crop criterion {}, start timepoint: {}, crop end timepoint: {}", cropCriterion, this.cropStart, this.cropEnd ); + this.minCellDivisions = minCellDivisions; + logger.debug( "Crop criterion {}, start: {}, end: {}", cropCriterion.getName(), this.cropStart, this.cropEnd ); + logger.debug( "Crop time, start: {}, end: {}", this.cropStartTime, this.cropEndTime ); } public void setComputeParams( SimilarityMeasure similarityMeasure, ClusteringMethod clusteringMethod, int numberOfClasses ) @@ -219,7 +229,7 @@ public List< String > getFeedback() List< String > feedback = new ArrayList<>(); if ( cropStart >= cropEnd ) { - String message = "Crop start (timepoint=" + cropStart + ") must be smaller than crop end (timepoint=" + cropEnd + ")"; + String message = "Crop start (" + cropStart + ") must be smaller than crop end (" + cropEnd + ")"; feedback.add( message ); logger.debug( message ); } From b2956debb7198a9ecfc4919e87df91190c49e183 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 13:16:22 +0200 Subject: [PATCH 4/6] Add new method getTagSetName() and unit test for it --- .../clustering/ClusterRootNodesController.java | 16 ++++++++++++++++ .../ClusterRootNodesControllerTest.java | 1 + 2 files changed, 17 insertions(+) diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java index 1212748f2..8630ff1c7 100644 --- a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java +++ b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java @@ -249,4 +249,20 @@ public boolean isValidParams() { return getFeedback().isEmpty(); } + + private String getTagSetName() + { + return "Classification" + + " (" + + cropCriterion.getNameShort() + + ": " + + cropStart + + "-" + + cropEnd + + ", classes: " + + numberOfClasses + + ", min. div: " + + minCellDivisions + + ") "; + } } diff --git a/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java b/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java index b3de30d0c..fc002d456 100644 --- a/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java +++ b/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java @@ -63,6 +63,7 @@ public void testCreateTagSet() Set< Integer > expectedClassCounts = new HashSet<>( Arrays.asList( 9, 12, 14 ) ); Set< Integer > actualClassCounts = new HashSet<>( Arrays.asList( tag0Spots.size(), tag1Spots.size(), tag2Spots.size() ) ); + assertEquals( "Classification (time: 0-100, classes: 3, min. div: 1) ", tagSet0.getName() ); assertTrue( controller.isValidParams() ); assertEquals( 1, tagSets.size() ); assertEquals( 3, tags.size() ); From 1fc4679908063f32f5162750714e851d03939c57 Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 13:30:08 +0200 Subject: [PATCH 5/6] Use method getTagSetName() to generate a differentiable name for the tag set resulting from the classification --- .../mastodon/mamut/clustering/ClusterRootNodesController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java index 8630ff1c7..80fe84c10 100644 --- a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java +++ b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java @@ -147,7 +147,7 @@ private Collection< Pair< String, Integer > > createTagsAndColors() private void applyClassification( Classification< BranchSpotTree > classification, Collection< Pair< String, Integer > > tagsAndColors ) { Set< Set< BranchSpotTree > > classifiedObjects = classification.getClassifiedObjects(); - TagSetStructure.TagSet tagSet = TagSetUtils.addNewTagSetToModel( model, "Classification", tagsAndColors ); + TagSetStructure.TagSet tagSet = TagSetUtils.addNewTagSetToModel( model, getTagSetName(), tagsAndColors ); int i = 0; for ( Set< BranchSpotTree > entry : classifiedObjects ) { From 6befc1818b622e156ecb64a75a8b33d0a669a83f Mon Sep 17 00:00:00 2001 From: Stefan Hahmann Date: Thu, 14 Sep 2023 13:37:17 +0200 Subject: [PATCH 6/6] Add unit test for testGetParameters() in ClusterRootNodesController --- .../clustering/ClusterRootNodesController.java | 4 ++-- .../ClusterRootNodesControllerTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java index 80fe84c10..125e62555 100644 --- a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java +++ b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java @@ -102,7 +102,7 @@ private void runClassification() showDendrogram(); } - private String getParameters() + String getParameters() { StringJoiner joiner = new StringJoiner( ", " ); joiner.add( "Crop criterion: " + cropCriterion.getName() ); @@ -112,7 +112,7 @@ private String getParameters() joiner.add( "Minimum cell divisions: " + minCellDivisions ); joiner.add( "Similarity measure: " + similarityMeasure.getName() ); joiner.add( "Clustering method: " + clusteringMethod.getName() ); - joiner.add( "Resulting root nodes: " + getRoots().size() ); + joiner.add( "Resulting lineage trees: " + getRoots().size() ); return joiner.toString(); } diff --git a/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java b/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java index fc002d456..f891f821a 100644 --- a/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java +++ b/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java @@ -85,6 +85,21 @@ public void testGetFeedback() assertThrows( IllegalArgumentException.class, controller::createTagSet ); } + @Test + public void testGetParameters() + { + ExampleGraph2 exampleGraph = new ExampleGraph2(); + final BranchGraphSynchronizer synchronizer = new BranchGraphSynchronizer( null, null ); + ClusterRootNodesController controller = new ClusterRootNodesController( exampleGraph.getModel(), synchronizer ); + controller.setInputParams( CropCriteria.TIMEPOINT, 1, 10, 1 ); + controller.setComputeParams( SimilarityMeasure.NORMALIZED_DIFFERENCE, ClusteringMethod.AVERAGE_LINKAGE, 3 ); + + assertEquals( + "Crop criterion: Timepoint, Crop start: 1, Crop end: 10, Number of classes: 3, Minimum cell divisions: 1, Similarity measure: Normalized Zhang Tree Distance, Clustering method: Average linkage, Resulting lineage trees: 1", + controller.getParameters() + ); + } + /** *
 	 *                             branchSpot1(lifespan=20)