Merged much of the stanford htsworkflow frontend into trunk.
authorDiane Trout <diane@caltech.edu>
Wed, 14 Jan 2009 01:12:47 +0000 (01:12 +0000)
committerDiane Trout <diane@caltech.edu>
Wed, 14 Jan 2009 01:12:47 +0000 (01:12 +0000)
Updated to be compatable with Django 1.0

A big change for the 1.0 compatibility is the Admin class that was
attached to models was moved into a seperate file admin.py

I probably munged some of the fieldset formatting in the conversion process.

19 files changed:
docs/Conv_CaltechDB_Nov112008.txt [new file with mode: 0644]
htsworkflow/frontend/analysis/admin.py [new file with mode: 0644]
htsworkflow/frontend/analysis/models.py
htsworkflow/frontend/eland_config/forms.py
htsworkflow/frontend/experiments/admin.py [new file with mode: 0644]
htsworkflow/frontend/experiments/models.py
htsworkflow/frontend/experiments/views.py
htsworkflow/frontend/reports/admin.py [new file with mode: 0644]
htsworkflow/frontend/reports/libinfopar.py
htsworkflow/frontend/reports/reports.py [new file with mode: 0755]
htsworkflow/frontend/reports/urls.py
htsworkflow/frontend/samples/admin.py [new file with mode: 0644]
htsworkflow/frontend/samples/models.py
htsworkflow/frontend/settings.py
htsworkflow/frontend/templates/admin/base_site.html [new file with mode: 0644]
htsworkflow/frontend/templates/experiments/detail.html [new file with mode: 0644]
htsworkflow/frontend/templates/experiments/flowcellSheet.html [new file with mode: 0644]
htsworkflow/frontend/templates/experiments/index.html [new file with mode: 0644]
htsworkflow/frontend/urls.py

