added checking on parser Status check: if !='OK' print err message and skip the count...
authorRami Rauch <rrauch@stanford.edu>
Tue, 2 Dec 2008 21:29:48 +0000 (21:29 +0000)
committerRami Rauch <rrauch@stanford.edu>
Tue, 2 Dec 2008 21:29:48 +0000 (21:29 +0000)
htswfrontend/htswfrontend/fctracker/models.py

index b7d3abde55bc5a1692c0a75ab473481ac92d9759..d7ae0d575b39dcab6f408ec18aaa28d498917fd6 100644 (file)
@@ -44,6 +44,7 @@ class Antibody(models.Model):
 
 class Cellline(models.Model):
   cellline_name = models.CharField(max_length=100, unique=True, db_index=True)
+  nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
   notes = models.TextField(blank=True)
   def __str__(self):
     return '%s' % (self.cellline_name)
@@ -52,15 +53,16 @@ class Cellline(models.Model):
     ordering = ["cellline_name"]
 
   class Admin:
-      list_display = ('cellline_name','notes')
+      list_display = ('cellline_name','nickname','notes')
       fields = (
         (None, {
-            'fields': (('cellline_name'),('notes'),)
+            'fields': (('cellline_name','nickname'),('notes'),)
         }),
        )
 
 class Condition(models.Model):
   condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
+  nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
   notes = models.TextField(blank=True)
   def __str__(self):
     return '%s' % (self.condition_name)
@@ -69,10 +71,10 @@ class Condition(models.Model):
     ordering = ["condition_name"]
 
   class Admin:
-      list_display = ('condition_name','notes')
+      list_display = ('condition_name','nickname','notes')
       fields = (
         (None, {
-            'fields': (('condition_name'),('notes'),)
+            'fields': (('condition_name','nickname'),('notes'),)
         }),
        )
 
@@ -118,6 +120,31 @@ class Affiliation(models.Model):
         }),
       )
 
+class Tag(models.Model):
+  tag_name = models.CharField(max_length=100, db_index=True,core=True,blank=False,null=False)
+  TAG_CONTEXT = (
+      #('Antibody','Antibody'),
+      #('Cellline', 'Cellline'),
+      #('Condition', 'Condition'),
+      ('Library', 'Library'),
+      ('ANY','ANY'),
+    )
+  context = models.CharField(max_length=50, choices=TAG_CONTEXT, default='Library')
+
+  def __str__(self):
+    return '%s' % (self.tag_name)
+
+  class Meta:
+    ordering = ["context","tag_name"]
+
+  class Admin:
+      list_display = ('tag_name','context')
+      fields = (
+        (None, {
+            'fields': ('tag_name','context')
+        }),
+      )
+
 class Library(models.Model):
   library_id = models.CharField(max_length=30, unique=True, db_index=True, core=True)
   library_name = models.CharField(max_length=100, unique=True, core=True)
@@ -127,6 +154,8 @@ class Library(models.Model):
   antibody = models.ForeignKey(Antibody,blank=True,null=True,core=True)
   # New field Aug/25/08. SQL: alter table fctracker_library add column "lib_affiliation" varchar(256)  NULL;
   affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True,filter_interface=models.HORIZONTAL)
+  # New field Nov/14/08
+  tags = models.ManyToManyField(Tag,related_name='library_tags',blank=True,null=True,filter_interface=models.HORIZONTAL)
   # New field Aug/19/08
   # SQL to add column: alter table fctracker_library add column "replicate" smallint unsigned NULL;
   REPLICATE_NUM = ((1,1),(2,2),(3,3),(4,4))
@@ -174,11 +203,16 @@ class Library(models.Model):
     ordering = ["-creation_date"] #["-library_id"]
   
   def antibody_name(self):
-    return self.antibody.nickname
+    str ='<a target=_self href="/admin/fctracker/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.nickname+'</a>'
+    return str
+  antibody_name.allow_tags = True
 
   def org(self):
     return self.library_species.common_name
 
+  def cond(self):
+    return self.condition.nickname
+
   def affiliation(self):
     affs = self.affiliations.all().order_by('name')
     tstr = ''
@@ -187,14 +221,34 @@ class Library(models.Model):
         ar.append(t.__str__())
     return '%s' % (", ".join(ar))
 
+  def libtags(self):
+    affs = self.tags.all().order_by('tag_name')
+    tstr = ''
+    ar = []
+    for t in affs:
+        ar.append(t.__str__())
+    return '%s' % (", ".join(ar))
+
+  def DataRun(self):
+    str ='<a target=_self href="/admin/exp_track/datarun/?q='+self.library_id+'" title="Check All Data Runs for This Specific Library ..." ">DataRuns ..</a>'
+    return str
+  DataRun.allow_tags = True
+
+  def aligned_m_reads(self):
+    return getLibReads(self.library_id)
 
   def aligned_reads(self):
     res = getLibReads(self.library_id)
+
+    # Check data sanlty
+    if res[2] != 'OK':
+      return '<div style="border:solid red 2px">'+res[2]+'</div>'
+
     rc = "%1.2f" % (res[1]/1000000.0)
-    # Color Scheme: green is more than 10M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds should be doubled
+    # Color Scheme: green is more than 12M, blue is more than 5M, orange is more than 3M and red is less. For RNAseq, all those thresholds should be doubled
     if res[0] > 0:
-      bgcolor = '#ff3300'  # Red
-      rc_thr = [10000000,5000000,3000000]
+      bgcolor = '#ff3300'  # Red, the color for minimum read count
+      rc_thr = [12000000,5000000,3000000]
       if self.experiment_type == 'RNA-seq':
         rc_thr = [20000000,10000000,6000000]
 
@@ -207,7 +261,7 @@ class Library(models.Model):
            if res[1] > rc_thr[2]: 
              bgcolor ='#ffcc33'  # Orange
       tstr = '<div style="background-color:'+bgcolor+';color:black">'
-      tstr += res[0].__str__()+' Lanes, '+rc+' M Reads'
+      tstr += res[0].__str__()+' Lanes, '+rc+' M'
       tstr += '</div>'
     else: tstr = 'not processed yet' 
     return tstr
@@ -219,9 +273,9 @@ class Library(models.Model):
     save_on_top = True
     ##search_fields = ['library_id','library_name','affiliations__name','affiliations__contact','made_by','made_for','antibody__antigene','antibody__catalog','antibody__antibodies','antibody__source','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
     search_fields = ['library_id','library_name','cell_line__cellline_name','library_species__scientific_name','library_species__common_name','library_species__use_genome_build']
-    list_display = ('affiliation','library_id','aligned_reads','library_name','experiment_type','org','replicate','antibody_name','cell_line','made_by','creation_date')
+    list_display = ('affiliation','library_id','aligned_reads','DataRun','library_name','experiment_type','org','replicate','antibody_name','cell_line','cond','libtags','made_by','creation_date')
     list_display_links = ('library_id', 'library_name')
-    list_filter = ('experiment_type','affiliations','library_species','made_for', 'made_by','replicate')
+    list_filter = ('experiment_type','affiliations','library_species','tags','made_for', 'made_by','replicate','antibody','cell_line','condition')
     fields = (
         (None, {
             'fields': (('replicate','library_id','library_name'),('library_species'),('experiment_type'),('cell_line','condition','antibody'),)
@@ -230,6 +284,6 @@ class Library(models.Model):
             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
         }),
         ('Library/Project Affiliation:', {
-            'fields' : (('affiliations'),)
+            'fields' : (('affiliations'),('tags'),)
         }),
         )