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

Use scijavas new custom labels feature for the config enums #55

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,13 @@ private void runClassification()
String getParameters()
{
StringJoiner joiner = new StringJoiner( ", " );
joiner.add( "Crop criterion: " + cropCriterion.getName() );
joiner.add( "Crop criterion: " + cropCriterion );
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( "Similarity measure: " + similarityMeasure );
joiner.add( "Clustering method: " + clusteringMethod );
joiner.add( "Resulting lineage trees: " + getRoots().size() );
return joiner.toString();
}
Expand Down Expand Up @@ -244,7 +244,7 @@ public void setInputParams( final CropCriteria cropCriterion, final int cropStar
this.cropStart = cropStart;
this.cropEnd = cropEnd;
this.minCellDivisions = minCellDivisions;
logger.debug( "Crop criterion {}, start: {}, end: {}", cropCriterion.getName(), this.cropStart, this.cropEnd );
logger.debug( "Crop criterion {}, start: {}, end: {}", cropCriterion, this.cropStart, this.cropEnd );
}

public void setComputeParams( SimilarityMeasure similarityMeasure, ClusteringMethod clusteringMethod, int numberOfClasses )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
import com.apporiented.algorithm.clustering.SingleLinkageStrategy;
import org.mastodon.mamut.clustering.util.AverageLinkageUPGMAStrategy;

import java.util.NoSuchElementException;

public enum ClusteringMethod
{
AVERAGE_LINKAGE( "Average linkage", new AverageLinkageUPGMAStrategy() ),
Expand All @@ -51,19 +49,12 @@ public enum ClusteringMethod
this.linkageStrategy = linkageStrategy;
}

public String getName()
@Override
public String toString()
{
return name;
}

public static ClusteringMethod getByName(final String name) {
for (final ClusteringMethod method : values())
if (method.getName().equals(name))
return method;

throw new NoSuchElementException();
}