diff --git a/docs/Conv_CaltechDB_Nov112008.txt b/docs/Conv_CaltechDB_Nov112008.txt
new file mode 100644 (file)
index 0000000..9d6997a
--- /dev/null
@@ -0,0 +1,76 @@
+Conversion SQLs for Caltech DB (schema of 2008Aug08 @ 5:06 PM) 
+______________________________________________________________
+
+
+Step by step do the following:
+
+''' Note: Instead of '?' you can put one of your machine names.
+sqlite> ALTER TABLE fctracker_flowcell ADD cluster_mac_id varchar(50) NOT NULL DEFAULT '?';
+sqlite> ALTER TABLE fctracker_flowcell ADD seq_mac_id varchar(50) NOT NULL DEFAULT '?';
+sqlite> ALTER TABLE fctracker_library RENAME TO PREV_fctracker_library;
+
+Now, do a syncdb. The output should look like this (assuming you have migrated to the new models.py):
+sh-3.2# pym syncdb
+Creating table fctracker_cellline
+Creating table fctracker_library
+Creating table fctracker_primer
+Creating table fctracker_antibody
+Creating table fctracker_condition
+Creating table exp_track_datarun
+Creating table exp_track_flowcell
+Creating table analys_track_project
+Creating table analys_track_task
+Creating table htsw_reports_progressreport
+Installing index for fctracker.Library model
+Failed to install index for fctracker.Library model: index fctracker_library_library_species_id already existsInstalling index for fctracker.Primer model
+Installing index for fctracker.Antibody model
+Installing index for exp_track.DataRun model
+Installing index for exp_track.FlowCell model
+Installing index for analys_track.Task model
+Installing index for htsw_reports.ProgressReport model
+sh-3.2# 
+
+''' Copy all records from "fctracker_flowcell" to "exp_track_flowcell" table. (Why? Because, Flowcell table moves now from the "fctracker" to the "exp_track" component). 
+sqlite> insert into experiments_flowcell select * from fctracker_flowcell;
+
+''' Now to fctracker_library, a bit more complex case
+
+'''Back to the sqlite prompt..
+sqlite> insert into samples_cellline (cellline_name,notes) values('Unknown','Unknown');
+sqlite> insert into samples_condition (condition_name,notes) values('Unknown','Unknown');
+''' Now we can put 1 in these fields for the Library insert.
+''' Note: avg_lib_size field is missing in Caltech DB (although it's in the models.py Trac), so I put default value 225.
+
+''' Now the actual migration to the new fctracker_library table
+''' (This version looses data, the current Nov 11, 2008 schema, has made_for as a one to many 
+''' relationship to the auth_user table, instead of being a text field. Here I just assigned
+''' the made for to a (semi)-random user.
+sqlite> INSERT INTO samples_library (library_id,library_name,library_species_id,experiment_type,cell_line_id,condition_id,replicate,made_by,creation_date,made_for_id,stopping_point,amplified_from_sample_id,undiluted_concentration,ten_nM_dilution,successful_pM,avg_lib_size,notes) select library_id,library_name,library_species_id,'unknown',1,1,1,made_by,creation_date,12,stopping_point,amplified_from_sample_id,undiluted_concentration,ten_nM_dilution,successful_pM,0,notes from PREV_fctracker_library; 
+
+''' Set the right values for "experiment_type"
+sqlite> update samples_library set experiment_type = "RNA-seq" where library_idin (select library_id from prev_fctracker_library where RNASeq = 1);
+''' YOU CAN ADD SIMILAR SQL CMD TO SET THE VALUE FOR "avg_lib_size" FIELD (WHICH IS NOW SET TO 0) ...  
+
+----------------------------------------------------------------------------------------
+THAT SHOULD BE IT --- NOW YOUR WEB SITE SHOULD SUCESSFULY LOAD THE NEW DB WITH YOUR DATA.
+
+2009 Jan 13 
+
+I had a working database and then merged in a few more changes from
+stanford. I ended up needing to do the following:
+
+alter table analysis_task add task_params varchar(200) null;
+alter table samples_cellline add nickname varchar(20) null;
+alter table samples_condition add nickname varchar(20) null;
+
+Those changes might happen automatically when reconverting from our 
+original database, or they might not.
+
+CREATE TABLE "samples_library_tags" (
+    "id" integer NOT NULL PRIMARY KEY,
+    "library_id" varchar(30) NOT NULL REFERENCES "samples_library" ("library_id"),
+    "tag_id" integer NOT NULL REFERENCES "samples_tag" ("id"),
+    UNIQUE ("library_id", "tag_id")
+)
+;
+
diff --git a/htsworkflow/frontend/analysis/admin.py b/htsworkflow/frontend/analysis/admin.py
new file mode 100644 (file)
index 0000000..d3f903e
--- /dev/null
@@ -0,0 +1,31 @@
+from htsworkflow.frontend.analysis.models import Task, Project
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+class ProjectOptions(admin.ModelAdmin):
+  list_display = ('ProjTitle','ProjectTasks')
+  list_filter = ()
+  search_fieldsets = ['project_name','=tasks__subject1__library_id','=tasks__subject2__library_id','tasks__subject1__library_name','tasks__subject2__library_name','project_notes']
+  fieldsets = (
+    (None, {
+      'fields': (('project_name'),('tasks'),('project_notes'))}),
+  )
+  filter_horizontal = ('tasks',)
+
+class TaskOptions(admin.ModelAdmin):
+  list_display = ('task_name','apply_calc','subject1','subject2','task_params','InProjects','submitted_on','task_status')
+  list_filter = ('apply_calc',)
+  search_fieldsets = ['task_name','id','=subject1__library_id','=subject2__library_id']
+  fieldsets = (
+      (None, {
+        'fields': (('task_name'),('apply_calc'),('subject1'),('subject2'),('task_params'))
+         }),
+        ('system fields', {
+           'classes': ('collapse',),
+         'fields': (('submitted_on'),('task_status','run_note'))
+        }),
+      )
+
+admin.site.register(Project, ProjectOptions)
+admin.site.register(Task, TaskOptions)
+
index 4b1c72d1d0b1faa9af538a622f0e69ab3dafc3be..b98cfac652bdcd64f5f23d34938953edeaf1cdbb 100644 (file)
@@ -18,6 +18,7 @@ class Task(models.Model):
     )
   apply_calc = models.CharField(max_length=50,choices=CALCS,verbose_name='Applied Calculation')
   ## userid = # logged in user
+  task_params = models.CharField(max_length=200,blank=True,null=True,default="")
   task_status = models.CharField(max_length=500,blank=True,null=True,default='defined')
   results_location = models.CharField(max_length=2000,blank=True,null=True) 
   submitted_on = models.DateTimeField(default=datetime.now())
@@ -35,24 +36,10 @@ class Task(models.Model):
         pstr += '%s, ' % (p.project_name) 
       return pstr
 
-  class Admin:
-    list_display = ('task_name','apply_calc','subject1','subject2','InProjects','submitted_on','task_status')
-    list_filter = ('apply_calc',)
-    search_fields = ['task_name','id','=subject1__library_id','=subject2__library_id']
-    fields = (
-        (None, {
-          'fields': (('task_name'),('apply_calc'),('subject1'),('subject2'))
-           }),
-          ('system fields', {
-             'classes': 'collapse',
-           'fields': (('submitted_on'),('task_status','run_note'))
-          }),
-        )
-    
     
 class Project(models.Model):
     project_name = models.CharField(max_length=50,unique=True, db_index=True)
-    tasks = models.ManyToManyField(Task,related_name='project_tasks',null=True,filter_interface=models.HORIZONTAL)
+    tasks = models.ManyToManyField(Task,related_name='project_tasks',null=True)
     project_notes = models.CharField(max_length=500,blank=True,null=True)
     
     def __str__(self):
@@ -60,7 +47,7 @@ class Project(models.Model):
 
     def ProjectTasks(self):
       ptasks = self.tasks.all().order_by('id')
-      surl = 'http://m304-apple-server.stanford.edu/projects/' 
+      surl = settings.ANALYSIS_SERVER+'/projects/' 
       tstr = '<script>'
       tstr += 'function togView(eid){'
       tstr += 'f=document.getElementById(eid);'
@@ -79,7 +66,12 @@ class Project(models.Model):
       tstr += '<table><tr><th>Tasks</th><th>Job Status</th>'
       isregistered = False
       for t in ptasks:
-        tstr += '<tr><td width=250>%s</td><td>%s</td></tr>'  % (t.task_name,replace(t.task_status,'Complete','<span style="color:green;font-weight:bolder">Complete</span>'))
+        taskdesc = t.task_name+'<div style="font-size:80%">Details: '+t.apply_calc+' on '+t.subject1.library_id
+        if t.subject2 is not None:
+          taskdesc += ' and '+t.subject2.library_id
+        taskdesc += ' (TaskId:'+t.id.__str__()+')'
+        tstr += '<tr><td width=250>%s</td><td>%s</td></tr>'  % (taskdesc,replace(t.task_status,'Complete','<span style="color:green;font-weight:bolder">Complete</span>'))
+
         if t.task_status != 'defined': isregistered = True
 
       tstr += '</table>'
@@ -107,11 +99,3 @@ class Project(models.Model):
 
     ProjTitle.allow_tags = True
 
-    class Admin:
-      list_display = ('ProjTitle','ProjectTasks')
-      list_filter = ()
-      search_fields = ['project_name','=tasks__subject1__library_id','=tasks__subject2__library_id','tasks__subject1__library_name','tasks__subject2__library_name','project_notes']
-      fields = (
-        (None, {
-          'fields': (('project_name'),('tasks'),('project_notes'))}),
-        )
index 2488359a451727e0c017dfe07b26fed3fc301542..a2245f9f35548fe8f231f30cfd7505e18230ea9f 100644 (file)
@@ -1,5 +1,5 @@
-from django import newforms as forms
-from django.newforms.util import ErrorList
+from django import forms
+from django.forms.util import ErrorList
 
 
 SPECIES_LIST = [#('--choose--', '--Choose--'),
@@ -160,4 +160,4 @@ class ConfigForm(forms.Form):
     return '\n'.join(html)
     
     
-    
\ No newline at end of file
+    
diff --git a/htsworkflow/frontend/experiments/admin.py b/htsworkflow/frontend/experiments/admin.py
new file mode 100644 (file)
index 0000000..a33aa41
--- /dev/null
@@ -0,0 +1,35 @@
+from htsworkflow.frontend.experiments.models import FlowCell, DataRun
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+class DataRunOptions(admin.ModelAdmin):
+  search_fieldsets = ['run_folder','run_note','config_params','=fcid__lane_1_library__library_id','=fcid__lane_2_library__library_id','=fcid__lane_3_library__library_id','=fcid__lane_4_library__library_id','=fcid__lane_5_library__library_id','=fcid__lane_6_library__library_id','=fcid__lane_7_library__library_id','=fcid__lane_8_library__library_id']
+
+class FlowCellOptions(admin.ModelAdmin):
+    date_hierarchy = "run_date"
+    save_on_top = True
+    search_fieldsets = ('flowcell_id',
+        'seq_mac_id',
+        'cluster_mac_id',
+        '=lane_1_library__library_id',
+        '=lane_2_library__library_id',
+        '=lane_3_library__library_id',
+        '=lane_4_library__library_id',
+        '=lane_5_library__library_id',
+        '=lane_6_library__library_id',
+        '=lane_7_library__library_id',
+        '=lane_8_library__library_id')
+    list_display = ('flowcell_id','seq_mac_id','run_date', 'Create_LOG','Lanes')
+    list_filter = ('seq_mac_id','cluster_mac_id')
+    fieldsets = (
+        (None, {
+            'fields': ('run_date', ('flowcell_id','cluster_mac_id','seq_mac_id'), ('read_length'),)
+        }),
+        ('Lanes:', {
+           'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate'),)
+        }),
+    )
+
+admin.site.register(DataRun, DataRunOptions)
+admin.site.register(FlowCell, FlowCellOptions)
+
index 4e7e696797a1f6afb6a93a18ee315dff2d46d868..17a315e2fc68dc0dc50ba7cc81b48331bb4f8e98 100755 (executable)
@@ -4,7 +4,7 @@ from htsworkflow.frontend.samples.models import *
 class FlowCell(models.Model):
   
   flowcell_id = models.CharField(max_length=20, unique=True, db_index=True)
-  run_date = models.DateTimeField(core=True)
+  run_date = models.DateTimeField()
   advanced_run = models.BooleanField(default=False)
   read_length = models.IntegerField(default=32) #Stanford is currenlty 25
   
@@ -64,13 +64,12 @@ class FlowCell(models.Model):
   
   notes = models.TextField(blank=True)
 
-  def __str__(self):
-    #return '%s (%s)' % (self.flowcell_id, self.run_date) 
-    return '%s' % (self.flowcell_id) 
+  def __unicode__(self):
+      return unicode(self.flowcell_id) 
 
   def Create_LOG(self):
     str = '' #<span style="color:red;font-size:80%;margin-right:3px">New!</span>'
