Skip to content

Commit

Permalink
updates for v2.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
dominik-kopczynski committed Sep 12, 2023
1 parent 9a642b0 commit 3e7e691
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 69 deletions.
53 changes: 49 additions & 4 deletions parsers/src/main/java/org/lifstools/jgoslin/domain/Headgroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public final class Headgroup {
public static HashMap<String, Integer> StringClass = new HashMap<>();
public static HashMap<Integer, String> ClassString = new HashMap<>();
public static HashSet<String> exceptionHeadgroups = new HashSet<>(Arrays.asList("Cer", "SPB"));
protected KnownFunctionalGroups knownFunctionalGroups = new KnownFunctionalGroups();

private String headgroup;
private LipidCategory lipidCategory;
Expand All @@ -55,17 +56,57 @@ public final class Headgroup {
entry(LipidCategory.FA, "FA"),
entry(LipidCategory.SL, "SL")
);

private static final Map<String, ArrayList<String>> GLYCO_TABLE = Map.ofEntries(
entry("ga2", new ArrayList<String>(Arrays.asList("GalNAc", "Gal", "Glc"))),
entry("gb3", new ArrayList<String>(Arrays.asList("Gal", "Gal", "Glc"))),
entry("gb4", new ArrayList<String>(Arrays.asList("GalNAc", "Gal", "Gal", "Glc"))),
entry("gd1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gd1a", new ArrayList<String>(Arrays.asList("Hex", "Hex", "Hex", "HexNAc", "NeuAc", "NeuAc"))),
entry("gd2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gd3", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gm1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "Gal", "Glc"))),
entry("gm2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "Gal", "Glc"))),
entry("gm3", new ArrayList<String>(Arrays.asList("NeuAc", "Gal", "Glc"))),
entry("gm4", new ArrayList<String>(Arrays.asList("NeuAc", "Gal"))),
entry("gp1", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gq1", new ArrayList<String>(Arrays.asList("NeuAc", "Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt3", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "NeuAc", "Gal", "Glc")))
);

public Headgroup(String _headgroup) {
this(_headgroup, null, false);
}

public Headgroup(String _headgroup, ArrayList<HeadgroupDecorator> _decorators, boolean _use_headgroup) {
decorators = new ArrayList<>();

String hg = _headgroup.toLowerCase();
if (GLYCO_TABLE.containsKey(hg)){
for (String carbohydrate : GLYCO_TABLE.get(hg)){
FunctionalGroup functional_group = null;
try {
functional_group = knownFunctionalGroups.get(carbohydrate);
} catch (Exception e) {
throw new LipidParsingException("Carbohydrate '" + carbohydrate + "' unknown");
}

functional_group.getElements().put(Element.O, functional_group.getElements().get(Element.O) - 1);
decorators.add((HeadgroupDecorator) functional_group);

}
_headgroup = "Cer";
}

headgroup = _headgroup;
lipidCategory = getCategory(_headgroup);
lipidClass = getClass(headgroup);
useHeadgroup = _use_headgroup;
decorators = (_decorators != null) ? _decorators : new ArrayList<>();
if (_decorators != null){
for (HeadgroupDecorator hgd : _decorators) decorators.add(hgd);
}
spException = (lipidCategory == LipidCategory.SP) && exceptionHeadgroups.contains(LipidClasses.getInstance().get(lipidClass).lipidClassName) && (decorators.isEmpty());
}

Expand Down Expand Up @@ -136,9 +177,13 @@ public String getLipidString(LipidLevel level) {
if (!LipidLevel.isLevel(level, LipidLevel.COMPLETE_STRUCTURE.level | LipidLevel.FULL_STRUCTURE.level | LipidLevel.STRUCTURE_DEFINED.level)) {
ArrayList<HeadgroupDecorator> decoratorsTmp = new ArrayList<>();
for (HeadgroupDecorator hgd : decorators) {
if (!hgd.isSuffix()) {
decoratorsTmp.add((HeadgroupDecorator)hgd.copy());
}
if (hgd.isSuffix()) continue;

HeadgroupDecorator hgd_copy = (HeadgroupDecorator)hgd.copy();
hgd_copy.name = hgd_copy.name.replace("Gal", "Hex");
hgd_copy.name = hgd_copy.name.replace("Glc", "Hex");
hgd_copy.name = hgd_copy.name.replace("S(3')", "S");
decoratorsTmp.add(hgd_copy);
}
Collections.sort(decoratorsTmp);
for (int i = decoratorsTmp.size() - 1; i > 0; --i){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,11 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import static java.util.Map.entry;
import java.util.TreeMap;
import org.lifstools.jgoslin.domain.Cycle;
import org.lifstools.jgoslin.domain.DoubleBonds;
import org.lifstools.jgoslin.domain.Element;
import org.lifstools.jgoslin.domain.FunctionalGroup;
import org.lifstools.jgoslin.domain.KnownFunctionalGroups;
import org.lifstools.jgoslin.domain.LipidParsingException;

/**
*
Expand All @@ -64,25 +61,6 @@ public abstract class LipidBaseParserEventHandler extends BaseParserEventHandler
protected ArrayList<HeadgroupDecorator> headgroupDecorators = new ArrayList<>();
protected boolean useHeadGroup = false;
protected KnownFunctionalGroups knownFunctionalGroups;

private static final Map<String, ArrayList<String>> GLYCO_TABLE = Map.ofEntries(
entry("ga2", new ArrayList<String>(Arrays.asList("GalNAc", "Gal", "Glc"))),
entry("gb3", new ArrayList<String>(Arrays.asList("Gal", "Gal", "Glc"))),
entry("gb4", new ArrayList<String>(Arrays.asList("GalNAc", "Gal", "Gal", "Glc"))),
entry("gd1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gd1a", new ArrayList<String>(Arrays.asList("Hex", "Hex", "Hex", "HexNAc", "NeuAc", "NeuAc"))),
entry("gd2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gd3", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gm1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "Gal", "Glc"))),
entry("gm2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "Gal", "Glc"))),
entry("gm3", new ArrayList<String>(Arrays.asList("NeuAc", "Gal", "Glc"))),
entry("gm4", new ArrayList<String>(Arrays.asList("NeuAc", "Gal"))),
entry("gp1", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gq1", new ArrayList<String>(Arrays.asList("NeuAc", "Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt1", new ArrayList<String>(Arrays.asList("Gal", "GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt2", new ArrayList<String>(Arrays.asList("GalNAc", "NeuAc", "NeuAc", "NeuAc", "Gal", "Glc"))),
entry("gt3", new ArrayList<String>(Arrays.asList("NeuAc", "NeuAc", "NeuAc", "Gal", "Glc")))
);

protected static HashSet<String> SP_EXCEPTION_CLASSES = new HashSet<>(Arrays.asList("Cer", "Ceramide", "Sphingosine", "So", "Sphinganine", "Sa", "SPH", "Sph", "LCB"));

Expand All @@ -99,25 +77,6 @@ protected boolean spRegularLcb() {
}

protected Headgroup prepareHeadgroupAndChecks() {

String hg = headGroup.toLowerCase();
if (GLYCO_TABLE.containsKey(hg)){
for (String carbohydrate : GLYCO_TABLE.get(hg)){
FunctionalGroup functional_group = null;
try {
functional_group = knownFunctionalGroups.get(carbohydrate);
} catch (Exception e) {
throw new LipidParsingException("Carbohydrate '" + carbohydrate + "' unknown");
}

functional_group.getElements().put(Element.O, functional_group.getElements().get(Element.O) - 1);
headgroupDecorators.add((HeadgroupDecorator) functional_group);

}
headGroup = "Cer";
}


Headgroup headgroup = new Headgroup(headGroup, headgroupDecorators, useHeadGroup);
if (useHeadGroup) {
return headgroup;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ public LipidMapsParserEventHandler(KnownFunctionalGroups knownFunctionalGroups)
} catch (Exception e) {
throw new LipidParsingException("Cannot initialize LipidMapsParserEventHandler.");
}

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public ShorthandParserEventHandler(KnownFunctionalGroups knownFunctionalGroups)
entry("hg_pip_pure_t_pre_event", this::setHeadgroupName),
entry("hg_PE_PS_pre_event", this::setHeadgroupName),
// set head group headgroupDecorators
entry("carbohydrate_pre_event", this::setCarbohydrate),
entry("carbohydrate_sulfo_pre_event", this::setCarbohydrate),
entry("carbohydrate_structural_pre_event", this::setCarbohydrateStructural),
entry("carbohydrate_sn_pre_event", this::setCarbohydrate),
entry("carbohydrate_iso_pre_event", this::setCarbohydrate),
entry("carbohydrate_sn_position_pre_event", this::setCarbohydrateSnPosition),
entry("carbohydrate_isomeric_pre_event", this::setCarbohydrateIsomeric),
entry("glyco_sphingo_lipid_pre_event", this::setGlycoSphingoLipid),
entry("carbohydrate_number_pre_event", this::setCarbohydrateNumber),
Expand Down Expand Up @@ -350,8 +350,8 @@ private void setFattyAcylStereo(TreeNode node){
}


private void setCarbohydrateStructural(TreeNode node) {
setLipidLevel(LipidLevel.STRUCTURE_DEFINED);
private void setCarbohydrateSnPosition(TreeNode node) {
setLipidLevel(LipidLevel.SN_POSITION);
tmp.put("func_group_head", 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ public static void setupParser() {
handler = parser.newEventHandler();
}


@Test
public void testDefaultConstructorTest() {
LipidMapsParser gp = new LipidMapsParser();
assertNotNull(gp);
}

@Test
public void testLipidMapsParserTest() {
public void testLipidMapsParserTest() {
LipidAdduct lipid = parser.parse("Cer(d18:1(8Z)/24:0)", handler);
assertEquals("Cer 18:1(8);(OH)2/24:0", lipid.getLipidString(LipidLevel.STRUCTURE_DEFINED));
assertEquals("Cer 18:1;O2/24:0", lipid.getLipidString(LipidLevel.SN_POSITION));
Expand Down Expand Up @@ -124,10 +125,8 @@ public void testLipidMapsParserTest() {
lipid = parser.parse("TG(20:0/22:3(10Z,13Z,16Z)/22:5(7Z,10Z,13Z,16Z,19Z))[iso6]", handler);
assertEquals("TG", lipid.getClassName());

//lipid = parser.parse("GalNAcβ1-4(Galβ1-4GlcNAcβ1-3)Galβ1-4Glcβ-Cer(d18:1/24:1(15Z))", handler);
// Lipid Maps Species name is currently "Hex(3)-HexNAc(2)-Cer 42:2;O2"
//assertEquals("GalGalGalNAcGlcGlcNAcCer 42:2;O2", lipid.getLipidString(LipidLevel.SPECIES));
//assertEquals(1539.9388d, lipid.getMass(), 1.0e-4);
lipid = parser.parse("GalNAc-4(Gal-4GlcNAc-3)Gal-4Glc-Cer(d18:1/24:1(15Z))", handler);
assertEquals("Hex3HexNAc2Cer 42:2;O2", lipid.getLipidString(LipidLevel.SPECIES));
}

@Test
Expand All @@ -140,7 +139,7 @@ public void testLabeledLipids() {
assertEquals(767.6290d, lipid.getMass(), 1.0e-4);
assertEquals("C42H76NO8PH'7", lipid.getSumFormula());
}


@ParameterizedTest(name = "{index}: {0}")
@CsvFileSource(resources = "/testfiles/lipid-maps-test.csv", numLinesToSkip = 0, delimiter = ',', encoding = "UTF-8", lineSeparator = "\n")
Expand All @@ -149,6 +148,7 @@ public void testLipidMapsParserFromFileTest(String lipid_name, String correct_li
//skip test
assertTrue(true, "Skipping trivial / unsupported name: " + lipid_name);
} else {
System.out.println(lipid_name);
LipidAdduct lipid = parser.parse(lipid_name, handler);
assertTrue(lipid != null);
if (!correct_lipid_name.equals("Unsupported lipid") && correct_lipid_name.length() > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,25 @@ public void testShorthandParserTest() {
l = parser.parse("Gal-Cer(1) 18:1(5Z);3OH/24:0", handler);
assertEquals("Gal-Cer(1) 18:1(5Z);3OH/24:0", l.getLipidString());
assertEquals("Gal-Cer 18:1(5);OH/24:0", l.getLipidString(LipidLevel.STRUCTURE_DEFINED));
assertEquals("GalCer 18:1;O2/24:0", l.getLipidString(LipidLevel.SN_POSITION));
assertEquals("GalCer 18:1;O2/24:0", l.getLipidString(LipidLevel.MOLECULAR_SPECIES));
assertEquals("GalCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("HexCer 18:1;O2/24:0", l.getLipidString(LipidLevel.SN_POSITION));
assertEquals("HexCer 18:1;O2/24:0", l.getLipidString(LipidLevel.MOLECULAR_SPECIES));
assertEquals("HexCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("C48H93NO8", l.getSumFormula());

l = parser.parse("Gal-Cer 18:1(5);OH/24:0", handler);
assertEquals("Gal-Cer 18:1(5);OH/24:0", l.getLipidString());
assertEquals("GalCer 18:1;O2/24:0", l.getLipidString(LipidLevel.SN_POSITION));
assertEquals("GalCer 18:1;O2/24:0", l.getLipidString(LipidLevel.MOLECULAR_SPECIES));
assertEquals("GalCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("HexCer 18:1;O2/24:0", l.getLipidString(LipidLevel.SN_POSITION));
assertEquals("HexCer 18:1;O2/24:0", l.getLipidString(LipidLevel.MOLECULAR_SPECIES));
assertEquals("HexCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("C48H93NO8", l.getSumFormula());

l = parser.parse("GalCer 18:1;O2/24:0", handler);
assertEquals("GalCer 18:1;O2/24:0", l.getLipidString());
assertEquals("GalCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("HexCer 18:1;O2/24:0", l.getLipidString());
assertEquals("HexCer 42:1;O2", l.getLipidString(LipidLevel.SPECIES));
assertEquals("C48H93NO8", l.getSumFormula());

l = parser.parse("GalCer 42:1;O2", handler);
assertEquals("GalCer 42:1;O2", l.getLipidString());
assertEquals("HexCer 42:1;O2", l.getLipidString());
assertEquals("C48H93NO8", l.getSumFormula());

l = parser.parse("SPB 18:1(4Z);1OH,3OH", handler);
Expand Down Expand Up @@ -181,12 +181,12 @@ public void testShorthandParserTest() {
assertEquals("EPC 34:2;O2", l.getLipidString());
assertEquals("C36H71N2O6P", l.getSumFormula());

l = parser.parse("Hex-Hex-Cer(1) 17:1(5E);15Me[R];3OH[R],4OH[S]/22:0;2OH[R]", handler);
l = parser.parse("Gal-Glc-Cer(1) 17:1(5E);15Me[R];3OH[R],4OH[S]/22:0;2OH[R]", handler);
assertEquals(LipidLevel.COMPLETE_STRUCTURE, l.getLipidLevel());
l = parser.parse("Hex-Hex-Cer(1) 17:1(5E);15Me;3OH,4OH/22:0;2OH", handler);
l = parser.parse("Gal-Glc-Cer(1) 17:1(5E);15Me;3OH,4OH/22:0;2OH", handler);
assertEquals(LipidLevel.FULL_STRUCTURE, l.getLipidLevel());
assertEquals("Hex-Hex-Cer(1) 17:1(5E);15Me;3OH,4OH/22:0;2OH", l.getLipidString());
assertEquals("Hex-Hex-Cer 17:1(5);Me;(OH)2/22:0;OH", l.getLipidString(LipidLevel.STRUCTURE_DEFINED));
assertEquals("Gal-Glc-Cer(1) 17:1(5E);15Me;3OH,4OH/22:0;2OH", l.getLipidString());
assertEquals("Gal-Glc-Cer 17:1(5);Me;(OH)2/22:0;OH", l.getLipidString(LipidLevel.STRUCTURE_DEFINED));
assertEquals("Hex2Cer 18:1;O3/22:0;O", l.getLipidString(LipidLevel.SN_POSITION));

assertThrows(LipidException.class, () -> {
Expand Down

0 comments on commit 3e7e691

Please sign in to comment.