Search in sources :

Example 1 with KovatsIndex

use of net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method loadFile.

/**
 * @return number of loaded files
 */
private int loadFile() {
    File lastFile = parameterSet.getParameter(KovatsIndexExtractionParameters.lastSavedFile).getValue();
    JFileChooser chooser = new JFileChooser();
    FileNameExtensionFilter ff = new FileNameExtensionFilter("Comma-separated values", "csv");
    chooser.addChoosableFileFilter(ff);
    chooser.setFileFilter(ff);
    if (lastFile != null)
        chooser.setSelectedFile(lastFile);
    chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    chooser.setMultiSelectionEnabled(true);
    if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
        File[] f = chooser.getSelectedFiles();
        TreeMap<KovatsIndex, Double> values = new TreeMap<>();
        // combine all
        for (File cf : f) {
            try {
                List<String> lines = Files.readLines(cf, StandardCharsets.UTF_8);
                for (String s : lines) {
                    String[] value = s.split(",");
                    try {
                        double time = Double.parseDouble(value[1]);
                        KovatsIndex ki = KovatsIndex.getByString(value[0]);
                        // average if already inserted
                        if (values.get(ki) != null) {
                            time = (time + values.get(ki)) / 2.0;
                            values.put(ki, time);
                        } else {
                            values.put(ki, time);
                        }
                    } catch (Exception e) {
                    // this try catch only identifies value columns
                    }
                }
                // set last file
                setLastFile(cf);
            } catch (IOException e) {
                logger.log(Level.WARNING, "Cannot read lines of " + cf.getAbsolutePath(), e);
            }
        }
        // all files are combined
        // to values component
        setValues(values);
        return f.length;
    }
    return 0;
}
Also used : IOException(java.io.IOException) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) TreeMap(java.util.TreeMap) IOException(java.io.IOException) JFileChooser(javax.swing.JFileChooser) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) File(java.io.File)

Example 2 with KovatsIndex

use of net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method updateKovatsList.

/**
 * Update kuvats list min max
 */
