Add RDFa data to our library pages.
[htsworkflow.git] / htsworkflow / frontend / samples / models.py
index cda52a308f994fe673dd65b73f4ad94b0bc8c1ea..8314c71f5e685f2cd44d28805959ddafeb3e5adf 100644 (file)
@@ -1,3 +1,4 @@
+import logging
 import urlparse
 from django.db import models
 from django.contrib.auth.models import User, UserManager
@@ -6,7 +7,9 @@ from django.db import connection
 from htsworkflow.frontend import settings
 from htsworkflow.frontend.reports.libinfopar import *
 
+
 # Create your models here.
+logger = logging.getLogger(__name__)
 
 class Antibody(models.Model):
     antigene = models.CharField(max_length=500, db_index=True)
@@ -127,6 +130,7 @@ class LibraryType(models.Model):
   def __unicode__(self):
     return unicode(self.name)
 
+
 class Library(models.Model):
   id = models.CharField(max_length=10, primary_key=True)
   library_name = models.CharField(max_length=100, unique=True)
@@ -160,10 +164,13 @@ class Library(models.Model):
       ('1A', 'Ligation, then gel'),
       ('PCR', 'Ligation, then PCR'),
       ('1Ab', 'Ligation, PCR, then gel'),
-      ('1Aa', 'Ligation, gel, then PCR'),
+      ('1Ac', 'Ligation, gel, then 12x PCR'),
+      ('1Aa', 'Ligation, gel, then 18x PCR'),
       ('2A', 'Ligation, PCR, gel, PCR'),
       ('Done', 'Completed'),
     )
+  PROTOCOL_END_POINTS_DICT = dict(PROTOCOL_END_POINTS)
+  
   stopping_point = models.CharField(max_length=25, choices=PROTOCOL_END_POINTS, default='Done')
   amplified_from_sample = models.ForeignKey('self', blank=True, null=True, related_name='amplified_into_sample')  
   
@@ -173,16 +180,23 @@ class Library(models.Model):
       # note \u00b5 is the micro symbol in unicode
   successful_pM = models.DecimalField(max_digits=9, decimal_places=1, blank=True, null=True)
   ten_nM_dilution = models.BooleanField()
-  avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
+  gel_cut_size = models.IntegerField(default=225, blank=True, null=True)
+  insert_size = models.IntegerField(blank=True, null=True)
   notes = models.TextField(blank=True)
+
+  bioanalyzer_summary = models.TextField(blank=True,default="")
+  bioanalyzer_concentration = models.DecimalField(max_digits=5, 
+                                decimal_places=2, blank=True, null=True,
+                                help_text=u"(ng/\u00b5l)")
+  bioanalyzer_image_url = models.URLField(blank=True,default="")
   
   def __unicode__(self):
     return u'#%s: %s' % (self.id, self.library_name)
   
   class Meta:
-    verbose_name_plural = "libraries"
-    #ordering = ["-creation_date"] 
-    ordering = ["-id"]
+      verbose_name_plural = "libraries"
+      #ordering = ["-creation_date"] 
+      ordering = ["-id"]
   
   def antibody_name(self):
     str ='<a target=_self href="/admin/samples/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.nickname+'</a>' 
@@ -209,6 +223,15 @@ class Library(models.Model):
     else:
         return False
 
+  def stopping_point_name(self):
+      end_points = Library.PROTOCOL_END_POINTS_DICT
+      name = end_points.get(self.stopping_point, None)
+      if name is None:
+          name = "Lookup Error"
+          logger.error("protocol stopping point in database didn't match names in library model")
+      return name
+      
+
   def libtags(self):
     affs = self.tags.all().order_by('tag_name')
     ar = []
@@ -253,16 +276,20 @@ class Library(models.Model):
     else: tstr = 'not processed yet' 
     return tstr
   aligned_reads.allow_tags = True
-
+  
   def public(self):
     SITE_ROOT = '/'
     summary_url = self.get_absolute_url()
     return '<a href="%s">S</a>' % (summary_url,)
   public.allow_tags = True
-
+    
   @models.permalink
   def get_absolute_url(self):
     return ('htsworkflow.frontend.samples.views.library_to_flowcells', [str(self.id)])
+    
+  
+    
+
 
 class HTSUser(User):
     """
@@ -271,13 +298,14 @@ class HTSUser(User):
     #objects = UserManager()
 
     class Meta:
-        ordering = ['username']
+        ordering = ['first_name', 'last_name', 'username']
 
     def admin_url(self):
         return '/admin/%s/%s/%d' % (self._meta.app_label, self._meta.module_name, self.id)
 
     def __unicode__(self):
-        return unicode(self.username) + u" (" + unicode(self.get_full_name()) + u")"
+        #return unicode(self.username) + u" (" + unicode(self.get_full_name()) + u")"
+        return unicode(self.get_full_name()) + u' (' + unicode(self.username) + ')'
     
 def HTSUserInsertID(sender, instance, **kwargs):
     """