-    str +='<a target=_balnk href="/exp_track/'+self.flowcell_id+'" title="Create XLS like sheet for this Flowcell ..." ">Create LOG</a>'
+    str +='<a target=_balnk href="/experiments/'+self.flowcell_id+'" title="Create XLS like sheet for this Flowcell ..." ">Create LOG</a>'
     return str
   Create_LOG.allow_tags = True 
 
@@ -78,28 +77,6 @@ class FlowCell(models.Model):
     return '<div><span style="margin-right:10px">1)%s</span><span style="margin-right:10px">2)%s</span><span style="margin-right:10px">3)%s</span><span style="margin-right:10px">4)%s</span><span style="margin-right:10px">5)%s</span><span style="margin-right:10px">6)%s</span><span style="margin-right:10px">7)%s</span><span style="margin-right:10px">8)%s</span></div>' % (self.lane_1_library,self.lane_2_library,self.lane_3_library,self.lane_4_library,self.lane_5_library,self.lane_6_library,self.lane_7_library,self.lane_8_library)
   Lanes.allow_tags = True
  
-  class Meta:
-    ordering = ["-run_date"]
-  
-  class Admin:
-    save_on_top = True
-    date_hierarchy = "run_date"
-    save_on_top = True
-    search_fields = ['flowcell_id','seq_mac_id','cluster_mac_id','=lane_1_library__library_id','=lane_2_library__library_id','=lane_3_library__library_id','=lane_4_library__library_id','=lane_5_library__library_id','=lane_6_library__library_id','=lane_7_library__library_id','=lane_8_library__library_id']
-    list_display = ('flowcell_id','seq_mac_id','run_date', 'Create_LOG','Lanes')
-    list_filter = ('seq_mac_id','cluster_mac_id')
-    fields = (
-        (None, {
-            'fields': ('run_date', ('flowcell_id','cluster_mac_id','seq_mac_id'), ('read_length'),)
-        }),
-        ('Lanes:', {
-            ##'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate', 'lane_1_primer'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate', 'lane_2_primer'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate', 'lane_3_primer'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate', 'lane_4_primer'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate', 'lane_5_primer'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate', 'lane_6_primer'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate', 'lane_7_primer'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate', 'lane_8_primer'),)
-           'fields' : (('lane_1_library', 'lane_1_pM', 'lane_1_cluster_estimate'), ('lane_2_library', 'lane_2_pM', 'lane_2_cluster_estimate'), ('lane_3_library', 'lane_3_pM', 'lane_3_cluster_estimate'), ('lane_4_library', 'lane_4_pM', 'lane_4_cluster_estimate'), ('lane_5_library', 'lane_5_pM', 'lane_5_cluster_estimate'), ('lane_6_library', 'lane_6_pM', 'lane_6_cluster_estimate'), ('lane_7_library', 'lane_7_pM', 'lane_7_cluster_estimate'), ('lane_8_library', 'lane_8_pM', 'lane_8_cluster_estimate'),)
-        }),
-       (None, {
-           'fields' : ('notes',)
-       }),
-    )
 
 
 ### -----------------------
@@ -108,7 +85,7 @@ class DataRun(models.Model):
   run_folder = models.CharField(max_length=50,unique=True, db_index=True)
   fcid = models.ForeignKey(FlowCell,verbose_name="Flowcell Id")
   config_params = models.TextField(default=ConfTemplate)
