BiGaussian { private double InterpolationX(List<Triplet> horizontalSlice, int mu, double halfHeight, int leftBound, int rightBound, int roundedmz, Direction direction) { int step = direction == Direction.RIGHT ? 1 : -1; Comparator<Triplet> compareMzScan = (t1, t2) -> (t1.mz != t2.mz) ? Integer.compare(t1.mz, t2.mz) : Integer.compare(t1.scanListIndex, t2.scanListIndex); Collections.sort(horizontalSlice, compareMzScan); Triplet searchTriplet1 = new Triplet(); searchTriplet1.mz = roundedmz; searchTriplet1.scanListIndex = mu + step; int index1 = Collections.binarySearch(horizontalSlice, searchTriplet1, compareMzScan); if (index1 < 0) { throw new IllegalArgumentException("Cannot find peak apex."); } double Y1 = Double.NaN; double Y2 = Double.NaN; for ( ; index1 >= 0 && index1 < horizontalSlice.size() ; index1 += step) { Triplet triplet1 = horizontalSlice.get(index1); if (triplet1.mz != roundedmz || triplet1.scanListIndex < leftBound || triplet1.scanListIndex > rightBound) { break; } if (triplet1.intensity != 0 && triplet1.intensity < halfHeight) { Triplet triplet2 = horizontalSlice.get(index1 - step); if (triplet2.mz != roundedmz || triplet1.scanListIndex < leftBound || triplet1.scanListIndex > rightBound) { break; } Y1 = triplet1.intensity; if (triplet2.intensity != 0) { Y2 = triplet2.intensity; break; } } } if (Double.isNaN(Y1) || Double.isNaN(Y2)) throw new IllegalArgumentException("Cannot find BiGaussian."); return ((halfHeight - Y2) * (horizontalSlice.get(index1 - step).scanListIndex - horizontalSlice.get(index1).scanListIndex)) / (Y2 - Y1) + horizontalSlice.get(index1 - step).scanListIndex; } BiGaussian(List<Triplet> horizontalSlice, int roundedmz, int leftBound, int rightBound); double getValue(int x); final double maxHeight; final int mu; final double sigmaLeft; final double sigmaRight; }
@Test public void testInterpolationX() { final int numTriplets = 5; List<Triplet> triplets = new ArrayList<>(numTriplets); for (int i = 0; i < numTriplets; ++i) triplets.add(new Triplet()); triplets.get(0).mz = 40; triplets.get(0).scanListIndex = 1; triplets.get(0).intensity = 100; triplets.get(1).mz = 40; triplets.get(1).scanListIndex = 3; triplets.get(1).intensity = 900; triplets.get(2).mz = 40; triplets.get(2).scanListIndex = 4; triplets.get(2).intensity = 1000; triplets.get(3).mz = 40; triplets.get(3).scanListIndex = 5; triplets.get(3).intensity = 900; triplets.get(4).mz = 40; triplets.get(4).scanListIndex = 7; triplets.get(4).intensity = 100; BiGaussian biGaussian = new BiGaussian(triplets, 40, 1, 7); Assert.assertEquals(1.6986436005760381, biGaussian.sigmaLeft, 1e-12); Assert.assertEquals(1.6986436005760381, biGaussian.sigmaRight, 1e-12); }