Skip to content

Commit

Permalink
added possibility of incomplete molecular species structures such as …
Browse files Browse the repository at this point in the history
…'TG 18:0_42:2'
  • Loading branch information
dominik-kopczynski committed Oct 19, 2023
1 parent 5b53b56 commit b52820c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
6 changes: 6 additions & 0 deletions pygoslin/domain/FattyAcid.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def __init__(self, name, num_carbon = 0, double_bonds = 0, functional_groups = N
super().__init__(name, double_bonds = double_bonds, position = position, functional_groups = functional_groups)
self.num_carbon = num_carbon
self.lipid_FA_bond_type = lipid_FA_bond_type
self.unresolved_hidden_fa = False

if lipid_FA_bond_type == LipidFaBondType.LCB_REGULAR: self.functional_groups["[X]"] = [get_functional_group("X")]

Expand Down Expand Up @@ -184,6 +185,11 @@ def num_oxygens(self):

def compute_elements(self):
self.elements = {e: 0 for e in Element}
if self.unresolved_hidden_fa:
self.elements[Element.O] = 1
self.elements[Element.H] = -1
return self.elements

num_double_bonds = len(self.double_bonds) if type(self.double_bonds) != int else self.double_bonds
if self.lipid_FA_bond_type == LipidFaBondType.ETHER_PLASMENYL: num_double_bonds += 1

Expand Down
1 change: 1 addition & 0 deletions pygoslin/domain/LipidMolecularSpecies.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def __init__(self, head_group, fa = []):
# add 0:0 dummys
for i in range(len(fa), self.info.total_fa):
fatty_acid = FattyAcid("FA%i" % (i + 1), position = -1)
fatty_acid.unresolved_hidden_fa = 1 < len(fa) < self.info.poss_fa
self.info.add(fatty_acid)
self.fa[fatty_acid.name] = fatty_acid
self.fa_list.append(fatty_acid)
Expand Down
1 change: 1 addition & 0 deletions pygoslin/domain/LipidSpeciesInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def __init__(self, lipid_class):
self.level = None
self.num_ethers = 0
self.num_specified_fa = 0
self.poss_fa = all_lipids[lipid_class]["poss_fa"]
self.total_fa = all_lipids[lipid_class]["max_fa"]
self.extended_class = LipidFaBondType.ESTER
self.lipid_class = lipid_class
Expand Down
28 changes: 15 additions & 13 deletions pygoslin/parser/LipidBaseParserEventHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def sp_regular_lcb(self):



def prepare_headgroup_and_checks(self):
def prepare_headgroup_and_checks(self, allow_class_shift = True):
# checking if head group is a glyco-sphingolipid
"""
hg = self.head_group.lower()
Expand Down Expand Up @@ -118,17 +118,19 @@ def prepare_headgroup_and_checks(self):
# make lyso
can_be_lyso = "Lyso" in all_lipids[get_class("L" + self.head_group)]["specials"] if get_class("L" + self.head_group) < len(all_lipids) else False

if (true_fa + 1 == poss_fa or true_fa + 2 == poss_fa) and self.level != LipidLevel.SPECIES and headgroup.lipid_category == LipidCategory.GP and can_be_lyso:
if true_fa + 1 == poss_fa: self.head_group = "L" + self.head_group
else: self.head_group = "DL" + self.head_group
headgroup = HeadGroup(self.head_group, self.headgroup_decorators, self.use_head_group)
poss_fa = all_lipids[headgroup.lipid_class]["poss_fa"] if headgroup.lipid_class < len(all_lipids) else 0

elif (true_fa + 1 == poss_fa or true_fa + 2 == poss_fa) and self.level != LipidLevel.SPECIES and headgroup.lipid_category == LipidCategory.GL and self.head_group == "TG":
if true_fa + 1 == poss_fa: self.head_group = "DG"
else: self.head_group = "MG"
headgroup = HeadGroup(self.head_group, self.headgroup_decorators, self.use_head_group)
poss_fa = all_lipids[headgroup.lipid_class]["poss_fa"] if headgroup.lipid_class < len(all_lipids) else 0
if allow_class_shift:
if (true_fa + 1 == poss_fa or true_fa + 2 == poss_fa) and self.level != LipidLevel.SPECIES and headgroup.lipid_category == LipidCategory.GP and can_be_lyso:
if true_fa + 1 == poss_fa: self.head_group = "L" + self.head_group
else: self.head_group = "DL" + self.head_group
headgroup = HeadGroup(self.head_group, self.headgroup_decorators, self.use_head_group)
poss_fa = all_lipids[headgroup.lipid_class]["poss_fa"] if headgroup.lipid_class < len(all_lipids) else 0

elif (true_fa + 1 == poss_fa or true_fa + 2 == poss_fa) and self.level != LipidLevel.SPECIES and headgroup.lipid_category == LipidCategory.GL and self.head_group == "TG":
if true_fa + 1 == poss_fa: self.head_group = "DG"
else: self.head_group = "MG"
print(self.head_group)
headgroup = HeadGroup(self.head_group, self.headgroup_decorators, self.use_head_group)
poss_fa = all_lipids[headgroup.lipid_class]["poss_fa"] if headgroup.lipid_class < len(all_lipids) else 0


# check if all functional groups have a position to be full structure
Expand All @@ -143,7 +145,7 @@ def prepare_headgroup_and_checks(self):
if true_fa == 0 and poss_fa != 0:
raise ConstraintViolationException("No fatty acyl information lipid class '%s' provided." % headgroup.headgroup)

elif true_fa != poss_fa and self.level in {LipidLevel.COMPLETE_STRUCTURE, LipidLevel.FULL_STRUCTURE, LipidLevel.STRUCTURE_DEFINED, LipidLevel.SN_POSITION, LipidLevel.MOLECULAR_SPECIES}:
elif true_fa > poss_fa and self.level in {LipidLevel.COMPLETE_STRUCTURE, LipidLevel.FULL_STRUCTURE, LipidLevel.STRUCTURE_DEFINED, LipidLevel.SN_POSITION, LipidLevel.MOLECULAR_SPECIES}:
raise ConstraintViolationException("Number of specified fatty acyl chains (%i) not allowed for lipid class '%s' (having %i fatty aycl chains)." % (true_fa, headgroup.headgroup, poss_fa))

elif "Lyso" in all_lipids[get_class(self.head_group)]["specials"] and true_fa > poss_fa:
Expand Down
2 changes: 1 addition & 1 deletion pygoslin/parser/ShorthandParserEventHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ def set_double_bond_count(self, node):

def build_lipid(self, node):
if self.acer_species: self.fa_list[0].num_carbon -= 2
headgroup = self.prepare_headgroup_and_checks()
headgroup = self.prepare_headgroup_and_checks(False)

lipid = LipidAdduct()
lipid.adduct = self.adduct
Expand Down

0 comments on commit b52820c

Please sign in to comment.