Search in sources :

Example 6 with IsotopePattern

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;
            }
        }
    }
}
Also used : IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) PreparedStatement(java.sql.PreparedStatement) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ByteArrayInputStream(java.io.ByteArrayInputStream) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 7 with IsotopePattern

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;
    }
}
Also used : ParameterSet(net.sf.mzmine.parameters.ParameterSet) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern)

Example 8 with IsotopePattern

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);
}
Also used : ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) ProcessedDataPoint(net.sf.mzmine.modules.visualization.spectra.simplespectra.datapointprocessing.datamodel.ProcessedDataPoint) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) IsotopesDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet)

Example 9 with IsotopePattern

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);
}
Also used : ScanDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet) Color(java.awt.Color) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) IsotopesDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.IsotopesDataSet)

Example 10 with IsotopePattern

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;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakIdentity(net.sf.mzmine.datamodel.impl.SimplePeakIdentity) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimpleIsotopePattern(net.sf.mzmine.datamodel.impl.SimpleIsotopePattern) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList) HashSet(java.util.HashSet)

Aggregations

IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)31 DataPoint (net.sf.mzmine.datamodel.DataPoint)19 Feature (net.sf.mzmine.datamodel.Feature)14 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)9 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)8 ArrayList (java.util.ArrayList)7 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)7 PeakList (net.sf.mzmine.datamodel.PeakList)6 PeakIdentity (net.sf.mzmine.datamodel.PeakIdentity)5 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)4 ParameterSet (net.sf.mzmine.parameters.ParameterSet)4 HashMap (java.util.HashMap)3 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)3 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)3 ExitCode (net.sf.mzmine.util.ExitCode)3 Component (dulab.adap.datamodel.Component)2 Peak (dulab.adap.datamodel.Peak)2 PeakInfo (dulab.adap.datamodel.PeakInfo)2