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 _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. 3
0
def collect_scan_lines(mzs, rts, mgfs):
    """

    Parameters
    ----------
    mzs :
        
    rts :
        
    mgfs :
        

    Returns
    -------

    """
    
    result = []
    
    for mz, rt in zip(mzs, rts):
        
        fe = ms2.MS2Feature(mz, ionmode = 'pos', mgfs = mgfs, rt = rt)
        fe.build_scans()
        
        for sc, drt in zip(fe.scans, fe.deltart):
            
            ids = sc.identify()
            
            smrec = list(
                sc.get_ms1_records(hg = 'SM', databases = {'lipyd.lipid'})
            )
            
            chainid = set()
            
            for sm in smrec:
                
                ccomb = sc.chain_combinations(sm[0])
                
                for cc in ccomb:
                    
                    chainid.add(
                        '%s[full=%s,frags=[%s,%s],i=[%.03f,%.03f]]' % (
                            sm[0].summary_str(),
                            lipproc.full_str(sm[0].hg, cc[0]),
                            cc[1].fragtype[0],
                            cc[1].fragtype[1],
                            cc[1].i[0] * 100,
                            cc[1].i[1] * 100,
                        )
                    )
            
            for ms1id, ms2ids in ids.items():
                
                if ms2ids and ms2ids[0].hg.main == 'SM':
                    
                    this_line = [
                        '%.07f' % mz,
                        '%.02f - %.02f' % rt,
                        '%u' % sc.scan_id,
                        '%.02f' % drt,
                        sc.sample,
                        ms1id,
                        '%u' % ms2ids[0].score_pct,
                    ]
                    
                    isph = min(
                        sc.fragments_by_chain_type(frag_type = 'Sph-2xH2O+H'),
                        default = None
                    )
                    
                    irel_sph = (
                        '%.03f' % (sc.inorm[isph] * 100)
                        if isph is not None
                        else ''
                    )
                    
                    this_line.append(irel_sph)
                    
                    for frag in sm_frags:
                        
                        i = sc.fragment_by_name(frag)
                        reli = (
                            '%.03f' % (sc.inorm[i] * 100)
                            if i is not None
                            else ''
                        )
                        
                        this_line.append(reli)
                    
                    this_line.append(';'.join(chainid))
                    
                    result.append(this_line)
    
    return result
Esempio n. 4
0
    def make_index(self):
        def cc2str(cc):

            return ('%s%s%u:%u' %
                    (cc[0], '-' if cc[0] in {'O', 'P'} else '', cc[1], cc[2]))

        self.close_plainfile()

        self.load()
        self.index = collections.defaultdict(lambda: set([]))
        self.hg_index = collections.defaultdict(lambda: set([]))
        self.species_index = collections.defaultdict(lambda: set([]))
        self.subspec_index = collections.defaultdict(lambda: set([]))
        self.isomer_index = collections.defaultdict(lambda: set([]))

        if not self.silent:

            self.prg = progress.Progress(self._curl.size,
                                         'Indexing SwissLipids', 101)

        self._plainfilename = '%s.extracted' % self._gzfile.name

        with open(self._plainfilename, 'wb') as fpp:

            offset = self._gzfile.tell()

            for l in self._gzfile:

                if not self.silent:
                    self.prg.step(len(l))

                ll = l.decode('utf-8').split('\t')

                if ll[1] in self.levels:

                    names = self.names(ll)
                    self.index[ll[0]].add(offset)  # SwissLipids ID
                    self.index[ll[8]].add(offset)  # SMILES
                    self.index[ll[10]].add(offset)  # InChI key

                    for n in names.split('|'):

                        self.index[n].add(offset)

                    hg, chainsum, chains = self.nameproc.process(names)

                    if hg:

                        self.hg_index[hg].add(offset)

                    if hg and chainsum:

                        self.species_index[lipproc.summary_str(
                            hg, chainsum)].add(offset)

                    if hg and chains:

                        self.subspec_index[lipproc.full_str(
                            hg, chains)].add(offset)

                    if hg and chains:

                        self.isomer_index[lipproc.full_str(
                            hg, chains, iso=True)].add(offset)

                offset = self._gzfile.tell()
                fpp.write(l)

        if not self.silent:
            self.prg.terminate()

        self.index = dict(self.index)
        self._plainfile = open(self._plainfilename, 'r')