Search in sources :

Example 6 with MassList

use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.

the class ScanSelectPanel method getFilteredDataPointsRemoved.

/**
 * Removed data points
 *
 * @return
 */
@Nullable
public DataPoint[] getFilteredDataPointsRemoved() {
    if (scans != null && !scans.isEmpty()) {
        Scan scan = scans.get(selectedScanI);
        MassList massList = ScanUtils.getMassListOrFirst(scan, massListName);
        if (massList != null)
            return ScanUtils.getBelowThreshold(massList.getDataPoints(), noiseLevel);
    }
    return null;
}
Also used : Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList) Nullable(javax.annotation.Nullable)

Example 7 with MassList

use of net.sf.mzmine.datamodel.MassList 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 8 with MassList

use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.

the class Candidates method getAvgPeakHeights.

/**
 * @param ID
 * @return avg heights of all with the ids, but only if they are contained in same scans and mass
 *         lists
 */
private double[] getAvgPeakHeights(int[] ID) {
    PeakListRow[] rows = plh.getRowsByID(ID);
    RawDataFile[] raws = rows[0].getRawDataFiles();
    if (raws.length < 1)
        return null;
    double[] mzs = new double[ID.length];
    for (int i = 0; i < rows.length; i++) mzs[i] = rows[i].getAverageMZ();
    double[] avgHeights = new double[ID.length];
    int pointsAdded = 0;
    for (RawDataFile raw : raws) {
        if (!raw.getDataMZRange().contains(rows[0].getAverageMZ()))
            continue;
        int[] scanNums = raw.getScanNumbers();
        for (int i = 0; i < scanNums.length; i++) {
            Scan scan = raw.getScan(scanNums[i]);
            MassList list = scan.getMassList(massListName);
            if (list == null || !massListContainsEveryMZ(list, mzs, minHeight))
                continue;
            double[] avgBuffer = new double[mzs.length];
            boolean allFound = true;
            for (int j = 0; j < mzs.length; j++) {
                DataPoint[] points = getMassListDataPointsByMass(list, mzTolerance.getToleranceRange(mzs[j]));
                if (points.length == 0)
                    continue;
                DataPoint dp = getClosestDataPoint(points, rows[j].getAverageMZ(), minHeight);
                if (// yes the list contained something close to every datapoint that was over
                dp == null) // minHeight, BUT
                {
                    // the closest might not have been. Check is done inside getClosestDataPoint();
                    allFound = false;
                    break;
                }
                avgBuffer[j] = dp.getIntensity();
            }
            if (allFound) {
                pointsAdded++;
                for (int j = 0; j < mzs.length; j++) avgHeights[j] += avgBuffer[j];
            }
        }
    }
    if (pointsAdded == 0) {
        logger.warning("Error: Peaks with ids: " + Arrays.toString(ID) + " were not in same scans at all. Please update the parameters.");
        return null;
    }
    for (int i = 0; i < avgHeights.length; i++) avgHeights[i] /= (pointsAdded);
    return avgHeights;
}
Also used : PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Example 9 with MassList

use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.

the class RawDataFileSaveHandler method fillScanElement.

/**
 * Create the part of the XML document related to the scans
 *
 * @param scan
 * @param element
 */
