use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class PeakUtils method copyPeakRow.
/**
* Creates a copy of a PeakListRow.
* @param row A row.
* @return A copy of row.
*/
public 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.Feature in project mzmine2 by mzmine.
the class ADAPInterface method getComponent.
public static Component getComponent(final PeakListRow row) {
if (row.getNumberOfPeaks() == 0)
throw new IllegalArgumentException("No peaks found");
NavigableMap<Double, Double> spectrum = new TreeMap<>();
// Read Spectrum information
IsotopePattern ip = row.getBestIsotopePattern();
if (ip != null) {
for (DataPoint dataPoint : ip.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
}
// Read Chromatogram
final Feature peak = row.getBestPeak();
final RawDataFile dataFile = peak.getDataFile();
NavigableMap<Double, Double> chromatogram = new TreeMap<>();
for (final int scan : peak.getScanNumbers()) {
final DataPoint dataPoint = peak.getDataPoint(scan);
if (dataPoint != null)
chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
}
return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class FormulaPredictionPeakListTask method checkConstraints.
private boolean checkConstraints(IMolecularFormula cdkFormula, PeakListRow peakListRow) {
// Check elemental ratios
if (checkRatios) {
boolean check = ElementalHeuristicChecker.checkFormula(cdkFormula, ratiosParameters);
if (!check) {
return false;
}
}
Double rdbeValue = RDBERestrictionChecker.calculateRDBE(cdkFormula);
// Check RDBE condition
if (checkRDBE && (rdbeValue != null)) {
boolean check = RDBERestrictionChecker.checkRDBE(rdbeValue, rdbeParameters);
if (!check) {
return false;
}
}
// Calculate isotope similarity score
IsotopePattern detectedPattern = peakListRow.getBestIsotopePattern();
IsotopePattern predictedIsotopePattern = null;
Double isotopeScore = null;
if ((checkIsotopes) && (detectedPattern != null)) {
String stringFormula = MolecularFormulaManipulator.getString(cdkFormula);
String adjustedFormula = FormulaUtils.ionizeFormula(stringFormula, ionType, charge);
final double isotopeNoiseLevel = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopeNoiseLevel).getValue();
final double detectedPatternHeight = detectedPattern.getHighestDataPoint().getIntensity();
final double minPredictedAbundance = isotopeNoiseLevel / detectedPatternHeight;
predictedIsotopePattern = IsotopePatternCalculator.calculateIsotopePattern(adjustedFormula, minPredictedAbundance, charge, ionType.getPolarity());
isotopeScore = IsotopePatternScoreCalculator.getSimilarityScore(detectedPattern, predictedIsotopePattern, isotopeParameters);
final double minScore = isotopeParameters.getParameter(IsotopePatternScoreParameters.isotopePatternScoreThreshold).getValue();
if (isotopeScore < minScore) {
return false;
}
}
// MS/MS evaluation is slowest, so let's do it last
Double msmsScore = null;
Feature bestPeak = peakListRow.getBestPeak();
RawDataFile dataFile = bestPeak.getDataFile();
int msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
if ((checkMSMS) && (msmsScanNumber > 0)) {
Scan msmsScan = dataFile.getScan(msmsScanNumber);
String massListName = msmsParameters.getParameter(MSMSScoreParameters.massList).getValue();
MassList ms2MassList = msmsScan.getMassList(massListName);
if (ms2MassList == null) {
setStatus(TaskStatus.ERROR);
setErrorMessage("The MS/MS scan #" + msmsScanNumber + " in file " + dataFile.getName() + " does not have a mass list called '" + massListName + "'");
return false;
}
MSMSScore score = MSMSScoreCalculator.evaluateMSMS(cdkFormula, msmsScan, msmsParameters);
double minMSMSScore = msmsParameters.getParameter(MSMSScoreParameters.msmsMinScore).getValue();
if (score != null) {
msmsScore = score.getScore();
// Check the MS/MS condition
if (msmsScore < minMSMSScore) {
return false;
}
}
}
return true;
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class MzTabImportTask method importSmallMolecules.
private void importSmallMolecules(PeakList newPeakList, MZTabFile mzTabFile, Map<Integer, RawDataFile> rawDataFiles) {
SortedMap<Integer, Assay> assayMap = mzTabFile.getMetadata().getAssayMap();
Collection<SmallMolecule> smallMolecules = mzTabFile.getSmallMolecules();
// Loop through SML data
String formula, description, database, url = "";
double mzExp = 0, abundance = 0, peak_mz = 0, peak_rt = 0, peak_height = 0, rtValue = 0;
// int charge = 0;
int rowCounter = 0;
for (SmallMolecule smallMolecule : smallMolecules) {
// Stop the process if cancel() was called
if (isCanceled())
return;
rowCounter++;
formula = smallMolecule.getChemicalFormula();
// smile = smallMolecule.getSmiles();
// inchiKey = smallMolecule.getInchiKey();
description = smallMolecule.getDescription();
// species = smallMolecule.getSpecies();
database = smallMolecule.getDatabase();
if (smallMolecule.getURI() != null) {
url = smallMolecule.getURI().toString();
}
String identifier = smallMolecule.getIdentifier().toString();
SplitList<Double> rt = smallMolecule.getRetentionTime();
if (smallMolecule.getExpMassToCharge() != null) {
mzExp = smallMolecule.getExpMassToCharge();
}
// Calculate average RT if multiple values are available
if (rt != null && !rt.isEmpty()) {
rtValue = DoubleMath.mean(rt);
}
if ((url != null) && (url.equals("null"))) {
url = null;
}
if (identifier.equals("null")) {
identifier = null;
}
if (description == null && identifier != null) {
description = identifier;
}
// Add shared information to row
SimplePeakListRow newRow = new SimplePeakListRow(rowCounter);
newRow.setAverageMZ(mzExp);
newRow.setAverageRT(rtValue);
if (description != null) {
SimplePeakIdentity newIdentity = new SimplePeakIdentity(description, formula, database, identifier, url);
newRow.addPeakIdentity(newIdentity, false);
}
// Add raw data file entries to row
for (Entry<Integer, RawDataFile> rawDataEntry : rawDataFiles.entrySet()) {
RawDataFile rawData = rawDataEntry.getValue();
Assay dataFileAssay = assayMap.get(rawDataEntry.getKey());
abundance = 0;
peak_mz = 0;
peak_rt = 0;
peak_height = 0;
if (smallMolecule.getAbundanceColumnValue(dataFileAssay) != null) {
abundance = smallMolecule.getAbundanceColumnValue(dataFileAssay);
}
if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz") != null) {
peak_mz = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_mz"));
} else {
peak_mz = mzExp;
}
if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt") != null) {
peak_rt = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_rt"));
} else {
peak_rt = rtValue;
}
if (smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height") != null) {
peak_height = Double.parseDouble(smallMolecule.getOptionColumnValue(dataFileAssay, "peak_height"));
} else {
peak_height = 0.0;
}
int[] scanNumbers = {};
DataPoint[] finalDataPoint = new DataPoint[1];
finalDataPoint[0] = new SimpleDataPoint(peak_mz, peak_height);
int representativeScan = 0;
int fragmentScan = 0;
int[] allFragmentScans = new int[] { 0 };
Range<Double> finalRTRange = Range.singleton(peak_rt);
Range<Double> finalMZRange = Range.singleton(peak_mz);
Range<Double> finalIntensityRange = Range.singleton(peak_height);
FeatureStatus status = FeatureStatus.DETECTED;
Feature peak = new SimpleFeature(rawData, peak_mz, peak_rt, peak_height, abundance, scanNumbers, finalDataPoint, status, representativeScan, fragmentScan, allFragmentScans, finalRTRange, finalMZRange, finalIntensityRange);
if (abundance > 0) {
newRow.addPeak(rawData, peak);
}
}
// Add row to feature list
newPeakList.addRow(newRow);
}
}
use of net.sf.mzmine.datamodel.Feature in project mzmine2 by mzmine.
the class GnpsFbmnMgfExportTask method export.
private int export(PeakList peakList, FileWriter writer, File curFile) throws IOException {
final String newLine = System.lineSeparator();
// count exported
int count = 0;
int countMissingMassList = 0;
for (PeakListRow row : peakList.getRows()) {
// do not export if no MSMS
if (!filter.filter(row))
continue;
String rowID = Integer.toString(row.getID());
double retTimeInSeconds = ((row.getAverageRT() * 60 * 100.0) / 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 heighest peak with a MS/MS scan number (with mass list)
boolean missingMassList = false;
msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
while (msmsScanNumber < 1 || getScan(bestPeak, msmsScanNumber).getMassList(massListName) == null) {
// missing masslist
if (msmsScanNumber > 0)
missingMassList = true;
copyRow.removePeak(bestPeak.getDataFile());
if (copyRow.getPeaks().length == 0)
break;
bestPeak = copyRow.getBestPeak();
msmsScanNumber = bestPeak.getMostIntenseFragmentScanNumber();
}
if (missingMassList)
countMissingMassList++;
}
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) {
continue;
}
writer.write("BEGIN IONS" + newLine);
if (rowID != null)
writer.write("FEATURE_ID=" + rowID + newLine);
String mass = mzForm.format(row.getAverageMZ());
if (mass != null)
writer.write("PEPMASS=" + mass + newLine);
if (rowID != null) {
writer.write("SCANS=" + rowID + newLine);
writer.write("RTINSECONDS=" + rtsForm.format(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(mzForm.format(peak.getMZ()) + " " + intensityForm.format(peak.getIntensity()) + newLine);
}
writer.write("END IONS" + newLine);
writer.write(newLine);
count++;
}
}
if (count == 0)
LOG.log(Level.WARNING, "No MS/MS scans exported.");
else
LOG.info(MessageFormat.format("Total of {0} feature rows (MS/MS mass lists) were exported ({1})", count, peakList.getName()));
if (countMissingMassList > 0)
LOG.warning(MessageFormat.format("WARNING: Total of {0} feature rows have an MS/MS scan but NO mass list (this shouldn't be a problem if a scan filter was applied in the mass detection step) ({1})", countMissingMassList, peakList.getName()));
return count;
}
Aggregations