87afc9ee8b3107a1d5cbf317f4df0586a9c24085
[htsworkflow.git] / gaworkflow / frontend / fctracker / models.py
1 from django.db import models
2 from gaworkflow.frontend import settings
3
4 class Antibody(models.Model):
5
6   antibody_name = models.CharField(max_length=100, unique=True, db_index=True, core=True)
7   notes = models.TextField(blank=True)
8   def __str__(self):
9     return self.antibody_name
10   class Meta:
11     verbose_name_plural = "antibodies"
12     ordering = ["antibody_name"]
13   class Admin:
14       fields = (
15         (None, {
16             'fields': (('antibody_name','notes'),)
17         }),
18        )
19
20 class Cellline(models.Model):
21
22   cellline_name = models.CharField(max_length=100, unique=True, db_index=True, core=True)
23   notes = models.TextField(blank=True)
24   def __str__(self):
25     return self.cellline_name
26
27   class Meta:
28     ordering = ["cellline_name"]
29
30   class Admin:
31       fields = (
32         (None, {
33             'fields': (('cellline_name','notes'),)
34         }),
35        )
36
37 class Condition(models.Model):
38
39   condition_name = models.CharField(max_length=2000, unique=True, db_index=True, core=True)
40   notes = models.TextField(blank=True)
41   def __str__(self):
42     return self.condition_name
43
44   class Meta:
45     ordering = ["condition_name"]
46
47   class Admin:
48       fields = (
49         (None, {
50             'fields': (('condition_name','notes'),)
51         }),
52        )
53
54 class Species(models.Model):
55   
56   scientific_name = models.CharField(max_length=256, unique=False, db_index=True, core=True)
57   common_name = models.CharField(max_length=256, blank=True)
58   use_genome_build = models.CharField(max_length=100, blank=True) #blank=False, null=False)
59
60   def __str__(self):
61     return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
62   
63   class Meta:
64     verbose_name_plural = "species"
65     ordering = ["scientific_name"]
66   
67   class Admin:
68       fields = (
69         (None, {
70             'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
71         }),
72       )
73
74 class Library(models.Model):
75   
76   library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
77   library_name = models.CharField(max_length=100, unique=True, core=True)
78   library_species = models.ForeignKey(Species, core=True)
79   #use_genome_build = models.CharField(max_length=100, blank=False, null=False)
80   #RNAseq = models.BooleanField()
81   cell_line = models.ForeignKey(Cellline, blank=True, core=True)
82   condition = models.ForeignKey(Condition,blank=True,core=True)
83   antibody = models.ForeignKey(Antibody,blank=True,core=True)
84   
85   EXPERIMENT_TYPES = (
86       ('INPUT_RXLCh','INPUT_RXLCh'),
87       ('ChIP-seq', 'ChIP-seq'),
88       ('Sheared', 'Sheared'),
89       ('RNA-seq', 'RNA-seq'),
90       ('Methyl-seq', 'Methyl-seq'),
91       ('DIP-seq', 'DIP-seq'),
92     ) 
93   experiment_type = models.CharField(max_length=50, choices=EXPERIMENT_TYPES, default='ChIP-seq')
94
95   made_by = models.CharField(max_length=50, blank=True)
96   creation_date = models.DateField(blank=True, null=True)
97   made_for = models.CharField(max_length=50, blank=True)
98   made_by = models.CharField(max_length=50, blank=True)
99   
100   PROTOCOL_END_POINTS = (
101       ('Completed','Completed'),
102       ('?', 'Unknown'),
103       ('Sample', 'Raw sample'),
104       ('Gel', 'Ran gel'),
105       ('1A', 'Gel purification'),
106       ('2A', '2nd PCR'),
107       ('Progress', 'In progress'),
108     )
109   stopping_point = models.CharField(max_length=50, choices=PROTOCOL_END_POINTS, default='Completed')
110   amplified_from_sample = models.ForeignKey('self', blank=True, null=True)
111   
112   undiluted_concentration = models.DecimalField("Template concentr. (ng/ul)",max_digits=5, decimal_places=2, blank=True, null=True)
113   ten_nM_dilution = models.BooleanField()
114   successful_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=True, null=True)
115   avg_lib_size = models.IntegerField()
116   notes = models.TextField(blank=True)
117   
118   def __str__(self):
119     return '#%s: %s' % (self.library_id, self.library_name)
120   
121   class Meta:
122     verbose_name_plural = "libraries"
123     ordering = ["-library_id"]
124   
125   class Admin:
126     date_hierarchy = "creation_date"
127     save_as = True
128     save_on_top = True
129     search_fields = ['library_name']
130     list_display = ('library_id', 'library_name', 'made_by', 'creation_date', 'ten_nM_dilution', 'stopping_point', 'successful_pM')
131     list_display_links = ('library_id', 'library_name')
132     list_filter = ('stopping_point', 'ten_nM_dilution', 'library_species', 'made_for', 'made_by')
133     fields = (
134         (None, {
135             'fields': (('library_id', 'library_name'), ('library_species'),)
136         }),
137         ('Creation Information:', {
138             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
139         }),
140         )
141
142 class FlowCell(models.Model):
143   
144   flowcell_id = models.CharField(max_length=20, unique=True, db_index=True, core=True)
145   run_date = models.DateTimeField(core=True)
146   advanced_run = models.BooleanField(default=False)
147   read_length = models.IntegerField(default=32) #Stanford is currenlty 25
148   
149   lane_1_library = models.ForeignKey(Library, related_name="lane_1_library")
150   lane_2_library = models.ForeignKey(Library, related_name="lane_2_library")
151   lane_3_library = models.ForeignKey(Library, related_name="lane_3_library")
152   lane_4_library = models.ForeignKey(Library, related_name="lane_4_library")
153   lane_5_library = models.ForeignKey(Library, related_name="lane_5_library")
154   lane_6_library = models.ForeignKey(Library, related_name="lane_6_library")
155   lane_7_library = models.ForeignKey(Library, related_name="lane_7_library")
156   lane_8_library = models.ForeignKey(Library, related_name="lane_8_library")
157
158   lane_1_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
159   lane_2_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
160   lane_3_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
161   lane_4_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
162   lane_5_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
163   lane_6_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
164   lane_7_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
165   lane_8_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
166   
167   lane_1_cluster_estimate = models.IntegerField(blank=True, null=True)
168   lane_2_cluster_estimate = models.IntegerField(blank=True, null=True)
169   lane_3_cluster_estimate = models.IntegerField(blank=True, null=True)
170   lane_4_cluster_estimate = models.IntegerField(blank=True, null=True)
171   lane_5_cluster_estimate = models.IntegerField(blank=True, null=True)
172   lane_6_cluster_estimate = models.IntegerField(blank=True, null=True)
173   lane_7_cluster_estimate = models.IntegerField(blank=True, null=True)
174   lane_8_cluster_estimate = models.IntegerField(blank=True, null=True)
175   
176   #Machine Names
177   CLUSTER_MAC = (
178       ('M304','M304'),
179       ('R349','R349'),
180       ('Tinkerbell','Tinkerbell'),
181       ('BitBit','BitBit'),
182     )
183   
184   SEQ_MAC = (
185       ('EAS149','EAS149'),
186       ('EAS46','EAS46'),
187       ('EAS45','Paris'),
188       ('Britney','Britney'),
189     )
190   
191   #kit_id = models.CharField(max_length=50, blank=True)
192   cluster_mac_id = models.CharField(max_length=50, choices=CLUSTER_MAC, default='M304')
193   seq_mac_id = models.CharField(max_length=50, choices=SEQ_MAC, default='EAS149')
194   
195   notes = models.TextField(blank=True)
196
197   def __str__(self):
198     #return '%s (%s)' % (self.flowcell_id, self.run_date) 
199     return '%s' % (self.flowcell_id) 
200  
201   class Meta:
202     ordering = ["run_date"]
203   
204   class Admin:
205     save_on_top = True
206     date_hierarchy = "run_date"
207     save_on_top = True
208     search_fields = ['lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library']
209     list_display = ('flowcell_id', 'run_date', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library')
210     fields = (
211         (None, {
212             'fields': ('run_date', ('flowcell_id','cluster_mac_id','seq_mac_id'), ('read_length'),)
213         }),
214         ('Lanes:', {
215             'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate'),)
216         }),
217         (None, {
218             'fields' : ('notes',)
219         }),
220     )
221
222 #class ElandResult(models.Model):
223 #  
224 #  class Admin: pass
225 #  
226 #  flow_cell = models.ForeignKey(FlowCell)
227 #  config_file = models.FileField(upload_to=settings.UPLOADTO_CONFIG_FILE)
228 #  eland_result_pack = models.FileField(upload_to=settings.UPLOADTO_ELAND_RESULT_PACKS)
229 #  bed_file_pack = models.FileField(upload_to=settings.UPLOADTO_BED_PACKS)
230 #  
231 #  notes = models.TextField(blank=True)