private void updateKovatsList() {
    updateParameterSetFromComponents();
    try {
        int min = parameterSet.getParameter(KovatsIndexExtractionParameters.minKovats).getValue();
        int max = parameterSet.getParameter(KovatsIndexExtractionParameters.maxKovats).getValue();
        KovatsIndex[] newValues = KovatsIndex.getRange(min, max);
        KovatsIndex[] newSelected = Stream.of(newValues).filter(k -> ArrayUtils.contains(selectedKovats, k)).toArray(KovatsIndex[]::new);
        parameterSet.getParameter(KovatsIndexExtractionParameters.kovats).setChoices(newValues);
        parameterSet.getParameter(KovatsIndexExtractionParameters.kovats).setValue(newSelected);
        MultiChoiceComponent kovatsc = (MultiChoiceComponent) getComponentForParameter(KovatsIndexExtractionParameters.kovats);
        kovatsc.setChoices(newValues);
        kovatsc.setValue(newSelected);
        revalidate();
        repaint();
        handleKovatsSelectionChange();
        // update parameters again
        updateParameterSetFromComponents();
    } catch (Exception e) {
    }
}
Also used : Color(java.awt.Color) StringComponent(net.sf.mzmine.parameters.parametertypes.StringComponent) Arrays(java.util.Arrays) FileAndPathUtil(net.sf.mzmine.util.files.FileAndPathUtil) ChartGestureHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureHandler) ValueMarker(org.jfree.chart.plot.ValueMarker) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) ParameterSet(net.sf.mzmine.parameters.ParameterSet) Event(net.sf.mzmine.chartbasics.gestures.ChartGesture.Event) JFileChooser(javax.swing.JFileChooser) BorderLayout(java.awt.BorderLayout) JComboBox(javax.swing.JComboBox) Image(java.awt.Image) Key(net.sf.mzmine.chartbasics.gestures.ChartGesture.Key) Font(java.awt.Font) Range(com.google.common.collect.Range) MZRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.MZRangeComponent) Icon(javax.swing.Icon) Logger(java.util.logging.Logger) StandardCharsets(java.nio.charset.StandardCharsets) Box(javax.swing.Box) ChartGestureDragDiffEvent(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffEvent) Dimension(java.awt.Dimension) List(java.util.List) Stream(java.util.stream.Stream) XYDataset(org.jfree.data.xy.XYDataset) Entry(java.util.Map.Entry) JCheckBox(javax.swing.JCheckBox) Entity(net.sf.mzmine.chartbasics.gestures.ChartGesture.Entity) RTRangeComponent(net.sf.mzmine.parameters.parametertypes.ranges.RTRangeComponent) BasicStroke(java.awt.BasicStroke) JPanel(javax.swing.JPanel) MZmineCore(net.sf.mzmine.main.MZmineCore) ColorPalettes(net.sf.mzmine.util.ColorPalettes) JTextField(javax.swing.JTextField) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) MzRangeFormulaCalculatorModule(net.sf.mzmine.modules.tools.mzrangecalculator.MzRangeFormulaCalculatorModule) RawDataFile(net.sf.mzmine.datamodel.RawDataFile) ArrayUtils(org.apache.commons.lang3.ArrayUtils) NumberFormat(java.text.NumberFormat) Button(net.sf.mzmine.chartbasics.gestures.ChartGesture.Button) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) GridLayout(java.awt.GridLayout) IntegerComponent(net.sf.mzmine.parameters.parametertypes.IntegerComponent) FileNameComponent(net.sf.mzmine.parameters.parametertypes.filenames.FileNameComponent) DelayedDocumentListener(net.sf.mzmine.framework.listener.DelayedDocumentListener) Files(com.google.common.io.Files) ChartGesture(net.sf.mzmine.chartbasics.gestures.ChartGesture) TxtWriter(net.sf.mzmine.util.io.TxtWriter) ImageIcon(javax.swing.ImageIcon) TICPlot(net.sf.mzmine.modules.visualization.tic.TICPlot) ParameterSetupDialog(net.sf.mzmine.parameters.dialogs.ParameterSetupDialog) BoxLayout(javax.swing.BoxLayout) Stroke(java.awt.Stroke) FlowLayout(java.awt.FlowLayout) MZTolerance(net.sf.mzmine.parameters.parametertypes.tolerances.MZTolerance) JButton(javax.swing.JButton) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) TICPlotType(net.sf.mzmine.modules.visualization.tic.TICPlotType) MigLayout(net.miginfocom.swing.MigLayout) Window(java.awt.Window) DecimalFormat(java.text.DecimalFormat) RawDataFilesSelection(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelection) TICSumDataSet(net.sf.mzmine.modules.visualization.tic.TICSumDataSet) IOException(java.io.IOException) IonizationType(net.sf.mzmine.datamodel.IonizationType) File(java.io.File) Consumer(java.util.function.Consumer) RectangleInsets(org.jfree.chart.ui.RectangleInsets) TreeMap(java.util.TreeMap) ChartGestureDragDiffHandler(net.sf.mzmine.chartbasics.gestures.ChartGestureDragDiffHandler) JLabel(javax.swing.JLabel) RawDataFilesSelectionType(net.sf.mzmine.parameters.parametertypes.selectors.RawDataFilesSelectionType) DialogLoggerUtil(net.sf.mzmine.util.DialogLoggerUtil) DoubleComponent(net.sf.mzmine.parameters.parametertypes.DoubleComponent) MultiChoiceComponent(net.sf.mzmine.parameters.parametertypes.MultiChoiceComponent) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) IOException(java.io.IOException)

Example 3 with KovatsIndex

use of net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method getCsvTable.

/**
 * GNPS GC MS formatted table (comma-separated)
 *
 * @param values
 *
 * @return
 */
private String getCsvTable(TreeMap<KovatsIndex, Double> values) {
    StringBuilder s = new StringBuilder();
    String nl = "\n";
    // header for GNPS
    // alkane name, num carbon(int), rt (seconds)
    s.append("Compound_Name,Carbon_Number,RT" + nl);
    DecimalFormat f = new DecimalFormat("0.##");
    for (Entry<KovatsIndex, Double> e : values.entrySet()) {
        s.append(e.getKey().getAlkaneName());
        s.append(",");
        s.append(String.valueOf(e.getKey().getNumCarbon()));
        s.append(",");
        // export rt in seconds for GNPS GC
        s.append(f.format(e.getValue() * 60.0));
        s.append(nl);
    }
    return s.toString();
}
Also used : DecimalFormat(java.text.DecimalFormat) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex)

