New Lane Table migration progress.
[htsworkflow.git] / htsworkflow / frontend / experiments / models.py
index 0ac386eea254b0e72cfe13a44b52b95bb3e0edb2..690c18bdc99c824da8fedd31fec5ad2914ffa404 100755 (executable)
@@ -1,6 +1,8 @@
 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)
@@ -14,6 +16,15 @@ class Sequencer(models.Model):
   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):
   
   flowcell_id = models.CharField(max_length=20, unique=True, db_index=True)
@@ -31,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)
@@ -58,10 +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")
 
-  #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)
-  sequencer = models.ForeignKey(Sequencer)
+  cluster_station = models.ForeignKey(ClusterStation, default=3)
+  sequencer = models.ForeignKey(Sequencer, default=1)
   
   notes = models.TextField(blank=True)
 
@@ -81,13 +90,19 @@ 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
 
@@ -147,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)