use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class RowsSpectralMatchTask method run.
/**
* @see java.lang.Runnable#run()
*/
@Override
public void run() {
setStatus(TaskStatus.PROCESSING);
for (PeakListRow row : rows) {
if (isCanceled()) {
logger.info("Added " + count + " spectral library matches (before being cancelled)");
repaintWindow();
return;
}
try {
// All MS2 or only best MS2 scan
// best MS1 scan
// check for MS1 or MSMS scan
List<Scan> scans = getScans(row);
List<DataPoint[]> rowMassLists = new ArrayList<>();
for (Scan scan : scans) {
// get mass list and perform deisotoping if active
DataPoint[] rowMassList = getDataPoints(scan, true);
if (removeIsotopes)
rowMassList = removeIsotopes(rowMassList);
rowMassLists.add(rowMassList);
}
// match against all library entries
for (SpectralDBEntry ident : list) {
SpectralDBPeakIdentity best = null;
// match all scans against this ident to find best match
for (int i = 0; i < scans.size(); i++) {
SpectralSimilarity sim = spectraDBMatch(row, rowMassLists.get(i), ident);
if (sim != null && (!needsIsotopePattern || SpectralMatchTask.checkForIsotopePattern(sim, mzToleranceSpectra, minMatchedIsoSignals)) && (best == null || best.getSimilarity().getScore() < sim.getScore())) {
best = new SpectralDBPeakIdentity(scans.get(i), massListName, ident, sim, METHOD);
}
}
// has match?
if (best != null) {
addIdentity(row, best);
count++;
}
}
// sort identities based on similarity score
SortSpectralDBIdentitiesTask.sortIdentities(row);
} catch (MissingMassListException e) {
logger.log(Level.WARNING, "No mass list in spectrum for rowID=" + row.getID(), e);
errorCounter++;
}
// check for max error (missing masslist)
if (errorCounter > MAX_ERROR) {
logger.log(Level.WARNING, "Data base matching failed. To many missing mass lists ");
setStatus(TaskStatus.ERROR);
setErrorMessage("Data base matching failed. To many missing mass lists ");
list = null;
return;
}
// next row
finishedRows++;
}
if (count > 0)
logger.info("Added " + count + " spectral library matches");
// Repaint the window to reflect the change in the feature list
repaintWindow();
list = null;
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class RowsSpectralMatchTask method spectraDBMatch.
/**
* @param row
* @param ident
* @return spectral similarity or null if no match
*/
private SpectralSimilarity spectraDBMatch(PeakListRow row, DataPoint[] rowMassList, SpectralDBEntry ident) {
// MS level 1 or check precursorMZ
if (checkRT(row, ident) && (msLevel == 1 || checkPrecursorMZ(row, ident))) {
DataPoint[] library = ident.getDataPoints();
if (removeIsotopes)
library = removeIsotopes(library);
// crop the spectra to their overlapping mz range
// helpful when comparing spectra, acquired with different fragmentation energy
DataPoint[] query = rowMassList;
if (cropSpectraToOverlap) {
DataPoint[][] cropped = ScanAlignment.cropToOverlap(mzToleranceSpectra, library, query);
library = cropped[0];
query = cropped[1];
}
// check spectra similarity
SpectralSimilarity sim = createSimilarity(library, query);
if (sim != null) {
return sim;
}
}
return null;
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class AdapMgfExportTask method exportRow.
private void exportRow(FileWriter writer, PeakListRow row, IsotopePattern ip) throws IOException {
// data points of this cluster
DataPoint[] dataPoints = ip.getDataPoints();
if (!fractionalMZ)
dataPoints = integerDataPoints(dataPoints, roundMode);
// get m/z and rt
double mz = getRepresentativeMZ(row, dataPoints);
String retTimeInSeconds = rtsForm.format(row.getAverageRT() * 60);
// write
writer.write("BEGIN IONS" + newLine);
writer.write("FEATURE_ID=" + row.getID() + newLine);
writer.write("PEPMASS=" + formatMZ(mz) + newLine);
writer.write("RTINSECONDS=" + retTimeInSeconds + newLine);
writer.write("SCANS=" + row.getID() + newLine);
// needs to be MSLEVEL=2 for GC-GNPS (even for GC-EI-MS data)
writer.write("MSLEVEL=2" + newLine);
writer.write("CHARGE=1+" + newLine);
for (DataPoint point : dataPoints) {
String line = formatMZ(point.getMZ()) + " " + intensityForm.format(point.getIntensity());
writer.write(line + newLine);
}
writer.write("END IONS" + newLine);
writer.write(newLine);
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class GnpsJsonGenerator method genJSONData.
/**
* JSON of data points array
*
* @param dps
* @return
*/
private static JsonArray genJSONData(DataPoint[] dps) {
JsonArrayBuilder data = Json.createArrayBuilder();
JsonArrayBuilder signal = Json.createArrayBuilder();
for (DataPoint dp : dps) {
// round to five digits. thats more than enough
signal.add(((int) (dp.getMZ() * 1000000)) / 1000000.0);
signal.add(dp.getIntensity());
data.add(signal.build());
}
return data.build();
}
use of net.sf.mzmine.datamodel.DataPoint in project mzmine2 by mzmine.
the class TICDataSet method calculateValues.
private void calculateValues() {
// Determine plot type (now done from constructor).
final TICPlotType plotType = this.plotType;
// Process each scan.
for (int index = 0; status != TaskStatus.CANCELED && index < totalScans; index++) {
// Current scan.
final Scan scan = scans[index];
// Determine base peak value.
final DataPoint basePeak = mzRange.encloses(scan.getDataPointMZRange()) ? scan.getHighestDataPoint() : ScanUtils.findBasePeak(scan, mzRange);
if (basePeak != null) {
basePeakValues[index] = basePeak.getMZ();
}
// Determine peak intensity.
double intensity = 0.0;
if (plotType == TICPlotType.TIC) {
// Total ion count.
intensity = mzRange.encloses(scan.getDataPointMZRange()) ? scan.getTIC() : ScanUtils.calculateTIC(scan, mzRange);
} else if (plotType == TICPlotType.BASEPEAK && basePeak != null) {
intensity = basePeak.getIntensity();
}
intensityValues[index] = intensity;
rtValues[index] = scan.getRetentionTime();
// Update min and max.
if (index == 0) {
intensityMin = intensity;
intensityMax = intensity;
} else {
intensityMin = Math.min(intensity, intensityMin);
intensityMax = Math.max(intensity, intensityMax);
}
processedScans++;
// Refresh every REDRAW_INTERVAL ms.
synchronized (TICDataSet.class) {
if (System.currentTimeMillis() - lastRedrawTime > REDRAW_INTERVAL) {
refresh();
lastRedrawTime = System.currentTimeMillis();
}
}
}
}
Aggregations