IsotopePatternSimilarity { public double compare(IsotopePattern isoto1, IsotopePattern isoto2) { IsotopePattern iso1 = IsotopePatternManipulator.sortAndNormalizedByIntensity(isoto1); IsotopePattern iso2 = IsotopePatternManipulator.sortAndNormalizedByIntensity(isoto2); if (isoto1.getCharge() == 1) chargeToAdd = massE; else if (isoto1.getCharge() == -1) chargeToAdd = -massE; else chargeToAdd = 0; for (IsotopeContainer isoC : iso1.getIsotopes()) { double mass = isoC.getMass(); isoC.setMass(mass + chargeToAdd); } double diffMass, diffAbun, factor, totalFactor = 0d; double score = 0d, tempScore; int length = iso1.getNumberOfIsotopes(); for (int i = 0; i < length; i++) { IsotopeContainer isoContainer = iso1.getIsotopes().get(i); factor = isoContainer.getIntensity(); totalFactor += factor; int closestDp = getClosestDataDiff(isoContainer, iso2); if (closestDp == -1) continue; diffMass = isoContainer.getMass() - iso2.getIsotopes().get(closestDp).getMass(); diffMass = Math.abs(diffMass); diffAbun = 1.0d - (isoContainer.getIntensity() / iso2.getIsotopes().get(closestDp).getIntensity()); diffAbun = Math.abs(diffAbun); tempScore = 1 - (diffMass + diffAbun); if (tempScore < 0) tempScore = 0; score += (tempScore * factor); } return score / totalFactor; } IsotopePatternSimilarity(); void seTolerance(double tolerance); double getTolerance(); double compare(IsotopePattern isoto1, IsotopePattern isoto2);  }
@Test public void testCompare_IsotopePattern_IsotopePattern() { IsotopePatternSimilarity is = new IsotopePatternSimilarity(); IsotopePattern spExp = new IsotopePattern(); spExp.setMonoIsotope(new IsotopeContainer(156.07770, 1)); spExp.addIsotope(new IsotopeContainer(157.07503, 0.0004)); spExp.addIsotope(new IsotopeContainer(157.08059, 0.0003)); spExp.addIsotope(new IsotopeContainer(158.08135, 0.002)); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C6H10N3O2", builder); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.1); IsotopePattern patternIsoPredicted = isotopeGe.getIsotopes(formula); IsotopePattern patternIsoNormalize = IsotopePatternManipulator.normalize(patternIsoPredicted); double score = is.compare(spExp, patternIsoNormalize); Assert.assertNotSame(0.0, score); }
@Test public void testSelectingMF() { IsotopePatternSimilarity is = new IsotopePatternSimilarity(); IsotopePattern spExp = new IsotopePattern(); spExp.setCharge(1); spExp.setMonoIsotope(new IsotopeContainer(156.07770, 1)); spExp.addIsotope(new IsotopeContainer(157.07503, 0.0101)); spExp.addIsotope(new IsotopeContainer(157.08059, 0.074)); spExp.addIsotope(new IsotopeContainer(158.08135, 0.0024)); double score = 0; String mfString = ""; String[] listMF = {"C4H8N6O", "C2H12N4O4", "C3H12N2O5", "C6H10N3O2", "CH10N5O4", "C4H14NO5"}; for (int i = 0; i < listMF.length; i++) { IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula(listMF[i], builder); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.01); IsotopePattern patternIsoPredicted = isotopeGe.getIsotopes(formula); IsotopePattern patternIsoNormalize = IsotopePatternManipulator.normalize(patternIsoPredicted); double tempScore = is.compare(spExp, patternIsoNormalize); if (score < tempScore) { mfString = MolecularFormulaManipulator.getString(formula); score = tempScore; } } Assert.assertEquals("C6H10N3O2", mfString); }
@Test public void testExperiment() { IsotopePattern spExp = new IsotopePattern(); spExp.setMonoIsotope(new IsotopeContainer(762.6006, 124118304)); spExp.addIsotope(new IsotopeContainer(763.6033, 57558840)); spExp.addIsotope(new IsotopeContainer(764.6064, 15432262)); spExp.setCharge(1.0); IMolecularFormula formula = MolecularFormulaManipulator.getMajorIsotopeMolecularFormula("C42H85NO8P", SilentChemObjectBuilder.getInstance()); IsotopePatternGenerator isotopeGe = new IsotopePatternGenerator(0.01); IsotopePattern patternIsoPredicted = isotopeGe.getIsotopes(formula); IsotopePatternSimilarity is = new IsotopePatternSimilarity(); double score = is.compare(spExp, patternIsoPredicted); Assert.assertEquals(0.97, score, .01); }