Example 4 with KovatsIndex

use of net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method kovatsValuesChanged.

/**
 * replace markers
 */
private void kovatsValuesChanged() {
    // parse values
    if (parseValues() && chart != null) {
        // 
        chart.getChart().getXYPlot().clearDomainMarkers();
        if (markers == null)
            markers = new ArrayList<>();
        else
            markers.clear();
        for (Entry<KovatsIndex, Double> e : parsedValues.entrySet()) {
            ValueMarker marker = new ValueMarker(e.getValue(), ColorPalettes.getPositiveColor(MZmineCore.getConfiguration().getColorVision()), markerStroke);
            marker.setLabelOffset(new RectangleInsets(10, 0, 0, 0));
            marker.setLabelFont(new Font("Arial", Font.PLAIN, 12));
            marker.setLabelBackgroundColor(Color.WHITE);
            marker.setLabel(e.getKey().getShortName());
            chart.getChart().getXYPlot().addDomainMarker(marker);
            markers.add(marker);
        }
        revalidate();
        repaint();
    }
}
Also used : ArrayList(java.util.ArrayList) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) RectangleInsets(org.jfree.chart.ui.RectangleInsets) ValueMarker(org.jfree.chart.plot.ValueMarker) Font(java.awt.Font)

Example 5 with KovatsIndex

use of net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex in project mzmine2 by mzmine.

the class KovatsIndexExtractionDialog method pickRetentionTimes.

/**
 * Peak picking to define Kovats index retention times
 */
private void pickRetentionTimes() {
    updateParameterSetFromComponents();
    XYDataset data = getData();
    if (data == null)
        return;
    int items = data.getItemCount(0);
    List<Double> results = new ArrayList<>();
    // auto set noiselevel to max/20 if 0
    if (Double.compare(noiseLevel, 0d) <= 0) {
        for (int i = 0; i < items; i++) {
            double intensity = data.getYValue(0, i);
            noiseLevel = Math.max(noiseLevel, intensity);
        }
        noiseLevel = noiseLevel / 20.0;
    }
    double max = 0;
    double startI = Double.MAX_VALUE;
    double maxRT = 0;
    for (int i = 0; i < items; i++) {
        double rt = data.getXValue(0, i);
        double intensity = data.getYValue(0, i);
        // find max
        if (intensity > max && intensity >= noiseLevel) {
            max = intensity;
            maxRT = rt;
        }
        // minimize startI above noiseLevel
        if (intensity >= noiseLevel && (intensity < startI)) {
            startI = intensity;
            max = 0;
            maxRT = rt;
        }
        // is peak?
        if (max / startI > ratioEdge && max / intensity > ratioEdge) {
            // add peak
            results.add(maxRT);
            max = 0;
            startI = intensity;
            maxRT = rt;
        }
    }
    // set rt values
    StringBuilder s = new StringBuilder();
    int i = 0;
    double lastRT = 1;
    for (KovatsIndex ki : selectedKovats) {
        double rt = i < results.size() ? results.get(i) : lastRT + 1;
        s.append(ki.name() + ":" + rtFormat.format(rt) + ",");
        i++;
        lastRT = rt;
    }
    valuesComponent.setText(s.toString());
    kovatsValuesChanged();
}
Also used : ArrayList(java.util.ArrayList) KovatsIndex(net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex) XYDataset(org.jfree.data.xy.XYDataset)

Aggregations

KovatsIndex (net.sf.mzmine.modules.tools.kovats.KovatsValues.KovatsIndex)7 File (java.io.File)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 JFileChooser (javax.swing.JFileChooser)3 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)3 RawDataFile (net.sf.mzmine.datamodel.RawDataFile)3 Font (java.awt.Font)2 DecimalFormat (java.text.DecimalFormat)2 TreeMap (java.util.TreeMap)2 Range (com.google.common.collect.Range)1 Files (com.google.common.io.Files)1 BasicStroke (java.awt.BasicStroke)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 GridLayout (java.awt.GridLayout)1 Image (java.awt.Image)1 Stroke (java.awt.Stroke)1