New Lane Table migration progress.
[htsworkflow.git] / htsworkflow / frontend / experiments / models.py
index 5fdd7b25ce052564dc3caa152fdc5f159489c69a..690c18bdc99c824da8fedd31fec5ad2914ffa404 100755 (executable)
@@ -1,6 +1,29 @@
 from django.db import models
 from htsworkflow.frontend.samples.models import *
+from htsworkflow.frontend.settings import options
 from django.core.exceptions import ObjectDoesNotExist
+import logging
+
+class ClusterStation(models.Model):
+  name = models.CharField(max_length=50, unique=True)
+
+  def __unicode__(self):
+    return unicode(self.name)
+
+class Sequencer(models.Model):
+  name = models.CharField(max_length=50, unique=True)
+
+  def __unicode__(self):
+    return unicode(self.name)
+
+default_pM = 5
+try:
+  default_pM = int(options.get('frontend', 'default_pm'))
+except ValueError,e:
+  logging.error("invalid value for frontend.default_pm")
+
+
+  
 
 class FlowCell(models.Model):
   
@@ -19,14 +42,14 @@ class FlowCell(models.Model):
   lane_7_library = models.ForeignKey(Library, related_name="lane_7_library")
   lane_8_library = models.ForeignKey(Library, related_name="lane_8_library")
 
-  lane_1_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_2_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_3_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_4_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_5_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_6_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_7_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
-  lane_8_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=2.5)
+  lane_1_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_2_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_3_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_4_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_5_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_6_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_7_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  lane_8_pM = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
   
   lane_1_cluster_estimate = models.IntegerField(blank=True, null=True)
   lane_2_cluster_estimate = models.IntegerField(blank=True, null=True)
@@ -46,23 +69,8 @@ class FlowCell(models.Model):
   # lane_7_primer = models.ForeignKey(Primer,blank=True,null=True,related_name="lane_7_primer")
   # lane_8_primer = models.ForeignKey(Primer,blank=True,null=True,related_name="lane_8_primer")
 
-  #Machine Names
-  CLUSTER_MAC = (
-      ('M304','Cardinal'),
-      ('R349','R349'),
-      ('Tinkerbell','Tinkerbell'),
-      ('BitBit','BitBit'),
-    )
-  
-  SEQ_MAC = (
-      ('EAS149','Stanford'),
-      ('EAS46','EAS46'),
-      ('EAS45','Paris'),
-      ('Britney','Britney'),
-    )
-  
-  cluster_mac_id = models.CharField(max_length=50, choices=CLUSTER_MAC, default='BitBit')
-  seq_mac_id = models.CharField(max_length=50, choices=SEQ_MAC, verbose_name = 'Sequencer', default='Britney')
+  cluster_station = models.ForeignKey(ClusterStation, default=3)
+  sequencer = models.ForeignKey(Sequencer, default=1)
   
   notes = models.TextField(blank=True)
 
@@ -82,20 +90,25 @@ class FlowCell(models.Model):
 
   def Lanes(self):
     library_url = '/admin/samples/library/%s' 
-    html = ['<ol>']
+    html = ['<table>']
     for i in range(1,9):
-       library_id = getattr(self, 'lane_%d_library_id' % i)
+        cluster_estimate = getattr(self, 'lane_%d_cluster_estimate' % (i,))
+        if cluster_estimate is not None:
+            cluster_estimate = "%s k" % ((int(cluster_estimate)/1000), )
+        else:
+            cluster_estimate = 'None'
+       library_id = getattr(self, 'lane_%d_library_id' % (i,))
         library = getattr(self, 'lane_%d_library' % i)
-       element = '<li><a href="%s">%s</a></li>'
-        html.append(element % (library_url % library_id, library))
-    html.append('</ol>')
+       element = '<tr><td>%d</td><td><a href="%s">%s</a></td><td>%s</td></tr>'
+        expanded_library_url = library_url %(library_id,)
+        html.append(element % (i, expanded_library_url, library, cluster_estimate))
+    html.append('</table>')
     return "\n".join(html)
   Lanes.allow_tags = True
 
   class Meta:
     ordering = ["-run_date"]
   
-
 ### -----------------------
 class DataRun(models.Model):
   ConfTemplate = "CONFIG PARAMS WILL BE GENERATED BY THE PIPELINE SCRIPT.\nYOU'LL BE ABLE TO EDIT AFTER IF NEEDED."
@@ -149,3 +162,12 @@ class DataRun(models.Model):
     str += '</div>'    
     return str
   Flowcell_Info.allow_tags = True
+
+
+class Lane(models.Model):
+  flowcell = models.ForeignKey(FlowCell)
+  lane_number = models.IntegerField(choices=[(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8)])
+  library = models.ForeignKey(Library)
+  pm = models.DecimalField(max_digits=5, decimal_places=2,blank=False, null=False,default=default_pM)
+  cluster_estimate = models.IntegerField(blank=True, null=True)
+  comment = models.TextField(null=True, blank=True)