-  run_start_time = models.DateTimeField(core=True)
+  run_start_time = models.DateTimeField()
   RUN_STATUS_CHOICES = (
       (0, 'Sequencer running'), ##Solexa Data Pipeline Not Yet Started'),
       (1, 'Data Pipeline Started'),
@@ -156,8 +133,3 @@ class DataRun(models.Model):
     return str
   Flowcell_Info.allow_tags = True
 
-  class Admin:
-    search_fields = ['run_folder','run_note','config_params','=fcid__lane_1_library__library_id','=fcid__lane_2_library__library_id','=fcid__lane_3_library__library_id','=fcid__lane_4_library__library_id','=fcid__lane_5_library__library_id','=fcid__lane_6_library__library_id','=fcid__lane_7_library__library_id','=fcid__lane_8_library__library_id']
-
-    list_display = ('run_folder','Flowcell_Info','run_start_time','main_status','run_note')
-    list_filter = ('run_status','run_start_time')
index 11d09cfe23a8ce068d324bb7ef4bab48fe34987b..3b6dbff81de6b19d72bc177055a70bb5238028b7 100755 (executable)
@@ -9,19 +9,19 @@ from django.core.exceptions import ObjectDoesNotExist
 
 def index(request):
     all_runs = DataRun.objects.all().order_by('-run_start_time')
-    #t = loader.get_template('exptrack/index.html')
+    #t = loader.get_template('experiments/index.html')
     #c = Context({
     #    'data_run_list': all_runs,
     #})
     #return HttpResponse(t.render(c)) 
     # shortcut to the above module usage
-    return render_to_response('exptrack/index.html',{'data_run_list': all_runs}) 
+    return render_to_response('experiments/index.html',{'data_run_list': all_runs}) 
     
 def detail(request, run_folder):
     html_str = '<h2>Exp Track Details Page</h2>'
     html_str += 'Run Folder: '+run_folder
     r = get_object_or_404(DataRun,run_folder=run_folder)
-    return render_to_response('exptrack/detail.html',{'run_f': r})
+    return render_to_response('experiments/detail.html',{'run_f': r})
 
 def makeFCSheet(request,fcid):
   # get Flowcell by input fcid
@@ -32,7 +32,7 @@ def makeFCSheet(request,fcid):
   except ObjectDoesNotExist:
     pass
   lanes = ['1','2','3','4','5','6','7','8']
-  return render_to_response('exptrack/flowcellSheet.html',{'fc': rec})
+  return render_to_response('experiments/flowcellSheet.html',{'fc': rec})
 
 def test_Libs(request):
   str = ''
diff --git a/htsworkflow/frontend/reports/admin.py b/htsworkflow/frontend/reports/admin.py
new file mode 100644 (file)
index 0000000..b5a0eb2
--- /dev/null
@@ -0,0 +1,10 @@
+from htsworkflow.frontend.reports.models import ProgressReport
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+class ProgressReportOptions(admin.ModelAdmin):
+  list_display = ('Study','ab_batch','cell_line','library','sequencing','aligned_reads','QPCR','submit_to_DCC','submit_to_NCBI','interactome_complete')
+  ## list_filter = ('interactome_complete')
+
+admin.site.register(ProgressReport, ProgressReportOptions)
+
index 56c75ad21028c005fd88b0218d69d461b7acc9a6..954fce693dc847d725fddc8b3e62b627fe8b924c 100644 (file)
@@ -1,3 +1,4 @@
+from htsworkflow.frontend import settings
 from django.http import HttpResponse
 from datetime import datetime
 from string import *
@@ -22,16 +23,19 @@ class LibInfoHandler(ContentHandler):
     self.searchTerm= searchTerm
     self.currlibid = ''
     self.LanesCount, self.ReadsCount = 0, 0
-    self.Msg = ''
+    self.Msg = 'OK'
        
   def startElement(self, name, attrs):
-    if name == 'Library':     
-      self.currlibid = attrs.get('Name',"")      
-    elif name == 'Track' and self.searchTerm == self.currlibid:
-      self.LanesCount += len(attrs.get('Lane',""))
-      self.ReadsCount += int(attrs.get('Count',""))
-    else:
-      self.Msg += ' | name = '+name+', currlibid = '+ self.currlibid
+    try:
+      if name == 'Library':     
+        self.currlibid = attrs.get('Name',"")      
+      elif name == 'Track' and self.searchTerm == self.currlibid:
+        self.LanesCount += len(attrs.get('Lane',""))
+        self.ReadsCount += int(attrs.get('Count',""))
+      #else:
+      #  self.Msg += ' | name = '+name+', currlibid = '+ self.currlibid
+    except: 
+      self.Msg = 'failed parsing xml file'
     return
 
   #def characters (self, ch):
@@ -48,10 +52,14 @@ def getLibReads(libid):
   parser = make_parser()   
   curHandler = LibInfoHandler(searchTerm)
   parser.setContentHandler(curHandler)
-  parser.parse(open('/htsworkflow/htswfrontend/htswfrontend/htsw_reports/LibInfo/LibraryInfo.xml'))
+  reports_dir = os.path.split(__file__)[0]
+  library_info = os.path.join(reports_dir, 'LibraryInfo.xml')
+  parser.parse(open(library_info))
   arRes = []
   arRes.append(curHandler.LanesCount) 
   arRes.append(curHandler.ReadsCount)
+  arRes.append(curHandler.Msg)
+
   return arRes
 
 def getWebPage(url,params):
@@ -64,7 +72,7 @@ def getWebPage(url,params):
 
 def refreshLibInfoFile(request): 
  varStatus = 'getting conf file from exp trac server'
- url = 'http://m304-apple-server.stanford.edu/ENCODE/LibraryInfo.xml'
+ url = settings.TASKS_PROJS_SERVER+'/LibraryInfo.xml'
  params = {}
  readw = getWebPage(url,params)
  # make sure file content starts as xml
@@ -80,7 +88,9 @@ def refreshLibInfoFile(request):
    if day < 10: day = "0"+day.__str__()
    else: day = day.__str__()
    mydate = year+month+day
-   folder = '/htsworkflow/htswfrontend/htswfrontend/htsw_reports/LibInfo/'
+   folder_loc = '/htsworkflow/htswfrontend/htswfrontend'  # DEV                                                                                                                          
+   #folder_loc = '/Library/WebServer/gaworkflow/gaworkflow/frontend'  # PROD
+   folder = folder_loc+'/htsw_reports/LibInfo/'
    os.rename(folder+'LibraryInfo.xml',folder+mydate+'_LibraryInfo.xml')
    # create file in curret folder
    file_path = os.path.join(folder,'LibraryInfo.xml')
diff --git a/htsworkflow/frontend/reports/reports.py b/htsworkflow/frontend/reports/reports.py
new file mode 100755 (executable)
index 0000000..712dd14
--- /dev/null
@@ -0,0 +1,308 @@
+from htsworkflow.frontend.experiments.models import *
+from django.http import HttpResponse
+from django.core.exceptions import ObjectDoesNotExist
+from django.shortcuts import render_to_response, get_object_or_404
+
+def getBgColor(reads_cnt,exp_type):
+  # 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 are ~ double
+  bgcolor = '#ff3300'  # Red is the color for minimum read counts                                                                                                                            
+  rc_thr = [12000000,5000000,3000000] # Default for ChIP-Seq and Methyl-Seq
+  if exp_type == 'RNA-seq':
+    rc_thr = [20000000,10000000,6000000]
+
+  if reads_cnt > rc_thr[0]:
+    bgcolor = '#66ff66'  # Green                                                                                                                                                                                                                                               
+  else:
+    if reads_cnt > rc_thr[1]:
+      bgcolor ='#00ccff'  # Blue                                                                                                                                                                                                                                               
+    else:
+       if reads_cnt > rc_thr[2]:
+         bgcolor ='#ffcc33'  # Orange                                                                                                                                                                                                                                          
+  #tstr = '<div style="background-color:'+bgcolor+';color:black">'
+  #tstr += res[0].__str__()+' Lanes, '+rc+' M Reads'
+  #tstr += '</div>'
+
+  return bgcolor
+
+def report1(request):
+  EXP = 'ChIP-seq'
+
+  if request.has_key('aflid'):
+    AFL_Id = request['aflid']
+    try:
+      AFL = Affiliation.objects.get(id=AFL_Id).name
+      AFL_CNT = Affiliation.objects.get(id=AFL_Id).contact
+    except ObjectDoesNotExist:
+      return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL_ID+"'")
+  else:
+    AFL = 'ENCODE_Tier1'
+    AFL_CNT = ''
+    try:
+      AFL_Id = Affiliation.objects.get(name=AFL,contact=AFL_CNT).id.__str__()
+    except ObjectDoesNotExist:
+      return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL+"'")
+  
+  TFall = Library.objects.values('antibody').order_by('antibody').distinct()
+  CLLall = Library.objects.values('cell_line').order_by('cell_line').distinct()
+
+  TFs = TFall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT)
+  CLLs = CLLall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT)
+
+  # Check Replicate numbers
+  Reps = 1
+  RepRecs = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT).order_by('-replicate')
+  if len(RepRecs) > 0: Reps = RepRecs[0].replicate
+  
+  ########
+  str = ''
+  str += '<span style="margin-right:20px"><a target=_self href="/admin" target=_self">Main Page</a></span>'
+  ##str += '<span style="margin-right:20px">Max Replicates: '+MaxRep.replicate.__str__()+'</span>'
+  str += '<span>Select another <b>'+EXP+'</b> Report:</span>  <select>'
+  for af in Affiliation.objects.distinct():
+    str += '<option value='+af.id.__str__()
+    if AFL_Id == af.id.__str__():
+      str += ' selected'
+    str += ' onclick="window.location=\'/htsw_reports/report?aflid='+af.id.__str__()+'\'; return false;">'+af.name+' '+af.contact+'</option>'  
+  str += '</select>'
+
+  str += '<span style="margin-left:20px;padding:1px;border:solid #cccccc 1px">color scheme: <span style="margin-left:5px;background-color:#66ff66"> > 12 M</span><span style="margin-left:5px;background-color:#00ccff"> >  5 M</span><span style="margin-left:5px;background-color:#ffcc33"> > 3 M</span><span style="margin-left:5px;background-color:#ff3300"> < 3 M</span></span>' 
+
+  str += '<span style="margin-left:20px">'
+  str += '<u>Switch to:</u> '+AFL+' '+AFL_CNT+' <a target=_self href="/htsw_reports/report_RM?exp=RNA-seq&aflid='+AFL_Id+'"><b>RNA-Seq</b> Report</a>'
+  str += '  | '
+  str += '<a target=_self href="/htsw_reports/report_RM?exp=Methyl-seq&aflid='+AFL_Id+'"><b>Methyl-Seq</b> Report</a>'
+
+  bgc = '#ffffff' 
+  pbgc = '#f7f7f7'
+  str += '<br/><br/><table border=1 cellspacing="2">'
+  str += '<tr><th style="text-align:right">PROJECT</th><th colspan='+(Reps*len(CLLs)).__str__()+' style="text-align:center">'+AFL+' '+AFL_CNT+' <span style="font-size:140%">'+EXP+'</span></th></tr>'
+  str += '<tr><th style="text-align:right">CELL LINE</th>'
+  for H in CLLs: 
+    str += '<th colspan='+Reps.__str__()+' style="text-align:center;background-color:'+bgc+'">'+Cellline.objects.get(id=H['cell_line']).cellline_name+'</th>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc 
+  str += '</tr><tr><th style="text-align:left">TF</th>'
+  bgc = '#ffffff'
+  pbgc = '#f7f7f7'
+  for H in CLLs:
+    for r in range(1,Reps+1):
+      str += '<th style="text-align:center;background-color:'+bgc+'">Rep. '+r.__str__()+'</th>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc
+  str += '</tr>'
+  str += '<tr><td align=right><a title="View Libraries Records" target=_self href=/admin/fctracker/library/?affiliations__id__exact='+AFL_Id+'&experiment_type__exact=INPUT_RXLCh>Total Chromatin</a></td>'
+  bgc = '#ffffff'
+  pbgc = '#f7f7f7'
+  for H in CLLs:
+    for r in range(1,Reps+1):
+      repReads = Library.objects.filter(experiment_type='INPUT_RXLCh',affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'].__str__(),replicate=r)
+      str += "<td align=center style='background-color:"+bgc+"'>"
+      if len(repReads) == 0:
+        str += 'No Libraries'
+      else:
+        cnt = 0
+        for R1 in repReads:
+          rres = R1.aligned_m_reads()
+          # Check data sanlty                                                                                                                                           
+          if rres[2] != 'OK':
+            str += '<div style="border:solid red 2px">'+rres[2]
+          else:
+            cnt = rres[1]
+            if cnt > 0:
+              str += "<div style='background-color:"+getBgColor(cnt,EXP)+";font-size:140%'>"
+              str += "%1.2f" % (cnt/1000000.0)+" M"
+            else:  str += "<div style='background-color:#ff3300;width:100%;font-size:140%'>0 Reads"
+          str += "<div style='font-size:70%'>"+R1.library_id+", "+R1.condition.nickname+"</div>"
+          str += "</div>"
+      str += '</td>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc
+  str += '</tr>' 
+
+  for T in TFs:
+    str += '<tr>'
+    try:
+      if T['antibody']:
+        str += '<td><a title="View Libraries Records" target=_self href=/admin/fctracker/library/?affiliations__id__exact='+AFL_Id+'&antibody__id__exact='+T['antibody'].__str__()+'>'+Antibody.objects.get(id=T['antibody']).nickname+'</a></td>'
+    except Antibody.DoesNotExist:
+      str += '<td>n/a</td>'
+
+    bgc = '#ffffff'
+    pbgc = '#f7f7f7'
+    for H in CLLs:
+      for r in range(1,Reps+1):
+        repReads = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'].__str__(),antibody=T['antibody'].__str__(),replicate=r)
+        str += "<td align=center style='background-color:"+bgc+"'>"
+        if len(repReads) == 0: 
+          str += 'No Libraries'
+        else:
+          cnt = 0
+          for R1 in repReads:
+            rres = R1.aligned_m_reads()
+            # Check data sanlty
+            if rres[2] != 'OK':
+              str += '<div style="border:solid red 2px">'+rres[2]
+            else:
+              cnt = rres[1]
+              if cnt > 0:
+                str += "<div style='background-color:"+getBgColor(cnt,EXP)+";font-size:140%'>"
+                str += "%1.2f" % (cnt/1000000.0)+" M"
+              else:  str += "<div style='background-color:#ff3300;width:100%;font-size:140%'>0 Reads"
+            str += "<div style='font-size:70%'>"+R1.library_id+", "+R1.condition.nickname+"</div>"
+            str += "</div>"
+        str += '</td>'
+      tbgc = bgc
+      bgc = pbgc
+      pbgc = tbgc
+    str += '</tr>'
+  str += '</table>'
+
+  return render_to_response('htsw_reports/report.html',{'main': str})
+
+
+def report_RM(request): #for RNA-Seq and Methyl-Seq
+  EXP = 'RNA-seq'  
+
+  if request.has_key('exp'):
+    EXP = request['exp'] # Methyl-seq
+
+  if request.has_key('aflid'):
+    AFL_Id = request['aflid']
+    try:
+      AFL = Affiliation.objects.get(id=AFL_Id).name
+      AFL_CNT = Affiliation.objects.get(id=AFL_Id).contact
+    except ObjectDoesNotExist:
+      return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL_ID+"'")
+  else:
+    AFL = 'ENCODE_Tier1'
+    AFL_CNT = ''
+    try:
+      AFL_Id = Affiliation.objects.get(name=AFL,contact=AFL_CNT).id.__str__()
+    except ObjectDoesNotExist:
+      return HttpResponse("ERROR: Affiliation Record Not Found for: '"+AFL+"'")
+
+  CLLall = Library.objects.values('cell_line').order_by('cell_line').distinct()
+  CLLs = CLLall.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT)
+
+  ########
+  # Check Replicate numbers
+  Reps = 1
+  RepRecs = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT).order_by('-replicate')
+  if len(RepRecs) > 0: Reps = RepRecs[0].replicate
+                                                                                                                                                                              
+  str = ''
+  str += '<span style="margin-right:20px"><a  target=_self href="/admin" target=_self">Main Page</a></span>'
+  str += '<span>Select another <b>'+EXP+'</b> Report:</span> <select>'
+  for af in Affiliation.objects.distinct():
+    str += '<option value='+af.id.__str__()
+    if AFL_Id == af.id.__str__():
+      str += ' selected'
+    str += ' onclick="window.location=\'/htsw_reports/report_RM?exp='+EXP+'&aflid='+af.id.__str__()+'\'; return false;">'+af.name+' '+af.contact+'</option>'
+  str += '</select>'
+
+  if EXP == 'RNA-seq':
+    str += '<span style="margin-left:20px;padding:1px;border:solid #cccccc 1px">color scheme: <span style="margin-left:5px;background-color:#66ff66"> > 20 M</span><span style="margin-left:5px;background-color:#00ccff"> >  10 M</span><span style="margin-left:5px;background-color:#ffcc33"> > 6 M</span><span style="margin-left:5px;background-color:#ff3300"> < 6 M</span></span>'
+    str += '<span style="margin-left:20px">'
+    str += '<u>Switch to:</u> '+AFL+' '+AFL_CNT+' <a target=_self href="/htsw_reports/report?exp=RNA-seq&aflid='+AFL_Id+'"><b>ChIP-Seq</b> Report</a>'
+    str += '  | '
+    str += '<a target=_self href="/htsw_reports/report_RM?exp=Methyl-seq&aflid='+AFL_Id+'"><b>Methyl-Seq</b> Report</a>'
+  else:
+    str += '<span style="margin-left:20px;padding:1px;border:solid #cccccc 1px">color scheme: <span style="margin-left:5px;background-color:#66ff66"> > 12 M</span><span style="margin-left:5px;background-color:#00ccff"> >  5 M</span><span style="margin-left:5px;background-color:#ffcc33"> > 3 M</span><span style="margin-left:5px;background-color:#ff3300"> < 3 M</span></span>'
+    str += '<span style="margin-left:20px">'
+    str += '<u>Switch to:</u> '+AFL+' '+AFL_CNT+' <a target=_self href="/htsw_reports/report?exp=RNA-seq&aflid='+AFL_Id+'"><b>ChIP-Seq</b> Report</a>'
+    str += '  | '
+    str += '<a target=_self href="/htsw_reports/report_RM?exp=RNA-seq&aflid='+AFL_Id+'"><b>RNA-Seq</b> Report</a>'
+
+  str += '<br/><br/><table border=1 cellspacing="2">'
+  str += '<tr><th colspan='+(Reps*len(CLLs)).__str__()+' style="text-align:center">'+AFL+' '+AFL_CNT+'  <span style="font-size:140%">'+EXP+'</span></th></tr>'
+  str += '<tr>'
+  bgc = '#ffffff'
+  pbgc = '#f7f7f7'
+  for H in CLLs:
+    str += '<th colspan='+Reps.__str__()+' style="text-align:center;background-color:'+bgc+'">'+Cellline.objects.get(id=H['cell_line']).cellline_name+'</th>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc
+  str += '</tr><tr>'
+  bgc = '#ffffff'
+  pbgc = '#f7f7f7'
+  for H in CLLs:
+    for r in range(1,Reps+1):
+      str += '<th style="text-align:center;background-color:'+bgc+'">Rep. '+r.__str__()+'</th>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc
+  str += '</tr>'
+
+  str += '<tr>' 
+  bgc = '#ffffff'
+  pbgc = '#f7f7f7'
+  for H in CLLs:
+    for r in range(1,Reps+1):
+      repReads = Library.objects.filter(experiment_type=EXP,affiliations__name=AFL,affiliations__contact=AFL_CNT,cell_line=H['cell_line'],replicate=r)                                                                                                                    
+      str += "<td align=center valign=top style='background-color:"+bgc+"'>"
+      if len(repReads) == 0:
+        str += 'No Libraries'
+      else:
+        cnt = 0
+        for R1 in repReads:
+          rres = R1.aligned_m_reads()
+          # Check data sanlty   
+          if rres[2] != 'OK':
+            str += '<div style="border:solid red 2px">'+rres[2]
+          else:
+            cnt = rres[1]
+            if cnt > 0:
+              str += "<div style='background-color:"+getBgColor(cnt,EXP)+";border:solid #cccccc 1px;font-size:140%'>"
+              str += "%1.2f" % (cnt/1000000.0)+" M"
+            else:  str += "<div style='background-color:#ff3300;border:solid #cccccc 1px;width:100%;font-size:140%'>0 Reads"
+          str += "<div style='font-size:80%'><a title='View Record' target=_self href=/admin/fctracker/library/?q="+R1.library_id+">"+R1.library_id+"</a>, "+R1.condition.nickname+", "+R1.library_species.common_name+"</div>"
+          str += "<div style='font-size:70%'>\""+R1.library_name+"\"</div"
+          str += "</div>"
+      str += '</td>'
+    tbgc = bgc
+    bgc = pbgc
+    pbgc = tbgc
+  str += '</tr>'
+  str += '</table>'
+
+  return render_to_response('htsw_reports/report.html',{'main': str})
+
+def getNotRanFCs(request):
+  FCall = FlowCell.objects.order_by('-run_date').distinct()
+  str = '<table><tr><th>FlowCell</th><th>Lanes</th><th>Creation Date</th></tr>'
+  for f in FCall:
+    try:
+      t = DataRun.objects.get(fcid=f.id)
+    except ObjectDoesNotExist:
+      str += '<tr><td>'+f.flowcell_id+'</td><td>'+f.Lanes()+'</td><td>'+f.run_date.__str__()+'</td></tr>'
+  str += "</table>"
+  return render_to_response('htsw_reports/report.html',{'main':str})
+def test_Libs(request):
+  str = ''
+  str += '<table border=1><tr><th>Lib ID</th><th>Current Libaray Name (Free Text)</th><th>Auto-composed Libaray Name (antibody + celline + libid + species + [replicate])</th></tr>'
+  allLibs = Library.objects.all()
+  #allLibs = Library.objects.filter(antibody__isnull=False)
+  for L in allLibs:
+    str += '<tr>'
+    str += '<td>'+L.library_id+'</td><td>'+L.library_name+'</td>'   
+    str += '<td>'
+    str += L.experiment_type+'_'
+    if L.cell_line.cellline_name != 'Unknown':
+      str += L.cell_line.cellline_name+'_'
+
+    try:
+      if L.antibody is not None:
+        str += L.antibody.nickname + '_'
+    except Antibody.DoesNotExist:
+      pass
+  
+    str += 'Rep'+L.replicate.__str__()
+    str += '</td></tr>' 
+
+  str += '</table>'
+  return HttpResponse(str)  
index 9b0acf94add6fa9558020d106ff29a687edbcbc7..69a9f12b5656f9eb35ef8d02239be73a7d7f0ffa 100644 (file)
@@ -2,4 +2,8 @@ from django.conf.urls.defaults import *
 
 urlpatterns = patterns('',                                               
     (r'^updLibInfo$', 'htsworkflow.reports.libinfopar.refreshLibInfoFile'),
+    (r'^report$', 'htsworkflow.reports.reports.report1'),
+    (r'^report_RM$', 'htsworkflow.reports.reports.report_RM'),
+    (r'^report_FCs$', 'htsworkflow.reports.reports.getNotRanFCs'),
+    (r'^liblist$', 'htsworkflow.reports.reports.test_Libs')
 )
