use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class ScanUtils method findMzRange.
/**
* Find the m/z range of the data points in the array. We assume there is at least one data point,
* and the data points are sorted by m/z.
*/
@Nonnull
public static Range<Double> findMzRange(@Nonnull DataPoint[] dataPoints) {
assert dataPoints.length > 0;
double lowMz = dataPoints[0].getMZ();
double highMz = lowMz;
for (int i = 1; i < dataPoints.length; i++) {
if (dataPoints[i].getMZ() < lowMz) {
lowMz = dataPoints[i].getMZ();
continue;
}
if (dataPoints[i].getMZ() > highMz)
highMz = dataPoints[i].getMZ();
}
return Range.closed(lowMz, highMz);
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class ScanUtils method findBasePeak.
/**
* Find a base peak of a given scan in a given m/z range
*
* @param scan Scan to search
* @param mzRange mz range to search in
* @return double[2] containing base peak m/z and intensity
*/
@Nonnull
public static DataPoint findBasePeak(@Nonnull Scan scan, @Nonnull Range<Double> mzRange) {
DataPoint[] dataPoints = scan.getDataPointsByMass(mzRange);
DataPoint basePeak = null;
for (DataPoint dp : dataPoints) {
if ((basePeak == null) || (dp.getIntensity() > basePeak.getIntensity()))
basePeak = dp;
}
return basePeak;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class ScanUtils method encodeDataPointsToBytes.
public static byte[] encodeDataPointsToBytes(DataPoint[] dataPoints) {
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
DataOutputStream peakStream = new DataOutputStream(byteStream);
for (int i = 0; i < dataPoints.length; i++) {
try {
peakStream.writeDouble(dataPoints[i].getMZ());
peakStream.writeDouble(dataPoints[i].getIntensity());
} catch (IOException e) {
e.printStackTrace();
}
}
byte[] peakBytes = byteStream.toByteArray();
return peakBytes;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class ScanUtils method probabilityProductUnnormalized.
/**
* Calculates the probability product without normalization. Usually, this method is only useful
* if you plan to normalize the spectra (or value) yourself.
*
* @see #probabilityProduct(DataPoint[], DataPoint[], MZTolerance, double, Range)
*/
public static double probabilityProductUnnormalized(DataPoint[] scanLeft, DataPoint[] scanRight, MZTolerance expectedMassDeviationInPPM, double noiseLevel, @Nullable Range<Double> mzRange) {
int i, j;
double score = 0d;
// =left.length, nr=right.length;
final int nl, nr;
if (mzRange == null) {
nl = scanLeft.length;
nr = scanRight.length;
i = 0;
j = 0;
} else {
nl = findLastPeakWithin(scanLeft, mzRange) + 1;
nr = findLastPeakWithin(scanRight, mzRange) + 1;
i = findFirstPeakWithin(scanLeft, mzRange);
j = findFirstPeakWithin(scanRight, mzRange);
if (i < 0 || j < 0)
return 0d;
}
// gaussians are set to zero above allowedDifference to speed up computation
final double allowedDifference = expectedMassDeviationInPPM.getMzToleranceForMass(1000d) * 5;
while (i < nl && j < nr) {
DataPoint lp = scanLeft[i];
if (lp.getIntensity() < noiseLevel) {
++i;
continue;
}
DataPoint rp = scanRight[j];
if (rp.getIntensity() < noiseLevel) {
++j;
continue;
}
final double difference = lp.getMZ() - rp.getMZ();
if (Math.abs(difference) <= allowedDifference) {
final double mzabs = expectedMassDeviationInPPM.getMzToleranceForMass(Math.round((lp.getMZ() + rp.getMZ()) / 2d));
final double variance = mzabs * mzabs;
double matchScore = probabilityProductScore(lp, rp, variance);
score += matchScore;
for (int k = i + 1; k < nl; ++k) {
DataPoint lp2 = scanLeft[k];
final double difference2 = lp2.getMZ() - rp.getMZ();
if (Math.abs(difference2) <= allowedDifference) {
matchScore = probabilityProductScore(lp2, rp, variance);
score += matchScore;
} else
break;
}
for (int l = j + 1; l < nr; ++l) {
DataPoint rp2 = scanRight[l];
final double difference2 = lp.getMZ() - rp2.getMZ();
if (Math.abs(difference2) <= allowedDifference) {
matchScore = probabilityProductScore(lp, rp2, variance);
score += matchScore;
} else
break;
}
++i;
++j;
} else if (difference > 0) {
++j;
} else {
++i;
}
}
return score;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class CompositeCosineSpectralSimilarity method calcRelativeNeighbourFactor.
/**
* sum of relative ratios of neighbours in both mass lists
*
* @param aligned
* @return
*/
private double calcRelativeNeighbourFactor(List<DataPoint[]> aligned) {
// remove all unaligned signals
List<DataPoint[]> filtered = removeUnaligned(aligned);
// sort by mz
sortByMZ(filtered);
// overlapping within mass tolerance
int overlap = calcOverlap(aligned);
// sum of relative ratios of neighbours in both mass lists
double factor = 0;
for (int i = 1; i < filtered.size(); i++) {
DataPoint[] match1 = filtered.get(i - 1);
DataPoint[] match2 = filtered.get(i);
// 0 is library
// 1 is query
double ratioLibrary = match2[0].getIntensity() / match1[0].getIntensity();
double ratioQuery = match2[1].getIntensity() / match1[1].getIntensity();
factor += Math.min(ratioLibrary, ratioQuery) / Math.max(ratioLibrary, ratioQuery);
}
// factor ranges from 0-1 * overlap
return factor / (overlap);
}
Aggregations