use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class SQLExportTask method exportPeakListRow.
private void exportPeakListRow(PeakListRow row) throws SQLException {
// Cancel?
if (isCanceled()) {
return;
}
// Value for looping through raw data files
boolean loopDataFiles = false;
StringBuilder sql = new StringBuilder();
sql.append("INSERT INTO ");
sql.append(tableName);
sql.append(" (");
for (int i = 0; i < exportColumns.getRowCount(); i++) {
sql.append(exportColumns.getValueAt(i, 0));
if (i < exportColumns.getRowCount() - 1)
sql.append(",");
}
sql.append(" ) VALUES (");
for (int i = 0; i < exportColumns.getRowCount(); i++) {
sql.append("?");
if (i < exportColumns.getRowCount() - 1)
sql.append(",");
}
sql.append(")");
PreparedStatement statement = dbConnection.prepareStatement(sql.toString());
if (row == null) {
for (int i = 0; i < exportColumns.getRowCount(); i++) {
SQLExportDataType dataType = (SQLExportDataType) exportColumns.getValueAt(i, 1);
String dataValue = (String) exportColumns.getValueAt(i, 2);
switch(dataType) {
case CONSTANT:
statement.setString(i + 1, dataValue);
break;
case RAWFILE:
RawDataFile[] rawdatafiles = peakList.getRawDataFiles();
statement.setString(i + 1, rawdatafiles[0].getName());
break;
default:
statement.setString(i + 1, null);
break;
}
}
statement.executeUpdate();
} else {
for (RawDataFile rawDataFile : row.getRawDataFiles()) {
Feature peak = row.getPeak(rawDataFile);
for (int i = 0; i < exportColumns.getRowCount(); i++) {
SQLExportDataType dataType = (SQLExportDataType) exportColumns.getValueAt(i, 1);
String dataValue = (String) exportColumns.getValueAt(i, 2);
switch(dataType) {
case CONSTANT:
statement.setString(i + 1, dataValue);
break;
case MZ:
statement.setDouble(i + 1, row.getAverageMZ());
break;
case RT:
statement.setDouble(i + 1, row.getAverageRT());
break;
case ID:
statement.setInt(i + 1, row.getID());
break;
case PEAKCHARGE:
statement.setDouble(i + 1, peak.getCharge());
loopDataFiles = true;
break;
case PEAKDURATION:
statement.setDouble(i + 1, RangeUtils.rangeLength(peak.getRawDataPointsRTRange()));
loopDataFiles = true;
break;
case PEAKSTATUS:
statement.setString(i + 1, peak.getFeatureStatus().name());
loopDataFiles = true;
break;
case PEAKMZ:
statement.setDouble(i + 1, peak.getMZ());
loopDataFiles = true;
break;
case PEAKRT:
statement.setDouble(i + 1, peak.getRT());
loopDataFiles = true;
break;
case PEAKRT_START:
statement.setDouble(i + 1, peak.getRawDataPointsRTRange().lowerEndpoint());
loopDataFiles = true;
break;
case PEAKRT_END:
statement.setDouble(i + 1, peak.getRawDataPointsRTRange().upperEndpoint());
loopDataFiles = true;
break;
case PEAKHEIGHT:
statement.setDouble(i + 1, peak.getHeight());
loopDataFiles = true;
break;
case PEAKAREA:
statement.setDouble(i + 1, peak.getArea());
loopDataFiles = true;
break;
case DATAPOINTS:
statement.setDouble(i + 1, peak.getScanNumbers().length);
loopDataFiles = true;
break;
case FWHM:
statement.setDouble(i + 1, peak.getFWHM());
loopDataFiles = true;
break;
case TAILINGFACTOR:
statement.setDouble(i + 1, peak.getTailingFactor());
loopDataFiles = true;
break;
case ASYMMETRYFACTOR:
statement.setDouble(i + 1, peak.getAsymmetryFactor());
loopDataFiles = true;
break;
case RAWFILE:
statement.setString(i + 1, rawDataFile.getName());
loopDataFiles = true;
break;
case HEIGHT:
statement.setDouble(i + 1, row.getAverageHeight());
break;
case AREA:
statement.setDouble(i + 1, row.getAverageArea());
break;
case COMMENT:
statement.setString(i + 1, row.getComment());
break;
case IDENTITY:
PeakIdentity id = row.getPreferredPeakIdentity();
if (id != null) {
statement.setString(i + 1, id.getName());
} else {
statement.setNull(i + 1, Types.VARCHAR);
}
break;
case ISOTOPEPATTERN:
IsotopePattern isotopes = row.getBestIsotopePattern();
if (isotopes == null) {
statement.setNull(i + 1, Types.BLOB);
break;
}
DataPoint[] dataPoints = isotopes.getDataPoints();
byte[] bytes = ScanUtils.encodeDataPointsToBytes(dataPoints);
ByteArrayInputStream is = new ByteArrayInputStream(bytes);
statement.setBlob(i + 1, is);
break;
case MSMS:
int msmsScanNum = row.getBestPeak().getMostIntenseFragmentScanNumber();
// Check if there is any MS/MS scan
if (msmsScanNum <= 0) {
statement.setNull(i + 1, Types.BLOB);
break;
}
RawDataFile dataFile = row.getBestPeak().getDataFile();
Scan msmsScan = dataFile.getScan(msmsScanNum);
MassList msmsMassList = msmsScan.getMassList(dataValue);
// Check if there is a masslist for the scan
if (msmsMassList == null) {
statement.setNull(i + 1, Types.BLOB);
break;
}
dataPoints = msmsMassList.getDataPoints();
bytes = ScanUtils.encodeDataPointsToBytes(dataPoints);
is = new ByteArrayInputStream(bytes);
statement.setBlob(i + 1, is);
break;
default:
break;
}
}
statement.executeUpdate();
// data files in feature list
if (!loopDataFiles) {
break;
}
}
}
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class RTScore method calculateScore.
public double calculateScore(AlignmentPath path, PeakListRow peak, ParameterSet parameters) {
try {
rtTolerance = parameters.getParameter(PathAlignerParameters.RTTolerance).getValue();
mzTolerance = parameters.getParameter(PathAlignerParameters.MZTolerance).getValue();
Range<Double> rtRange = rtTolerance.getToleranceRange(path.getRT());
Range<Double> mzRange = mzTolerance.getToleranceRange(path.getMZ());
if (!rtRange.contains(peak.getAverageRT()) || !mzRange.contains(peak.getAverageMZ())) {
return WORST_SCORE;
}
double mzDiff = Math.abs(path.getMZ() - peak.getAverageMZ());
double rtDiff = Math.abs(path.getRT() - peak.getAverageRT());
double score = ((mzDiff / (RangeUtils.rangeLength(mzRange) / 2.0))) + ((rtDiff / (RangeUtils.rangeLength(rtRange) / 2.0)));
if (parameters.getParameter(PathAlignerParameters.SameChargeRequired).getValue()) {
if (!PeakUtils.compareChargeState(path.convertToAlignmentRow(0), peak)) {
return WORST_SCORE;
}
}
if (parameters.getParameter(PathAlignerParameters.SameIDRequired).getValue()) {
if (!PeakUtils.compareIdentities(path.convertToAlignmentRow(0), peak)) {
return WORST_SCORE;
}
}
if (parameters.getParameter(PathAlignerParameters.compareIsotopePattern).getValue()) {
IsotopePattern ip1 = path.convertToAlignmentRow(0).getBestIsotopePattern();
IsotopePattern ip2 = peak.getBestIsotopePattern();
if ((ip1 != null) && (ip2 != null)) {
ParameterSet isotopeParams = parameters.getParameter(PathAlignerParameters.compareIsotopePattern).getEmbeddedParameters();
if (!IsotopePatternScoreCalculator.checkMatch(ip1, ip2, isotopeParams)) {
return WORST_SCORE;
}
}
}
return score;
} catch (NullPointerException e) {
e.printStackTrace();
return WORST_SCORE;
}
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class DPPIsotopeGrouperTask method compressIsotopeDataSets.
/**
* This method generates a single IsotopesDataSet from all detected isotope patterns in the
* results.
*
* @param dataPoints
* @return
*/
private IsotopesDataSet compressIsotopeDataSets(ProcessedDataPoint[] dataPoints) {
List<IsotopePattern> list = new ArrayList<>();
for (ProcessedDataPoint dp : dataPoints) {
if (dp.resultTypeExists(ResultType.ISOTOPEPATTERN)) {
list.add(((DPPIsotopePatternResult) dp.getFirstResultByType(ResultType.ISOTOPEPATTERN)).getValue());
}
}
if (list.isEmpty())
return null;
List<DataPoint> dpList = new ArrayList<>();
for (IsotopePattern pattern : list) {
for (DataPoint dp : pattern.getDataPoints()) dpList.add(dp);
}
if (dpList.isEmpty())
return null;
IsotopePattern full = new SimpleIsotopePattern(dpList.toArray(new DataPoint[0]), IsotopePatternStatus.DETECTED, "Isotope patterns");
return new IsotopesDataSet(full);
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class SpectraVisualizerWindow method loadIsotopes.
public void loadIsotopes(IsotopePattern newPattern) {
// We need to find a normalization factor for the new isotope
// pattern, to show meaningful intensity range
double mz = newPattern.getHighestDataPoint().getMZ();
Range<Double> searchMZRange = Range.closed(mz - 0.5, mz + 0.5);
ScanDataSet scanDataSet = spectrumPlot.getMainScanDataSet();
double normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);
// whole scan as normalization factor.
if (normalizationFactor == 0) {
searchMZRange = Range.atLeast(0.0);
normalizationFactor = scanDataSet.getHighestIntensity(searchMZRange);
}
IsotopePattern normalizedPattern = IsotopePatternCalculator.normalizeIsotopePattern(newPattern, normalizationFactor);
Color newColor;
if (newPattern.getStatus() == IsotopePatternStatus.DETECTED)
newColor = detectedIsotopesColor;
else
newColor = predictedIsotopesColor;
IsotopesDataSet newDataSet = new IsotopesDataSet(normalizedPattern);
spectrumPlot.addDataSet(newDataSet, newColor, true);
}
use of net.sf.mzmine.datamodel.IsotopePattern in project mzmine2 by mzmine.
the class CameraSearchTask method groupPeaksByIsotope.
/**
* Uses Isotope-field in PeakIdentity to group isotopes and build spectrum
*
* @param peakList PeakList object
* @return new PeakList object
*/
private PeakList groupPeaksByIsotope(PeakList peakList) {
// Create new feature list.
final PeakList combinedPeakList = new SimplePeakList(peakList + " " + parameters.getParameter(CameraSearchParameters.SUFFIX).getValue(), peakList.getRawDataFiles());
// Load previous applied methods.
for (final PeakList.PeakListAppliedMethod method : peakList.getAppliedMethods()) {
combinedPeakList.addDescriptionOfAppliedTask(method);
}
// Add task description to feature list.
combinedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Bioconductor CAMERA", parameters));
// ------------------------------------------------
// Find unique isotopes belonging to the same group
// ------------------------------------------------
Set<String> isotopeGroups = new HashSet<>();
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null)
continue;
String isotopeGroup = isotope.substring(1, isotope.indexOf("]"));
if (isotopeGroup == null || isotopeGroup.length() == 0)
continue;
isotopeGroups.add(isotopeGroup);
}
List<PeakListRow> groupRows = new ArrayList<>();
Set<String> groupNames = new HashSet<>();
Map<Double, Double> spectrum = new HashMap<>();
List<PeakListRow> newPeakListRows = new ArrayList<>();
for (String isotopeGroup : isotopeGroups) {
// -----------------------------------------
// Find all peaks belonging to isotopeGroups
// -----------------------------------------
groupRows.clear();
groupNames.clear();
spectrum.clear();
int minLength = Integer.MAX_VALUE;
PeakListRow groupRow = null;
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null)
continue;
String isoGroup = isotope.substring(1, isotope.indexOf("]"));
if (isoGroup == null)
continue;
if (isoGroup.equals(isotopeGroup)) {
groupRows.add(row);
groupNames.add(identity.getName());
spectrum.put(row.getAverageMZ(), row.getAverageHeight());
if (isoGroup.length() < minLength) {
minLength = isoGroup.length();
groupRow = row;
}
}
}
// Skip peaks that have different identity names (belong to different pcgroup)
if (groupRow == null || groupNames.size() != 1)
continue;
if (groupRow == null)
continue;
PeakIdentity identity = groupRow.getPreferredPeakIdentity();
if (identity == null)
continue;
DataPoint[] dataPoints = new DataPoint[spectrum.size()];
int count = 0;
for (Entry<Double, Double> e : spectrum.entrySet()) dataPoints[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
groupRow.getBestPeak().setIsotopePattern(pattern);
// combinedPeakList.addRow(groupRow);
newPeakListRows.add(groupRow);
}
if (includeSingletons) {
for (PeakListRow row : peakList.getRows()) {
PeakIdentity identity = row.getPreferredPeakIdentity();
if (identity == null)
continue;
String isotope = identity.getPropertyValue("Isotope");
if (isotope == null || isotope.length() == 0) {
DataPoint[] dataPoints = new DataPoint[1];
dataPoints[0] = new SimpleDataPoint(row.getAverageMZ(), row.getAverageHeight());
IsotopePattern pattern = new SimpleIsotopePattern(dataPoints, IsotopePatternStatus.PREDICTED, "Spectrum");
row.getBestPeak().setIsotopePattern(pattern);
newPeakListRows.add(row);
}
}
}
// ------------------------------------
// Sort new peak rows by retention time
// ------------------------------------
Collections.sort(newPeakListRows, new Comparator<PeakListRow>() {
@Override
public int compare(PeakListRow row1, PeakListRow row2) {
double retTime1 = row1.getAverageRT();
double retTime2 = row2.getAverageRT();
return Double.compare(retTime1, retTime2);
}
});
for (PeakListRow row : newPeakListRows) combinedPeakList.addRow(row);
return combinedPeakList;
}
Aggregations