source: trunk/mzcms/models.py @ 24

Last change on this file since 24 was 24, checked in by j@…, 10 years ago

imported previously written dat parser from Pavel Pevzner project

File size: 2.3 KB
RevLine 
[24]1"""Models for mzcms.
2
3"""
[13]4from persistent import Persistent
5from repoze.folder import Folder
[1]6
[24]7from parsers import parse_dats
8
[13]9class Experiment(Folder):
[1]10    __parent__ = __name__ = None
[23]11    def __init__(self, proteins, peptides, spectra, psms):
12        super(Experiment, self).__init__()
13        self['proteins'] = Proteins(proteins)
14        self['peptides'] = Peptides(peptides)
15        self['spectra'] = Spectra(spectra)
16        self['psms'] = Psms(psms)
[1]17
[13]18class Proteins(Folder):
[23]19    """Proteins folder factory"""
20    def __init__(self, proteins):
[21]21        self.name = 'proteins'
[13]22
23class Protein(Persistent):
[14]24    """A Protein"""
25    def __init__(self, native_id, sequence, pep_refs):
26        self.sequence = str(native_id)
27        self.sequence = str(sequence)
[18]28        self.pep_refs = tuple(pep_refs)
[13]29
30class Peptides(Folder):
[23]31    """Peptides folder factory"""
[21]32    def __init__(self):
33        self.name = 'peptides'
[13]34
35class Peptide(Persistent):
[17]36    """A peptide"""
37    def __init__(self, sequence, mass):
38        self.sequence = str(sequence)
39        self.mass = float(mass)
40        self.length = len(sequence)
[13]41
[18]42class Spectra(Folder):
[23]43    """Spectra folder factory"""
[21]44    def __init__(self):
45        self.name = 'spectra'
[13]46
[21]47
[18]48class Spectrum(Persistent):
[19]49    """A Spectrum"""
50    def __init__(self, scan, run, peaks, prec_mz, prec_charge):
51        self.scan = int(scan)
52        self.run = str(scan)
53        self.peaks = tuple(peaks)
54        self.prec_mz = float(prec_mz)
55        self.prec_charge = int(prec_charge)
[13]56
[18]57class Psms(Folder):
[23]58    """Psms folder factory"""
[21]59    def __init__(self):
60        self.name = 'psms'
[13]61
[18]62class Psm(Persistent):
63    """A Peptide to Spectrum Match"""
64    def __init__(self, score, rank, delta_mass, delta_score,
65                 sequence_rank2, pep_ref, spec_ref):
66        self.score = float(score)
67        self.rank = int(rank)
68        self.delta_mass = float(delta_mass)
69        self.delta_score = float(delta_score)
70        self.sequence_rank2 = str(sequence_rank2)
71        self.pep_ref = str(pep_ref)
72        self.spec_ref = str(spec_ref)
[13]73
[1]74def appmaker(zodb_root):
75    if not 'app_root' in zodb_root:
[24]76        data = parse_dats('./dats')
77        app_root = Experiment(data)
[23]78        zodb_root['app_root'] = app_root
[22]79        import transaction
80        transaction.commit()
[21]81
[1]82    return zodb_root['app_root']
Note: See TracBrowser for help on using the repository browser.