private void fillScanElement(Scan scan, TransformerHandler hd) throws SAXException, IOException {
    // <SCAN_ID>
    AttributesImpl atts = new AttributesImpl();
    hd.startElement("", "", RawDataElementName.SCAN_ID.getElementName(), atts);
    hd.characters(String.valueOf(scan.getScanNumber()).toCharArray(), 0, String.valueOf(scan.getScanNumber()).length());
    hd.endElement("", "", RawDataElementName.SCAN_ID.getElementName());
    // <MS_LEVEL>
    hd.startElement("", "", RawDataElementName.MS_LEVEL.getElementName(), atts);
    hd.characters(String.valueOf(scan.getMSLevel()).toCharArray(), 0, String.valueOf(scan.getMSLevel()).length());
    hd.endElement("", "", RawDataElementName.MS_LEVEL.getElementName());
    if (scan.getMSLevel() >= 2) {
        // <PRECURSOR_MZ>
        hd.startElement("", "", RawDataElementName.PRECURSOR_MZ.getElementName(), atts);
        hd.characters(String.valueOf(scan.getPrecursorMZ()).toCharArray(), 0, String.valueOf(scan.getPrecursorMZ()).length());
        hd.endElement("", "", RawDataElementName.PRECURSOR_MZ.getElementName());
        // <PRECURSOR_CHARGE>
        hd.startElement("", "", RawDataElementName.PRECURSOR_CHARGE.getElementName(), atts);
        hd.characters(String.valueOf(scan.getPrecursorCharge()).toCharArray(), 0, String.valueOf(scan.getPrecursorCharge()).length());
        hd.endElement("", "", RawDataElementName.PRECURSOR_CHARGE.getElementName());
    }
    // <RETENTION_TIME>
    hd.startElement("", "", RawDataElementName.RETENTION_TIME.getElementName(), atts);
    // In the project file, retention time is represented in seconds, for
    // historical reasons
    double rt = scan.getRetentionTime() * 60d;
    hd.characters(String.valueOf(rt).toCharArray(), 0, String.valueOf(rt).length());
    hd.endElement("", "", RawDataElementName.RETENTION_TIME.getElementName());
    // <CENTROIDED>
    hd.startElement("", "", RawDataElementName.CENTROIDED.getElementName(), atts);
    hd.characters(String.valueOf(scan.getSpectrumType()).toCharArray(), 0, String.valueOf(scan.getSpectrumType()).length());
    hd.endElement("", "", RawDataElementName.CENTROIDED.getElementName());
    // <QUANTITY_DATAPOINTS>
    hd.startElement("", "", RawDataElementName.QUANTITY_DATAPOINTS.getElementName(), atts);
    hd.characters(String.valueOf((scan.getNumberOfDataPoints())).toCharArray(), 0, String.valueOf((scan.getNumberOfDataPoints())).length());
    hd.endElement("", "", RawDataElementName.QUANTITY_DATAPOINTS.getElementName());
    // <FRAGMENT_SCAN>
    if (scan.getFragmentScanNumbers() != null) {
        int[] fragmentScans = scan.getFragmentScanNumbers();
        atts.addAttribute("", "", RawDataElementName.QUANTITY.getElementName(), "CDATA", String.valueOf(fragmentScans.length));
        hd.startElement("", "", RawDataElementName.QUANTITY_FRAGMENT_SCAN.getElementName(), atts);
        atts.clear();
        for (int i : fragmentScans) {
            hd.startElement("", "", RawDataElementName.FRAGMENT_SCAN.getElementName(), atts);
            hd.characters(String.valueOf(i).toCharArray(), 0, String.valueOf(i).length());
            hd.endElement("", "", RawDataElementName.FRAGMENT_SCAN.getElementName());
        }
        hd.endElement("", "", RawDataElementName.QUANTITY_FRAGMENT_SCAN.getElementName());
    }
    // <MASS_LIST>
    MassList[] massLists = scan.getMassLists();
    for (MassList massList : massLists) {
        StorableMassList stMassList = (StorableMassList) massList;
        atts.addAttribute("", "", RawDataElementName.NAME.getElementName(), "CDATA", stMassList.getName());
        atts.addAttribute("", "", RawDataElementName.STORAGE_ID.getElementName(), "CDATA", String.valueOf(stMassList.getStorageID()));
        hd.startElement("", "", RawDataElementName.MASS_LIST.getElementName(), atts);
        atts.clear();
        hd.endElement("", "", RawDataElementName.MASS_LIST.getElementName());
    }
    // <POLARITY>
    hd.startElement("", "", RawDataElementName.POLARITY.getElementName(), atts);
    String pol = scan.getPolarity().toString();
    hd.characters(pol.toCharArray(), 0, pol.length());
    hd.endElement("", "", RawDataElementName.POLARITY.getElementName());
    // <SCAN_DESCRIPTION>
    hd.startElement("", "", RawDataElementName.SCAN_DESCRIPTION.getElementName(), atts);
    String scanDesc = scan.getScanDefinition();
    hd.characters(scanDesc.toCharArray(), 0, scanDesc.length());
    hd.endElement("", "", RawDataElementName.SCAN_DESCRIPTION.getElementName());
    // <SCAN_MZ_RANGE>
    hd.startElement("", "", RawDataElementName.SCAN_MZ_RANGE.getElementName(), atts);
    Range<Double> mzRange = scan.getScanningMZRange();
    String mzRangeStr = mzRange.lowerEndpoint() + "-" + mzRange.upperEndpoint();
    hd.characters(mzRangeStr.toCharArray(), 0, mzRangeStr.length());
    hd.endElement("", "", RawDataElementName.SCAN_MZ_RANGE.getElementName());
}
Also used : AttributesImpl(org.xml.sax.helpers.AttributesImpl) StorableMassList(net.sf.mzmine.project.impl.StorableMassList) MassList(net.sf.mzmine.datamodel.MassList) StorableMassList(net.sf.mzmine.project.impl.StorableMassList)

