Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
93 commits
Select commit Hold shift + click to select a range
8de58f2
Fix conflict
Jul 20, 2023
440b14c
Merge branch 'master' into Add_Cacao_lipid
Jul 21, 2023
c5f52e7
Add NAAnt annotation(Anthranilic acid) method
Jul 21, 2023
d5f64e7
Fix NALeu (neg) annotation method
Jul 21, 2023
20c5789
Merge branch 'master' into Add_Cacao_lipid
Jul 25, 2023
2600098
Add BisMeLPA [M-H]- and some fix
Jul 25, 2023
54d3e7b
added temporatly file of pc spectrum generator
Jan 6, 2025
39b4e15
Add SourceGenerator for lipid spectrum
YukiMatsuzawa Jan 7, 2025
f6d7b64
Add test project for lipid spectrum generator
YukiMatsuzawa Jan 7, 2025
7c606f5
Fix LipidSpectrumGeneratorTypeGenerator
YukiMatsuzawa Jan 8, 2025
504acb2
Add LipidSpectrumGeneratorTest
YukiMatsuzawa Jan 8, 2025
c105277
Add FormulaStringParser and related tests
YukiMatsuzawa Apr 28, 2025
5d90e75
Refactor element parsing and update ion metadata
YukiMatsuzawa Apr 28, 2025
62e8edd
Add support for ion charge and formula in calculations
YukiMatsuzawa May 9, 2025
ad79bac
Add FormulaSentenceParser with tests for chemical formulas
YukiMatsuzawa May 9, 2025
69a63f9
Update metadata key and enhance test project setup
YukiMatsuzawa May 13, 2025
409aff4
Fix class name
YukiMatsuzawa May 13, 2025
115a3d1
Add Term class
YukiMatsuzawa May 13, 2025
90a6945
Refactor and test Context class for term resolution
YukiMatsuzawa May 13, 2025
5368212
Reorder Context.Resolve process
YukiMatsuzawa May 13, 2025
8b88029
Move types
YukiMatsuzawa May 13, 2025
ae1728d
Enhance Context and parsing with dynamic variable resolution
YukiMatsuzawa May 14, 2025
03f3909
Refactor constants handling and improve test coverage
YukiMatsuzawa May 15, 2025
13c1d2c
Improve term resolution formatting in Context class
YukiMatsuzawa May 15, 2025
8ed7748
Add IsMarkupFormula method and corresponding unit tests
YukiMatsuzawa May 16, 2025
1eb387c
Add IsMarkupFormula method and improve regex handling
YukiMatsuzawa May 16, 2025
a5d09db
Add ParseMarkupFormula method and related unit tests
YukiMatsuzawa May 16, 2025
66e02ba
Refactor formula parsing and add markup formula support
YukiMatsuzawa May 16, 2025
a68ea0a
Handle markup formulas in FormulaSentenceParser
YukiMatsuzawa May 16, 2025
fe00569
Refactor and enhance formula parsing and resolution
YukiMatsuzawa May 16, 2025
13cb84f
Update <ClassIon> block values and add commented <NL> block
YukiMatsuzawa May 16, 2025
be80734
update \CompMs.Common.Lipidomics.SourceGeneratorTests\MsdialLipidCidS…
May 26, 2025
1e00a93
update xml
May 26, 2025
ffc5b8e
update xml(test)
May 26, 2025
a80941e
Fix a bug
YukiMatsuzawa May 27, 2025
030c7fe
add xml description and test code
May 30, 2025
8abc05b
Fix xml and some
May 30, 2025
47b6096
Update LipidClass Parsers and TotalChainParser
Jun 3, 2025
d8b670d
Update Lipid Source Generator
Jun 3, 2025
abc12f6
Update (WIP)
Jun 16, 2025
b8eea43
update (WIP)
Jun 18, 2025
4a13b63
Merge branch 'master' into experimental/lipid_spectrum_generator_by_m…
Jun 18, 2025
2001e61
update
Jun 20, 2025
05b8935
update
Jun 23, 2025
29783df
update
Jun 23, 2025
8e742fa
update lipid parsers (WIP)
Jul 2, 2025
a8a4e22
Merge branch 'master' into experimental/lipid_spectrum_generator_by_m…
Jul 2, 2025
ec3606d
update (lipid parser)
Jul 2, 2025
27f9b76
Merge remote-tracking branch 'origin/master' into experimental/lipid_…
Jul 4, 2025
0782e6f
fix
Jul 4, 2025
0f65125
Restore
Jul 4, 2025
70add4d
update
Jul 4, 2025
1a59819
(WIP) add TG_ESTLipidParser
Jul 8, 2025
7943e69
update tg_est lipid parser
Jul 9, 2025
e2c9a9f
update TG_EST lipid parser
Jul 9, 2025
e6dda08
update (cer classes)
Jul 16, 2025
5190ba9
update Lipid parsers and Lipidmics type generator
Jul 23, 2025
8f6d2be
update (cer classes and some)
Jul 31, 2025
c7d5ee6
Add lipidParsers
Aug 7, 2025
4678ecf
update
Aug 7, 2025
792b04b
Modified to enable calculation of divalent ions
Aug 22, 2025
2a4d11d
update (about HexCer and some)
Aug 22, 2025
bc0413d
Merge branch 'master' into experimental/lipid_spectrum_generator_by_m…
Sep 17, 2025
65e683c
Update LipidParser and more (WIP)
Sep 17, 2025
cd7e786
Add lipid parsers
Sep 18, 2025
484c6aa
update
Sep 19, 2025
0e2d18f
Temporary
Sep 19, 2025
71318a0
Merge branch 'Add_Cacao_lipid' into recovering_forgotten_merges
Sep 19, 2025
9148c77
fix error
Sep 19, 2025
bdab109
Fix error
Sep 19, 2025
cdfc267
Merge branch 'recovering_forgotten_merges' into experimental/lipid_sp…
Sep 19, 2025
d0acafe
update
Sep 19, 2025
f4ac66c
Merge branch 'master' into experimental/lipid_spectrum_generator_by_m…
Oct 1, 2025
921b814
Merge branch 'master' into experimental/lipid_spectrum_generator_by_m…
Oct 28, 2025
8147539
add lipid parser
Oct 29, 2025
5b867d5
update
Nov 4, 2025
09d4a92
Add lipid parsers
Nov 13, 2025
de4e447
update
Nov 13, 2025
718bb94
add lipid parsers
Nov 20, 2025
94e728d
Fix error
Nov 20, 2025
54339a3
update lipid parsers
Nov 26, 2025
c516e82
update lipidSpectrumGenerator
Nov 26, 2025
83e0f76
update
Dec 16, 2025
f383070
update
Dec 16, 2025
5b0441a
update XML
Dec 25, 2025
d532125
update xml and modify LipidSpectrumGeneratorTypeGenerator
Jan 29, 2026
e39ae89
update xml
Feb 2, 2026
dbdd3ff
update xml
Feb 3, 2026
9654d16
fix xml
Feb 3, 2026
d7e4024
Remove accidentally committed temp files
YukiMatsuzawa Sep 16, 2026
2934aa4
Merge remote-tracking branch 'origin/master' into claude/branch-verif…
YukiMatsuzawa Sep 16, 2026
2f5e0c9
Fix type mismatch in FormulaSentenceParserTest
YukiMatsuzawa Sep 16, 2026
b1d5aaa
Merge remote-tracking branch 'origin/master' into claude/sync-with-ma…
YukiMatsuzawa Oct 16, 2026
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ Assemblies/*.dll
/src/MSFINDER/MsfinderCommonStandard/Resources/InchikeyClassyfireDB-VS*.icd
/src/MSFINDER/MsfinderCommonStandard/Resources/MINEs-StructureDB-vs*.msd
/src/MSFINDER/MsfinderCommonStandard/Resources/MsfinderStructureDB-VS*.esd
/src/MSFINDER/MsfinderCommonStandard/Resources/MSMS-DBs-vs*.etm
/src/MSFINDER/MsfinderCommonStandard/Resources/MSMS-DBs-vs*.etm
45 changes: 45 additions & 0 deletions MsdialWorkbench.sln
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{DC2AD876-6
THIRD-PARTY-LICENSE-README.md = THIRD-PARTY-LICENSE-README.md
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompMs.Common.Lipidomics.SourceGenerator", "src\Common\CompMs.Common.Lipidomics.SourceGenerator\CompMs.Common.Lipidomics.SourceGenerator.csproj", "{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CompMs.Common.Lipidomics.SourceGeneratorTests", "tests\Common\CompMs.Common.Lipidomics.SourceGeneratorTests\CompMs.Common.Lipidomics.SourceGeneratorTests.csproj", "{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug vendor unsupported|Any CPU = Debug vendor unsupported|Any CPU
Expand Down Expand Up @@ -1864,6 +1868,46 @@ Global
{B1A4AFD3-ACF3-48B7-A55C-E37E082FEEBD}.Release|Any CPU.Build.0 = Release|Any CPU
{B1A4AFD3-ACF3-48B7-A55C-E37E082FEEBD}.Release|x64.ActiveCfg = Release|Any CPU
{B1A4AFD3-ACF3-48B7-A55C-E37E082FEEBD}.Release|x64.Build.0 = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug vendor unsupported|Any CPU.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug vendor unsupported|Any CPU.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug vendor unsupported|x64.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug vendor unsupported|x64.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug with args|Any CPU.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug with args|Any CPU.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug with args|x64.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug with args|x64.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug|x64.ActiveCfg = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Debug|x64.Build.0 = Debug|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release vendor unsupported|Any CPU.ActiveCfg = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release vendor unsupported|Any CPU.Build.0 = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release vendor unsupported|x64.ActiveCfg = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release vendor unsupported|x64.Build.0 = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release|Any CPU.Build.0 = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release|x64.ActiveCfg = Release|Any CPU
{DF6C0B4E-9148-423A-A8A0-F17B034FEEFA}.Release|x64.Build.0 = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug vendor unsupported|Any CPU.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug vendor unsupported|Any CPU.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug vendor unsupported|x64.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug vendor unsupported|x64.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug with args|Any CPU.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug with args|Any CPU.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug with args|x64.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug with args|x64.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug|x64.ActiveCfg = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Debug|x64.Build.0 = Debug|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release vendor unsupported|Any CPU.ActiveCfg = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release vendor unsupported|Any CPU.Build.0 = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release vendor unsupported|x64.ActiveCfg = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release vendor unsupported|x64.Build.0 = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release|Any CPU.Build.0 = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release|x64.ActiveCfg = Release|Any CPU
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46}.Release|x64.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -1888,6 +1932,7 @@ Global
{D8B8B716-2710-41F3-9C0F-A6709420C96F} = {B1471530-7779-4A57-9664-1E3A06F1A449}
{AF6A5BEF-8D19-4846-BC82-03782B53C092} = {765ED28C-F085-4C96-8E81-683BBAE67B01}
{B1A4AFD3-ACF3-48B7-A55C-E37E082FEEBD} = {26C4466E-49D5-404B-8777-8A92DDBBC35D}
{ACFCA3C6-FE86-4AE0-A890-D3C01E206A46} = {765ED28C-F085-4C96-8E81-683BBAE67B01}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A1654BE4-26EA-48AA-841E-6C2E3DEBDCCF}
Expand Down
56 changes: 56 additions & 0 deletions src/Common/CommonStandard/Lipidomics/ADGGALipidParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using CompMs.Common.Enum;
using CompMs.Common.FormulaGenerator.DataObj;
using System.Linq;
using System.Text.RegularExpressions;

namespace CompMs.Common.Lipidomics
{
public class ADGGALipidParser : ILipidParser
{
public string Target { get; } = "ADGGA";

private static readonly TotalChainParser chainsParser = TotalChainParser.BuildParser(3);
public static readonly string Pattern = $"^ADGGA\\s*(\\(O-)?(?<sn>{chainsParser.Pattern})$";
private static readonly Regex pattern = new Regex(Pattern, RegexOptions.Compiled);
private static readonly string AcylChainsPattern = $"(?<Chain>{AcylChainParser.Pattern})";

private static readonly TotalChainParser chainsParserSub = TotalChainParser.BuildParser(2);
public static readonly string PatternSub = $"^ADGGA\\s*\\(O-(?<OAcyl>{AcylChainsPattern})\\)?(?<sn1sn2>{chainsParserSub.Pattern})*?$";
private static readonly Regex patternSub = new Regex(PatternSub, RegexOptions.Compiled);


private static readonly double Skelton = new[]
{
MassDiffDictionary.CarbonMass * 9,
MassDiffDictionary.HydrogenMass * 13,
MassDiffDictionary.OxygenMass * 9,
}.Sum();


public ILipid Parse(string lipidStr)
{
var match = pattern.Match(lipidStr); //need consider
if (match.Success)
{
var group = match.Groups;
var chains = chainsParser.Parse(group["sn"].Value);
return new Lipid(LbmClass.ADGGA, Skelton + chains.Mass, chains);
}
else
{
var matchSub = patternSub.Match(lipidStr);
if (matchSub.Success)
{
matchSub = patternSub.Match(lipidStr.Replace("_","/"));
var groupSub = matchSub.Groups;
if (groupSub["sn1sn2"].Value != "")
{
var chains = chainsParser.Parse(groupSub["OAcyl"].Value + "/" + groupSub["sn1sn2"].Value);
return new Lipid(LbmClass.ADGGA, Skelton + chains.Mass, chains);
}
}
}
return null;
}
}
}
115 changes: 115 additions & 0 deletions src/Common/CommonStandard/Lipidomics/AHexCerLipidParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
using CompMs.Common.Enum;
using CompMs.Common.FormulaGenerator.DataObj;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace CompMs.Common.Lipidomics
{
public class AHexCerLipidParser : ILipidParser
{
public string Target { get; } = "AHexCer";

private static readonly AHexCerChainParser chainsParser = new AHexCerChainParser();
public static readonly string AHexCerPattern = $"^AHexCer\\s*(?<sn>{chainsParser.Pattern})$";
private static readonly Regex AHexCerpattern = new Regex(AHexCerPattern, RegexOptions.Compiled);

private static readonly double Skelton = new[]
{
MassDiffDictionary.CarbonMass * 6,
MassDiffDictionary.HydrogenMass * 9,
MassDiffDictionary.OxygenMass * 5,
}.Sum();


public ILipid Parse(string lipidStr)
{
var match = AHexCerpattern.Match(lipidStr);
if (match.Success)
{
var group = match.Groups;
var chains = chainsParser.Parse(group["sn"].Value);
if (group["MolecularSpeciesLevel"].Success)
{
return new Lipid(LbmClass.AHexCer, Skelton + MassDiffDictionary.OxygenMass - MassDiffDictionary.HydrogenMass + chains.Mass, chains);
}
return new Lipid(LbmClass.AHexCer, Skelton + chains.Mass, chains);
}
return null;
}
}
public class AHexCerChainParser : TotalChainParser
{
private static readonly string CarbonPattern = @"(?<carbon>\d+)";
private static readonly string DoubleBondPattern = @"(?<db>\d+)";
private static readonly string OxidizedPattern = @";(?<ox>O(?<oxnum>\d+)?)";
private static readonly string AcylChainsPattern = $"(?<CerAcyl>{AcylChainParser.Pattern})?";
private static readonly string OAcylPattern = $"\\(O-(?<OChain>{CarbonPattern}:{DoubleBondPattern})\\)";

private static readonly AcylChainParser AcylParser = new AcylChainParser();
private static readonly SphingoChainParser SphingoParser = new SphingoChainParser();

public int ChainCount { get; }

Check warning on line 52 in src/Common/CommonStandard/Lipidomics/AHexCerLipidParser.cs

View workflow job for this annotation

GitHub Actions / test

'AHexCerChainParser.ChainCount' hides inherited member 'TotalChainParser.ChainCount'. Use the new keyword if hiding was intended.
public int Capacity { get; }

Check warning on line 53 in src/Common/CommonStandard/Lipidomics/AHexCerLipidParser.cs

View workflow job for this annotation

GitHub Actions / test

'AHexCerChainParser.Capacity' hides inherited member 'TotalChainParser.Capacity'. Use the new keyword if hiding was intended.
public string Pattern { get; }

Check warning on line 54 in src/Common/CommonStandard/Lipidomics/AHexCerLipidParser.cs

View workflow job for this annotation

GitHub Actions / test

'AHexCerChainParser.Pattern' hides inherited member 'TotalChainParser.Pattern'. Use the new keyword if hiding was intended.
public bool HasSphingosine { get; }
private readonly Regex Expression;

private static readonly int chainCount = 3;
private static readonly int capacity = 3;
private readonly bool hasSphingosine;

public AHexCerChainParser()
: base(chainCount: chainCount, capacity: capacity, hasSphingosine: true, hasEther: false, atLeastSpeciesLevel: false)
{
ChainCount = chainCount;
Capacity = capacity;
var submolecularLevelPattern = $"(?<TotalChain>{CarbonPattern}:{DoubleBondPattern}({OxidizedPattern})?)";
var molecularSpeciesLevelPattern =
$"(?<MolecularSpeciesLevel>{OAcylPattern}(?<Sph>{CarbonPattern}:{DoubleBondPattern}({OxidizedPattern})?)?)";
var positionLevelPattern =
$"(?<PositionLevel>{OAcylPattern}(?<Sph>{SphingoChainParser.Pattern})/({AcylChainsPattern}))";

var totalPattern = new[] { positionLevelPattern, molecularSpeciesLevelPattern, submolecularLevelPattern };
Pattern = string.Join("|", totalPattern);
Expression = new Regex(Pattern, RegexOptions.Compiled);
HasSphingosine = hasSphingosine;
}

public new ITotalChain Parse(string lipidStr)
{
var match = Expression.Match(lipidStr);
if (match.Success)
{
var groups = match.Groups;
if (groups["TotalChain"].Success)
{
return ParseTotalChains(groups, ChainCount);
}
else
{
var chains = ParsePositionLevelChains(groups);
return chains;
}
}
return null;
}
private new PositionLevelChains ParsePositionLevelChains(GroupCollection groups)
{
var OAcyl = groups["OChain"].Captures.Cast<Capture>();
var Sph = SphingoParser.Parse(groups["Sph"].Value);
var CerAcyl = AcylParser.Parse(groups["CerAcyl"].Value);
var chains = OAcyl
.Select(c => AcylParser.Parse(c.Value))
.ToList();
chains.Add(Sph);
if (CerAcyl != null)
{
chains.Add(CerAcyl);
}
return new PositionLevelChains(chains.ToArray());
}

}
}

116 changes: 116 additions & 0 deletions src/Common/CommonStandard/Lipidomics/ASHexCerLipidParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using CompMs.Common.Enum;
using CompMs.Common.FormulaGenerator.DataObj;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace CompMs.Common.Lipidomics
{
public class ASHexCerLipidParser : ILipidParser
{
public string Target { get; } = "ASHexCer";

private static readonly ASHexCerChainParser chainsParser = new ASHexCerChainParser();
public static readonly string ASHexCerPattern = $"^ASHexCer\\s*(?<sn>{chainsParser.Pattern})$";
private static readonly Regex ASHexCerpattern = new Regex(ASHexCerPattern, RegexOptions.Compiled);

private static readonly double Skelton = new[]
{
MassDiffDictionary.CarbonMass * 6,
MassDiffDictionary.HydrogenMass * 9,
MassDiffDictionary.OxygenMass * 8,
MassDiffDictionary.SulfurMass * 1,
}.Sum();


public ILipid Parse(string lipidStr)
{
var match = ASHexCerpattern.Match(lipidStr);
if (match.Success)
{
var group = match.Groups;
var chains = chainsParser.Parse(group["sn"].Value);
if (group["MolecularSpeciesLevel"].Success)
{
return new Lipid(LbmClass.ASHexCer, Skelton + MassDiffDictionary.OxygenMass - MassDiffDictionary.HydrogenMass + chains.Mass, chains);
}
return new Lipid(LbmClass.ASHexCer, Skelton + chains.Mass, chains);
}
return null;
}
}
public class ASHexCerChainParser : TotalChainParser
{
private static readonly string CarbonPattern = @"(?<carbon>\d+)";
private static readonly string DoubleBondPattern = @"(?<db>\d+)";
private static readonly string OxidizedPattern = @";(?<ox>O(?<oxnum>\d+)?)";
private static readonly string AcylChainsPattern = $"(?<CerAcyl>{AcylChainParser.Pattern})?";
private static readonly string OAcylPattern = $"\\(O-(?<OChain>{AcylChainParser.Pattern})\\)";

private static readonly AcylChainParser AcylParser = new AcylChainParser();
private static readonly SphingoChainParser SphingoParser = new SphingoChainParser();

public int ChainCount { get; }
public int Capacity { get; }
public string Pattern { get; }
public bool HasSphingosine { get; }
private readonly Regex Expression;

private static readonly int chainCount = 3;
private static readonly int capacity = 3;
private readonly bool hasSphingosine;

public ASHexCerChainParser()
: base(chainCount: chainCount, capacity: capacity, hasSphingosine: true, hasEther: false, atLeastSpeciesLevel: false)
{
ChainCount = chainCount;
Capacity = capacity;
var submolecularLevelPattern = $"(?<TotalChain>{CarbonPattern}:{DoubleBondPattern}({OxidizedPattern})?)";
var molecularSpeciesLevelPattern =
$"(?<MolecularSpeciesLevel>{OAcylPattern}(?<Sph>{CarbonPattern}:{DoubleBondPattern}({OxidizedPattern})?)?)";
var positionLevelPattern =
$"(?<PositionLevel>{OAcylPattern}(?<Sph>{SphingoChainParser.Pattern})/({AcylChainsPattern}))";

var totalPattern = new[] { positionLevelPattern, molecularSpeciesLevelPattern, submolecularLevelPattern };
Pattern = string.Join("|", totalPattern);
Expression = new Regex(Pattern, RegexOptions.Compiled);
HasSphingosine = hasSphingosine;
}

public new ITotalChain Parse(string lipidStr)
{
var match = Expression.Match(lipidStr);
if (match.Success)
{
var groups = match.Groups;
if (groups["TotalChain"].Success)
{
return ParseTotalChains(groups, ChainCount);
}
else
{
var chains = ParsePositionLevelChains(groups);
return chains;
}
}
return null;
}
private new PositionLevelChains ParsePositionLevelChains(GroupCollection groups)
{
var OAcyl = groups["OChain"].Captures.Cast<Capture>();
var Sph = SphingoParser.Parse(groups["Sph"].Value);
var CerAcyl = AcylParser.Parse(groups["CerAcyl"].Value);
var chains = OAcyl
.Select(c => AcylParser.Parse(c.Value))
.ToList();
chains.Add(Sph);
if (CerAcyl != null)
{
chains.Add(CerAcyl);
}
return new PositionLevelChains(chains.ToArray());
}

}
}

Loading
Loading