IsotopePatternGeneratorAlgorithm { public static @Nonnull MsSpectrum generateIsotopes(@Nonnull String chemicalFormula, @Nonnull Double minAbundance, @Nonnull Float intensityScale, @Nonnull Double mzTolerance) { Matcher m = formulaPattern.matcher(chemicalFormula); if (!m.matches()) throw new IllegalArgumentException("Invalid chemical formula: " + chemicalFormula); String formulaNoCharge = m.group(1); String chargeCount = m.group(4); String chargeSign = m.group(5); int charge = 0; if (!Strings.isNullOrEmpty(chargeCount)) charge = Integer.parseInt(chargeCount); if ((charge == 0) && (!Strings.isNullOrEmpty(chargeSign))) charge = 1; if ("-".equals(chargeSign)) charge *= -1; IMolecularFormula cdkFormula = MolecularFormulaManipulator.getMolecularFormula(formulaNoCharge, SilentChemObjectBuilder.getInstance()); if (cdkFormula == null) throw new MSDKRuntimeException( "Could not generate CDK chemical formula for " + formulaNoCharge); return generateIsotopes(cdkFormula, charge, minAbundance, intensityScale, mzTolerance); }  static @Nonnull MsSpectrum generateIsotopes(@Nonnull String chemicalFormula,
      @Nonnull Double minAbundance, @Nonnull Float intensityScale, @Nonnull Double mzTolerance); static @Nonnull MsSpectrum generateIsotopes(@Nonnull IMolecularFormula cdkFormula,
      @Nonnull Integer charge, @Nonnull Double minAbundance, @Nonnull Float intensityScale,
      @Nonnull Double mzTolerance);  }
@Test public void testC10() throws MSDKException { String formula = "C10"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.0001, 1000.0f, 0.001); Assert.assertEquals(new Integer(4), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[0], 0.0001); Assert.assertEquals(123.01006452, pattern.getMzValues()[3], 0.0000001); Assert.assertEquals(5.264099f, pattern.getIntensityValues()[2], 0.0001); }
@Test public void testC39H60N14O14() throws MSDKException { String formula = "C39H60N14O14"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.01, 1.0f, 0.1); Assert.assertEquals(new Integer(4), pattern.getNumberOfDataPoints()); Assert.assertEquals(1.0f, pattern.getIntensityValues()[0], 0.000001); Assert.assertEquals(951.4501830990874, pattern.getMzValues()[3], 0.00001); }
@Ignore @Test public void testC20H30Fe2P2S4Cl4() throws MSDKException { String formula = "C20H30Fe2P2S4Cl4"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.01, 1000.0f, 0.0); Assert.assertEquals(new Integer(35), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[10], 0.000001); Assert.assertEquals(713.8128938499999, pattern.getMzValues()[10], 0.0000001); }
@Test public void testF1000() throws MSDKException { String formula = "F1000"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.001, 1000.0f, 0.001); Assert.assertEquals(new Integer(1), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[0], 0.000001); Assert.assertEquals(18998.40322, pattern.getMzValues()[0], 0.0000001); }
@Test public void testCharge1Pos() throws MSDKException { String formula = "C+"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.01, 1000.0f, 0.005); Assert.assertEquals(new Integer(2), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[0], 0.000001); Assert.assertEquals(11.99945142009, pattern.getMzValues()[0], 0.0000001); }
@Test public void testCharge2Pos() throws MSDKException { String formula = "[C]2+"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.01, 1000.0f, 0.0); Assert.assertEquals(new Integer(2), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[0], 0.000001); Assert.assertEquals(5.99945142, pattern.getMzValues()[0], 0.0000001); }
@Test public void testCharge2Neg() throws MSDKException { String formula = "[C]2-"; MsSpectrum pattern = IsotopePatternGeneratorAlgorithm.generateIsotopes(formula, 0.01, 1000.0f, 0.0); Assert.assertEquals(new Integer(2), pattern.getNumberOfDataPoints()); Assert.assertEquals(1000.0f, pattern.getIntensityValues()[0], 0.000001); Assert.assertEquals(6.00054858, pattern.getMzValues()[0], 0.0000001); }