diff --git a/htsworkflow/frontend/samples/admin.py b/htsworkflow/frontend/samples/admin.py
new file mode 100644 (file)
index 0000000..f8d45d0
--- /dev/null
@@ -0,0 +1,118 @@
+from htsworkflow.frontend.samples.models import Antibody, Cellline, Condition, Species, Affiliation, Library, Tag
+from django.contrib import admin
+from django.utils.translation import ugettext_lazy as _
+
+class Library_Inline(admin.TabularInline):
+  model = Library
+
+class CelllineOptions(admin.ModelAdmin):
+    fieldsets = (
+      (None, {
+          'fields': (('cellline_name'),('notes'),)
+      }),
+     )
+
+class LibraryOptions(admin.ModelAdmin):
+    date_hierarchy = "creation_date"
+    save_as = True
+    save_on_top = True
+    search_fieldsets = (
+        'library_id',
+        'library_name',
+        'cell_line__cellline_name',
+        'library_species__scientific_name',
+        'library_species__common_name',
+    )
+    list_display = (
+        'library_id',
+        'aligned_reads',
+        'DataRun',
+        'library_name',
+        'experiment_type',
+        'organism',
+        'antibody_name',
+        'cell_line',
+        'libtags',
+        'made_for',
+        'made_by',
+        'stopping_point',
+        'creation_date',
+        'condition',
+    )
+    list_filter = (
+        'experiment_type', 
+        'library_species', 
+        'tags',
+        'made_for',
+        'made_by', 
+        'antibody',
+        'cell_line',
+        'condition',
+        'stopping_point')
+    list_display_links = ('library_id', 'library_name',)
+    fieldsets = (
+      (None, {
+        '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'), ('avg_lib_size','undiluted_concentration', 'ten_nM_dilution', 'successful_pM'), 'notes',)
+         }),
+         ('Library/Project Affiliation:', {
+             'fields' : (('affiliations'), ('tags'),)
+         }),
+         )
+
+class AffiliationOptions(admin.ModelAdmin):
+    list_display = ('name','contact','email')
+    fieldsets = (
+      (None, {
+          'fields': (('name','contact','email'))
+      }),
+    )
+
+# class UserOptions(admin.ModelAdmin):
+#   inlines = [Library_Inline]
+
+class AntibodyOptions(admin.ModelAdmin):
+    list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
+    list_filter = ('antibodies','source')
+    fieldsets = (
+      (None, {
+          'fields': (('antigene','nickname','antibodies'),('catalog','source'),('biology'),('notes'))
+      }),
+     )
+
+class SpeciesOptions(admin.ModelAdmin):
+    fieldsets = (
+      (None, {
+          'fields': (('scientific_name', 'common_name'),)
+      }),
+    )
+
+class ConditionOptions(admin.ModelAdmin):
+    list_display = (('condition_name'), ('notes'),)
+    fieldsets = (
+      (None, {
+          'fields': (('condition_name'),('nickname'),('notes'),)
+      }),
+     )
+
+class TagOptions(admin.ModelAdmin):
+    list_display = ('tag_name', 'context')
+    fieldsets = ( 
+        (None, {
+          'fields': ('tag_name', 'context')
+          }),
+        )
+
+admin.site.register(Affiliation, AffiliationOptions)
+admin.site.register(Antibody, AntibodyOptions)
+admin.site.register(Cellline, CelllineOptions)
+admin.site.register(Condition, ConditionOptions)
+admin.site.register(Library, LibraryOptions)
+admin.site.register(Species, SpeciesOptions)
+admin.site.register(Tag, TagOptions)
index b393028c62cf038d03739c98ebdfd62aee7929c9..9cc0b926f8af1d0cd617735e6e2d0686ef0f7f7b 100644 (file)
 from django.db import models
 from django.contrib.auth.models import User
 from htsworkflow.frontend import settings
