Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed polarity from String to Enum #1567

Merged
merged 1 commit into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import org.eclipse.chemclipse.msd.model.core.IIon;
import org.eclipse.chemclipse.msd.model.core.IMassSpectra;
import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;
import org.eclipse.chemclipse.msd.model.exceptions.IonLimitExceededException;
import org.eclipse.chemclipse.msd.model.implementation.Ion;
import org.eclipse.chemclipse.msd.model.implementation.MassSpectra;
Expand Down Expand Up @@ -256,9 +257,9 @@ private void addMassSpectrum(IMassSpectra massSpectra, String massSpectrumData,
//
String ionMode = extractContentAsString(massSpectrumData, ionModePattern, 2);
if(ionMode.equals("POSITIVE")) {
massSpectrum.setPolarity("+");
massSpectrum.setPolarity(Polarity.POSITIVE);
} else if(ionMode.equals("NEGATIVE")) {
massSpectrum.setPolarity("-");
massSpectrum.setPolarity(Polarity.NEGATIVE);
}
/*
* MS/MS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public abstract class AbstractRegularLibraryMassSpectrum extends AbstractRegular
//
private ILibraryInformation libraryInformation;
private String precursorType;
private String polarity; // TODO enum?
private Polarity polarity;
private double neutralMass = 0.0d;
private Map<String, String> properties = null; // Initialization on demand

Expand Down Expand Up @@ -87,25 +87,24 @@ public void setNeutralMass(double neutralMass) {
}

@Override
public String getPolarity() {
public Polarity getPolarity() {

if(polarity != null) {
return polarity;
}
if(properties != null) {
String precursorType = getProperty(PROPERTY_PRECURSOR_TYPE);
if(precursorType.contains("]+")) {
return "+";
return Polarity.POSITIVE;
} else if(precursorType.contains("]-")) {
return "-";
return Polarity.NEGATIVE;
}
}
//
return "";
return Polarity.NONE;
}

@Override
public void setPolarity(String polarity) {
public void setPolarity(Polarity polarity) {

this.polarity = polarity;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ public interface IRegularLibraryMassSpectrum extends IRegularMassSpectrum, ILibr

void setNeutralMass(double neutralMass);

/**
* Returns the polarity if set.
*
* Otherwise returns the polarity (+) or (-)
* if the precursor type is set.
*
* If none is available "" will be returned.
*
* @return String
*/
String getPolarity();

void setPolarity(String polarity);
Polarity getPolarity();

void setPolarity(Polarity polarity);

Set<String> getPropertyKeySet();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2023 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.msd.model.core;

import org.eclipse.chemclipse.support.text.ILabel;

public enum Polarity implements ILabel {

POSITIVE("+"), //
NEGATIVE("-"), //
NONE("");

private String label;

private Polarity(String label) {

this.label = label;
}

@Override
public String label() {

return label;
}

public static String[][] getOptions() {

return ILabel.getOptions(values());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.chemclipse.msd.converter.supplier.amdis.io.ImportConverterMspTestCase;
import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.IScanMSD;
import org.eclipse.chemclipse.msd.model.core.Polarity;
import org.junit.Test;

public class MassBankMS2ImportConverter_ITest extends ImportConverterMspTestCase {
Expand Down Expand Up @@ -51,7 +52,7 @@ public void testMassSpectrum() {
assertEquals(288.1225d, regularLibraryMassSpectrum.getPrecursorIon());
assertEquals(287.11575d, regularLibraryMassSpectrum.getNeutralMass());
assertEquals("30(NCE)", regularLibraryMassSpectrum.getProperty(IRegularLibraryMassSpectrum.PROPERTY_COLLISION_ENERGY));
assertEquals("+", regularLibraryMassSpectrum.getPolarity());
assertEquals(Polarity.POSITIVE, regularLibraryMassSpectrum.getPolarity());
assertEquals("[M+H]+", regularLibraryMassSpectrum.getProperty(IRegularLibraryMassSpectrum.PROPERTY_PRECURSOR_TYPE));
assertEquals("Q-Exactive Orbitrap Thermo Scientific", regularLibraryMassSpectrum.getProperty(IRegularLibraryMassSpectrum.PROPERTY_INSTRUMENT_NAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.chemclipse.msd.model.implementation;

import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;

import junit.framework.TestCase;

Expand Down Expand Up @@ -52,7 +53,7 @@ public void test3() {

public void test4() {

assertEquals("", massSpectrum.getPolarity());
assertEquals(Polarity.NONE, massSpectrum.getPolarity());
}

public void test5() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.chemclipse.msd.model.implementation;

import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;

import junit.framework.TestCase;

Expand Down Expand Up @@ -55,7 +56,7 @@ public void test3() {

public void test4() {

assertEquals("+", massSpectrum.getPolarity());
assertEquals(Polarity.POSITIVE, massSpectrum.getPolarity());
}

public void test5() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.chemclipse.msd.model.implementation;

import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;

import junit.framework.TestCase;

Expand Down Expand Up @@ -55,7 +56,7 @@ public void test3() {

public void test4() {

assertEquals("-", massSpectrum.getPolarity());
assertEquals(Polarity.NEGATIVE, massSpectrum.getPolarity());
}

public void test5() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.chemclipse.msd.model.implementation;

import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;

import junit.framework.TestCase;

Expand Down Expand Up @@ -55,7 +56,7 @@ public void test3() {

public void test4() {

assertEquals("+", massSpectrum.getPolarity());
assertEquals(Polarity.POSITIVE, massSpectrum.getPolarity());
}

public void test5() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.chemclipse.msd.model.implementation;

import org.eclipse.chemclipse.msd.model.core.IRegularLibraryMassSpectrum;
import org.eclipse.chemclipse.msd.model.core.Polarity;

import junit.framework.TestCase;

Expand Down Expand Up @@ -55,7 +56,7 @@ public void test3() {

public void test4() {

assertEquals("+", massSpectrum.getPolarity());
assertEquals(Polarity.POSITIVE, massSpectrum.getPolarity());
}

public void test5() {
Expand Down