(no commit message)
authorRami Rauch <rrauch@stanford.edu>
Thu, 14 Aug 2008 00:02:07 +0000 (00:02 +0000)
committerRami Rauch <rrauch@stanford.edu>
Thu, 14 Aug 2008 00:02:07 +0000 (00:02 +0000)
gaworkflow/frontend/analys_track/__init__.py [new file with mode: 0644]
gaworkflow/frontend/analys_track/an_urls.py [new file with mode: 0644]
gaworkflow/frontend/analys_track/main.py [new file with mode: 0644]
gaworkflow/frontend/analys_track/models.py [new file with mode: 0644]

diff --git a/gaworkflow/frontend/analys_track/__init__.py b/gaworkflow/frontend/analys_track/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/gaworkflow/frontend/analys_track/an_urls.py b/gaworkflow/frontend/analys_track/an_urls.py
new file mode 100644 (file)
index 0000000..3079cbe
--- /dev/null
@@ -0,0 +1,8 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',                                               
+    (r'^$', 'gaworkflow.frontend.analys_track.views.index'),
+    (r'^(?P<run_folder>.+)/$', 'gaworkflow.frontend.analys_track.views.detail'),
+    (r'^updStatus$', 'gaworkflow.frontend.analys_track.main.updStatus'),
+    (r'^getProjects$', 'gaworkflow.frontend.analys_track.main.getProjects'),
+)
diff --git a/gaworkflow/frontend/analys_track/main.py b/gaworkflow/frontend/analys_track/main.py
new file mode 100644 (file)
index 0000000..802ade1
--- /dev/null
@@ -0,0 +1,91 @@
+# some core functions of analysis manager module
+from django.http import HttpResponse
+from datetime import datetime
+from string import *
+import re
+from gaworkflow.frontend import settings
+from gaworkflow.frontend.analys_track.models import Task, Project
+from django.core.exceptions import ObjectDoesNotExist
+
+def updStatus(request):
+    ClIP = request.META['REMOTE_ADDR']
+    #Check client access permission                                                                                                                                       
+    granted = False
+    if (settings.ALLOWED_ANALYS_IPS.has_key(ClIP)):  granted = True
+    if not granted: return HttpResponse("access denied.")
+
+    output=''
+    taskid=-1;
+    # Check required param
+    if request.has_key('taskid'): taskid = request['taskid']
+    else:  return HttpResponse('missing param task id')
+
+    try:
+      rec = Task.objects.get(id=taskid)
+      mytimestamp = datetime.now().__str__()
+      mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
+      if request.has_key('msg'):
+        rec.task_status += ", "+request['msg']+" ("+mytimestamp+")"
+      else :
+        rec.task_status = "Registered ("+mytimestamp+")"
+      rec.save()
+      output = "Hello "+settings.ALLOWED_ANALYS_IPS[ClIP]+". Updated status for task "+taskid
+    except ObjectDoesNotExist:
+      output = "entry not found: taskid="+taskid
+
+    return HttpResponse(output)
+    
+      
+def getProjects(request):
+    ClIP = request.META['REMOTE_ADDR']
+    #Check client access permission 
+    granted = False
+    if (settings.ALLOWED_ANALYS_IPS.has_key(ClIP)):  granted = True
+    if not granted: return HttpResponse("access denied.")
+
+    outputfile = ''
+    
+    All=False
+    if (request.has_key('mode')):
+      if request['mode']=='all':
+        All=True
+
+    try:                                                                                   
+      if(All):
+        rec = Project.objects.all().distinct()
+      else:
+        rec = Project.objects.filter(tasks__task_status__exact='defined').distinct()
+      
+      outputfile = '<?xml version="1.0" ?>'
+      outputfile += '\n<Projects Client="'+settings.ALLOWED_ANALYS_IPS[ClIP]+'">'
+      for p in rec:
+        outputfile += '\n'
+        outputfile += '\n<Project ProjectId="'+p.id.__str__()+'" Name="'+p.project_name+'">'
+        prj_tasks = p.tasks.all()
+        for t in prj_tasks:
+          outputfile += '\n'
+          if (t.apply_calc == 'QuEST' or t.apply_calc == 'WingPeaks' or t.apply_calc == 'MACS'):
+            outputfile += '\n<PeakCalling TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Caller="'+t.apply_calc+'" Genome="'+t.subject1.library_species.use_genome_build+'">'
+            outputfile += '\n<Signal Library="'+t.subject1.library_id+'"/>'
+            outputfile += '\n<Background Library="'+t.subject2.library_id+'"/>'
+            outputfile += '\n</PeakCalling>'
+
+          if (t.apply_calc == 'ProfileReads' or t.apply_calc == 'qPCR'):
+            outputfile += '\n<'+t.apply_calc+' TaskId="'+t.id.__str__()+'" Name="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'" Library="'+t.subject1.library_id+'"/>'
+
+          if (t.apply_calc == 'CompareLibs'):
+            outputfile += '\n<CompareLibraries TaskId="'+t.id.__str__()+'" TF="'+t.task_name+'" Genome="'+t.subject1.library_species.use_genome_build+'">'
+            outputfile += '\n<Library Library="'+t.subject1.library_id+'"/>'
+            outputfile += '\n<Library Library="'+t.subject2.library_id+'"/>'
+            outputfile += '\n</CompareLibraries>'
+
+          #if (t.apply_calc == 'ComparePeakCalls'):                                                                                                                            
+          # <ComparePeakCalls Genome="hg18" Caller1="QuEST" Set1="A549 GR Dex ChIP" Caller2="QuEST" Set2="A549 GR EtOH ChIP" />                                                
+          # outputfile += '\n<ComparePeakCalls TaskId='+t.id.__str__()+' Genome="'+t.subject1.library_species.use_genome_build+'" Caller1="'+t.pcaller1+'" Caller1="'+t.pcaller1+'" Caller2="'+t.pcaller2+'" Set1="'+t.set1+'" Set1="'+t.set2+'"/>' 
+          # TO DO: Define these new fields in Task: PCaller1 (QuEST,WingPeaks), PCaller2, Set1(FK to self), Set2 (FK..) ALL NULL=TRUE                                  
+        outputfile += '\n</Project>'
+      outputfile += '\n</Projects>'
+    except ObjectDoesNotExist:
+      outputfile = "<?xml version='1.0' ?><Projects></Projects>"
+
+    return HttpResponse(outputfile)
diff --git a/gaworkflow/frontend/analys_track/models.py b/gaworkflow/frontend/analys_track/models.py
new file mode 100644 (file)
index 0000000..be0bb9c
--- /dev/null
@@ -0,0 +1,115 @@
+from django.db import models
+from datetime import datetime
+from gaworkflow.frontend.fctracker.models import Library 
+from string import *
+
+class Task(models.Model):
+  task_name = models.CharField(max_length=50,unique=True, db_index=True)
+  subject1 = models.ForeignKey(Library,related_name='sbj1_library',verbose_name="Subject")
+  subject2 = models.ForeignKey(Library,related_name='sbj2_library',verbose_name="Subject 2 / Control",blank=True,null=True)
+  CALCS = (
+      ('QuEST', 'QuEST Peak Calling'),
+      ('WingPeaks', 'Wing Peak Calling'),
+      ('MACS', 'MACS Peak Calling'),
+      ('qPCR', 'In Silico qPCR'),
+      ('CompareLibs', 'Compare Libaraies'),
+      ('ComparePeakCalls','Compare Peak Calls'),
+      ('ProfileReads','Profile Reads')
+    )
+  apply_calc = models.CharField(max_length=50,choices=CALCS,verbose_name='Applied Calculation')
+  ## userid = # logged in user
+  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(core=True,default=datetime.now())
+  run_note = models.CharField(max_length=500,blank=True,null=True)
+  
+  def __str__(self):
+      return '"%s" - %s on [%s]/[%s]' % (self.task_name,self.apply_calc,self.subject1,self.subject2)
+
+  def InProjects(self):
+      return '...'
+      ps = self.project_set.all()
+      pstr = 'In '
+      return pstr
+      for p in ps:
+        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',)
+    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)
+    project_notes = models.CharField(max_length=500,blank=True,null=True)
+    
+    def __str__(self):
+      return '%s' % (self.project_name)
+
+    def ProjectTasks(self):
+      ptasks = self.tasks.all().order_by('id')
+      surl = 'http://m304-apple-server.stanford.edu/projects/' 
+      tstr = '<script>'
+      tstr += 'function togView(eid){'
+      tstr += 'f=document.getElementById(eid);'
+      tstr += 'if(f.height==0){'
+      tstr += 'f.height=600;'
+      tstr += 'f.style.border=\'solid #cccccc 3px\';'
+      tstr += '}else{'
+      tstr += 'f.height=0;'
+      tstr += 'f.style.border=\'none\';'
+      tstr += '}'
+      tstr += '}'
+      tstr += '</script>'
+      Style = ''
+      if len(ptasks) > 8:  Style = ' style="height:200px;overflow:auto" '
+      tstr += '<div '+Style+'>'
+      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>'))
+        if t.task_status != 'defined': isregistered = True
+
+      tstr += '</table>'
+      tstr += '</div>'
+      tstr += '<div>'
+      tstr += '<div align=center>'
+      if isregistered:
+        tstr += '<a onClick="togView(\'RFrame'+self.id.__str__()+'\');" href="'+surl+self.id.__str__()+'/" title="View Results Page" target="RFrame'+self.id.__str__()+'">VIEW PROJECT RESULTS</a>'
+        tstr += '<a href="'+surl+self.id.__str__()+'/" title="View Results Page" target="_blank" style="margin-left:10px">(view in new window)</a>'
+      else:
+        tstr += 'REGISTERING ...'    
+      tstr += '</div>'    
+      tstr += '<iframe width="100%" height="0" frameborder="0" style="background-color:#ffffff" name="RFrame'+self.id.__str__()+'" id="RFrame'+self.id.__str__()+'"/></iframe>'
+      tstr += '</div>'
+      return tstr
+    
+    ProjectTasks.allow_tags = True
+
+    def ProjTitle(self):
+      ptasks = self.tasks.all().order_by('id')
+      tasks_counter = '<span style="color:#666666;font-size:85%">('+len(ptasks).__str__() + ' tasks)</span>'
+      htmlstr = '%s<br/>%s'  % (self.project_name,tasks_counter)
+      return htmlstr
+
+    ProjTitle.allow_tags = True
+
+    class Admin:
+      list_display = ('ProjTitle','ProjectTasks')
+      # list_filter = ('...',)
+      fields = (
+        (None, {
+          'fields': (('project_name'),('tasks'),('project_notes'))}),
+        )