diff --git a/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java b/src/main/java/org/mastodon/mamut/clustering/ClusterRootNodesController.java index ba7d9d715..125e62555 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; @@ -96,16 +102,17 @@ private void runClassification() showDendrogram(); } - private String getParameters() + 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 ); 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(); } @@ -140,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 ) { @@ -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 ); } @@ -239,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/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" }; 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; + } } diff --git a/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java b/src/test/java/org/mastodon/mamut/clustering/ClusterRootNodesControllerTest.java index b3de30d0c..f891f821a 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() ); @@ -84,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)