source: trunk/mzcms/models.py @ 25

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

Pseudocode for parse_dats

File size: 2.4 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, subfolders):
12        super(Experiment, self).__init__()
13        for subfolder in subfolders:
14            self[subfolder.name] = subfolder
15
16class Proteins(Folder):
17    """Proteins folder factory"""
18    def __init__(self, proteins):
19        self.name = 'proteins'
20
21class Protein(Persistent):
22    """A Protein"""
23    def __init__(self, native_id, sequence, pep_refs):
24        self.sequence = str(native_id)
25        self.sequence = str(sequence)
26        self.pep_refs = tuple(pep_refs)
27
28class Peptides(Folder):
29    """Peptides folder factory"""
30    def __init__(self):
31        self.name = 'peptides'
32
33class Peptide(Persistent):
34    """A peptide"""
35    def __init__(self, sequence, mass):
36        self.sequence = str(sequence)
37        self.mass = float(mass)
38        self.length = len(sequence)
39
40class Spectra(Folder):
41    """Spectra folder factory"""
42    def __init__(self):
43        self.name = 'spectra'
44
45
46class Spectrum(Persistent):
47    """A Spectrum"""
48    def __init__(self, scan, run, peaks, prec_mz, prec_charge):
49        self.scan = int(scan)
50        self.run = str(scan)
51        self.peaks = tuple(peaks)
52        self.prec_mz = float(prec_mz)
53        self.prec_charge = int(prec_charge)
54
55class Psms(Folder):
56    """Psms folder factory"""
57    def __init__(self):
58        self.name = 'psms'
59
60class Psm(Persistent):
61    """A Peptide to Spectrum Match"""
62    def __init__(self, score, rank, delta_mass, delta_score,
63                 sequence_rank2, pep_ref, spec_ref):
64        self.score = float(score)
65        self.rank = int(rank)
66        self.delta_mass = float(delta_mass)
67        self.delta_score = float(delta_score)
68        self.sequence_rank2 = str(sequence_rank2)
69        self.pep_ref = str(pep_ref)
70        self.spec_ref = str(spec_ref)
71
72def appmaker(zodb_root):
73    if not 'app_root' in zodb_root:
74        folders = parse_dats('./dats', proteins_factory=Proteins,
75                             peptides_factory=Peptides,
76                             spectra_factory=Spectra,
77                             psms_factory=Psms,
78                             )
79        app_root = Experiment(folders)
80        zodb_root['app_root'] = app_root
81        import transaction
82        transaction.commit()
83
84    return zodb_root['app_root']
Note: See TracBrowser for help on using the repository browser.