Search in sources :

Example 26 with RawDataFile

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

the class ProjectParametersSetupDialog method copyParameterValuesToRawDataFiles.

private void copyParameterValuesToRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    // Remove all previous parameters from project
    UserParameter<?, ?>[] parameters = currentProject.getParameters();
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.removeParameter(parameter);
    }
    // Add new parameters
    parameters = parameterValues.keySet().toArray(new UserParameter[0]);
    for (UserParameter<?, ?> parameter : parameters) {
        currentProject.addParameter(parameter);
    }
    // Set values for new parameters
    for (int columnIndex = 0; columnIndex < parameterValues.keySet().size(); columnIndex++) {
        UserParameter<?, ?> parameter = tablemodelParameterValues.getParameter(columnIndex + 1);
        for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
            RawDataFile file = dataFiles[dataFileIndex];
            Object value = tablemodelParameterValues.getValueAt(dataFileIndex, columnIndex + 1);
            if (parameter instanceof DoubleParameter) {
                Double doubleValue = null;
                if (value instanceof Double)
                    doubleValue = (Double) value;
                if (value instanceof String)
                    doubleValue = Double.parseDouble((String) value);
                currentProject.setParameterValue(parameter, file, doubleValue);
            }
            if (parameter instanceof StringParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
            if (parameter instanceof ComboParameter) {
                if (value == null)
                    value = "";
                currentProject.setParameterValue(parameter, file, (String) value);
            }
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) StringParameter(net.sf.mzmine.parameters.parametertypes.StringParameter) DoubleParameter(net.sf.mzmine.parameters.parametertypes.DoubleParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject) ComboParameter(net.sf.mzmine.parameters.parametertypes.ComboParameter)

Example 27 with RawDataFile

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

the class ProjectParametersSetupDialog method copyParameterValuesFromRawDataFiles.

private void copyParameterValuesFromRawDataFiles() {
    MZmineProject currentProject = MZmineCore.getProjectManager().getCurrentProject();
    for (int dataFileIndex = 0; dataFileIndex < dataFiles.length; dataFileIndex++) {
        RawDataFile file = dataFiles[dataFileIndex];
        UserParameter<?, ?>[] parameters = currentProject.getParameters();
        // Loop through all parameters defined for this file
        for (UserParameter<?, ?> p : parameters) {
            // Check if this parameter has been seen before?
            Object[] values;
            if (!(parameterValues.containsKey(p))) {
                // No, initialize a new array of values for this parameter
                values = new Object[dataFiles.length];
                for (int i = 0; i < values.length; i++) values[i] = p.getValue();
                parameterValues.put(p, values);
            } else {
                values = parameterValues.get(p);
            }
            // Set value of this parameter for the current raw data file
            values[dataFileIndex] = currentProject.getParameterValue(p, file);
        }
    }
}
Also used : UserParameter(net.sf.mzmine.parameters.UserParameter) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) MZmineProject(net.sf.mzmine.datamodel.MZmineProject)

Example 28 with RawDataFile

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

the class ProjectParametersSetupDialog method initComponents.

private void initComponents() {
    panelParameterValues = new JPanel(new BorderLayout());
    scrollParameterValues = new JScrollPane();
    tablemodelParameterValues = new ParameterTableModel(new RawDataFile[0], new Hashtable<UserParameter<?, ?>, Object[]>());
    tableParameterValues = new JTable(tablemodelParameterValues);
    tableParameterValues.setColumnSelectionAllowed(true);
    tableParameterValues.setRowSelectionAllowed(false);
    scrollParameterValues.setViewportView(tableParameterValues);
    scrollParameterValues.setMinimumSize(new Dimension(100, 100));
    scrollParameterValues.setPreferredSize(new Dimension(100, 100));
    panelRemoveParameterButton = new JPanel(new FlowLayout(FlowLayout.LEFT));
    buttonAddParameter = new JButton("Add new parameter");
    buttonAddParameter.addActionListener(this);
    buttonImportParameters = new JButton("Import parameters and values...");
    buttonImportParameters.addActionListener(this);
    buttonRemoveParameter = new JButton("Remove selected parameter");
    buttonRemoveParameter.addActionListener(this);
    panelRemoveParameterButton.add(buttonAddParameter);
    panelRemoveParameterButton.add(buttonImportParameters);
    panelRemoveParameterButton.add(buttonRemoveParameter);
    panelParameterValues.add(scrollParameterValues, BorderLayout.CENTER);
    panelParameterValues.add(panelRemoveParameterButton, BorderLayout.SOUTH);
    panelParameterValues.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    panelOKCancelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT));
    buttonOK = new JButton("OK");
    buttonOK.addActionListener(this);
    buttonCancel = new JButton("Cancel");
    buttonCancel.addActionListener(this);
    panelOKCancelButtons.add(buttonOK);
    panelOKCancelButtons.add(buttonCancel);
    setLayout(new BorderLayout());
    add(panelParameterValues, BorderLayout.CENTER);
    add(panelOKCancelButtons, BorderLayout.SOUTH);
    pack();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) Hashtable(java.util.Hashtable) JTable(javax.swing.JTable) JButton(javax.swing.JButton) Dimension(java.awt.Dimension)

Example 29 with RawDataFile

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

the class RansacAlignerSetupDialog method updatePreview.