Example 10 with MassList

use of net.sf.mzmine.datamodel.MassList in project mzmine2 by mzmine.

the class ShoulderPeaksFilterSetupDialog method loadPreview.

/**
 * This function set all the information into the plot chart
 *
 * @param scanNumber
 */
protected void loadPreview(SpectraPlot spectrumPlot, Scan previewScan) {
    // Remove previous data sets
    spectrumPlot.removeAllDataSets();
    // Add scan data set
    ScanDataSet scanDataSet = new ScanDataSet(previewScan);
    spectrumPlot.addDataSet(scanDataSet, SpectraVisualizerWindow.scanColor, false);
    // If the scan is centroided, switch to centroid mode
    spectrumPlot.setPlotMode(previewScan.getSpectrumType());
    // If the parameters are not complete, exit
    ArrayList<String> errors = new ArrayList<String>();
    boolean paramsOK = parameters.checkParameterValues(errors);
    if (!paramsOK)
        return;
    // Get mass list
    String massListName = parameters.getParameter(ShoulderPeaksFilterParameters.massList).getValue();
    MassList massList = previewScan.getMassList(massListName);
    if (massList == null)
        return;
    // Perform filtering
    DataPoint[] mzValues = massList.getDataPoints();
    DataPoint[] remainingMzValues = ShoulderPeaksFilter.filterMassValues(mzValues, parameters);
    Vector<DataPoint> removedPeaks = new Vector<DataPoint>();
    removedPeaks.addAll(Arrays.asList(mzValues));
    removedPeaks.removeAll(Arrays.asList(remainingMzValues));
    DataPoint[] removedMzValues = removedPeaks.toArray(new DataPoint[0]);
    // Add mass list data sets
    DataPointsDataSet removedPeaksDataSet = new DataPointsDataSet("Removed peaks", removedMzValues);
    DataPointsDataSet remainingPeaksDataSet = new DataPointsDataSet("Remaining peaks", remainingMzValues);
    spectrumPlot.addDataSet(removedPeaksDataSet, removedPeaksColor, false);
    spectrumPlot.addDataSet(remainingPeaksDataSet, SpectraVisualizerWindow.peaksColor, false);
}
Also used : ScanDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.ScanDataSet) DataPoint(net.sf.mzmine.datamodel.DataPoint) ArrayList(java.util.ArrayList) Vector(java.util.Vector) MassList(net.sf.mzmine.datamodel.MassList) DataPointsDataSet(net.sf.mzmine.modules.visualization.spectra.simplespectra.datasets.DataPointsDataSet)

Aggregations

MassList (net.sf.mzmine.datamodel.MassList)36 Scan (net.sf.mzmine.datamodel.Scan)25 DataPoint (net.sf.mzmine.datamodel.DataPoint)24 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)14 Feature (net.sf.mzmine.datamodel.Feature)9 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)9 ArrayList (java.util.ArrayList)6 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)5 PeakList (net.sf.mzmine.datamodel.PeakList)5 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)4 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)4 Range (com.google.common.collect.Range)3 FileWriter (java.io.FileWriter)3 IOException (java.io.IOException)3 TreePath (javax.swing.tree.TreePath)3 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)3 MZmineProject (net.sf.mzmine.datamodel.MZmineProject)3 MergedSpectrum (net.sf.mzmine.modules.tools.msmsspectramerge.MergedSpectrum)3 MsMsSpectraMergeModule (net.sf.mzmine.modules.tools.msmsspectramerge.MsMsSpectraMergeModule)3 BufferedWriter (java.io.BufferedWriter)2