def test_residue_string(): r = Residue(15, 3) assert r.residue_string == "15:3" r = Residue(15, 3, 2) assert r.residue_string == '15:3;2' r = Residue(15, 3, 2, ResidueModification('O-')) assert r.residue_string == 'O-15:3;2' r = Residue(15, 3, 2, ResidueModification('d')) assert r.residue_string == 'd15:3;2'
def test_eq(): r1 = ResidueModification('a') r2 = ResidueModification('a') r3 = ResidueModification('b') assert r1 == r2 assert r1 != r3 assert r2 != r3 assert 4 != r1 assert r1 != 4 assert r1 != None assert None != r1
def test_lipid_abbreviation(): l = Lipid(LipidClass('CE'), ResidueList([Residue(16, 2)])) assert l.abbreviation() == 'CE(16:2)' l = Lipid(LipidClass('CE'), ResidueList([Residue(16, 2), Residue(18, 1)])) assert l.abbreviation() == 'CE(16:2/18:1)' assert l.abbreviation(summed=True) == 'CE(34:3)' l = Lipid( LipidClass('CE'), ResidueList([ Residue(16, 2, modification=ResidueModification('O-')), Residue(18, 1) ])) assert l.abbreviation() == 'CE(O-16:2/18:1)' assert l.abbreviation(summed=True) == 'CE(O-34:3)' # no residues, assure that abbreviation/summed fails with AttributeError l = Lipid(LipidClass('CE')) assert l.abbreviation() == 'CE' assert l.abbreviation(summed=True) == 'CE'
def some_lipids_plain_list(): """ A handful of well formatted lipids, using all annotation elements. Return as Python list, not as LipidList Object """ # lists of names to draw from lipidclass_names = ['CE', 'Cer', 'TG'] modifications = ['d', 'O-', None, None] lipidlist = [] for i in range(10): lipidclass = LipidClass(random.choice(lipidclass_names)) num_of_residues = random.choice([1, 2, 3]) residuelist = ResidueList() for i in range(0, num_of_residues): residuelist.residues.append( Residue(random.randint(6, 50), random.randint(0, 10), modification=ResidueModification( random.choice(modifications)))) lipidlist.append(Lipid(lipidclass, residuelist)) return lipidlist
def parse(cls, string: str) -> Residue: """ Parse a string to create Residue. This will fail if a string with more than one residue is passed, the ResidueList is the default entrypoint. :param string: :return: """ string = string.strip() modification = False zstatelist = False # get zstatelist # check if ( and ) are in string if '(' in string and ')' in string: # get zstate string to continue, add leading ( again zstate_string = '(' + string.split('(', 1)[1] zstatelist = ZstateList.parse(zstate_string) # carbon atom part of the string to continue string = string.split('(', 1)[0] # get modifications # match if string does not start with digit if not re.match('^[0-9]', string): # get index of first digit index_first_digit = re.search('[0-9]', string).span()[0] prefix = string[:index_first_digit] modification = ResidueModification(prefix) string = string[index_first_digit:] log.debug(string) chain_def = string.split(';')[0] carbon_atoms, double_bonds = chain_def.split(':') if ';' in string: oxidation = int(string.split(';')[1]) else: oxidation = None return cls(int(carbon_atoms), int(double_bonds), oxidation, modification, zstatelist)
from lipidhandler.residuemodification import ResidueModification ############################################################## # A collection of mapping dictionaries ############################################################## PREFERRED_CLASS = {'TAG': 'TG', 'DAG': 'DG'} # TODO understand modifications and figure out if a default makes sense # or if we should output multiple Lipids if modification is not known CLASS_DEFAULT_MODIFICATION = { 'Cer': ResidueModification('d'), 'SM': ResidueModification('d'), 'HexCer': ResidueModification('d') }