private void updatePreview() {
    PeakList peakListX = (PeakList) peakListsComboX.getSelectedItem();
    PeakList peakListY = (PeakList) peakListsComboY.getSelectedItem();
    if ((peakListX == null) || (peakListY == null))
        return;
    // Select the rawDataFile which has more peaks in each peakList
    int numPeaks = 0;
    RawDataFile file = null;
    RawDataFile file2 = null;
    for (RawDataFile rfile : peakListX.getRawDataFiles()) {
        if (peakListX.getPeaks(rfile).length > numPeaks) {
            numPeaks = peakListX.getPeaks(rfile).length;
            file = rfile;
        }
    }
    numPeaks = 0;
    for (RawDataFile rfile : peakListY.getRawDataFiles()) {
        if (peakListY.getPeaks(rfile).length > numPeaks) {
            numPeaks = peakListY.getPeaks(rfile).length;
            file2 = rfile;
        }
    }
    // Update the parameter set from dialog components
    updateParameterSetFromComponents();
    // Check the parameter values
    ArrayList<String> errorMessages = new ArrayList<String>();
    boolean parametersOK = super.parameterSet.checkParameterValues(errorMessages);
    if (!parametersOK) {
        StringBuilder message = new StringBuilder("Please check the parameter settings:\n\n");
        for (String m : errorMessages) {
            message.append(m);
            message.append("\n");
        }
        MZmineCore.getDesktop().displayMessage(this, message.toString());
        return;
    }
    // Ransac Alignment
    Vector<AlignStructMol> list = this.getVectorAlignment(peakListX, peakListY, file, file2);
    RANSAC ransac = new RANSAC(super.parameterSet);
    ransac.alignment(list);
    // Plot the result
    this.chart.removeSeries();
    this.chart.addSeries(list, peakListX.getName() + " vs " + peakListY.getName(), super.parameterSet.getParameter(RansacAlignerParameters.Linear).getValue());
    this.chart.printAlignmentChart(peakListX.getName() + " RT", peakListY.getName() + " RT");
}
Also used : RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayList(java.util.ArrayList) PeakList(net.sf.mzmine.datamodel.PeakList)

Example 30 with RawDataFile

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

the class RansacAlignerTask method run.

public void run() {
    setStatus(TaskStatus.PROCESSING);
    logger.info("Running Ransac aligner");
    // twice, first for score calculation, second for actual alignment.
    for (int i = 0; i < peakLists.length; i++) {
        totalRows += peakLists[i].getNumberOfRows() * 2;
    }
    // Collect all data files
    List<RawDataFile> allDataFiles = new ArrayList<RawDataFile>();
    for (PeakList peakList : peakLists) {
        for (RawDataFile dataFile : peakList.getRawDataFiles()) {
            // Each data file can only have one column in aligned feature list
            if (allDataFiles.contains(dataFile)) {
                setStatus(TaskStatus.ERROR);
                setErrorMessage("Cannot run alignment, because file " + dataFile + " is present in multiple feature lists");
                return;
            }
            allDataFiles.add(dataFile);
        }
    }
    // Create a new aligned feature list
    alignedPeakList = new SimplePeakList(peakListName, allDataFiles.toArray(new RawDataFile[0]));
    // Iterate source feature lists
    for (PeakList peakList : peakLists) {
        HashMap<PeakListRow, PeakListRow> alignmentMapping = this.getAlignmentMap(peakList);
        PeakListRow[] allRows = peakList.getRows();
        // Align all rows using mapping
        for (PeakListRow row : allRows) {
            PeakListRow targetRow = alignmentMapping.get(row);
            // If we have no mapping for this row, add a new one
            if (targetRow == null) {
                targetRow = new SimplePeakListRow(newRowID);
                newRowID++;
                alignedPeakList.addRow(targetRow);
            }
            // Add all peaks from the original row to the aligned row
            for (RawDataFile file : row.getRawDataFiles()) {
                targetRow.addPeak(file, row.getPeak(file));
            }
            // Add all non-existing identities from the original row to the
            // aligned row
            PeakUtils.copyPeakListRowProperties(row, targetRow);
            processedRows++;
        }
    }
    // Next feature list
    // Add new aligned feature list to the project
    project.addPeakList(alignedPeakList);
    // Edit by Aleksandr Smirnov
    PeakListRow row = alignedPeakList.getRow(1);
    double alignedRetTime = row.getAverageRT();
    for (Feature peak : row.getPeaks()) {
        double retTimeDelta = alignedRetTime - peak.getRT();
        RawDataFile dataFile = peak.getDataFile();
        SortedMap<Double, Double> chromatogram = new TreeMap<>();
        for (int scan : peak.getScanNumbers()) {
            DataPoint dataPoint = peak.getDataPoint(scan);
            double retTime = dataFile.getScan(scan).getRetentionTime() + retTimeDelta;
            if (dataPoint != null)
                chromatogram.put(retTime, dataPoint.getIntensity());
        }
    }
    // End of Edit
    // Add task description to peakList
    alignedPeakList.addDescriptionOfAppliedTask(new SimplePeakListAppliedMethod("Ransac aligner", parameters));
    logger.info("Finished RANSAC aligner");
    setStatus(TaskStatus.FINISHED);
}
Also used : ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) SimplePeakListAppliedMethod(net.sf.mzmine.datamodel.impl.SimplePeakListAppliedMethod) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) Feature(net.sf.mzmine.datamodel.Feature) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimplePeakListRow(net.sf.mzmine.datamodel.impl.SimplePeakListRow) PeakListRow(net.sf.mzmine.datamodel.PeakListRow) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) DataPoint(net.sf.mzmine.datamodel.DataPoint) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) SimplePeakList(net.sf.mzmine.datamodel.impl.SimplePeakList) PeakList(net.sf.mzmine.datamodel.PeakList)

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