Skip to content

Commit

Permalink
Add named wavelengths for the DAD chromatogram overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
Mailaender committed Aug 4, 2021
1 parent 96beeca commit ad58847
Show file tree
Hide file tree
Showing 27 changed files with 2,332 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ Export-Package: org.eclipse.chemclipse.model.baseline,
org.eclipse.chemclipse.model.traces,
org.eclipse.chemclipse.model.types,
org.eclipse.chemclipse.model.updates,
org.eclipse.chemclipse.model.versioning
org.eclipse.chemclipse.model.versioning,
org.eclipse.chemclipse.model.wavelengths
Import-Package: org.osgi.service.component.annotations;version="1.2.0"
Service-Component: OSGI-INF/org.eclipse.chemclipse.model.supplier.IMeasurementFilterProcessTypeSupplier.xml,
OSGI-INF/org.eclipse.chemclipse.model.supplier.IPeakFilterProcessTypeSupplier.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthias Mailänder - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.model.wavelengths;

public class NamedWavelength {

private String identifier = "";
private String wavelength = "";

public NamedWavelength(String identifier, String wavelength) {

this.identifier = identifier;
this.wavelength = wavelength;
}

public String getIdentifier() {

return identifier;
}

public void setIdentifier(String identifier) {

this.identifier = identifier;
}

public String getWavelengths() {

return wavelength;
}

public void setWavelengths(String wavelength) {

this.wavelength = wavelength;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2021 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Matthias Mailänder - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.model.wavelengths;

public class NamedWavelengthUtil {

private static final String TRADITIONAL = "Traditional Wavelengths";
private static final String MERCURY_LAMP = "Low Pressure Mercury Lamp";
private static final String ZINC_LAMP = "Zinc Lamp";
//

public static final String getDefaultWavelengths() {

NamedWavelengths namedWavelengths = new NamedWavelengths();
//
namedWavelengths.add(new NamedWavelength(TRADITIONAL, "214 254 280 365"));
namedWavelengths.add(new NamedWavelength(MERCURY_LAMP, "254")); // 253.7 nm
namedWavelengths.add(new NamedWavelength(ZINC_LAMP, "214"));
//
return namedWavelengths.save();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*******************************************************************************
* Copyright (c) 2020, 2021 Lablicate GmbH.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philip Wenig - initial API and implementation
* Matthias Mailänder - adapted for DAD
*******************************************************************************/
package org.eclipse.chemclipse.model.wavelengths;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.eclipse.chemclipse.logging.core.Logger;
import org.eclipse.chemclipse.support.util.NamedWavelengthListUtil;

public class NamedWavelengths {

private static final Logger logger = Logger.getLogger(NamedWavelengths.class);
//
private NamedWavelengthListUtil namedWavelengthListUtil = new NamedWavelengthListUtil();
private final Map<String, NamedWavelength> namedWavelengthMap = new HashMap<>();

public NamedWavelengths() {

}

/**
* Initializes this named Wavelengths from the given settings.
*
* @param namedWavelengths
*/
public NamedWavelengths(String namedWavelengths) {

load(namedWavelengths);
}

public void addAll(Collection<NamedWavelength> namedWavelengths) {

for(NamedWavelength namedWavelength : namedWavelengths) {
add(namedWavelength);
}
}

public void add(NamedWavelength namedWavelength) {

namedWavelengthMap.put(namedWavelength.getIdentifier(), namedWavelength);
}

public void remove(String identifier) {

namedWavelengthMap.remove(identifier);
}

public void remove(List<NamedWavelength> namedWavelengths) {

for(NamedWavelength namedWavelength : namedWavelengths) {
remove(namedWavelength);
}
}

public void remove(NamedWavelength namedWavelength) {

if(namedWavelength != null) {
namedWavelengthMap.remove(namedWavelength.getIdentifier());
}
}

public NamedWavelength get(String identifier) {

return namedWavelengthMap.get(identifier);
}

public Set<String> keySet() {

return namedWavelengthMap.keySet();
}

public Collection<NamedWavelength> values() {

return namedWavelengthMap.values();
}

public void clear() {

namedWavelengthMap.clear();
}

public String extractNamedWavelength(NamedWavelength namedWavelength) {

StringBuilder builder = new StringBuilder();
extractNamedWavelength(namedWavelength, builder);
return builder.toString();
}

public NamedWavelength extractNamedWavelength(String item) {

NamedWavelength namedWavelength = null;
//
if(!"".equals(item)) {
String[] values = item.split("\\" + NamedWavelengthListUtil.SEPARATOR_ENTRY);
String identifier = ((values.length > 0) ? values[0].trim() : "");
String Wavelengths = ((values.length > 1) ? values[1].trim() : "");
namedWavelength = new NamedWavelength(identifier, Wavelengths);
}
//
return namedWavelength;
}

public void load(String timeRanges) {

loadSettings(timeRanges);
}

public void loadDefault(String timeRanges) {

loadSettings(timeRanges);
}

public String save() {

StringBuilder builder = new StringBuilder();
Iterator<NamedWavelength> iterator = values().iterator();
while(iterator.hasNext()) {
NamedWavelength namedWavelength = iterator.next();
extractNamedWavelength(namedWavelength, builder);
if(iterator.hasNext()) {
builder.append(NamedWavelengthListUtil.SEPARATOR_TOKEN);
}
}
return builder.toString().trim();
}

public void importItems(File file) {

try (BufferedReader bufferedReader = new BufferedReader(new FileReader(file))) {
String line;
while((line = bufferedReader.readLine()) != null) {
NamedWavelength template = extractNamedWavelength(line);
if(template != null) {
add(template);
}
}
} catch(FileNotFoundException e) {
logger.warn(e);
} catch(IOException e) {
logger.warn(e);
}
}

public boolean exportItems(File file) {

try (PrintWriter printWriter = new PrintWriter(file)) {
/*
* Sort the items.
*/
List<NamedWavelength> namedWavelengths = new ArrayList<>(values());
Collections.sort(namedWavelengths, (r1, r2) -> r1.getIdentifier().compareTo(r2.getIdentifier()));
//
Iterator<NamedWavelength> iterator = namedWavelengths.iterator();
while(iterator.hasNext()) {
StringBuilder builder = new StringBuilder();
NamedWavelength template = iterator.next();
extractNamedWavelength(template, builder);
printWriter.println(builder.toString());
}
printWriter.flush();
return true;
} catch(FileNotFoundException e) {
logger.warn(e);
return false;
}
}

private void loadSettings(String timeRanges) {

if(!"".equals(timeRanges)) {
String[] items = namedWavelengthListUtil.parseString(timeRanges);
if(items.length > 0) {
for(String item : items) {
NamedWavelength namedWavelength = extractNamedWavelength(item);
if(namedWavelength != null) {
add(namedWavelength);
}
}
}
}
}

private void extractNamedWavelength(NamedWavelength namedWavelength, StringBuilder builder) {

builder.append(namedWavelength.getIdentifier());
builder.append(" ");
builder.append(NamedWavelengthListUtil.SEPARATOR_ENTRY);
builder.append(" ");
builder.append(namedWavelength.getWavelengths());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*******************************************************************************
* Copyright (c) 2020 Lablicate GmbH.
*
* All rights reserved.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Philip Wenig - initial API and implementation
*******************************************************************************/
package org.eclipse.chemclipse.support.util;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class NamedWavelengthListUtil {

public static final String SEPARATOR_TOKEN = ";";
public static final String SEPARATOR_ENTRY = "|";
public static final String SEPARATOR_TRACE = " ";

public String createList(String[] items) {

List<String> list = getValues(items);
String values = "";
for(String value : list) {
values = values.concat(value + SEPARATOR_TOKEN);
}
return values;
}

public String[] parseString(String stringList) {

String[] decodedArray;
if(stringList.contains(SEPARATOR_TOKEN)) {
decodedArray = stringList.split(SEPARATOR_TOKEN);
} else {
decodedArray = new String[]{stringList};
}
return decodedArray;
}

public List<String> getList(String preferenceEntry) {

List<String> values = new ArrayList<String>();
if(preferenceEntry != "") {
String[] items = parseString(preferenceEntry);
if(items.length > 0) {
for(String item : items) {
values.add(item);
}
}
}
Collections.sort(values);
return values;
}

private List<String> getValues(String[] items) {

List<String> values = new ArrayList<String>();
if(items != null) {
int size = items.length;
for(int i = 0; i < size; i++) {
values.add(items[i]);
}
}
return values;
}
}
Loading

0 comments on commit ad58847

Please sign in to comment.