source: trunk/mzcms/models.py @ 23

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

Creation of data folders directly from Experiment

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