Merge in model changes to fctracker from htsworkflow branch
authorDiane Trout <diane@caltech.edu>
Tue, 21 Oct 2008 19:39:50 +0000 (19:39 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 21 Oct 2008 19:39:50 +0000 (19:39 +0000)
htsworkflow/frontend/fctracker/models.py

index e12f0fe71c2cad09c7cb499378d1d6185292d759..c4e1e3ce97475acf280edb5e640bef3f368aa129 100644 (file)
@@ -1,11 +1,15 @@
 from django.db import models
 from django.contrib.auth.models import User
 from htsworkflow.frontend import settings
+from htsworkflow.reports.libinfopar import *
 
 # Create your models here.
 
 class Antibody(models.Model):
   antigene = models.CharField(max_length=500, db_index=True)
+  # New field Aug/20/08                                                                                                                                                            
+  # SQL to add column: alter table fctracker_antibody add column "nickname" varchar(20) NULL;
+  nickname = models.CharField(max_length=20,blank=True,null=True, db_index=True,verbose_name = 'Short Name')
   catalog = models.CharField(max_length=50, unique=True, db_index=True)
   antibodies = models.CharField(max_length=500, db_index=True)
   source = models.CharField(max_length=500, blank=True, db_index=True)
@@ -17,11 +21,11 @@ class Antibody(models.Model):
     verbose_name_plural = "antibodies"
     ordering = ["antigene"]
   class Admin:
-      list_display = ('antigene','antibodies','catalog','source','biology','notes')
+      list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
       list_filter = ('antibodies','source')
       fields = (
         (None, {
-            'fields': (('antigene','antibodies'),('catalog','source'),('biology'),('notes'))
+            'fields': (('antigene','nickname','antibodies'),('catalog','source'),('biology'),('notes'))
         }),
        )
 
@@ -77,40 +81,28 @@ class Species(models.Model):
         }),
       )
 
-class Lab(models.Model):
-  
-  name = models.CharField(max_length=100, blank=False, unique=True)
+class Affiliation(models.Model):
+  name = models.CharField(max_length=256, db_index=True, core=True,verbose_name='Group Name')
+  contact = models.CharField(max_length=256, null=True, blank=True,verbose_name='Contact Name')  
+  email = models.EmailField(null=True,blank=True)
   
   def __str__(self):
-    return self.name
-  
-  class Admin:
-    pass
+    str = self.name
+    if self.contact != '':
+      str += ' ('+self.contact+')' 
+    return str
 
-class UserProfile(models.Model):
-  
-  # This allows you to use user.get_profile() to get this object
-  user = models.ForeignKey(User, unique=True)
-
-  lab = models.ForeignKey(Lab)
-  #email = models.CharField(max_length=50, blank=True, null=True)
-  
-  def __str__(self):
-    return '%s (%s lab)' % (self.user, self.lab)
-  
   class Meta:
-    #verbose_name_plural = "people"
-    #ordering = ["lab"]
-    pass
-    
-  class Admin:
-    #fields = (
-    #  (None, {
-    #      'fields': (('email', 'lab'), ('email'))
-    #  }),
-    #)
-    pass
+    ordering = ["name","contact"]
+    unique_together = (("name", "contact"),)
 
+  class Admin:
+      list_display = ('name','contact','email')
+      fields = (
+        (None, {
+            'fields': (('name','contact','email'))
+        }),
+      )
 
 class Library(models.Model):
   
@@ -120,7 +112,13 @@ class Library(models.Model):
   cell_line = models.ForeignKey(Cellline,core=True)
   condition = models.ForeignKey(Condition,core=True)
   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 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))
