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;
}
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) {
}
}
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();
}
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();
}
}
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();
}
Aggregations