Ticket #5311: models.py

File models.py, 13.5 KB (added by raik.gruenberg@…, 17 years ago)

data model with errors

Line 
1## Brickit -- a repository and tools for synthetic biology
2## Copyright (C) 2007 Raik Gruenberg
3
4## Brickit is free software: you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation, either version 3 of the License, or
7## (at your option) any later version.
8
9## Brickit is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12## GNU General Public License for more details.
13
14## You should have received a copy of the GNU General Public License
15## along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18from django.db import models
19
20from django.contrib import databrowse
21
22# Create your models here.
23
24
25class Reference( models.Model ):
26 """
27 Minimalistic description of a URL link
28 """
29
30 REFERENCE_TYPE_CHOICES = ( ('web_site', 'web site'),
31 ('article', 'article'),
32 ('book', 'book'),
33 ('database_entry', 'database entry'),
34 ('mit_part', 'MIT part') )
35
36 name = models.CharField( maxlength=100, primary_key=True )
37
38 #: voluntary brief description
39 short_description = models.CharField( maxlength=200, blank=True )
40
41 #: obligate Link
42 url = models.URLField()
43
44 #: obligate category
45 reference_type = models.CharField( 'type of reference', maxlength=50,
46 choices=REFERENCE_TYPE_CHOICES,
47 default='web site' )
48 def __unicode__( self ):
49 return self.reference_type + ': ' + self.name
50
51 class Admin:
52 pass
53
54
55class StorageContainer( models.Model ):
56 """
57 A container holding several physical samples of DNA or other stuff.
58 """
59
60 STORAGE_CONTAINER_TYPES= (
61 ('96-well-plate', '96 well plate'),
62 ('384-well-plate','384 well plate'),
63 ('box', 'freezer box'),
64 ('other', 'other' ) )
65
66 #: bar-code label for this container
67 label = models.CharField('(bar code) label', maxlength=15,
68 primary_key=True )
69
70 #: human-readable name
71 nickname = models.CharField(maxlength=100)
72
73 #: [optional] annotation
74 description = models.CharField(maxlength=200, blank=True)
75
76 #: [optional]
77 comments = models.TextField(blank=True)
78
79 #: what type of container is it
80 container_type = models.CharField('type of container', maxlength=30,
81 choices=STORAGE_CONTAINER_TYPES )
82
83 location = models.CharField('location', maxlength=200)
84
85 # [optional] links_html
86 references = models.ManyToManyField( Reference, blank=True )
87
88 def __unicode__( self ):
89 return self.label
90
91 class Admin:
92 pass
93
94
95
96class Sample( models.Model ):
97 """
98 Sample describes a single tupe or well holding a bit of DNA or
99 another sample (?).
100 """
101
102 STORAGE_WELL_TYPES = ( ('tube','tube'), ('well','well'), ('other','other'))
103 STORAGE_TYPES = ( ('dna', 'DNA'), ('cells','cells') )
104
105
106 label = models.CharField('(bar code) label', maxlength=15,
107 primary_key=True)
108
109 #: link to a single container
110 container = models.ForeignKey( StorageContainer )
111
112 well_type = models.CharField('type of well or tube', maxlength=30,
113 choices=STORAGE_WELL_TYPES )
114
115 storage_type = models.CharField('stored as', maxlength=100,
116 choices=STORAGE_TYPES )
117
118 #: [optional]
119 comments = models.TextField(blank=True)
120
121 #: [optional] (for now)
122 well = models.CharField(maxlength=5, blank=True)
123
124 created = models.DateField('created at', auto_now_add=True)
125
126 #: link to the physical DNA contained in this sample
127 dna = models.ForeignKey( 'DNA',
128 verbose_name='physical DNA',
129 related_name='samples',
130 blank=False)
131
132 def __unicode__( self ):
133 return self.container.__unicode__() + ' / ' + self.label
134
135 class Admin:
136 pass
137
138
139
140class DNA( models.Model ):
141 """
142 DNA holds the information about a physical piece of DNA like,
143 in most cases, a plasmid + biobrick.
144
145 Thus it needs to have a sequence, and, earlier or later,
146 it should be stored in one or more places.
147
148 The samples holding this DNA are accessible via the field
149 'samples' which is imported from the DNA table.
150 """
151 DNA_TYPES = (('plasmid','Plasmid'), ('oligo','Oligo') )
152
153 name = models.CharField( maxlength=15, primary_key=True)
154
155 #: [optional] the parts.mit.edu ID
156 mit_id = models.CharField( maxlength=20, blank=True )
157
158 #: [optional]
159 description = models.CharField( maxlength=200, blank=True )
160
161 dna_type = models.CharField( 'type of DNA', maxlength=30,
162 choices=DNA_TYPES )
163
164 #: link to biobrick definition
165 #: [optional] to allow planning
166 biobrick = models.ForeignKey( 'Biobrick',
167 verbose_name='with biobrick',
168 related_name='implementations',
169 blank=True,
170 null=True)
171
172 #: link to host vector
173 #: [optional] to allow planning and oligos or cells
174 vector = models.ForeignKey( 'Vector',
175 verbose_name='in vector',
176 related_name='implementations',
177 blank=True,
178 null=True)
179
180 #: Strain this DNA is stored in, if any
181 cell = models.ForeignKey( 'Biobrick',
182 verbose_name='in cell',
183 related_name='hosted_biobricks',
184 blank=True,
185 null=True)
186
187 sequence = models.TextField()
188
189 #: [optional]
190 genebank_sequence = models.TextField('Genebank-formatted sequence',
191 blank=True)
192
193 #: [optional]
194 comments = models.TextField( blank=True )
195
196 # [optional] links_html
197 references = models.ManyToManyField( Reference, blank=True )
198
199 def __unicode__( self ):
200 return self.name
201
202
203 class Admin:
204
205 fields = (
206 (None, {
207 'fields': ('name','mit_id', 'description', 'dna_type')
208 }),
209 ('Details',{
210 'fields' : ('biobrick', 'vector', 'cell', 'sequence',)
211 }),
212 ('Additional information',{
213 'fields': ('comments','references', 'genebank_sequence'),
214 'classes':'collapse'
215 }),
216 )
217
218 class Meta:
219
220 verbose_name = 'physical DNA'
221
222
223class BrickType( models.Model ):
224 """
225 Describes the different types of Biobricks that are defined by
226 the MIT repository. The type of a biobrick should enter the name
227 with a type code letter:
228 C .. protein coding; G .. primer; M .. tag; P .. protein generator;
229 S .. intermediate; V .. cell strain; B .. basic or general part;
230 See: http://parts.mit.edu/registry/index.php/Help:BioBrick_Part_Names
231 """
232 name = models.CharField( maxlength=50, primary_key=True )
233
234 #: obligate brief description
235 short_description = models.CharField( maxlength=200 )
236
237 #: [optional] long description
238 description = models.TextField( 'detailed description', blank=True )
239
240 #: obligate type code letter that enters the name of the part
241 type_code = models.CharField('1-letter type code', maxlength=1)
242
243 def __unicode__(self):
244 return self.type_code + ':' + self.name
245
246 class Admin:
247 pass
248
249
250class BrickCategory( models.Model ):
251 """
252 Describes the different functional types of biobricks.
253 (regulators, protein, transcription, etc.)
254 """
255 name = models.CharField( maxlength=50, primary_key=True )
256
257 #: obligate brief description
258 short_description = models.CharField( maxlength=200 )
259
260 #: [optional] long description
261 description = models.TextField( 'detailed description', blank=True )
262
263
264 def __unicode__(self):
265 return self.name
266
267 class Admin:
268 pass
269
270 class Meta:
271 verbose_name_plural = 'BrickCategories'
272
273
274class ProgressCategory( models.Model ):
275 """
276 A customized set of progress tags like perhaps 'synthesis pending',
277 'sequenced'?
278 """
279
280 name = models.CharField( maxlength=50, primary_key=True )
281
282 #: obligate brief description
283 short_description = models.CharField( maxlength=200 )
284
285 #: [optional] long description
286 description = models.TextField( 'detailed description', blank=True )
287
288
289 def __unicode__(self):
290 return self.name
291
292 class Admin:
293 pass
294
295 class Meta:
296 verbose_name_plural = 'ProgressCategories'
297
298
299class Biobrick( models.Model ):
300 """
301 A Biobrick holds the description of a biobrick sequence.
302
303 Note: The connection from a Biobrick to its physical DNA implementations
304 is established by a relation 'biobrick' in DNA.
305 """
306 BRICK_FORMAT_CHOICES = ( ('classic', 'classic biobrick format'),
307 ('biofusion', 'protein biobrick / Biofusion'),
308 ('non_standard', 'non-standard (comment!)'),
309 ('unknown', 'unknown format (comment!)') )
310
311 STATUS_CHOICES = ( ('available', 'available'),
312 ('planning', 'planning'),
313 ('submitted', 'submitted to MIT') )
314
315 EXPERIENCE_CHOICES = ( ('works', 'works'),
316 ("worksnot", "doesn't work"),
317 ('none', 'no experience') )
318
319
320 name = models.CharField( maxlength=15, primary_key=True )
321
322 #: [optional] ID fetched from parts.mit.edu
323 mit_id = models.CharField( maxlength=20, blank=True )
324
325 #: obligate brief description
326 short_description = models.CharField( maxlength=200 )
327
328 #: [optional] long description
329 description = models.TextField( 'detailed description', blank=True )
330
331 #: obligate
332 brick_format = models.CharField( 'format of Biobrick', maxlength=30,
333 choices=BRICK_Format_CHOICES,
334 default='classic' )
335
336 #: obligate
337 brick_type = models.ForeignKey( 'type of Biobrick',
338 verbose_name='biobrick type',
339 related_name='child_biobricks')
340
341 #: link to table of functional categories
342 categories = models.ManyToManyField( BrickCategory )
343
344 status = models.CharField( 'implementation status', maxlength=30,
345 choices=STATUS_CHOICES,
346 default='planning')
347
348
349 experience = models.CharField( maxlength=30,
350 choices=EXPERIENCE_CHOICES,
351 default='none' )
352
353 #: [optional]
354 progress = models.ManyToManyField( ProgressCategory,
355 blank=True )
356
357 #: [optional]
358 comments = models.TextField( blank=True )
359
360 sequence = models.TextField()
361
362 #: [optional]
363 genebank_sequence = models.TextField('Genebank-formatted sequence',
364 blank=True)
365
366 #: [optional]
367 source_gid = models.CharField( 'source genebank entry', maxlength=10,
368 blank=True )
369
370 #: [optional]
371 source_txt = models.CharField( 'source free text', maxlength=200,
372 blank=True )
373
374 # [optional] links_html
375 references = models.ManyToManyField( Reference, blank=True )
376
377 def __unicode__(self):
378 return self.name
379
380
381 class Admin:
382
383 fields = (
384 (None,
385 {'fields': ('name','mit_id', 'short_description',
386 'status', 'experience')}),
387 ('Details',
388 {'fields' : ('brick_format', 'brick_type', 'categories',
389 'description')}),
390 ('Additional information',
391 {'fields': ('progress', 'source_gid', 'source_txt',
392 'references', 'comments',
393 'genebank_sequence'),
394 'classes':'collapse'}),
395 ('Sequence',
396 {'fields':('sequence',)}),
397 )
398
399
400class SelectiveMarker( models.Model ):
401 """
402 Describes an Antibiotic or similar resistence marker
403 """
404 name = models.CharField( maxlength=15, primary_key=True )
405
406 #: obligate brief description
407 short_description = models.CharField( maxlength=200 )
408
409 #: [optional] long description
410 description = models.TextField( 'detailed description', blank=True )
411
412 # [optional] links_html
413 references = models.ManyToManyField( Reference, blank=True )
414
415
416 def __unicode__(self):
417 return self.name
418
419 class Admin:
420 pass
421
422
423class Vector( models.Model ):
424 """
425 A vector describes a Plasmid (are there non-plasmid vectors?)
426 """
427 name = models.CharField( maxlength=15, primary_key=True )
428
429 #: [optional] ID fetched from parts.mit.edu
430 mit_id = models.CharField( maxlength=20, blank=True )
431
432 #: obligate brief description
433 short_description = models.CharField( maxlength=200 )
434
435 #: [optional] long description
436 description = models.TextField( 'detailed description', blank=True )
437
438 sequence = models.TextField()
439
440 #: [optional] link to resistence or similar marker
441 marker = models.ManyToManyField( SelectiveMarker,
442 verbose_name='selective marker(s)',
443 null=True,
444 blank=True)
445
446 #: [optional]
447 comments = models.TextField( blank=True )
448
449 # [optional] links_html
450 references = models.ManyToManyField( Reference, blank=True )
451
452 #: [optional]
453 genebank_sequence = models.TextField('Genebank-formatted sequence',
454 blank=True)
455 def __unicode__(self):
456 return self.name
457
458 class Admin:
459
460 fields = (
461 (None,
462 { 'fields': ('name','mit_id', 'short_description',)}),
463 ('Details',
464 {'fields': ('description', 'marker', 'sequence')}),
465 ('Additional information',
466 {'fields': ('comments', 'references', 'genebank_sequence'),
467 'classes':'collapse' }),
468 )
469
470######################################
471## register models to databrowsing app
472
473databrowse.site.register( Biobrick )
474databrowse.site.register( Vector )
475databrowse.site.register( DNA )
476databrowse.site.register( StorageContainer )
477databrowse.site.register( Sample )
478databrowse.site.register( BrickCategory )
479databrowse.site.register( SelectiveMarker )
480databrowse.site.register( Reference )
Back to Top