Skip to content

Commit c431a5c

Browse files
author
Stefan Hahmann
committed
Add scale factor to LineageMotifsUtils
1 parent 3662277 commit c431a5c

3 files changed

Lines changed: 16 additions & 12 deletions

File tree

src/main/java/org/mastodon/mamut/lineagemotifs/ui/FindLineageMotifsCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ private void findModules( boolean runOnBranchGraph )
117117
{
118118
BranchSpotTree lineageMotif = LineageMotifsUtils.getSelectedMotif( model, projectModel.getSelectionModel() );
119119
String lineageMotifName = lineageMotif.getStartSpotName();
120-
List< Pair< BranchSpotTree, Double > > similarModules = LineageMotifsUtils.getMostSimilarMotifs( lineageMotif,
121-
numberOfSimilarLineage, SimilarityMeasure.getByName( similarityMeasure ), spotRef, branchSpotRef, !runOnBranchGraph );
120+
List< Pair< BranchSpotTree, Double > > similarModules =
121+
LineageMotifsUtils.getMostSimilarMotifs( lineageMotif, numberOfSimilarLineage,
122+
SimilarityMeasure.getByName( similarityMeasure ), 1d, spotRef, branchSpotRef, !runOnBranchGraph );
122123
int numberOfDivisions = lineageMotif.getNumberOfDivisions();
123124
String optionalPlural = numberOfDivisions == 1 ? "" : "s";
124125
tagSetName = TAG_SET_NAME + lineageMotifName + " (" + numberOfDivisions + " division" + optionalPlural + ")";

src/main/java/org/mastodon/mamut/lineagemotifs/util/LineageMotifsUtils.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,11 @@ static int getEndTimepoint( final Spot selectedRoot, final Model model, final Se
108108
* @param lineageMotif the {@link BranchSpotTree} representing the given lineage motif
109109
* @param branchRef a reference to the branch graph
110110
* @param similarityMeasure the {@link SimilarityMeasure} to use for calculating the similarity
111+
* @param scaleFactor a scaling factor (i.e. in time) to apply to the similarity measure
111112
* @return a {@link RefDoubleMap} of {@link Spot}s and their respective similarity to the given lineage motif
112113
*/
113114
static RefDoubleMap< Spot > getMotifSimilarityBySpotIteration( final BranchSpotTree lineageMotif,
114-
final SimilarityMeasure similarityMeasure, final BranchSpot branchRef )
115+
final SimilarityMeasure similarityMeasure, final BranchSpot branchRef, final double scaleFactor )
115116
{
116117
Model model = lineageMotif.getModel();
117118
final int motifLength = lineageMotif.getDuration();
@@ -129,7 +130,7 @@ static RefDoubleMap< Spot > getMotifSimilarityBySpotIteration( final BranchSpotT
129130
int endTimepoint = startTimepoint + motifLength;
130131
BranchSpot branchSpot = model.getBranchGraph().getBranchVertex( spot, branchRef );
131132
BranchSpotTree candidateMotif = new BranchSpotTree( branchSpot, startTimepoint, endTimepoint, model );
132-
double distance = similarityMeasure.compute( lineageMotif, candidateMotif, 1d );
133+
double distance = similarityMeasure.compute( lineageMotif, candidateMotif, scaleFactor );
133134
candidates.put( spot, distance );
134135
}
135136
} );
@@ -143,10 +144,11 @@ static RefDoubleMap< Spot > getMotifSimilarityBySpotIteration( final BranchSpotT
143144
*
144145
* @param lineageMotif the {@link BranchSpotTree} representing the given lineage module
145146
* @param similarityMeasure the {@link SimilarityMeasure} to use for calculating the similarity
147+
* @param scaleFactor a scaling factor (i.e. in time) to apply to the similarity measure
146148
* @return a {@link RefDoubleMap} of {@link Spot}s and their respective similarity to the given lineage module
147149
*/
148150
static RefDoubleMap< Spot > getMotifSimilarityByBranchSpotIteration( final BranchSpotTree lineageMotif,
149-
final SimilarityMeasure similarityMeasure )
151+
final SimilarityMeasure similarityMeasure, final double scaleFactor )
150152
{
151153
final int motifLength = lineageMotif.getDuration();
152154
int moduleStartTimepoint = lineageMotif.getStartTimepoint();
@@ -162,7 +164,7 @@ static RefDoubleMap< Spot > getMotifSimilarityByBranchSpotIteration( final Branc
162164
{
163165
int endTimepoint = startTimepoint + motifLength;
164166
BranchSpotTree candidateMotif = new BranchSpotTree( branchSpot, startTimepoint, endTimepoint, model );
165-
double distance = similarityMeasure.compute( lineageMotif, candidateMotif, 1d );
167+
double distance = similarityMeasure.compute( lineageMotif, candidateMotif, scaleFactor );
166168
Iterator< Spot > spotIterator = model.getBranchGraph().vertexBranchIterator( branchSpot );
167169
// we need to iterate over the spots in the branch to get the correct spot for the candidate
168170
boolean foundMatchingSpot = false;
@@ -193,22 +195,23 @@ static RefDoubleMap< Spot > getMotifSimilarityByBranchSpotIteration( final Branc
193195
* @param lineageMotif the {@link BranchSpotTree} representing the lineage motif to compare
194196
* @param maxNumberOfMotifs the maximum number of similar motifs to retrieve
195197
* @param similarityMeasure the {@link SimilarityMeasure} used to compute the similarity between motifs
198+
* @param scaleFactor a scaling factor (i.e. in time) to apply to the similarity measure
196199
* @param spotRef a reference {@link Spot} used for accessing the graph's objects
197200
* @param branchRef a reference {@link BranchSpot} associated with the branch graph
198201
* @param isSpotIteration a boolean indicating whether to use spot iteration or branch spot iteration for similarity calculation.
199202
* Spot iteration may take significantly longer than branch spot iteration, but it is more accurate.
200203
* @return a {@link List} of {@link BranchSpotTree} objects representing the most similar lineage motifs, including their similarity scores.
201204
*/
202205
public static List< Pair< BranchSpotTree, Double > > getMostSimilarMotifs( final BranchSpotTree lineageMotif,
203-
int maxNumberOfMotifs, final SimilarityMeasure similarityMeasure, final Spot spotRef, final BranchSpot branchRef,
204-
boolean isSpotIteration )
206+
int maxNumberOfMotifs, final SimilarityMeasure similarityMeasure, final double scaleFactor, final Spot spotRef,
207+
final BranchSpot branchRef, boolean isSpotIteration )
205208
{
206209
int motifLength = lineageMotif.getDuration();
207210
RefDoubleMap< Spot > candidates;
208211
if ( isSpotIteration )
209-
candidates = getMotifSimilarityBySpotIteration( lineageMotif, similarityMeasure, branchRef );
212+
candidates = getMotifSimilarityBySpotIteration( lineageMotif, similarityMeasure, branchRef, 1d );
210213
else
211-
candidates = getMotifSimilarityByBranchSpotIteration( lineageMotif, similarityMeasure );
214+
candidates = getMotifSimilarityByBranchSpotIteration( lineageMotif, similarityMeasure, 1d );
212215

213216
Model model = lineageMotif.getModel();
214217
RefPool< Spot > refPool = model.getGraph().vertices().getRefPool();

src/test/java/org/mastodon/mamut/lineagemotifs/util/LineageMotifsUtilsTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,9 +321,9 @@ void testGetSimilarMotifs() throws IOException, SpimDataException
321321
}
322322
BranchSpotTree motif = LineageMotifsUtils.getSelectedMotif( model, selectionModel );
323323
List< Pair< BranchSpotTree, Double > > similarMotifsSpotIteration = LineageMotifsUtils.getMostSimilarMotifs( motif, 20,
324-
SimilarityMeasure.NORMALIZED_ZHANG_DIFFERENCE, spotRef, branchSpotRef, true );
324+
SimilarityMeasure.NORMALIZED_ZHANG_DIFFERENCE, 1d, spotRef, branchSpotRef, true );
325325
List< Pair< BranchSpotTree, Double > > similarMotifsBranchSpotIteration = LineageMotifsUtils.getMostSimilarMotifs( motif,
326-
20, SimilarityMeasure.NORMALIZED_ZHANG_DIFFERENCE, spotRef, branchSpotRef, false );
326+
20, SimilarityMeasure.NORMALIZED_ZHANG_DIFFERENCE, 1d, spotRef, branchSpotRef, false );
327327
boolean containsZeroValueSpotIteration = similarMotifsSpotIteration.stream().anyMatch( pair -> pair.getValue() == 0.0 );
328328
boolean containsBranchSpot220SpotIteration =
329329
similarMotifsSpotIteration.stream().anyMatch( pair -> pair.getKey().getBranchSpot().getLabel().equals( "220" ) );

0 commit comments

Comments
 (0)