Search in sources :

Example 26 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class CsvReadTask method run.

@Override
public void run() {
    setStatus(TaskStatus.PROCESSING);
    Scanner scanner;
    logger.setLevel(Level.ALL);
    try {
        scanner = new Scanner(file);
        dataSource = getFileName(scanner);
        if (dataSource == null) {
            setErrorMessage("Could not open data file " + file.getAbsolutePath());
            setStatus(TaskStatus.ERROR);
            return;
        }
        logger.info("opening raw file " + dataSource);
        String acquisitionDate = getAcqusitionDate(scanner);
        if (acquisitionDate == null) {
            setErrorMessage("Could not find acquisition date in file " + file.getAbsolutePath());
            setStatus(TaskStatus.ERROR);
            return;
        }
        logger.info("Date of acquisition " + acquisitionDate);
        // scanner.useDelimiter(",");
        List<String> mzsList = new ArrayList<String>();
        String mstype = "";
        String ions = "";
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            logger.fine("checking line: " + line + " for 'Time'...");
            if (line.startsWith("Time")) {
                String[] axes = line.split(",");
                logger.fine("Found axes" + Arrays.toString(axes));
                for (int i = 1; i < axes.length; i++) {
                    String axis = axes[i];
                    ions += axis + ", ";
                    if (axis.contains("->")) {
                        mstype = "MS/MS";
                        logger.fine("axis " + axis + " is an ms^2 scan");
                        String mz = axis.substring(axis.indexOf("-> ") + 3);
                        mz.trim();
                        logger.fine("Axis " + axis + " was scanned at m/z = '" + mz + "'");
                        mzsList.add(mz);
                    } else {
                        String mz = axis.replaceAll("[^0-9]", "");
                        logger.fine("axis " + axis + " was scanned at " + mz);
                        mzsList.add(mz);
                    }
                }
                break;
            }
        }
        int[] mzs = new int[mzsList.size()];
        for (int i = 0; i < mzsList.size(); i++) mzs[i] = Integer.valueOf(mzsList.get(i));
        Range<Double> mzRange = Range.closed((double) mzs[0] - 10, (double) mzs[1] + 10);
        int scanNumber = 1;
        while (scanner.hasNextLine()) {
            String line = scanner.nextLine();
            if (line == null || line.trim().equals(""))
                continue;
            String[] columns = line.split(",");
            if (columns == null || columns.length != mzs.length + 1)
                continue;
            double rt = Double.valueOf(columns[0]) / 60;
            DataPoint[] dataPoints = new SimpleDataPoint[mzs.length];
            for (int i = 0; i < dataPoints.length; i++) {
                String intensity = columns[i + 1];
                dataPoints[i] = new SimpleDataPoint(mzs[i], Double.valueOf(intensity));
            }
            Scan scan = new SimpleScan(null, scanNumber, 1, rt, 0.0, 1, null, dataPoints, MassSpectrumType.CENTROIDED, PolarityType.POSITIVE, "ICP-" + mstype + " " + ions.substring(0, ions.length() - 2), mzRange);
            newMZmineFile.addScan(scan);
            scanNumber++;
        }
        finalRawDataFile = newMZmineFile.finishWriting();
        project.addFile(finalRawDataFile);
    } catch (Exception e) {
        setErrorMessage(e.getMessage());
        setStatus(TaskStatus.ERROR);
        return;
    }
    this.setStatus(TaskStatus.FINISHED);
}
Also used : Scanner(java.util.Scanner) ArrayList(java.util.ArrayList) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Scan(net.sf.mzmine.datamodel.Scan) SimpleScan(net.sf.mzmine.datamodel.impl.SimpleScan)

Example 27 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class Gap method noMoreOffers.

