use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class GnpsFbmnExportTask method export.
private void export(PeakList peakList, FileWriter writer, File curFile) throws IOException {
final String newLine = System.lineSeparator();
for (PeakListRow row : peakList.getRows()) {
String rowID = Integer.toString(row.getID());
String retTimeInSeconds = Double.toString(Math.round(row.getAverageRT() * 60 * 100) / 100.);
// Get the MS/MS scan number
Feature bestPeak = row.getBestPeak();
if (bestPeak == null)
continue;
int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
if (rowID != null) {
PeakListRow copyRow = copyPeakRow(row);
// Best peak always exists, because feature list row has at least one peak
bestPeak = copyRow.getBestPeak();
// Get the MS/MS scan number
msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
while (msmsScanNumber < 1) {
copyRow.removePeak(bestPeak.getDataFile());
if (copyRow.getPeaks().length == 0)
break;
bestPeak = copyRow.getBestPeak();
msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
}
}
if (msmsScanNumber >= 1) {
// MS/MS scan must exist, because msmsScanNumber was > 0
Scan msmsScan = bestPeak.getDataFile().getScan(msmsScanNumber);
MassList massList = msmsScan.getMassList(massListName);
if (massList == null) {
MZmineCore.getDesktop().displayErrorMessage(MZmineCore.getDesktop().getMainWindow(), "There is no mass list called " + massListName + " for MS/MS scan #" + msmsScanNumber + " (" + bestPeak.getDataFile() + ")");
return;
}
writer.write("BEGIN IONS" + newLine);
if (rowID != null)
writer.write("FEATURE_ID=" + rowID + newLine);
String mass = Double.toString(Math.round(row.getAverageMZ() * 10000) / 10000.);
if (mass != null)
writer.write("PEPMASS=" + mass + newLine);
if (rowID != null) {
writer.write("SCANS=" + rowID + newLine);
writer.write("RTINSECONDS=" + retTimeInSeconds + newLine);
}
int msmsCharge = msmsScan.getPrecursorCharge();
String msmsPolarity = msmsScan.getPolarity().asSingleChar();
if (msmsPolarity.equals("0"))
msmsPolarity = "";
if (msmsCharge == 0) {
msmsCharge = 1;
msmsPolarity = "";
}
writer.write("CHARGE=" + msmsCharge + msmsPolarity + newLine);
writer.write("MSLEVEL=2" + newLine);
DataPoint[] dataPoints = massList.getDataPoints();
if (mergeParameters != null) {
MsMsSpectraMergeModule merger = MZmineCore.getModuleInstance(MsMsSpectraMergeModule.class);
MergedSpectrum spectrum = merger.getBestMergedSpectrum(mergeParameters, row, massListName);
if (spectrum != null) {
dataPoints = spectrum.data;
writer.write("MERGED_STATS=");
writer.write(spectrum.getMergeStatsDescription());
writer.write(newLine);
}
}
for (DataPoint peak : dataPoints) {
writer.write(peak.getMZ() + " " + peak.getIntensity() + newLine);
}
writer.write("END IONS" + newLine);
writer.write(newLine);
}
}
}
use of net.sf.mzmine.datamodel.PeakListRow 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.PeakListRow in project mzmine2 by mzmine.
the class SiriusExportTask method runSingleRows.
public void runSingleRows(PeakListRow[] rows) {
setStatus(TaskStatus.PROCESSING);
// prefill statistics
prefillStatistics(rows);
try (final BufferedWriter bw = new BufferedWriter(new FileWriter(fileName, true))) {
for (PeakListRow row : rows) exportPeakListRow(row, bw);
} catch (IOException e) {
setStatus(TaskStatus.ERROR);
setErrorMessage("Could not open file " + fileName + " for writing.");
}
if (getStatus() == TaskStatus.PROCESSING)
setStatus(TaskStatus.FINISHED);
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class GnpsFbmnMgfExportTask method copyPeakRow.
/**
* Create a copy of a feature list row.
*/
private static PeakListRow copyPeakRow(final PeakListRow row) {
// Copy the feature list row.
final PeakListRow newRow = new SimplePeakListRow(row.getID());
PeakUtils.copyPeakListRowProperties(row, newRow);
// Copy the peaks.
for (final Feature peak : row.getPeaks()) {
final Feature newPeak = new SimpleFeature(peak);
PeakUtils.copyPeakProperties(peak, newPeak);
newRow.addPeak(peak.getDataFile(), newPeak);
}
return newRow;
}
use of net.sf.mzmine.datamodel.PeakListRow in project mzmine2 by mzmine.
the class VanKrevelenDiagramParameters method showSetupDialog.
@Override
public ExitCode showSetupDialog(Window parent, boolean valueCheckRequired) {
PeakList[] selectedPeakLists = getParameter(peakList).getValue().getMatchingPeakLists();
if (selectedPeakLists.length > 0) {
PeakListRow[] plRows = selectedPeakLists[0].getRows();
Arrays.sort(plRows, new PeakListRowSorter(SortingProperty.MZ, SortingDirection.Ascending));
}
return super.showSetupDialog(parent, valueCheckRequired);
}
Aggregations