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

Improve cluster root nodes names #42

Merged
merged 6 commits into from
Sep 18, 2023
Merged
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 @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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 )
{
Expand All @@ -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;
Expand All @@ -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 )
Expand All @@ -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 );
}
Expand All @@ -239,4 +249,20 @@ public boolean isValidParams()
{
return getFeedback().isEmpty();
}

private String getTagSetName()
{
return "Classification"
+ " ("
+ cropCriterion.getNameShort()
+ ": "
+ cropStart
+ "-"
+ cropEnd
+ ", classes: "
+ numberOfClasses
+ ", min. div: "
+ minCellDivisions
+ ") ";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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" };

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
Expand All @@ -27,4 +30,9 @@ public String getName()
{
return name;
}

public String getNameShort()
{
return nameShort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand All @@ -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()
);
}

/**
* <pre>
* branchSpot1(lifespan=20)
Expand Down
Loading