Search in sources :

Example 91 with RawDataFile

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

the class MassListComponent method getMassListNames.

/**
 * Method returns the list of all identified MassList names in scans
 *
 * @return unique MassList names
 */
public static List<String> getMassListNames() {
    ArrayList<String> names = new ArrayList<>();
    RawDataFile[] dataFiles = MZmineCore.getProjectManager().getCurrentProject().getDataFiles();
    for (RawDataFile dataFile : dataFiles) {
        int[] scanNums = dataFile.getScanNumbers();
        for (int scanNum : scanNums) {
            Scan scan = dataFile.getScan(scanNum);
            MassList[] massLists = scan.getMassLists();
            for (MassList massList : massLists) {
                String name = massList.getName();
                if (!names.contains(name))
                    names.add(name);
            }
        }
    }
    return names;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) Scan(net.sf.mzmine.datamodel.Scan) MassList(net.sf.mzmine.datamodel.MassList)

Example 92 with RawDataFile

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

the class ScanUtils method findPrecursorScan.

/**
 * Finds the first MS1 scan preceding the given MS2 scan. If no such scan exists, returns null.
 */
@Nullable
public static Scan findPrecursorScan(@Nonnull Scan scan) {
    assert scan != null;
    final RawDataFile dataFile = scan.getDataFile();
    final int[] scanNumbers = dataFile.getScanNumbers();
    int startIndex = Arrays.binarySearch(scanNumbers, scan.getScanNumber());
    for (int i = startIndex; i >= 0; i--) {
        Scan s = dataFile.getScan(scanNumbers[i]);
        if (s.getMSLevel() == 1)
            return s;
    }
    // Didn't find any MS1 scan
    return null;
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Scan(net.sf.mzmine.datamodel.Scan) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimpleDataPoint(net.sf.mzmine.datamodel.impl.SimpleDataPoint) Nullable(javax.annotation.Nullable)

Example 93 with RawDataFile

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

the class PeakXICComponent method paint.

public void paint(Graphics g) {
    super.paint(g);
    // use Graphics2D for antialiasing
    Graphics2D g2 = (Graphics2D) g;
    // turn on antialiasing
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    // get canvas size
    Dimension size = getSize();
    // get scan numbers, one data point per each scan
    RawDataFile dataFile = peak.getDataFile();
    int[] scanNumbers = peak.getScanNumbers();
    // If we have no data, just return
    if (scanNumbers.length == 0)
        return;
    // for each datapoint, find [X:Y] coordinates of its point in painted
    // image
    int[] xValues = new int[scanNumbers.length];
    int[] yValues = new int[scanNumbers.length];
    // find one datapoint with maximum intensity in each scan
    for (int i = 0; i < scanNumbers.length; i++) {
        double dataPointIntensity = 0;
        DataPoint dataPoint = peak.getDataPoint(scanNumbers[i]);
        if (dataPoint != null)
            dataPointIntensity = dataPoint.getIntensity();
        // get retention time (X value)
        double retentionTime = dataFile.getScan(scanNumbers[i]).getRetentionTime();
        // calculate [X:Y] coordinates
        final double rtLen = rtRange.upperEndpoint() - rtRange.lowerEndpoint();
        xValues[i] = (int) Math.floor((retentionTime - rtRange.lowerEndpoint()) / rtLen * (size.width - 1));
        yValues[i] = size.height - (int) Math.floor(dataPointIntensity / maxIntensity * (size.height - 1));
    }
    // create a path for a peak polygon
    GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
    path.moveTo(xValues[0], size.height - 1);
    // add data points to the path
    for (int i = 0; i < (xValues.length - 1); i++) {
        path.lineTo(xValues[i + 1], yValues[i + 1]);
    }
    path.lineTo(xValues[xValues.length - 1], size.height - 1);
    // close the path to form a polygon
    path.closePath();
    // fill the peak area
    g2.setColor(XICColor);
    g2.fill(path);
}
Also used : GeneralPath(java.awt.geom.GeneralPath) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) Dimension(java.awt.Dimension) DataPoint(net.sf.mzmine.datamodel.DataPoint) Graphics2D(java.awt.Graphics2D)

