Skip to content

Commit

Permalink
Use crop start param also when finding roots
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanhahmann committed Sep 7, 2023
1 parent a4b1dd2 commit 907ddec
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.mastodon.mamut.clustering;

import org.apache.commons.lang3.tuple.Pair;
import org.mastodon.graph.algorithm.RootFinder;
import org.mastodon.collection.RefSet;
import org.mastodon.graph.algorithm.traversal.DepthFirstIterator;
import org.mastodon.mamut.clustering.config.ClusteringMethod;
import org.mastodon.mamut.clustering.config.CropCriteria;
Expand Down Expand Up @@ -167,8 +167,7 @@ private List< BranchSpotTree > getRoots()
{
if ( !synchronizer.isUptodate() )
model.getBranchGraph().graphRebuilt();
// TODO: take into account crop start - there may be more roots if the crop start is > 0
Set< Spot > roots = RootFinder.getRoots( model.getGraph() );
RefSet< Spot > roots = LineageTreeUtils.getRoots( model.getGraph(), cropStart );
List< BranchSpotTree > trees = new ArrayList<>();
for ( Spot root : roots )
{
Expand Down Expand Up @@ -197,8 +196,8 @@ public void setInputParams( CropCriteria cropCriterion, int cropStart, int cropE
if ( cropCriterion.equals( CropCriteria.NUMBER_OF_CELLS ) )
{
logger.debug( "Crop criterion cells, crop start cells: {}, crop end cells: {}", cropStart, cropEnd );
cropStart = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropStart );
cropEnd = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropEnd );
this.cropStart = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropStart );
this.cropEnd = LineageTreeUtils.getFirstTimepointWithNSpots( model, cropEnd );
}
logger.debug( "Crop criterion {}, start timepoint: {}, crop end timepoint: {}", cropCriterion, cropStart, cropEnd );
}
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/mastodon/mamut/util/LineageTreeUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.mastodon.mamut.util;

import org.mastodon.collection.RefCollection;
import org.mastodon.collection.RefCollections;
import org.mastodon.collection.RefSet;
import org.mastodon.graph.Edge;
import org.mastodon.graph.Graph;
Expand All @@ -9,6 +11,7 @@
import org.mastodon.graph.algorithm.traversal.GraphSearch;
import org.mastodon.graph.algorithm.traversal.SearchListener;
import org.mastodon.mamut.model.Model;
import org.mastodon.mamut.model.ModelGraph;
import org.mastodon.mamut.model.Spot;
import org.mastodon.pool.PoolCollectionWrapper;

Expand All @@ -17,6 +20,7 @@
import java.util.NoSuchElementException;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Predicate;

public class LineageTreeUtils {

Expand Down Expand Up @@ -126,4 +130,25 @@ public static int getFirstTimepointWithNSpots( final Model model, final int numb
"No time point with at least " + numberOfSpots + " spots in the range [minTimepoint=" + minTimepoint + ", maxTimepoint="
+ maxTimepoint + "]." );
}

// Replace with new method after has been resolved https://github.com/mastodon-sc/mastodon-tomancak/issues/13
public static RefSet< Spot > getRoots( ModelGraph graph, int timepoint )
{
Predicate< Spot > isRoot = spot -> spot.getTimepoint() == timepoint
|| ( spot.incomingEdges().isEmpty() && spot.getTimepoint() > timepoint );
return filterSet( graph.vertices(), isRoot );
}

/**
* Returns a new {@link RefSet} containing all elements of the given
* {@link RefCollection} that satisfy the given {@link Predicate}.
*/
public static < T > RefSet< T > filterSet( RefCollection< T > values, Predicate< T > predicate )
{
RefSet< T > filtered = RefCollections.createRefSet( values );
for ( T t : values )
if ( predicate.test( t ) )
filtered.add( t );
return filtered;
}
}

0 comments on commit 907ddec

Please sign in to comment.