231afec2eea931f2e7bb16d72c973a846e449a77
[htsworkflow.git] / gaworkflow / frontend / fctracker / models.py
1 from django.db import models
2 from django.contrib.auth.models import User
3 from gaworkflow.frontend import settings
4
5 # Create your models here.
6
7 class Antibody(models.Model):
8   antigene = models.CharField(max_length=500, db_index=True)
9   catalog = models.CharField(max_length=50, unique=True, db_index=True)
10   antibodies = models.CharField(max_length=500, db_index=True)
11   source = models.CharField(max_length=500, blank=True, db_index=True)
12   biology = models.TextField(blank=True)
13   notes = models.TextField(blank=True)
14   def __str__(self):
15     return '%s - %s (%s)' % (self.antigene, self.antibodies, self.catalog)
16   class Meta:
17     verbose_name_plural = "antibodies"
18     ordering = ["antigene"]
19   class Admin:
20       list_display = ('antigene','antibodies','catalog','source','biology','notes')
21       list_filter = ('antibodies','source')
22       fields = (
23         (None, {
24             'fields': (('antigene','antibodies'),('catalog','source'),('biology'),('notes'))
25         }),
26        )
27
28 class Cellline(models.Model):
29   cellline_name = models.CharField(max_length=100, unique=True, db_index=True)
30   notes = models.TextField(blank=True)
31   def __str__(self):
32     return '%s' % (self.cellline_name)
33
34   class Meta:
35     ordering = ["cellline_name"]
36
37   class Admin:
38       fields = (
39         (None, {
40             'fields': (('cellline_name'),('notes'),)
41         }),
42        )
43
44 class Condition(models.Model):
45   condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
46   notes = models.TextField(blank=True)
47   def __str__(self):
48     return '%s' % (self.condition_name)
49
50   class Meta:
51     ordering = ["condition_name"]
52
53   class Admin:
54       fields = (
55         (None, {
56             'fields': (('condition_name'),('notes'),)
57         }),
58        )
59
60 class Species(models.Model):
61   
62   scientific_name = models.CharField(max_length=256, unique=False, db_index=True, core=True)
63   common_name = models.CharField(max_length=256, blank=True)
64   use_genome_build = models.CharField(max_length=100, blank=False, null=False)
65
66   def __str__(self):
67     return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
68   
69   class Meta:
70     verbose_name_plural = "species"
71     ordering = ["scientific_name"]
72   
73   class Admin:
74       fields = (
75         (None, {
76             'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
77         }),
78       )
79
80 class Lab(models.Model):
81   
82   name = models.CharField(max_length=100, blank=False, unique=True)
83   
84   def __str__(self):
85     return self.name
86   
87   class Admin:
88     pass
89
90 class UserProfile(models.Model):
91   
92   # This allows you to use user.get_profile() to get this object
93   user = models.ForeignKey(User, unique=True)
94
95   lab = models.ForeignKey(Lab)
96   #email = models.CharField(max_length=50, blank=True, null=True)
97   
98   def __str__(self):
99     return '%s (%s lab)' % (self.user, self.lab)
100   
101   class Meta:
102     #verbose_name_plural = "people"
103     #ordering = ["lab"]
104     pass
105     
106   class Admin:
107     #fields = (
108     #  (None, {
109     #      'fields': (('email', 'lab'), ('email'))
110     #  }),
111     #)
112     pass
113
114
115 class Library(models.Model):
116   
117   library_id = models.CharField(max_length=30, primary_key=True, db_index=True, core=True)
118   library_name = models.CharField(max_length=100, unique=True, core=True)
119   library_species = models.ForeignKey(Species, core=True)
120   cell_line = models.ForeignKey(Cellline,core=True)
121   condition = models.ForeignKey(Condition,core=True)
122   antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
123   
124   EXPERIMENT_TYPES = (
125       ('INPUT_RXLCh','INPUT_RXLCh'),
126       ('ChIP-seq', 'ChIP-seq'),
127       ('Sheared', 'Sheared'),
128       ('RNA-seq', 'RNA-seq'),
129       ('Methyl-seq', 'Methyl-seq'),
130       ('DIP-seq', 'DIP-seq'),
131     ) 
132   experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES,
133                                      default='RNA-seq')
134   
135   creation_date = models.DateField(blank=True, null=True)
136   made_for = models.ForeignKey(User)
137   made_by = models.CharField(max_length=50, blank=True, default="Lorian")
138   
139   PROTOCOL_END_POINTS = (
140       ('?', 'Unknown'),
141       ('Sample', 'Raw sample'),
142       ('Progress', 'In progress'),
143       ('1A', 'Ligation, then gel'),
144       ('PCR', 'Ligation, then PCR'),
145       ('1Ab', 'Ligation, PCR, then gel'),
146       ('1Aa', 'Ligation, gel, then PCR'),
147       ('2A', 'Ligation, PCR, gel, PCR'),
148       ('Done', 'Completed'),
149     )
150   stopping_point = models.CharField(max_length=25, choices=PROTOCOL_END_POINTS, default='Done')
151   amplified_from_sample = models.ForeignKey('self', blank=True, null=True)  
152   
153   undiluted_concentration = models.DecimalField("Undiluted concentration (ng/ul)", max_digits=5, decimal_places=2, default=0, blank=True, null=True)
154   successful_pM = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True)
155   ten_nM_dilution = models.BooleanField()
156   avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
157   notes = models.TextField(blank=True)
158   
159   def __str__(self):
160     return '#%s: %s' % (self.library_id, self.library_name)
161   
162   class Meta:
163     verbose_name_plural = "libraries"
164     ordering = ["-library_id"]
165   
166   class Admin:
167     date_hierarchy = "creation_date"
168     save_as = True
169     save_on_top = True
170     search_fields = ['library_name', 'library_id']
171     list_display = ('library_id', 'library_name', 'made_for', 'creation_date', 'stopping_point')
172     list_display_links = ('library_id', 'library_name')
173     list_filter = ('stopping_point', 'library_species', 'made_for', 'made_by', 'experiment_type')
174     fields = (
175         (None, {
176             'fields': (('library_id', 'library_name'), ('library_species', 'experiment_type'),)
177         }),
178         ('Creation Information:', {
179             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('undiluted_concentration', 'library_size'), 'notes',)
180         }),
181         ('Run Information:', {
182             'fields' : (('ten_nM_dilution','successful_pM'),)
183         }),
184     )
185
186 class FlowCell(models.Model):
187   
188   flowcell_id = models.CharField(max_length=20, unique=True, db_index=True, core=True)
189   run_date = models.DateTimeField(core=True)
190   advanced_run = models.BooleanField(default=False)
191   read_length = models.IntegerField(default=32)
192   
193   
194   FLOWCELL_STATUSES = (
195       ('No', 'Not run'),
196       ('F', 'Failed'),
197       ('Del', 'Data deleted'),
198       ('A', 'Data available'),
199       ('In', 'In progress'),
200     )
201   flowcell_status = models.CharField(max_length=10, choices=FLOWCELL_STATUSES)
202   
203   lane_1_library = models.ForeignKey(Library, related_name="lane_1_library")
204   lane_2_library = models.ForeignKey(Library, related_name="lane_2_library")
205   lane_3_library = models.ForeignKey(Library, related_name="lane_3_library")
206   lane_4_library = models.ForeignKey(Library, related_name="lane_4_library")
207   lane_5_library = models.ForeignKey(Library, related_name="lane_5_library")
208   lane_6_library = models.ForeignKey(Library, related_name="lane_6_library")
209   lane_7_library = models.ForeignKey(Library, related_name="lane_7_library")
210   lane_8_library = models.ForeignKey(Library, related_name="lane_8_library")
211
212   lane_1_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
213   lane_2_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
214   lane_3_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
215   lane_4_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
216   lane_5_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
217   lane_6_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
218   lane_7_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
219   lane_8_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
220   
221   lane_1_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
222   lane_2_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
223   lane_3_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
224   lane_4_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
225   lane_5_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
226   lane_6_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
227   lane_7_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
228   lane_8_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
229   
230   kit_1000148 = models.IntegerField(blank=True, null=True)
231   kit_1000147 = models.IntegerField(blank=True, null=True)
232   kit_1000183 = models.IntegerField(blank=True, null=True)
233   kit_1001625 = models.IntegerField(blank=True, null=True)
234   
235   cluster_station_id = models.CharField(max_length=50, blank=True, null=True)
236   sequencer_id = models.CharField(max_length=50, blank=True, null=True)
237   
238   notes = models.TextField(blank=True)
239
240   def __str__(self):
241     return '%s (%s)' % (self.flowcell_id, self.run_date) 
242   
243   class Meta:
244     ordering = ["-run_date"]
245   
246   class Admin:
247     date_hierarchy = "run_date"
248     save_as = True
249     save_on_top = True
250     search_fields = ['flowcell_id', 'lane_1_library__library_id', 'lane_1_library__library_name', 'lane_2_library__library_id', 'lane_2_library__library_name', 'lane_3_library__library_id', 'lane_3_library__library_name', 'lane_4_library__library_id', 'lane_4_library__library_name', 'lane_5_library__library_id', 'lane_5_library__library_name', 'lane_6_library__library_id', 'lane_6_library__library_name', 'lane_7_library__library_id', 'lane_7_library__library_name', 'lane_8_library__library_id', 'lane_8_library__library_name']
251     list_display = ('run_date', 'flowcell_status', 'flowcell_id', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library')
252     list_display_links = ('run_date', 'flowcell_id', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library')
253     fields = (
254         (None, {
255             'fields': ('run_date', ('flowcell_id', 'flowcell_status'), ('read_length', 'advanced_run'),)
256         }),
257         ('Lanes:', {
258             'fields' : (('lane_1_library', 'lane_1_pM'), ('lane_2_library', 'lane_2_pM'), ('lane_3_library', 'lane_3_pM'), ('lane_4_library', 'lane_4_pM'), ('lane_5_library', 'lane_5_pM'), ('lane_6_library', 'lane_6_pM'), ('lane_7_library', 'lane_7_pM'), ('lane_8_library', 'lane_8_pM'),)
259         }),
260         (None, {
261             'fields' : ('notes',)
262         }),
263         ('Kits & Machines:', {
264             'classes': 'collapse',
265             'fields' : (('kit_1000148', 'kit_1000147', 'kit_1000183', 'kit_1001625'), ('cluster_station_id', 'sequencer_id'),)
266         }),
267         ('Cluster Estimates:', {
268             'classes': 'collapse',
269             'fields' : (('lane_1_cluster_estimate', 'lane_2_cluster_estimate'), ('lane_3_cluster_estimate', 'lane_4_cluster_estimate'), ('lane_5_cluster_estimate', 'lane_6_cluster_estimate'), ('lane_7_cluster_estimate', 'lane_8_cluster_estimate',),)
270         }),
271     )
272
273 # Did not finish implementing, removing to avoid further confusion.
274 #class ElandResult(models.Model):
275 #  
276 #  class Admin: pass
277 #  
278 #  flow_cell = models.ForeignKey(FlowCell)
279 #  config_file = models.FileField(upload_to=settings.UPLOADTO_CONFIG_FILE)
280 #  eland_result_pack = models.FileField(upload_to=settings.UPLOADTO_ELAND_RESULT_PACKS)
281 #  bed_file_pack = models.FileField(upload_to=settings.UPLOADTO_BED_PACKS)
282 #  
283 #  notes = models.TextField(blank=True)