Example 94 with RawDataFile

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

the class ADAP3AlignerTask method alignPeaks.

private PeakList alignPeaks() {
    // Collect all data files
    List<RawDataFile> allDataFiles = new ArrayList<>(peakLists.length);
    for (final PeakList peakList : peakLists) {
        RawDataFile[] dataFiles = peakList.getRawDataFiles();
        if (dataFiles.length != 1)
            throw new IllegalArgumentException("Found more then one data " + "file in some of the peaks lists");
        allDataFiles.add(dataFiles[0]);
    }
    for (int i = 0; i < peakLists.length; ++i) {
        PeakList peakList = peakLists[i];
        Sample sample = new Sample(i);
        for (final PeakListRow row : peakList.getRows()) {
            Component component = getComponent(row);
            if (component != null)
                sample.addComponent(component);
        }
        alignment.addSample(sample);
    }
    process();
    // Create new feature list
    final PeakList alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
    int rowID = 0;
    List<ReferenceComponent> alignedComponents = alignment.getComponents();
    Collections.sort(alignedComponents);
    for (final ReferenceComponent referenceComponent : alignedComponents) {
        SimplePeakListRow newRow = new SimplePeakListRow(++rowID);
        for (int i = 0; i < referenceComponent.size(); ++i) {
            Component component = referenceComponent.getComponent(i);
            Peak peak = component.getBestPeak();
            peak.getInfo().mzValue(component.getMZ());
            PeakListRow row = findPeakListRow(referenceComponent.getSampleID(i), peak.getInfo().peakID);
            if (row == null)
                throw new IllegalStateException(String.format("Cannot find a feature list row for fileId = %d and peakId = %d", referenceComponent.getSampleID(), peak.getInfo().peakID));
            RawDataFile file = row.getRawDataFiles()[0];
            // Create a new MZmine feature
            Feature feature = ADAPInterface.peakToFeature(file, peak);
            // Add spectrum as an isotopic pattern
            DataPoint[] spectrum = component.getSpectrum().entrySet().stream().map(e -> new SimpleDataPoint(e.getKey(), e.getValue())).toArray(DataPoint[]::new);
            feature.setIsotopePattern(new SimpleIsotopePattern(spectrum, IsotopePattern.IsotopePatternStatus.PREDICTED, "Spectrum"));
            newRow.addPeak(file, feature);
        }
        // Save alignment score
        SimplePeakInformation peakInformation = (SimplePeakInformation) newRow.getPeakInformation();
        if (peakInformation == null)
            peakInformation = new SimplePeakInformation();
        peakInformation.addProperty("Alignment score", Double.toString(referenceComponent.getScore()));
        newRow.setPeakInformation(peakInformation);
        alignedPeakList.addRow(newRow);
    }
    return alignedPeakList;
}
Also used : Peak(dulab.adap.datamodel.Peak) Project(dulab.adap.datamodel.Project) TaskStatus(net.sf.mzmine.taskcontrol.TaskStatus) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) net.sf.mzmine.datamodel.impl(net.sf.mzmine.datamodel.impl) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakList(net.sf.mzmine.datamodel.PeakList) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) Feature(net.sf.mzmine.datamodel.Feature) ParameterSet(net.sf.mzmine.parameters.ParameterSet) QualityParameters(net.sf.mzmine.modules.peaklistmethods.qualityparameters.QualityParameters) ADAPInterface(net.sf.mzmine.util.adap.ADAPInterface) PeakInfo(dulab.adap.datamodel.PeakInfo) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) AlignmentParameters(dulab.adap.workflow.AlignmentParameters) Nullable(javax.annotation.Nullable) OptimizationParameters(dulab.adap.common.algorithms.machineleanring.OptimizationParameters) NavigableMap(java.util.NavigableMap) Logger(java.util.logging.Logger) List(java.util.List) AbstractTask(net.sf.mzmine.taskcontrol.AbstractTask) Sample(dulab.adap.datamodel.Sample) TreeMap(java.util.TreeMap) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) PeakIdentity(net.sf.mzmine.datamodel.PeakIdentity) Collections(java.util.Collections) Sample(dulab.adap.datamodel.Sample) ArrayList(java.util.ArrayList) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) Peak(dulab.adap.datamodel.Peak) PeakList(net.sf.mzmine.datamodel.PeakList) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent)