public void noMoreOffers() {
    // Check peak that was last constructed
    if (currentPeakDataPoints != null) {
        checkCurrentPeak();
        currentPeakDataPoints = null;
    }
    // If we have best peak candidate, construct a SimpleChromatographicPeak
    if (bestPeakDataPoints != null) {
        double area = 0, height = 0, mz = 0, rt = 0;
        int[] scanNumbers = new int[bestPeakDataPoints.size()];
        DataPoint[] finalDataPoint = new DataPoint[bestPeakDataPoints.size()];
        Range<Double> finalRTRange = null, finalMZRange = null, finalIntensityRange = null;
        int representativeScan = 0;
        // Process all datapoints
        for (int i = 0; i < bestPeakDataPoints.size(); i++) {
            GapDataPoint dp = bestPeakDataPoints.get(i);
            if (i == 0) {
                finalRTRange = Range.singleton(dp.getRT());
                finalMZRange = Range.singleton(dp.getMZ());
                finalIntensityRange = Range.singleton(dp.getIntensity());
            } else {
                assert finalRTRange != null && finalMZRange != null && finalIntensityRange != null;
                finalRTRange = finalRTRange.span(Range.singleton(dp.getRT()));
                finalMZRange = finalMZRange.span(Range.singleton(dp.getMZ()));
                finalIntensityRange = finalIntensityRange.span(Range.singleton(dp.getIntensity()));
            }
            scanNumbers[i] = bestPeakDataPoints.get(i).getScanNumber();
            finalDataPoint[i] = new SimpleDataPoint(dp.getMZ(), dp.getIntensity());
            mz += bestPeakDataPoints.get(i).getMZ();
            // Check height
            if (bestPeakDataPoints.get(i).getIntensity() > height) {
                height = bestPeakDataPoints.get(i).getIntensity();
                rt = bestPeakDataPoints.get(i).getRT();
                representativeScan = bestPeakDataPoints.get(i).getScanNumber();
            }
            // Skip last data point
            if (i == bestPeakDataPoints.size() - 1) {
                break;
            }
            // X axis interval length
            double rtDifference = bestPeakDataPoints.get(i + 1).getRT() - bestPeakDataPoints.get(i).getRT();
            // Convert the RT scale to seconds
            rtDifference *= 60d;
            // intensity at the beginning and end of the interval
            double intensityStart = bestPeakDataPoints.get(i).getIntensity();
            double intensityEnd = bestPeakDataPoints.get(i + 1).getIntensity();
            // calculate area of the interval
            area += (rtDifference * (intensityStart + intensityEnd) / 2);
        }
        // Calculate average m/z value
        mz /= bestPeakDataPoints.size();
        // Find the best fragmentation scan, if available
        int fragmentScan = ScanUtils.findBestFragmentScan(rawDataFile, finalRTRange, finalMZRange);
        // Find all MS2 fragment scans, if available
        int[] allMS2fragmentScanNumbers = ScanUtils.findAllMS2FragmentScans(rawDataFile, finalRTRange, finalMZRange);
        // Is intensity above the noise level?
        if (height >= noiseLevel) {
            SimpleFeature newPeak = new SimpleFeature(rawDataFile, mz, rt, height, area, scanNumbers, finalDataPoint, FeatureStatus.ESTIMATED, representativeScan, fragmentScan, allMS2fragmentScanNumbers, finalRTRange, finalMZRange, finalIntensityRange);
            // Fill the gap
            peakListRow.addPeak(rawDataFile, newPeak);
        }
    }
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleFeature(net.sf.mzmine.datamodel.impl.SimpleFeature)

Example 28 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class WaveletMassDetector method performCWT.

/**
 * Perform the CWT over raw data points in the selected scale level
 *
 * @param dataPoints
 */
private SimpleDataPoint[] performCWT(DataPoint[] dataPoints, double waveletWindow, int scaleLevel) {
    int length = dataPoints.length;
    SimpleDataPoint[] cwtDataPoints = new SimpleDataPoint[length];
    double wstep = ((WAVELET_ESR - WAVELET_ESL) / NPOINTS);
    double[] W = new double[(int) NPOINTS];
    double waveletIndex = WAVELET_ESL;
    for (int j = 0; j < NPOINTS; j++) {
        // Pre calculate the values of the wavelet
        W[j] = cwtMEXHATreal(waveletIndex, waveletWindow, 0.0);
        waveletIndex += wstep;
    }
    /*
     * We only perform Translation of the wavelet in the selected scale
     */
    int d = (int) NPOINTS / (WAVELET_ESR - WAVELET_ESL);
    int a_esl = scaleLevel * WAVELET_ESL;
    int a_esr = scaleLevel * WAVELET_ESR;
    double sqrtScaleLevel = Math.sqrt(scaleLevel);
    for (int dx = 0; dx < length; dx++) {
        /* Compute wavelet boundaries */
        int t1 = a_esl + dx;
        if (t1 < 0)
            t1 = 0;
        int t2 = a_esr + dx;
        if (t2 >= length)
            t2 = (length - 1);
        /* Perform convolution */
        double intensity = 0.0;
        for (int i = t1; i <= t2; i++) {
            int ind = (int) (NPOINTS / 2) - (((int) d * (i - dx) / scaleLevel) * (-1));
            if (ind < 0)
                ind = 0;
            if (ind >= NPOINTS)
                ind = (int) NPOINTS - 1;
            intensity += dataPoints[i].getIntensity() * W[ind];
        }
        intensity /= sqrtScaleLevel;
        // Eliminate the negative part of the wavelet map
        if (intensity < 0)
            intensity = 0;
        cwtDataPoints[dx] = new SimpleDataPoint(dataPoints[dx].getMZ(), (double) intensity);
    }
    return cwtDataPoints;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 29 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class HistogramChartFactory method addDPToList.

private static void addDPToList(List<DataPoint> list, int[] bins, int i, double binwidth, double min, double max, DoubleFunction<Double> function) {
    // adds a data point to the series
    double x = min + (binwidth / 2.0) + i * binwidth;
    if (function != null)
        x = function.apply(x);
    list.add(new SimpleDataPoint(x, bins[i]));
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Example 30 with SimpleDataPoint

use of net.sf.mzmine.datamodel.impl.SimpleDataPoint in project mzmine2 by mzmine.

the class AdapMspExportTask method integerDataPoints.

private DataPoint[] integerDataPoints(final DataPoint[] dataPoints, final String mode) {
    int size = dataPoints.length;
    Map<Double, Double> integerDataPoints = new HashMap<>();
    for (int i = 0; i < size; ++i) {
        double mz = (double) Math.round(dataPoints[i].getMZ());
        double intensity = dataPoints[i].getIntensity();
        Double prevIntensity = integerDataPoints.get(mz);
        if (prevIntensity == null)
            prevIntensity = 0.0;
        switch(mode) {
            case AdapMspExportParameters.ROUND_MODE_SUM:
                integerDataPoints.put(mz, prevIntensity + intensity);
                break;
            case AdapMspExportParameters.ROUND_MODE_MAX:
                integerDataPoints.put(mz, Math.max(prevIntensity, intensity));
                break;
        }
    }
    DataPoint[] result = new DataPoint[integerDataPoints.size()];
    int count = 0;
    for (Entry<Double, Double> e : integerDataPoints.entrySet()) result[count++] = new SimpleDataPoint(e.getKey(), e.getValue());
    return result;
}
Also used : SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) HashMap(java.util.HashMap) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint)

Aggregations

SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)58 DataPoint (net.sf.mzmine.datamodel.DataPoint)56 Scan (net.sf.mzmine.datamodel.Scan)15 ArrayList (java.util.ArrayList)13 SimpleIsotopePattern (net.sf.mzmine.datamodel.impl.SimpleIsotopePattern)13 SimpleScan (net.sf.mzmine.datamodel.impl.SimpleScan)12 IOException (java.io.IOException)11 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)10 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)10 Feature (net.sf.mzmine.datamodel.Feature)8 HashMap (java.util.HashMap)7 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)7 IsotopePattern (net.sf.mzmine.datamodel.IsotopePattern)6 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)6 SimplePeakIdentity (net.sf.mzmine.datamodel.impl.SimplePeakIdentity)5 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)5 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 DataInputStream (java.io.DataInputStream)4 Vector (java.util.Vector)4