Search in sources :

Example 31 with MassList

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

the class IsotopePeakScannerTask method checkParameters.

private boolean checkParameters() {
    if (charge == 0) {
        setErrorMessage("Error: charge may not be 0!");
        setStatus(TaskStatus.ERROR);
        return false;
    }
    if (!FormulaUtils.checkMolecularFormula(element)) {
        setErrorMessage("Error: Invalid formula!");
        setStatus(TaskStatus.ERROR);
        return false;
    }
    if (accurateAvgIntensity || ratingType == RatingType.TEMPAVG) {
        if (massListName.equals("") && ratingType == RatingType.TEMPAVG) {
            setErrorMessage("Error: Rating Type = temporary average but no masslist was selected.\nYou can" + " select a mass list without checking accurate average.");
            setStatus(TaskStatus.ERROR);
            return false;
        }
        if (peakList.getNumberOfRawDataFiles() > 1) {
            setErrorMessage("The number of raw data files of feature list \"" + peakList.getName() + "\" is greater than 1. This is not supported by this module.");
            setStatus(TaskStatus.ERROR);
            return false;
        }
        RawDataFile[] raws = peakList.getRawDataFiles();
        boolean foundMassList = false;
        for (RawDataFile raw : raws) {
            int[] scanNumbers = raw.getScanNumbers();
            for (int scan : scanNumbers) {
                MassList[] massLists = raw.getScan(scan).getMassLists();
                for (MassList list : massLists) {
                    if (list.getName().equals(massListName))
                        foundMassList = true;
                }
            }
        }
        if (foundMassList == false) {
            setErrorMessage("Feature list \"" + peakList.getName() + "\" does not contain a mass list by the name of " + massListName + ".");
            setStatus(TaskStatus.ERROR);
            return false;
        }
    }
    return true;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) MassList(net.sf.mzmine.datamodel.MassList)

Example 32 with MassList

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

the class ScanSelectPanel method getFilteredDataPoints.

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

Example 33 with MassList

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

the class ScanSelectPanel method analyzeScan.

private void analyzeScan(Scan scan) {
    MassList massList = ScanUtils.getMassListOrFirst(scan, massListName);
    if (massList != null) {
        DataPoint[] dp = massList.getDataPoints();
        double tic = ScanUtils.getTIC(dp, noiseLevel);
        int signals = ScanUtils.getNumberOfSignals(dp, noiseLevel);
        lbTIC.setText(MZmineCore.getConfiguration().getIntensityFormat().format(tic));
        lbSignals.setText("" + signals);
        lbTIC.getParent().revalidate();
        lbTIC.getParent().repaint();
    }
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint)

Example 34 with MassList

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

the class ExtractScansTask method exportScans.