-#from htsworkflow.reports.libinfopar import *
+from htsworkflow.frontend.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)
-  biology = models.TextField(blank=True)
-  notes = models.TextField(blank=True)
-  def __str__(self):
-    return '%s - %s (%s)' % (self.antigene, self.antibodies, self.catalog)
-  class Meta:
-    verbose_name_plural = "antibodies"
-    ordering = ["antigene"]
-  class Admin:
-      list_display = ('antigene','nickname','antibodies','catalog','source','biology','notes')
-      list_filter = ('antibodies','source')
-      fields = (
-        (None, {
-            'fields': (('antigene','nickname','antibodies'),('catalog','source'),('biology'),('notes'))
-        }),
-       )
+    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)
+    biology = models.TextField(blank=True)
+    notes = models.TextField(blank=True)
+    def __unicode__(self):
+        return u'%s - %s (%s)' % (self.antigene, self.antibodies, self.catalog)
+    class Meta:
+        verbose_name_plural = "antibodies"
+        ordering = ["antigene"]
 
 class Cellline(models.Model):
-  cellline_name = models.CharField(max_length=100, unique=True, db_index=True)
-  notes = models.TextField(blank=True)
-  def __str__(self):
-    return '%s' % (self.cellline_name)
-
-  class Meta:
-    ordering = ["cellline_name"]
-
-  class Admin:
-      fields = (
-        (None, {
-            'fields': (('cellline_name'),('notes'),)
-        }),
-       )
+    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 __unicode__(self):
+        return unicode(self.cellline_name)
+
+    class Meta:
+        ordering = ["cellline_name"]
 
 class Condition(models.Model):