Example 95 with RawDataFile

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

the class ADAP3AlignerTask method getComponent.

/**
 * Convert a {@link PeakListRow} with one {@link Feature} into {@link Component}.
 *
 * @param row an instance of {@link PeakListRow}. This parameter cannot be null.
 * @return an instance of {@link Component} or null if the row doesn't contain any peaks or isotope patterns.
 */
@Nullable
private Component getComponent(final PeakListRow row) {
    if (row.getNumberOfPeaks() == 0)
        return null;
    // Read Spectrum information
    NavigableMap<Double, Double> spectrum = new TreeMap<>();
    IsotopePattern pattern = row.getBestIsotopePattern();
    if (pattern == null)
        throw new IllegalArgumentException("ADAP Alignment requires mass " + "spectra (or isotopic patterns) of peaks. No spectra found.");
    for (DataPoint dataPoint : pattern.getDataPoints()) spectrum.put(dataPoint.getMZ(), dataPoint.getIntensity());
    // Read Chromatogram
    final Feature peak = row.getBestPeak();
    final RawDataFile dataFile = peak.getDataFile();
    NavigableMap<Double, Double> chromatogram = new TreeMap<>();
    for (final int scan : peak.getScanNumbers()) {
        final DataPoint dataPoint = peak.getDataPoint(scan);
        if (dataPoint != null)
            chromatogram.put(dataFile.getScan(scan).getRetentionTime(), dataPoint.getIntensity());
    }
    return new Component(null, new Peak(chromatogram, new PeakInfo().mzValue(peak.getMZ()).peakID(row.getID())), spectrum, null);
}
Also used : DataPoint(net.sf.mzmine.datamodel.DataPoint) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) IsotopePattern(net.sf.mzmine.datamodel.IsotopePattern) Peak(dulab.adap.datamodel.Peak) TreeMap(java.util.TreeMap) Component(dulab.adap.datamodel.Component) ReferenceComponent(dulab.adap.datamodel.ReferenceComponent) Feature(net.sf.mzmine.datamodel.Feature) PeakInfo(dulab.adap.datamodel.PeakInfo) DataPoint(net.sf.mzmine.datamodel.DataPoint) Nullable(javax.annotation.Nullable)

Aggregations

RawDataFile (net.sf.mzmine.datamodel.RawDataFile)185 Feature (net.sf.mzmine.datamodel.Feature)59 PeakListRow (net.sf.mzmine.datamodel.PeakListRow)52 DataPoint (net.sf.mzmine.datamodel.DataPoint)51 Scan (net.sf.mzmine.datamodel.Scan)40 ArrayList (java.util.ArrayList)33 PeakList (net.sf.mzmine.datamodel.PeakList)33 Nonnull (javax.annotation.Nonnull)24 SimpleDataPoint (net.sf.mzmine.datamodel.impl.SimpleDataPoint)24 SimplePeakList (net.sf.mzmine.datamodel.impl.SimplePeakList)24 SimplePeakListRow (net.sf.mzmine.datamodel.impl.SimplePeakListRow)22 Task (net.sf.mzmine.taskcontrol.Task)20 SimplePeakListAppliedMethod (net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod)19 SimpleFeature (net.sf.mzmine.datamodel.impl.SimpleFeature)17 IOException (java.io.IOException)14 ParameterSet (net.sf.mzmine.parameters.ParameterSet)14 File (java.io.File)13 MassList (net.sf.mzmine.datamodel.MassList)13 PeakListAppliedMethod (net.sf.mzmine.datamodel.PeakList.PeakListAppliedMethod)13 TreeMap (java.util.TreeMap)10