public LinkageStrategy getLinkageStrategy()
{
return linkageStrategy;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
*/
package org.mastodon.mamut.clustering.config;

import java.util.NoSuchElementException;

public enum CropCriteria
{
TIMEPOINT( "Timepoint", "time" ),
Expand All @@ -45,22 +43,14 @@ public enum CropCriteria
this.nameShort = nameShort;
}

public static CropCriteria getByName( final String name )
public String getNameShort()
{
for ( final CropCriteria criteria : values() )
if ( criteria.getName().equals( name ) )
return criteria;

throw new NoSuchElementException();
return nameShort;
}

public String getName()
@Override
public String toString()
{
return name;
}

public String getNameShort()
{
return nameShort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.mastodon.mamut.treesimilarity.ZhangUnorderedTreeEditDistance;
import org.mastodon.mamut.treesimilarity.tree.Tree;

import java.util.NoSuchElementException;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;

Expand All @@ -53,21 +52,13 @@ public enum SimilarityMeasure
this.distanceFunction = distanceFunction;
}

public static SimilarityMeasure getByName(final String name)
{
for (final SimilarityMeasure measure : values())
if (measure.getName().equals(name))
return measure;

throw new NoSuchElementException();
}

public double compute( Tree< Double > tree1, Tree< Double > tree2, BinaryOperator< Double > costFunction )
{
return distanceFunction.apply( tree1, tree2, costFunction );
}

public String getName()
@Override
public String toString()
{
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ public class ClusterRootNodesView extends InteractiveCommand
+ "</html>\n";

@SuppressWarnings("all")
@Parameter(label = "Crop criterion", choices = { "Timepoint", "Number of cells" }, callback = "update")
private String cropCriterion = CropCriteria.TIMEPOINT.getName();
@Parameter(label = "Crop criterion", callback = "update")
private CropCriteria cropCriterion = CropCriteria.TIMEPOINT;

@SuppressWarnings("unused")
@Parameter(label = "Crop start", min = "0", callback = "update")
Expand All @@ -83,18 +83,12 @@ public class ClusterRootNodesView extends InteractiveCommand
private int numberOfCellDivisions;

@SuppressWarnings("all")
@Parameter(
label = "Similarity measure", choices = { "Normalized Zhang Tree Distance", "Per Branch Spot Zhang Tree Distance",
"Zhang Tree Distance" }, callback = "update"
)
private String similarityMeasure = SimilarityMeasure.NORMALIZED_DIFFERENCE.getName();
@Parameter(label = "Similarity measure", callback = "update")
private SimilarityMeasure similarityMeasure = SimilarityMeasure.NORMALIZED_DIFFERENCE;

@SuppressWarnings("all")
@Parameter(
label = "Linkage strategy for hierarchical clustering", choices = { "Average linkage", "Single Linkage",
"Complete Linkage" }, callback = "update"
)
private String clusteringMethod = ClusteringMethod.AVERAGE_LINKAGE.getName();
@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")
Expand Down Expand Up @@ -129,9 +123,8 @@ public void run()
@SuppressWarnings("unused")
private void update()
{
controller.setInputParams( CropCriteria.getByName( cropCriterion ), start, end, numberOfCellDivisions );
controller.setComputeParams(
SimilarityMeasure.getByName( similarityMeasure ), ClusteringMethod.getByName( clusteringMethod ), numberOfClasses );
controller.setInputParams( cropCriterion, start, end, numberOfCellDivisions );
controller.setComputeParams( similarityMeasure, clusteringMethod, numberOfClasses );
controller.setShowDendrogram( showDendrogram );

paramFeedback = "<html><body width=" + WIDTH_INPUT + "cm>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
*/
package org.mastodon.mamut.io.exporter.labelimage.config;

import java.util.NoSuchElementException;


public enum LabelOptions
{
Expand All @@ -46,15 +44,8 @@ public enum LabelOptions
this.name = name;
}

public static LabelOptions getByName( final String name )
{
for ( final LabelOptions options : values() )
if ( options.getName().equals( name ) )
return options;
throw new NoSuchElementException();
}

public String getName()
@Override
public String toString()
{
return name;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class ExportLabelImageView implements Command
+ "</html>\n";

@SuppressWarnings("all")
@Parameter(label = "Label Id", choices = { "Spot track Id", "Branch spot ID", "Spot ID" })
private String option = LabelOptions.BRANCH_SPOT_ID.getName();
@Parameter(label = "Label Id")
private LabelOptions option = LabelOptions.BRANCH_SPOT_ID;

@SuppressWarnings("all")
@Parameter(label = "Frame rate reduction", description = "Only export every n-th. 1 means no reduction. Value must be >= 1.", min = "1")
Expand All @@ -83,7 +83,6 @@ public class ExportLabelImageView implements Command
public void run()
{
ExportLabelImageController controller = new ExportLabelImageController( projectModel, context );
LabelOptions selectedOption = LabelOptions.getByName( option );
controller.saveLabelImageToFile( selectedOption, saveTo, showResult, frameRateReduction );
controller.saveLabelImageToFile( option, saveTo, showResult, frameRateReduction );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,9 @@ public class ClusteringMethodTest
{

@Test
public void testGetName()
public void testToString()
{
assertEquals( "Average linkage", ClusteringMethod.AVERAGE_LINKAGE.getName() );
assertEquals( "Average linkage", ClusteringMethod.AVERAGE_LINKAGE.toString() );
}

@Test
public void testGetByName()
{
assertEquals( ClusteringMethod.AVERAGE_LINKAGE, ClusteringMethod.getByName( "Average linkage" ) );
assertThrows( NoSuchElementException.class, () -> ClusteringMethod.getByName( "foo" ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,8 @@ public class CropCriteriaTest
{

@Test
public void testGetName()
public void testToString()
{
assertEquals( "Timepoint", CropCriteria.TIMEPOINT.getName() );
}

@Test
public void testGetByName()
{
assertEquals( CropCriteria.TIMEPOINT, CropCriteria.getByName( "Timepoint" ) );
assertThrows( NoSuchElementException.class, () -> CropCriteria.getByName( "foo" ) );
assertEquals( "Timepoint", CropCriteria.TIMEPOINT.toString() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,14 @@

import org.junit.Test;

import java.util.NoSuchElementException;

import static org.junit.Assert.*;

public class SimilarityMeasureTest
{

@Test
public void testGetName()
{
assertEquals( "Normalized Zhang Tree Distance", SimilarityMeasure.NORMALIZED_DIFFERENCE.getName() );
}

@Test
public void testGetByName()
public void testToString()
{
assertEquals( SimilarityMeasure.NORMALIZED_DIFFERENCE, SimilarityMeasure.getByName( "Normalized Zhang Tree Distance" ) );
assertThrows( NoSuchElementException.class, () -> SimilarityMeasure.getByName( "foo" ) );
assertEquals( "Normalized Zhang Tree Distance", SimilarityMeasure.NORMALIZED_DIFFERENCE.toString() );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,14 @@
package org.mastodon.mamut.io.exporter.labelimage.config;

import org.junit.Test;
import org.mastodon.mamut.io.exporter.labelimage.config.LabelOptions;

import java.util.NoSuchElementException;

import static org.junit.Assert.*;

public class LabelOptionsTest
{

@Test
public void getByName()
{
assertEquals( LabelOptions.SPOT_ID, LabelOptions.getByName( "Spot ID" ) );
assertEquals( LabelOptions.BRANCH_SPOT_ID, LabelOptions.getByName( "Branch spot ID" ) );
assertEquals( LabelOptions.TRACK_ID, LabelOptions.getByName( "Spot track Id" ) );
assertThrows( NoSuchElementException.class, () -> LabelOptions.getByName( "Foo" ) );
}

@Test
public void getName()
public void testToString()
{
assertEquals( "Spot ID", LabelOptions.SPOT_ID.getName() );
assertEquals( "Branch spot ID", LabelOptions.BRANCH_SPOT_ID.getName() );
assertEquals( "Spot track Id", LabelOptions.TRACK_ID.getName() );
assertEquals( "Spot ID", LabelOptions.SPOT_ID.toString() );
}
}
Loading