-  condition_name = models.CharField(max_length=2000, unique=True, db_index=True)
-  notes = models.TextField(blank=True)
-  def __str__(self):
-    return '%s' % (self.condition_name)
-
-  class Meta:
-    ordering = ["condition_name"]
-
-  class Admin:
-      fields = (
-        (None, {
-            'fields': (('condition_name'),('notes'),)
-        }),
-       )
-
+    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 __unicode__(self):
+        return unicode(self.condition_name)
+
+    class Meta:
+        ordering = ["condition_name"]
+
+class Tag(models.Model): 
+  tag_name = models.CharField(max_length=100, db_index=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 __unicode__(self): 
+    return u'%s' % (self.tag_name) 
+  class Meta: 
+    ordering = ["context","tag_name"] 
 class Species(models.Model):
-  
-  scientific_name = models.CharField(max_length=256, unique=False, db_index=True)
+  scientific_name = models.CharField(max_length=256, 
+      unique=False, 
+      db_index=True
+  )
   common_name = models.CharField(max_length=256, blank=True)
-  use_genome_build = models.CharField(max_length=100, blank=False, null=False)
+  #use_genome_build = models.CharField(max_length=100, blank=False, null=False)
 
-  def __str__(self):
-    return '%s (%s)|%s' % (self.scientific_name, self.common_name, self.use_genome_build)
+  def __unicode__(self):
+    return u'%s (%s)' % (self.scientific_name, self.common_name)
   
   class Meta:
     verbose_name_plural = "species"
     ordering = ["scientific_name"]
   
-  class Admin:
-      fields = (
-        (None, {
-            'fields': (('scientific_name', 'common_name'), ('use_genome_build'))
-        }),
-      )
-
 class Affiliation(models.Model):
   name = models.CharField(max_length=256, db_index=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):
-    str = self.name
-    if self.contact != '':
-      str += ' ('+self.contact+')' 
+  def __unicode__(self):
+    str = unicode(self.name)
+    if len(self.contact) != 0:
+      str += u' ('+self.contact+u')' 
     return str
 
   class Meta:
     ordering = ["name","contact"]
     unique_together = (("name", "contact"),)
 
-  class Admin:
-      list_display = ('name','contact','email')
-      fields = (
-        (None, {
-            'fields': (('name','contact','email'))
-        }),
-      )
-
 class Library(models.Model):
   
   library_id = models.CharField(max_length=30, primary_key=True, db_index=True)
@@ -113,7 +115,9 @@ class Library(models.Model):
   condition = models.ForeignKey(Condition)
   antibody = models.ForeignKey(Antibody,blank=True,null=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)
+  affiliations = models.ManyToManyField(Affiliation,related_name='library_affiliations',null=True)
+  # new field Nov/14/08
+  tags = models.ManyToManyField(Tag,related_name='library_tags',blank=True,null=True)
   # 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))
@@ -131,7 +135,7 @@ class Library(models.Model):
                                      default='RNA-seq')
   
   creation_date = models.DateField(blank=True, null=True)
