Beispiel #1
0
    def headgroup_from_lipid_name(self, names, database=None):
        """For one database record attempts to identify the lipid class
        by looking up keywords.
        Calls greek name identification, greek fatty acid names are
        identified as 'FA'.
        
        Returns tuple of `lipproc.Headgroup` object and expected chain types.

        Parameters
        ----------
        names :
            
        database :
             (Default value = None)

        Returns
        -------

        """

        if database is not None:

            database = database.lower()

        else:

            database = self.database

        names = '|'.join(names)

        db = 'lmp' if database == 'lipidmaps' else 'swl'

        for lipclass, spec in iteritems(self.lipnames):
            for kwset in spec[db]:
                matched = [kw in names for kw in kwset['pos']]
                if sum(matched) == len(kwset['pos']) and \
                    sum(matched) > 0:
                    matched = [kw in names for kw in kwset['neg']]
                    if sum(matched) == 0:
                        return (
                            lipproc.Headgroup(
                                main=lipclass[1],  # main class, e.g. Cer
                                sub=lipclass[0]  # subclass, e.g. Hex
                            ),
                            spec['chains'])

        fa_name = self.process_fa_name(names)

        if fa_name:

            return (lipproc.Headgroup(main=fa_name), (fa_name, ))

        return None, None
Beispiel #2
0
    def test_aggregator_adduct_lookup(self):
        """ """

        result = self.mda.adduct_lookup(728.605042778354,
                                        ionmode='pos')['[M+H]+'][1]

        assert 'SLM:000391523' in [i.lab.db_id for i in result]

        swl_cer1p = [i for i in result if i.lab.db_id == 'SLM:000391523'][0]

        assert 'Ceramide phosphate (d42:2)' in swl_cer1p.lab.names
        assert '' not in swl_cer1p.lab.names
        assert '1P' in swl_cer1p.hg.sub

        lyp_cer1p = lipproc.LipidRecord(
            lab=lipproc.LipidLabel(
                db_id=None,
                db='lipyd.lipid',
                names=('Cer-1P(DH42:2)', ),
                formula='C42H82N1O6P1',
            ),
            hg=lipproc.Headgroup(main='Cer', sub=('1P', )),
            chainsum=lipproc.ChainSummary(
                c=42,
                u=2,
                typ=('Sph', 'FA'),
                attr=(lipproc.ChainAttr(sph='DH', ether=False, oh=()),
                      lipproc.ChainAttr(sph='', ether=False, oh=())),
            ),
            chains=(),
        )

        assert lyp_cer1p in list(result)
Beispiel #3
0
    def __init__(self,
                 sn1='H',
                 sn2='H',
                 sn3='H',
                 charge=None,
                 pcharge=0,
                 ncharge=0,
                 hg=None,
                 name='Glycerol',
                 typ='G',
                 **kwargs):

        self.pcharge = pcharge
        self.ncharge = ncharge
        self.netcharge = (charge if charge is not None else self.pcharge -
                          self.ncharge)
        self.typ = typ
        hg = hg or lipproc.Headgroup(main=name)

        metabolite.AbstractMetabolite.__init__(self,
                                               core='C3H5O3',
                                               subs=[
                                                   self.get_substituent(sn1),
                                                   self.get_substituent(sn2),
                                                   self.get_substituent(sn3)
                                               ],
                                               charge=self.netcharge,
                                               name=name,
                                               hg=hg,
                                               **kwargs)
Beispiel #4
0
    def __init__(self,
                 c=None,
                 u=None,
                 fa_counts=None,
                 getname=None,
                 sub=(),
                 **kwargs):
        def _getname(parent, subs):
            """

            Parameters
            ----------
            parent :
                
            subs :
                

            Returns
            -------

            """

            return '%s(%u:%u)' % (parent.name, subs[0].c, subs[0].u)

        metabolite.AbstractMetabolite.__init__(
            self,
            core='OH',
            subs=[substituent.FattyAcyl(c=c, u=u, counts=fa_counts)],
            name='FA',
            hg=lipproc.Headgroup(main='FA', sub=()),
            getname=getname or _getname,
            **kwargs)
Beispiel #5
0
    def __init__(self, **kwargs):

        AbstractGPL.__init__(self,
                             headgroup='C2H4NH2',
                             name='PE',
                             typ='PE',
                             hg=lipproc.Headgroup('PE'),
                             pcharge=1,
                             ncharge=1,
                             **kwargs)
