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
Line 
1"""Models for mzcms.
2
3"""
4from persistent import Persistent
5from repoze.folder import Folder
6
7from parsers import parse_dats
8
9class Experiment(Folder):
10    __parent__ = __name__ = None
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)
17
18class Proteins(Folder):
19    """Proteins folder factory"""
20    def __init__(self, proteins):
21        self.name = 'proteins'
22
23class Protein(Persistent):
24    """A Protein"""
25    def __init__(self, native_id, sequence, pep_refs):
26        self.sequence = str(native_id)
27        self.sequence = str(sequence)
28        self.pep_refs = tuple(pep_refs)
29
30class Peptides(Folder):
31    """Peptides folder factory"""
32    def __init__(self):
33        self.name = 'peptides'
34
35class Peptide(Persistent):
36    """A peptide"""
37    def __init__(self, sequence, mass):
38        self.sequence = str(sequence)
39        self.mass = float(mass)
40        self.length = len(sequence)
41
42class Spectra(Folder):
43    """Spectra folder factory"""
44    def __init__(self):
45        self.name = 'spectra'
46
47
48class Spectrum(Persistent):
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)
56
57class Psms(Folder):
58    """Psms folder factory"""
59    def __init__(self):
60        self.name = 'psms'
61
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)
73
74def appmaker(zodb_root):
75    if not 'app_root' in zodb_root:
76        data = parse_dats('./dats')
77        app_root = Experiment(data)
78        zodb_root['app_root'] = app_root
79        import transaction
80        transaction.commit()
81
82    return zodb_root['app_root']
Note: See TracBrowser for help on using the repository browser.