-  made_for = models.ForeignKey(User, edit_inline=models.TABULAR)
+  made_for = models.ForeignKey(User)
   made_by = models.CharField(max_length=50, blank=True, default="Lorian")
   
   PROTOCOL_END_POINTS = (
@@ -154,17 +158,19 @@ class Library(models.Model):
   avg_lib_size = models.IntegerField(default=225, blank=True, null=True)
   notes = models.TextField(blank=True)
   
-  def __str__(self):
-    return '#%s: %s' % (self.library_id, self.library_name)
+  def __unicode__(self):
+    return u'#%s: %s' % (self.library_id, self.library_name)
   
   class Meta:
     verbose_name_plural = "libraries"
     ordering = ["-creation_date"] #["-library_id"]
   
   def antibody_name(self):
-    return self.antibody.nickname
+    str ='<a target=_self href="/admin/samples/antibody/'+self.antibody.id.__str__()+'/" title="'+self.antibody.__str__()+'">'+self.antibody.nickname+'</a>' 
+    return str
+  antibody_name.allow_tags = True
 
-  def org(self):
+  def organism(self):
     return self.library_species.common_name
 
   def affiliation(self):
@@ -172,12 +178,31 @@ class Library(models.Model):
     tstr = ''
     ar = []
     for t in affs:
-        ar.append(t.__str__())
+        ar.append(t.__unicode__())
     return '%s' % (", ".join(ar))
 
+  def libtags(self):
+    affs = self.tags.all().order_by('tag_name')
+    ar = []
+    for t in affs:
+      ar.append(t.__unicode__())
+    return u'%s' % ( ", ".join(ar))
+
+  def DataRun(self):
+    str ='<a target=_self href="/admin/experiments/datarun/?q='+self.library_id+'" title="Check All Data Runs for This Specific Library ..." ">Data Run</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 sanity
+    if res[2] != "OK":
+      return u'<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
     if res[0] > 0:
@@ -195,32 +220,9 @@ 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].__unicode__()+' 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_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 = ('library_id','library_name','experiment_type','replicate','antibody_name','made_by','creation_date')
-    #list_display_links = ('library_id', 'library_name')
-
-    list_filter = ('experiment_type','affiliations','library_species', 'made_by','replicate')
-    fields = (
-        (None, {
-        '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',)
-        }),
-        ('Library/Project Affiliation:', {
-            'fields' : (('affiliations'),)
-        }),
-        )
-
index 32272242a3548c5b943754f902e1241ccef2f737..76aa1f356fa2ec5697ac0c06c14d3f683c389ec3 100644 (file)
@@ -133,7 +133,7 @@ TEMPLATE_DIRS = (
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
-    os.path.abspath("../templates"),
+    os.path.join(os.path.split(__file__)[0], 'templates'),
 )
 
 INSTALLED_APPS = (
diff --git a/htsworkflow/frontend/templates/admin/base_site.html b/htsworkflow/frontend/templates/admin/base_site.html
new file mode 100644 (file)
index 0000000..c212302
--- /dev/null
@@ -0,0 +1,16 @@
+{% extends "admin/base.html" %}
+{% load i18n %}
+
+{% block title %}
+{{ title }}|{%trans "dev site admin" %}
+{% endblock %}
+
+{% block branding %}
+<h1 id="site-name" style="background-color:#cccccc;color:black">
+  {%block sitename %}
+    {% trans 'HTS Workflow Dev Server' %}
+  {%endblock%}
+</h1>
+{% endblock %}
+
+{% block nav-global %}{% endblock %}
diff --git a/htsworkflow/frontend/templates/experiments/detail.html b/htsworkflow/frontend/templates/experiments/detail.html
new file mode 100644 (file)
index 0000000..65d3c00
--- /dev/null
@@ -0,0 +1,7 @@
+{% if run_f %}
+    <ul>
+        RUN FOLDER:  <li>{{ run_f.run_folder }}</li>
+    </ul>
+{% else %}
+    <p>Run folder not found.</p>
+{% endif %}
diff --git a/htsworkflow/frontend/templates/experiments/flowcellSheet.html b/htsworkflow/frontend/templates/experiments/flowcellSheet.html
new file mode 100644 (file)
index 0000000..189ed10
--- /dev/null
@@ -0,0 +1,199 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<title>{{ fc.flowcell_id }} - GA SEQUENCING (SOLEXA) LOG</title>
+
+<style type="text/css">
+  table, td 
+  {
+    border-color: #600;
+    border-style: solid;
+  }
+  table
+  {
+    border-width: 0 0 1px 1px;
+    border-spacing: 0;
+    border-collapse: collapse;
+  }
+  td
+  {
+    margin:0 ;
+    padding: 4px;
+    border-width: 1px 1px 0 0;
+  }
+</style>
+</head>
+<body>
+  <p>{% if fc %}</p>
+<table>
+<thead>
+  <td colspan="3"><b>GA SEQUENCING (SOLEXA) LOG</b></td>
+</thead>
+<tbody>
+<tr>
+<td>Date Run Started</td>
+<td colspan="2">{{ fc.run_date }}</td>
+</tr>
+<tr>
+<td>Cluster station used</td>
+<td colspan="2" nowrap>{{ fc.cluster_mac_id }}</td>
+</tr>
+<tr>
+<td>GA used</td>
+<td colspan="2" nowrap>{{ fc.seq_mac_id }}</td>
+</tr>
+<tr>
+<td>Flowcell number</td>
+<td colspan="2" nowrap>{{ fc.flowcell_id }}</td>
+</tr>
+<tr>
+<td>Number of Tiles per Lane</td>
+<td>100</td>
+</tr>
+<tr>
+<td>Number of Cycles</td>
+<td>{{ fc.read_length }}</td>
+</tr>
+</tbody>
+</table>
+<br/>
+<table>
+<thead>
+  <td>
+    <font point-size="9" face="Arial">
+      <b>SAMPLE INFORMATION</b>
+  </font>
+</thead>
+<tbody>
+<tr>
+<td>&nbsp;</td>
+<td>FC#</td>
+<td>&nbsp;</td>
+<td>&nbsp;</td>
+<td>&nbsp;</td>
+<td>&nbsp;</td>
+<td>&nbsp;</td>
+<td colspan="2" nowrap>FC bar code</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Lane</td>
+<td>1</td>
+<td>2</td>
+<td>3</td>
+<td>4</td>
+<td>5</td>
+<td>6</td>
+<td>7</td>
+<td>8</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Solexa Library Number</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_library.library_id }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_library.library_id }}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Sample Name</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_library.library_name }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_library.library_name }}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Organism</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_1_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_2_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_3_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_4_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_5_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_6_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_7_library.library_species.common_name }}</td>
+<td bgcolor="#CCFFCC">{{
+fc.lane_8_library.library_species.common_name }}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Submitter</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_library.made_by }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_library.made_by }}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>First time run?</td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+<td bgcolor="#CCFFCC"></td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Average Library Size (bp)</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_library.avg_lib_size }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_library.avg_lib_size }}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Template Concentration (ng/ul)</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_library.undiluted_concentration
+}}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_library.undiluted_concentration
+}}</td>
+</tr>
+<tr>
+<td valign="middle" nowrap>Run Concentration (pM)</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_1_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_2_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_3_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_4_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_5_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_6_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_7_pM }}</td>
+<td bgcolor="#CCFFCC">{{ fc.lane_8_pM }}</td>
+</tr>
+</tbody>
+</table>
+{% else %}
+<p>Flowcell object missing. Can't create sheet.</p>
+{% endif %}
+</body>
+</html>
diff --git a/htsworkflow/frontend/templates/experiments/index.html b/htsworkflow/frontend/templates/experiments/index.html
new file mode 100644 (file)
index 0000000..1105bec
--- /dev/null
@@ -0,0 +1,9 @@
+{% if data_run_list %}
+    <ul>
+    {% for run in data_run_list %}
+        <li>{{ run.run_folder }}</li>
+    {% endfor %}
+    </ul>
+{% else %}
+    <p>No data runs are available.</p>
+{% endif %}
index 51bf8c41bab1cec970e7d735de87ae4a35610391..95552bd65f86d20d635d8102dac1a4ecf4d42077 100644 (file)
@@ -1,23 +1,25 @@
 from django.conf.urls.defaults import *
+from django.contrib import admin
+admin.autodiscover()
 
 # Databrowser:
-from django.contrib import databrowse
-from htsworkflow.frontend.samples.models import Library
-databrowse.site.register(Library)
+#from django.contrib import databrowse
+#from htsworkflow.frontend.samples.models import Library
+#databrowse.site.register(Library)
 #databrowse.site.register(FlowCell)
 
 urlpatterns = patterns('',
     # Base:
     (r'^eland_config/', include('htsworkflow.frontend.eland_config.urls')),
     # Admin:
-     (r'^admin/', include('django.contrib.admin.urls')),
-    # ExpTrack:
-     (r'^experiments/', include('htsworkflow.frontend.experiments.urls')),
+    (r'^admin/(.*)', admin.site.root),
+    # Experiments:
+    (r'^experiments/', include('htsworkflow.frontend.experiments.urls')),
     # AnalysTrack:
-     (r'^analysis/', include('htsworkflow.frontend.analysis.urls')),
+    #(r'^analysis/', include('htsworkflow.frontend.analysis.urls')),
     # Report Views:
     # (r'^reports/', include('gaworkflow.frontend....urls')),
     
     # databrowser
-    (r'^databrowse/(.*)', databrowse.site.root)
+    #(r'^databrowse/(.*)', databrowse.site.root)
 )