+  replicate =  models.PositiveSmallIntegerField(choices=REPLICATE_NUM,default=1) 
+
   EXPERIMENT_TYPES = (
       ('INPUT_RXLCh','INPUT_RXLCh'),
       ('ChIP-seq', 'ChIP-seq'),
@@ -161,123 +159,67 @@ class Library(models.Model):
   
   class Meta:
     verbose_name_plural = "libraries"
-    ordering = ["-library_id"]
-  
+    ordering = ["-creation_date"] #["-library_id"]
+  
+  def antibody_name(self):
+    return self.antibody.nickname
+
+  def org(self):
+    return self.library_species.common_name
+
+  def affiliation(self):
+    affs = self.affiliations.all().order_by('name')
+    tstr = ''
+    ar = []
+    for t in affs:
+        ar.append(t.__str__())
+    return '%s' % (", ".join(ar))
+
+
+  def aligned_reads(self):
+    res = getLibReads(self.library_id)
+    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
+    if res[0] > 0:
+      bgcolor = '#ff3300'  # Red
+      rc_thr = [10000000,5000000,3000000]
+      if self.experiment_type == 'RNA-seq':
+        rc_thr = [20000000,10000000,6000000]
+
+      if res[1] > rc_thr[0]:
+        bgcolor = '#66ff66'  # Green
+      else:
+        if res[1] > rc_thr[1]:
+          bgcolor ='#00ccff'  # Blue
+        else:
+           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 += '</div>'
+    else: tstr = 'not processed yet' 
+    return tstr
+  aligned_reads.allow_tags = True
+
   class Admin:
     date_hierarchy = "creation_date"
     save_as = True
     save_on_top = True
-    search_fields = ['library_name', 'library_id']
-    list_display = ('library_id', 'library_name', 'made_for', 'creation_date', 'stopping_point')
+    ##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_links = ('library_id', 'library_name')
-    list_filter = ('stopping_point', 'library_species', 'made_for', 'made_by', 'experiment_type')
+
+    list_filter = ('experiment_type','affiliations','library_species','made_for', 'made_by','replicate')
     fields = (
         (None, {
-            'fields': (('library_id', 'library_name'), ('library_species', 'experiment_type'),)
+            'fields': (('replicate','library_id','library_name'),('library_species'),('experiment_type'),('cell_line','condition','antibody'),)
         }),
         ('Creation Information:', {
             'fields' : (('made_for', 'made_by', 'creation_date'), ('stopping_point', 'amplified_from_sample'), ('undiluted_concentration', 'library_size'), 'notes',)
         }),
-       ('Run Information:', {
-           'fields' : (('ten_nM_dilution','successful_pM'),)
-       }),
-    )
-
-class FlowCell(models.Model):
-  
-  flowcell_id = models.CharField(max_length=20, unique=True, db_index=True, core=True)
-  run_date = models.DateTimeField(core=True)
-  advanced_run = models.BooleanField(default=False)
-  read_length = models.IntegerField(default=32)
-  
-  
-  FLOWCELL_STATUSES = (
-      ('No', 'Not run'),
-      ('F', 'Failed'),
-      ('Del', 'Data deleted'),
-      ('A', 'Data available'),
-      ('In', 'In progress'),
-    )
-  flowcell_status = models.CharField(max_length=10, choices=FLOWCELL_STATUSES)
-  
-  lane_1_library = models.ForeignKey(Library, related_name="lane_1_library")
-  lane_2_library = models.ForeignKey(Library, related_name="lane_2_library")
-  lane_3_library = models.ForeignKey(Library, related_name="lane_3_library")
-  lane_4_library = models.ForeignKey(Library, related_name="lane_4_library")
-  lane_5_library = models.ForeignKey(Library, related_name="lane_5_library")
-  lane_6_library = models.ForeignKey(Library, related_name="lane_6_library")
-  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, default=4)
-  lane_2_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_3_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_4_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_5_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_6_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_7_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  lane_8_pM = models.DecimalField(max_digits=5, decimal_places=2, default=4)
-  
-  lane_1_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_2_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_3_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_4_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_5_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_6_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_7_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  lane_8_cluster_estimate = models.CharField(max_length=25, blank=True, null=True)
-  
-  kit_1000148 = models.IntegerField(blank=True, null=True)
-  kit_1000147 = models.IntegerField(blank=True, null=True)
-  kit_1000183 = models.IntegerField(blank=True, null=True)
-  kit_1001625 = models.IntegerField(blank=True, null=True)
-  
-  cluster_station_id = models.CharField(max_length=50, blank=True, null=True)
-  sequencer_id = models.CharField(max_length=50, blank=True, null=True)
-  
-  notes = models.TextField(blank=True)
-
-  def __str__(self):
-    return '%s (%s)' % (self.flowcell_id, self.run_date) 
-  
-  class Meta:
-    ordering = ["-run_date"]
-  
-  class Admin:
-    date_hierarchy = "run_date"
-    save_as = True
-    save_on_top = True
-    search_fields = ['flowcell_id', 'lane_1_library__library_id', 'lane_1_library__library_name', 'lane_2_library__library_id', 'lane_2_library__library_name', 'lane_3_library__library_id', 'lane_3_library__library_name', 'lane_4_library__library_id', 'lane_4_library__library_name', 'lane_5_library__library_id', 'lane_5_library__library_name', 'lane_6_library__library_id', 'lane_6_library__library_name', 'lane_7_library__library_id', 'lane_7_library__library_name', 'lane_8_library__library_id', 'lane_8_library__library_name']
-    list_display = ('run_date', 'flowcell_status', 'flowcell_id', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library')
-    list_display_links = ('run_date', 'flowcell_id', 'lane_1_library', 'lane_2_library', 'lane_3_library', 'lane_4_library', 'lane_5_library', 'lane_6_library', 'lane_7_library', 'lane_8_library')
-    fields = (
-        (None, {
-            'fields': ('run_date', ('flowcell_id', 'flowcell_status'), ('read_length', 'advanced_run'),)
-        }),
-        ('Lanes:', {
-            'fields' : (('lane_1_library', 'lane_1_pM'), ('lane_2_library', 'lane_2_pM'), ('lane_3_library', 'lane_3_pM'), ('lane_4_library', 'lane_4_pM'), ('lane_5_library', 'lane_5_pM'), ('lane_6_library', 'lane_6_pM'), ('lane_7_library', 'lane_7_pM'), ('lane_8_library', 'lane_8_pM'),)
+        ('Library/Project Affiliation:', {
+            'fields' : (('affiliations'),)
         }),
-       (None, {
-           'fields' : ('notes',)
-       }),
-       ('Kits & Machines:', {
-           'classes': 'collapse',
-           'fields' : (('kit_1000148', 'kit_1000147', 'kit_1000183', 'kit_1001625'), ('cluster_station_id', 'sequencer_id'),)
-       }),
-       ('Cluster Estimates:', {
-           'classes': 'collapse',
-           'fields' : (('lane_1_cluster_estimate', 'lane_2_cluster_estimate'), ('lane_3_cluster_estimate', 'lane_4_cluster_estimate'), ('lane_5_cluster_estimate', 'lane_6_cluster_estimate'), ('lane_7_cluster_estimate', 'lane_8_cluster_estimate',),)
-       }),
-    )
+        )
 
-# Did not finish implementing, removing to avoid further confusion.
-#class ElandResult(models.Model):
-#  
-#  class Admin: pass
-#  
-#  flow_cell = models.ForeignKey(FlowCell)
-#  config_file = models.FileField(upload_to=settings.UPLOADTO_CONFIG_FILE)
-#  eland_result_pack = models.FileField(upload_to=settings.UPLOADTO_ELAND_RESULT_PACKS)
-#  bed_file_pack = models.FileField(upload_to=settings.UPLOADTO_BED_PACKS)
-#  
-#  notes = models.TextField(blank=True)