Beispiel #6
0
    def __init__(self,
                 sn1_1=None,
                 sn2_1=None,
                 sn1_2=None,
                 sn2_2=None,
                 sn1_1_fa_args=None,
                 sn1_2_fa_args=None,
                 sn2_1_fa_args=None,
                 sn2_2_fa_args=None,
                 fa_args=None,
                 charge=None,
                 pcharge=0,
                 ncharge=0,
                 name='CL',
                 typ='CL',
                 sub=(),
                 **kwargs):
        """
        Example: http://swisslipids.org/#/entity/SLM:000528939/
        >>> list(lipid.Cardiolipin(fa_args = {'c': 19, 'u': 2}))[0].mass
        Exact mass: 1505.0348
        """

        self.fa_args = fa_args or {}
        sn1_1_fa_args = self.fa_args or {}
        sn1_2_fa_args = self.fa_args or {}
        sn2_1_fa_args = self.fa_args or {}
        sn2_2_fa_args = self.fa_args or {}
        self.pcharge = pcharge
        self.ncharge = ncharge
        self.netcharge = (charge if charge is not None else self.pcharge -
                          self.ncharge)
        self.typ = typ
        hg = lipproc.Headgroup(main=name, sub=sub)

        metabolite.AbstractMetabolite.__init__(
            self,
            core='C9H18O13P2',
            subs=[
                self._get_substituent(sn1_1, args=sn1_1_fa_args),
                self._get_substituent(sn1_2, args=sn1_2_fa_args),
                self._get_substituent(sn2_1, args=sn2_1_fa_args),
                self._get_substituent(sn2_2, args=sn2_2_fa_args),
            ],
            charge=self.netcharge,
            name=name,
            hg=hg,
            **kwargs,
        )
Beispiel #7
0
    def get_hg_obmol(self, hg, sub=()):
        """

        Parameters
        ----------
        hg :
            
        sub :
             (Default value = ())

        Returns
        -------

        """

        if isinstance(hg, common.basestring):

            hg = lipproc.Headgroup(hg, sub=sub)

        return self.get_obmol(hg, index='hg')
Beispiel #8
0
    def __init__(self,
                 c=None,
                 u=None,
                 fa_counts=None,
                 getname=None,
                 sub=(),
                 **kwargs):
        def _getname(parent, subs):

            return '%s(%u:%u)' % (parent.name, subs[0].c, subs[0].u)

        metabolite.AbstractMetabolite.__init__(
            self,
            core='C19OH31',
            subs=[substituent.FattyAcyl(c=c, u=u, counts=fa_counts)],
            name='SE',
            hg=lipproc.Headgroup(main='SE', sub=()),
            getname=getname or _getname,
            **kwargs,
        )
Beispiel #9
0
    def __init__(self,
                 core='',
                 sph_args=None,
                 fa_args=None,
                 o='H',
                 lyso=False,
                 fa_hydroxy=False,
                 lcb_type='d',
                 name='Cer',
                 hg=None,
                 getname=None,
                 **kwargs):

        sph_args = sph_args or {}
        fa_args = fa_args or {}

        if lyso:
            fa = 'H'
        elif fa_hydroxy:
            fa = substituent.HydroxyFattyAcyl(**fa_args)
        else:
            fa = substituent.FattyAcyl(**fa_args)

        self.fa_hydroxy = fa_hydroxy

        hg = hg or lipproc.Headgroup(main='Cer')

        AbstractSphingolipid.__init__(self,
                                      o=o,
                                      n=fa,
                                      sph_args=sph_args,
                                      name=name,
                                      getname=getname,
                                      lcb_type=lcb_type,
                                      hg=hg,
                                      **kwargs)
Beispiel #10
0
    def __init__(self,
                 c=None,
                 u=None,
                 fa_counts=None,
                 getname=None,
                 sub=(),
                 **kwargs):
        def _getname(parent, subs):
            """

            Parameters
            ----------
            parent :
                
            subs :
                

            Returns
            -------

            """

            return 'Ret'

        metabolite.AbstractMetabolite.__init__(
            self,
            core='C19H26',
            subs=(metabolite.AbstractSubstituent(
                cores=('CH2OH', ),
                c=(0, ),
                u=(0, ),
            ), ),
            name='Ret',
            hg=lipproc.Headgroup(main='Ret', sub=('Ol', )),
            getname=getname or _getname,
            **kwargs)
