Esempio n. 1
0
 def iterlines(self):
     """Iterates standard lines."""
     
     for subs, inst in self.subsproduct():
         
         full_name = inst.getname()
         
         chains = tuple(
             s.attrs.chain for s in subs if hasattr(s.attrs, 'chain')
         )
         chainsum = lipproc.sum_chains(chains)
         name = (
             (lipproc.summary_str(self.hg, chainsum),)
                 if self.hg and self.sum_only else
             (lipproc.full_str(self.hg, chains),)
                 if self.hg and not self.sum_only else
             ()
         )
         lab = lipproc.LipidLabel(
             db_id   = None,
             db      = 'lipyd.lipid',
             names   = name,
             formula = inst.formula,
         )
         rec = lipproc.LipidRecord(
             lab = lab,
             hg  = self.hg,
             chainsum = chainsum if chainsum.c else None,
             chains = () if self.sum_only else chains,
         )
         
         yield inst.mass, rec
Esempio n. 2
0
    def idx_from_name(
            self,
            name=None,
            hg=None,
            chainsum=None,
            chains=(),
    ):
        """
        For a lipid name returns the indices of the matching records.
        
        Returns
        -------
        Set of indices. If name not in the database returns None.
        """

        if name is None and hg is not None:

            if chainsum is None:

                chainsum = lipproc.sum_chains(chains)

            name = lipproc.summary_str(hg=hg, chainsum=chainsum)

        if name in self.names:

            return self.names[name]
Esempio n. 3
0
    def fa_greek_cc(self, name):
        """
        From the greek name of a fatty acyl, fatty alcohol or fatty acyl CoA
        returns its carbon and unsaturation count.
        
        Parameters
        ----------
        name : str
            A greek name.
        
        Returns
        -------
        ``ChainSummary`` and ``Chain`` objects with the carbon and
        unsaturation counts.
        """

        chainsum, chains = None, None

        try:

            name1 = name.split('-')[1] if '-' in name else name

            for typ in {'FA', 'FAL', 'FACoA'}:

                if name1 in getattr(self, '%s_greek' % typ.lower()):

                    cc1 = getattr(self, '%s_greek' % typ.lower())[name1]
                    iso = (tuple(name.split(')')[0][1:].split(','))
                           if self.iso and '(' in name else ())
                    chains = [
                        lipproc.Chain(c=cc1[0], u=cc1[1], typ=typ, iso=iso)
                    ]
                    chainsum = lipproc.sum_chains(chains)

        except:
            pass

        return chainsum, chains
Esempio n. 4
0
        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'))))
Esempio n. 5
0
    def carbon_counts(
        self,
        name,
        ccexp=2,
        chainsexp=None,
        sphingo=False,
        iso=False,
        types=None,
        accept_less_chains=False,
    ):
        """
        Processes carbon and unsaturation counts from name.
        
        Parameters
        ----------
        str :
            name:
            Lipid name.
        int :
            ccexp:
            Expected number of fatty acyl or other residues constaining
            aliphatic chain. E.g. for DAG this should be 2 and for TAG 3
            as the latter has 3 fatty acyls.
        tuple :
            chainsexp:
            The type of the expected chains, e.g. `('Sph', 'FA')` for one
            sphingosine and a fatty acyl. This matters only if the chain
            types can not be inferred from the processed names.
        bool :
            sphingo:
            Is this a sphingolipid, is the first chain a sphingosine base?
        bool :
            iso:
            Process conformation isomer details for example 18:2(9E,11Z).
        tuple :
            types:
            Explicit types for each chains.
        name :
            
        ccexp :
             (Default value = 2)
        chainsexp :
             (Default value = None)
        sphingo :
             (Default value = False)
        iso :
             (Default value = False)
        types :
             (Default value = None)
        """

        # number of groups in one regex match unit
        _g = 5 if iso else 4
        _i = 3
        rechain = lipproc.rechainiso if iso else lipproc.rechain

        # regex finds the total carbon count
        cc1 = lipproc.rechainsum.search(name)
        cc1 = cc1.groups() if cc1 else cc1
        # regex finds 1-4 fatty acids
        cc2 = rechain.findall(name)

        if not cc2:

            # if no result do an attempt with the isomeric regex
            rechain = lipproc.rechainiso
            cc2 = rechain.findall(name)

            if cc2:

                _g = 5

        chains = []

        if (ccexp and cc2  #and
                #cc2[(ccexp - 1) * _g + 1] and
                #cc2[(ccexp - 1) * _g + 2]
            ):

            # in case of e.g. cardiolipin we have multiple groups of 2 chains
            for _cc2 in cc2:

                for i in xrange(len(_cc2) // _g):

                    if _cc2[i * _g + 1] and _cc2[i * _g + 2]:

                        c = int(_cc2[i * _g + 1])
                        u = int(_cc2[i * _g + 2])
                        attr = self.attr_proc(_cc2[i * _g:i * _g + _g], u)

                        # in lipidmaps one unsaturation
                        # for plasmalogens is implicit
                        if (self.database == 'lipidmaps'
                                and _cc2[i * _g] == 'P'):
                            u += 1

                        sphingo = sphingo or bool(attr.sph)

                        chains.append(
                            lipproc.Chain(
                                c=c,
                                u=u,
                                attr=attr,
                                typ=self.get_type(i, sphingo, attr.ether,
                                                  types, chainsexp),
                                # even if we used the isomeric regex
                                # we include the conformational isomer
                                # information only if requested
                                iso=(tuple(_cc2[i * _g + _i].split(','))
                                     if iso and _cc2[i * _g + _i] else
                                     ()) if iso else None))

            zerochains = sum(not c.c for c in chains)
            # ccexp = ccexp - zerochains
            chains = tuple(c for c in chains if c.c)
            chains = (() if (
                len(chains) != ccexp and
                (not accept_less_chains or len(chains) < accept_less_chains))
                      else tuple(chains))

        # the total carbon count
        if chains:

            chainsum = lipproc.sum_chains(chains)

        elif cc1:

            c = int(cc1[1])
            u = int(cc1[2])

            if not chainsexp:

                attrs = (self.attr_proc(cc1, u), )
                types = ()

            else:
                attrs, types = self.attrs_types(cc1, chainsexp)

            chainsum = lipproc.ChainSummary(
                c=c,
                u=u,
                attr=attrs,
                typ=types,
            )

        else:

            chainsum = None

        return chainsum, chains