Changeset 52


Ignore:
Timestamp:
Aug 11, 2010, 4:12:18 PM (10 years ago)
Author:
j@…
bzr:base-revision:
j@dannynavarro.net-20100810143112-0jej6qqxmiwr3465
bzr:committer:
Danny Navarro <j@dannynavarro.net>
bzr:file-ids:

mzcms/models.py models.py-20100730084238-fjjwldiefr0w07zv-4
mzcms/parsers.py parsers.py-20100806092910-g1sxvv1o5b9umkof-1
bzr:mapping-version:
v4
bzr:repository-uuid:
724254b2-fbe6-419d-9466-c04ef4c9d29d
bzr:revision-id:
j@dannynavarro.net-20100810145849-g8mqxp7cz04g865f
bzr:revno:
52
bzr:revprop:branch-nick:
trunk
bzr:root:
trunk
bzr:timestamp:
2010-08-10 16:58:49.384000063 +0200
bzr:user-agent:
bzr2.1.2+bzr-svn1.0.3
svn:original-date:
2010-08-10T14:58:49.384000Z
Message:

Succesfully populate database with 1 dat file

Location:
trunk/mzcms
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/mzcms/models.py

    r50 r52  
    99class Experiment(Folder):
    1010    __parent__ = __name__ = None
    11     def __init__(self, subfolders):
     11    def __init__(self):
    1212        super(Experiment, self).__init__()
    13         for subfolder in subfolders:
    14             self[subfolder.name] = subfolder
    15 
    16 class Proteins(Folder):
    17     """Proteins folder factory"""
    18     def __init__(self):
    19         self.name = 'proteins'
    2013
    2114class Protein(Persistent):
     
    2619        self.pep_refs = pep_refs
    2720
    28 class Peptides(Folder):
    29     """Peptides folder factory"""
    30     def __init__(self):
    31         self.name = 'peptides'
    32 
    3321class Peptide(Persistent):
    3422    """A peptide"""
     
    3725        self.mass = float(mass)
    3826        self.length = len(sequence)
    39 
    40 class Spectra(Folder):
    41     """Spectra folder factory"""
    42     def __init__(self):
    43         self.name = 'spectra'
    44 
    4527
    4628class Spectrum(Persistent):
     
    5234        self.prec_mz = float(prec_mz)
    5335        self.prec_charge = int(prec_charge)
    54 
    55 class Psms(Folder):
    56     """Psms folder factory"""
    57     def __init__(self):
    58         self.name = 'psms'
    5936
    6037class Psm(Persistent):
     
    7148def appmaker(zodb_root):
    7249    if not 'app_root' in zodb_root:
     50        app_root = Folder()
     51        zodb_root['app_root'] = app_root
     52        proteins = Folder()
     53        app_root['proteins'] = proteins
     54        peptides = Folder()
     55        app_root['peptides'] = peptides
     56        spectra = Folder()
     57        app_root['spectra'] = spectra
     58        psms = Folder()
     59        app_root['psms'] = psms
    7360        folders = parse_dats('./dats',
    74                              proteins_factory=Proteins,
    75                              peptides_factory=Peptides,
    76                              spectra_factory=Spectra,
    77                              psms_factory=Psms,
     61                             proteins_container=proteins,
     62                             peptides_container=peptides,
     63                             spectra_container=spectra,
     64                             psms_container=psms,
    7865                             protein_factory=Protein,
    7966                             peptide_factory=Peptide,
     
    8168                             psm_factory=Psm,
    8269                             )
    83         app_root = Experiment(folders)
    84         zodb_root['app_root'] = app_root
    8570        import transaction
    8671        transaction.commit()
  • trunk/mzcms/parsers.py

    r50 r52  
    215215                        if peptide not in proteins[prot_id].pep_refs:
    216216                            proteins[prot_id].pep_refs.append(peptide)
    217         import ipdb; ipdb.set_trace()
    218217        return proteins, peptides, spectra, psms
    219218
     
    261260        writer.writerow(psm)
    262261
    263 def parse_dats(dats_dir, proteins_factory=dict, peptides_factory=dict,
    264                spectra_factory=dict, psms_factory=dict,
     262def parse_dats(dats_dir, proteins_container=dict, peptides_container=dict,
     263               spectra_container=dict, psms_container=dict,
    265264               protein_factory=dict, peptide_factory=dict,
    266265               spectrum_factory=dict, psm_factory=dict):
    267266    """Parses all the dat files in dats_dir
    268267    """
    269     proteins = proteins_factory()
    270     peptides = peptides_factory()
    271     spectra = spectra_factory()
    272     psms = psms_factory()
     268    proteins = proteins_container
     269    peptides = peptides_container
     270    spectra = spectra_container
     271    psms = psms_container
    273272    dat_parser = DatParser(protein_factory=protein_factory,
    274273                           peptide_factory=peptide_factory,
    275274                           spectrum_factory=spectrum_factory,
    276275                           psm_factory=psm_factory)
     276    import transaction
    277277    for root, dirs, files in os.walk(dats_dir):
    278278        for dat_fn in files:
     
    281281                ser_proteins, ser_peptides, \
    282282                ser_spectra, ser_psms = dat_parser.parse(dat_file)
    283                 proteins.update(ser_proteins)
    284                 peptides.update(ser_peptides)
    285                 spectra.update(ser_spectra)
    286                 psms.update(ser_psms)
    287     return proteins, peptides, spectra, psms
     283                for k, v in ser_proteins.items():
     284                    if k not in proteins:
     285                        proteins[str(k)] = v
     286                transaction.savepoint()
     287                for k, v in ser_peptides.items():
     288                    if not k in peptides:
     289                        peptides[str(k)] = v
     290                transaction.savepoint()
     291                for k, v in ser_spectra.items():
     292                    if k not in spectra:
     293                        spectra[str(k)] = v
     294                transaction.savepoint()
     295                for k, v in ser_psms.items():
     296                    if k not in psms:
     297                        psms[str(k)] = v
     298                transaction.savepoint()
    288299
    289300def main():
Note: See TracChangeset for help on using the changeset viewer.