Beispiel #11
0
             '[M+HCOO]-',
         },
     },
     'pos': {
         1: {
             '[M+H]+',
             '[M+NH4]+',
             '[M+Na]+',
         },
     }
 },
 # additional constraints for adduct lookups at various species
 # e.g. by default `[M-H2O+H]+` is not used but at Vitamin A we use it:
 'adduct_constraints': {
     'pos': {
         lipproc.Headgroup(main = 'VA'): {
             '[M+H]+',
             '[M+NH4]+',
             '[M+Na]+',
             '[M-H2O+H]+',
         },
         lipproc.Headgroup(main = 'Cer', sub = ('Hex',)): {
             '[M+H]+',
             '[M+NH4]+',
             '[M+Na]+',
             '[M-H2O+H]+',
         },
         lipproc.Headgroup(main = 'Cer', sub = ('Hex2',)): {
             '[M+H]+',
             '[M+NH4]+',
             '[M+Na]+',
Beispiel #12
0
    def process(self, names, database=None, iso=None):
        """The main method of this class. Processes a lipid name string
        and returns a standard name, prefix, carbon counts and
        unsaturations.
        
        Args
        ----

        Parameters
        ----------
        list :
            names:
            One or more names to process. Single result will be returned
            and names will be attempted to be processed one after the other
            until processing is successful.
        names :
            
        database :
             (Default value = None)

        Returns
        -------

        """

        iso = iso if iso is not None else self.iso

        if hasattr(names, 'lower'):
            # ok, if one passes a string let us still process it
            names = (names, )

        database = database or self.database

        hg, chainsum, chains, chainsiso, chainsexp = (None, None, None, None,
                                                      None)

        hg, chainsexp = self.headgroup_from_lipid_name(names,
                                                       database=database)
        hg_modified = None

        # try greek fatty acyl carbon counts:
        if not hg and iso and database == 'swisslipids':

            try:

                for name0 in names:

                    fa_greek = name0.split('-')

                    if len(fa_greek) > 1:

                        hg = self.process_fa_name(fa_greek[1])

                        if hg:

                            hg = lipproc.Headgroup(main=fa_name)
                            chainsexp = (fa_name, )
                            break

            except:

                pass

        for n in names:

            lyso = hg and 'Lyso' in hg.sub

            # how many aliphatic chains this molecule has
            ccexp = (
                2
                if not hg else 1 if hg.main in {'FA', 'MAG'} or lyso else 3 if
                hg.main == 'TAG' else 4  # cardiolipin has 4 aliphatic chains,
                # but lyso or monolyso have 2 or 3,
                # respectively
                if hg.main == 'CL' else 2)

            # for CL accept also 2 or 3 chains
            accept_less_chains = 2 if hg and hg.main in {'CL'} else False

            _chainsum, _chains = self.carbon_counts(
                n,
                ccexp=ccexp,
                chainsexp=chainsexp,
                iso=iso,
                accept_less_chains=accept_less_chains,
            )

            chains = chains or _chains
            chainsum = chainsum or _chainsum

            if self.iso and _chains and any(c.iso for c in _chains):

                chains = _chains

            # TODO:
            # this part I turned off, CL name processing should be
            # imporoved later
            if False and hg and hg.main == 'CL':

                if _chains and len(_chains) == 2:

                    hg_modified = lipproc.Headgroup(
                        main='CL',
                        sub=('Lyso', ),
                    )

                elif len(_chains) == 3:

                    hg_modified = lipproc.Headgroup(
                        main='CL',
                        sub=('Monolyso', ),
                    )

            if (chainsum and chains
                    and (not iso or any(c.iso for c in chains))):

                break

        if hg and hg.main in {'FA', 'FAL', 'FACoA'} and not chainsum:

            for name0 in names:

                chainsum, chains = self.fa_greek_cc(name0)

                if chainsum:

                    break

        return hg_modified or hg, chainsum, chains
Beispiel #13
0
    def __init__(self,
                 core='',
                 o='H',
                 n='H',
                 sph=None,
                 sph_args=None,
                 charge=None,
                 pcharge=None,
                 ncharge=None,
                 lcb_type='d',
                 name='Sphingolipid',
                 subtype=(),
                 hg=None,
                 getname=None,
                 **kwargs):

        sph_args = sph_args or {}

        self.pcharge = pcharge or 0
        self.ncharge = ncharge or 0
        self.charge = (charge if type(charge) is int else self.pcharge -
                       self.ncharge)

        self.lcb_type = lcb_type
        self.hg = hg or lipproc.Headgroup(main=name, sub=subtype)

        if not sph:

            # this is necessary because we have only 8:0 standard for kSph
            # TODO: find a better solution for this
            if (lcb_type == 'k'
                    and ('keto8' not in sph_args or sph_args['keto8'])):

                if 'c' in sph_args:
                    sph_args['c'] = ((8, sph_args['c'])
                                     if type(sph_args['c']) is int else
                                     (8, sph_args['c'][1]))
                else:
                    sph_args['c'] = (8, 20)

            sph = substituent.Sphingosine(lcb_type=lcb_type, **sph_args)

        def _getname(parent, subs):
            """

            Parameters
            ----------
            parent :
                
            subs :
                

            Returns
            -------

            """

            return (lipproc.summary_str(
                self.hg,
                lipproc.sum_chains(
                    tuple(s.attrs.chain for s in subs
                          if hasattr(s.attrs, 'chain'))))
                    if self.sum_only else lipproc.full_str(
                        self.hg,
                        tuple(s.attrs.chain for s in subs
                              if hasattr(s.attrs, 'chain'))))

        metabolite.AbstractMetabolite.__init__(
            self,
            core='',
            subs=[sph, self.get_substituent(n),
                  self.get_substituent(o)],
            name=name,
            hg=hg,
            charge=self.charge,
            getname=getname or _getname,
            **kwargs)