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