Skip to content

Commit

Permalink
Merge branch '368-number-of-explained-peaks-incorrect-for-in-source-l…
Browse files Browse the repository at this point in the history
…osses' into 'master'

Resolve "Number of explained peaks incorrect for in-source losses."

Closes #368

See merge request bright-giant/sirius/sirius-frontend!138
  • Loading branch information
Markus Fleischauer committed Sep 17, 2024
2 parents 78c2645 + e82da6e commit 51c361d
Showing 1 changed file with 11 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import de.unijena.bioinf.ChemistryBase.algorithm.scoring.FormulaScore;
import de.unijena.bioinf.ChemistryBase.math.Statistics;
import de.unijena.bioinf.ChemistryBase.ms.AnnotatedPeak;
import de.unijena.bioinf.ChemistryBase.ms.Deviation;
import de.unijena.bioinf.ChemistryBase.ms.ft.*;
import de.unijena.bioinf.FragmentationTreeConstruction.computation.FragmentationPatternAnalysis;
Expand All @@ -32,6 +33,7 @@
import gnu.trove.list.array.TDoubleArrayList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.slf4j.LoggerFactory;

import java.util.HashSet;
import java.util.Optional;
Expand Down Expand Up @@ -164,7 +166,15 @@ public static int getNumberOfExplainablePeaks(@NotNull FTree tree) {
* @return
*/
public static int getNumOfExplainedPeaks(@NotNull FTree tree) {
return tree.numberOfVertices()-1;
// only count fragments that belong to a peak
FragmentAnnotation<AnnotatedPeak> peakAno = tree.getFragmentAnnotationOrNull(AnnotatedPeak.class);
LossAnnotation<LossType> lossAno = tree.getLossAnnotationOrNull(LossType.class);
if (peakAno==null) {
LoggerFactory.getLogger(FTreeMetricsHelper.class).error("Fragmentation tree has no peak annotation.");
return 0; // should never happen
}

return (int)tree.getFragmentsWithoutRoot().stream().filter(x->peakAno.get(x).isMeasured() && (lossAno==null || lossAno.get(x.getIncomingEdge(), LossType::regular)!=LossType.insource())).count();
}


Expand Down

0 comments on commit 51c361d

Please sign in to comment.