Skip to content

Commit

Permalink
fix missing adducts in FormulaSummaryWriter
Browse files Browse the repository at this point in the history
  • Loading branch information
mfleisch committed Jun 29, 2023
1 parent 8daa2b1 commit 77f79b2
Showing 1 changed file with 1 addition and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,31 +133,18 @@ public void addWriteCompoundSummary(ProjectWriter writer, @NotNull CompoundConta
globalResultsAll.put(results.get(0).getCandidate(), new ArrayList<>(results));
});
}
//todo @marcus what is this good for?

/* private FormulaResult resolveIonizationOnly(ResultEntry r) {
// FormulaResultId rid = r.getId();
FormulaResultId newRid = new FormulaResultId(rid.getParentId(), rid.getPrecursorFormula(), PrecursorIonType.getPrecursorIonType(rid.getIonType().getIonization()));
FormulaResult newResult = new FormulaResult(newRid);
r.annotations().forEach(newResult::setAnnotation);
return newResult;
}*/

private List<SScored<ResultEntry, ? extends FormulaScore>> extractAllTopScoringResults(List<? extends SScored<ResultEntry, ? extends FormulaScore>> sortedResults, List<Class<? extends FormulaScore>> rankingScores) {
if (sortedResults.isEmpty()) return Collections.emptyList();
if (sortedResults.size() == 1) return Collections.singletonList(sortedResults.get(0));

SScored<ResultEntry, ? extends FormulaScore> best = sortedResults.get(0);
FormulaScoring bestScore = best.getCandidate().getScoring();

Comparator<FormulaScoring> comparator = FormulaScoring.comparingMultiScore(rankingScores, true);

List<SScored<ResultEntry, ? extends FormulaScore>> topResultsWithAdducts = sortedResults.stream()
.takeWhile(r -> comparator.compare(bestScore, r.getCandidate().getScoring()) == 0)
.takeWhile(r -> best.getCandidate().preFormula.equals(r.getCandidate().preFormula))
.collect(Collectors.toList());

//candidates with same score should have the same adduct.
assert topResultsWithAdducts.stream().map(s -> s.getCandidate().ion).distinct().count() == 1;
return topResultsWithAdducts;
}

Expand Down

0 comments on commit 77f79b2

Please sign in to comment.