private void exportScans(File dir, RawDataFile raw, int start, int scans, double pp) {
    // Open file
    DecimalFormat format = new DecimalFormat("00");
    File fileDir = new File(dir, FileAndPathUtil.eraseFormat(raw.getName()));
    FileAndPathUtil.createDirectory(fileDir);
    int end = Math.min(scans + start, raw.getNumOfScans());
    String linescans = "scan" + delimiter + raw.getScanNumbers()[start] + delimiter + "to" + delimiter + raw.getScanNumbers()[end - 1] + "\n";
    String lineRT = "RT" + delimiter + raw.getScan(raw.getScanNumbers()[start]).getRetentionTime() + "to" + raw.getScan(raw.getScanNumbers()[end - 1]).getRetentionTime() + "\n";
    String linePath = raw.getName() + "\n";
    String lineOptions = "export of" + delimiter;
    if (!useCenterTime) {
        double st = raw.getScan(raw.getScanNumbers()[start]).getRetentionTime();
        double et = raw.getScan(raw.getScanNumbers()[end]).getRetentionTime();
        lineOptions += scans + delimiter + "scans from time " + delimiter + st + " to " + et + "\n";
    } else if (autoMax) {
        lineOptions += scans + delimiter + "scans around scan with maximum intensity:" + delimiter + raw.getScanNumbers()[scanMaxTIC] + "\n";
    } else {
        lineOptions += scans + delimiter + "scans around center time:" + delimiter + centerTime + "\n";
    }
    for (int i = start; i < end; i++) {
        FileWriter writer;
        File file = new File(fileDir, "scan" + format.format((i - start + 1)) + ".csv");
        StringBuilder out = new StringBuilder();
        try {
            writer = new FileWriter(file);
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
        // EXPORT
        try {
            Scan s = raw.getScan(raw.getScanNumbers()[i]);
            // write header
            if (exportHeader) {
                out.append(linePath);
                out.append(linescans);
                out.append(lineRT);
                out.append(lineOptions);
                out.append("TIC" + delimiter + s.getTIC() + "\n");
                out.append("scan number" + delimiter + raw.getScanNumbers()[i] + "\n");
                out.append("retention time" + delimiter + s.getRetentionTime() + "\n\n");
                out.append("mz" + delimiter + "intensity\n");
            }
            // write data
            if (useMassList) {
                MassList mass = s.getMassList(massList);
                DataPoint[] dp = mass.getDataPoints();
                for (int k = 0; k < dp.length; k++) {
                    out.append(dp[k].getMZ() + delimiter + dp[k].getIntensity() + "\n");
                }
            } else {
                for (int k = 0; k < s.getNumberOfDataPoints(); k++) {
                    DataPoint dp = s.getDataPoints()[k];
                    out.append(dp.getMZ() + delimiter + dp.getIntensity() + "\n");
                }
            }
            writeBuffered(writer, out.toString(), 8192);
        } catch (IOException e1) {
            e1.printStackTrace();
        } finally {
            // Close file
            try {
                writer.close();
            } catch (Exception e) {
                e.printStackTrace();
                return;
            }
        }
        // 
        perc += pp / (double) scans;
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) FileWriter(java.io.FileWriter) IOException(java.io.IOException) DataPoint(net.sf.mzmine.datamodel.DataPoint) IOException(java.io.IOException) DataPoint(net.sf.mzmine.datamodel.DataPoint) Scan(net.sf.mzmine.datamodel.Scan) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File) MassList(net.sf.mzmine.datamodel.MassList)

Example 35 with MassList

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

the class ExportScansTask method exportText.

/**
 * Export the chromatogram - text formats
 *
 * @throws IOException if there are i/o problems.
 */
public void exportText() throws IOException {
    // Open the writer - append data if file already exists
    final BufferedWriter writer = new BufferedWriter(new FileWriter(exportFile, true));
    try {
        for (Scan scan : scans) {
            LOG.info("Exporting scan #" + scan.getScanNumber() + " of raw file: " + scan.getDataFile().getName());
            // Write Header row
            switch(extension) {
                case "txt":
                    writer.write("Name: Scan#: " + scan.getScanNumber() + ", RT: " + scan.getRetentionTime() + " min");
                    writer.newLine();
                    break;
                case "mgf":
                    writer.write("BEGIN IONS");
                    writer.newLine();
                    writer.write("PEPMASS=" + scan.getPrecursorMZ());
                    writer.newLine();
                    writer.write("CHARGE=" + scan.getPrecursorCharge());
                    writer.newLine();
                    writer.write("MSLEVEL=" + scan.getMSLevel());
                    writer.newLine();
                    writer.write("Title: Scan#: " + scan.getScanNumber() + ", RT: " + scan.getRetentionTime() + " min");
                    writer.newLine();
                    break;
                case "msp":
                    break;
            }
            // Write the data points
            DataPoint[] dataPoints = null;
            if (useMassList && massListName != null) {
                MassList list = scan.getMassList(massListName);
                if (list != null)
                    dataPoints = list.getDataPoints();
            }
            if (dataPoints == null)
                dataPoints = scan.getDataPoints();
            final int itemCount = dataPoints.length;
            progressMax = itemCount;
            for (int i = 0; i < itemCount; i++) {
                // Write data point row
                writer.write(dataPoints[i].getMZ() + " " + dataPoints[i].getIntensity());
                writer.newLine();
                progress = i + 1;
            }
            // Write footer row
            if (extension.equals("mgf")) {
                writer.write("END IONS");
                writer.newLine();
            }
            writer.newLine();
        }
    } catch (Exception e) {
        throw (new IOException(e));
    } finally {
        // Close
        writer.close();
    }
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) FileWriter(java.io.FileWriter) Scan(net.sf.mzmine.datamodel.Scan) MZmineToMSDKMsScan(net.sf.mzmine.datamodel.impl.MZmineToMSDKMsScan) MsScan(io.github.msdk.datamodel.MsScan) IOException(java.io.IOException) MassList(net.sf.mzmine.datamodel.MassList) DataPoint(net.sf.mzmine.datamodel.DataPoint) MSDKException(io.github.msdk.MSDKException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

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