add stanfords experiment tracker component
authorRami Rauch <rrauch@stanford.edu>
Sat, 3 May 2008 00:01:55 +0000 (00:01 +0000)
committerRami Rauch <rrauch@stanford.edu>
Sat, 3 May 2008 00:01:55 +0000 (00:01 +0000)
gaworkflow/frontend/exp_track/__init__.py [new file with mode: 0644]
gaworkflow/frontend/exp_track/et_urls.py [new file with mode: 0644]
gaworkflow/frontend/exp_track/exptrack.py [new file with mode: 0644]
gaworkflow/frontend/exp_track/models.py [new file with mode: 0644]
gaworkflow/frontend/exp_track/views.py [new file with mode: 0644]

diff --git a/gaworkflow/frontend/exp_track/__init__.py b/gaworkflow/frontend/exp_track/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/gaworkflow/frontend/exp_track/et_urls.py b/gaworkflow/frontend/exp_track/et_urls.py
new file mode 100644 (file)
index 0000000..6acea12
--- /dev/null
@@ -0,0 +1,10 @@
+from django.conf.urls.defaults import *
+
+urlpatterns = patterns('',
+                                                                                                      
+    (r'^$', 'gaworkflow.frontend.exp_track.views.index'),
+    (r'^(?P<run_folder>.+)/$', 'gaworkflow.frontend.exp_track.views.detail'),
+    (r'^updStatus$', 'gaworkflow.frontend.exp_track.exptrack.updStatus'),
+    (r'^getConfile$', 'gaworkflow.frontend.exp_track.exptrack.getConfile'),
+    (r'^getLanesNames$', 'gaworkflow.frontend.exp_track.exptrack.getLaneLibs')   
+)
diff --git a/gaworkflow/frontend/exp_track/exptrack.py b/gaworkflow/frontend/exp_track/exptrack.py
new file mode 100644 (file)
index 0000000..18ed709
--- /dev/null
@@ -0,0 +1,182 @@
+# some core functions of the exp tracker module
+from django.http import HttpResponse
+from datetime import datetime
+from string import *
+import re
+from gaworkflow.frontend.exp_track.models import DataRun
+from gaworkflow.frontend.fctracker.models import FlowCell, Library
+from django.core.exceptions import ObjectDoesNotExist
+from django.core.mail import send_mail, mail_admins
+
+def updStatus(request):
+    output=''
+    user = 'none'
+    pswd = ''
+    UpdatedStatus = 'unknown'
+    ClIP = 'unknown'
+    granted = False
+    fcid = 'none'
+    runfolder = 'unknown'
+    
+    if request.has_key('fcid'):
+      fcid = request['fcid']
+    else:
+      return HttpResponse('missing fcid')
+    
+    if request.has_key('runf'):
+      runfolder = request['runf']
+    else:
+      return HttpResponse('missing runf')
+    
+    if request.has_key('user'):  
+      user = request['user']
+    else:
+      return HttpResponse('access denied')
+
+    #TO DO: pswd decode etc..
+    #if request.has_key('pswd'):
+    #  pswd = request['pswd']
+    #else: 
+    #  return HttpResponse('access denied')
+
+    ClIP = request.META['REMOTE_ADDR']
+    
+    #Check permission to update
+    if (user == 'rami' and (ClIP == '171.65.76.167' or ClIP == '171.65.76.51' or (ClIP == '74.51.115.100' or ClIP == '64.89.97.100'))): ## or ClIP == '127.0.0.1')):
+      granted = True
+    
+    if granted:
+      if request.has_key('updst'):
+        UpdatedStatus = request['updst']
+      else:
+        return HttpResponse('missing status')
+      # Update Data Run status in DB
+      # Try get rec. If not found return 'entry not found + <fcid><runfolder>', if found try update and return updated 
+      try:
+        rec = DataRun.objects.get(run_folder=runfolder)
+        rec.run_status = UpdatedStatus
+
+        #if there's a message update that too
+        mytimestamp = datetime.now().__str__()
+        mytimestamp = re.sub(pattern=":[^:]*$",repl="",string=mytimestamp)
+        if request.has_key('msg'):
+          rec.run_note += ", "+request['msg']+" ("+mytimestamp+")"
+        else :
+          if UpdatedStatus == '1':
+            rec.run_note = "Started ("+mytimestamp+")"
+
+        rec.save()
+        output = "updated to:'"+DataRun.RUN_STATUS_CHOICES[int(UpdatedStatus)][1].__str__()+"'"
+      except ObjectDoesNotExist:
+        output = "entry not found: "+fcid+", "+runfolder
+    else: 
+      output ="access denied.. u: "+user+", ClIP: "+ClIP
+
+    #Notify researcher by email
+    # Doesn't work
+    #send_mail('Exp Tracker', 'Data Run Status '+output, 'rrauch@stanford.edu', ['rrrami@gmail.com'], fail_silently=False)
+    #mail_admins("test subject", "testing , testing", fail_silently=False)
+    # gives error: (49, "Can't assign requested address")
+    return HttpResponse(output)
+
+def generateConfile(fcid):
+    cnfgfile = 'READ_LENGTH 25\n'
+    cnfgfile += 'ANALYSIS eland\n'
+    cnfgfile += 'GENOME_FILE all_chr.fa\n'
+    cnfgfile += 'ELAND_MULTIPLE_INSTANCES 8\n'
+    genome_dir = 'GENOME_DIR /Volumes/Genomes/'
+    eland_genome = 'ELAND_GENOME /Volumes/Genomes/'
+    
+    try:                                                                                                                                              
+      rec = FlowCell.objects.get(flowcell_id=fcid)
+      
+      cnfgfile += '1:'+genome_dir+rec.lane_1_library.library_species.use_genome_build+'\n'
+      cnfgfile += '1:'+eland_genome+rec.lane_1_library.library_species.use_genome_build+'\n'
+
+      cnfgfile += '2:'+genome_dir+rec.lane_2_library.library_species.use_genome_build+'\n'
+      cnfgfile += '2:'+eland_genome+rec.lane_2_library.library_species.use_genome_build+'\n'
+      cnfgfile += '3:'+genome_dir+rec.lane_3_library.library_species.use_genome_build+'\n'
+      cnfgfile += '3:'+eland_genome+rec.lane_3_library.library_species.use_genome_build+'\n'
+
+      cnfgfile += '4:'+genome_dir+rec.lane_4_library.library_species.use_genome_build+'\n'
+      cnfgfile += '4:'+eland_genome+rec.lane_4_library.library_species.use_genome_build+'\n'
+      
+      cnfgfile += '5:'+genome_dir+rec.lane_5_library.library_species.use_genome_build+'\n'
+      cnfgfile += '5:'+eland_genome+rec.lane_5_library.library_species.use_genome_build+'\n'
+
+      cnfgfile += '6:'+genome_dir+rec.lane_6_library.library_species.use_genome_build+'\n'
+      cnfgfile += '6:'+eland_genome+rec.lane_6_library.library_species.use_genome_build+'\n'
+
+      cnfgfile += '7:'+genome_dir+rec.lane_7_library.library_species.use_genome_build+'\n'
+      cnfgfile += '7:'+eland_genome+rec.lane_7_library.library_species.use_genome_build+'\n'
+
+      cnfgfile += '8:'+genome_dir+rec.lane_8_library.library_species.use_genome_build+'\n'
+      cnfgfile += '8:'+eland_genome+rec.lane_8_library.library_species.use_genome_build
+
+    except ObjectDoesNotExist:
+      cnfgfile = 'Entry not found for runfolder = '+runfolder
+
+    return cnfgfile
+
+def getConfile(request):
+    fcid = 'none'
+    cnfgfile = ''
+    runfolder = 'unknown'
+    if request.has_key('fcid'):
+      fcid = request['fcid']
+      if request.has_key('runf'):
+        runfolder = request['runf']
+        try:
+          rec = DataRun.objects.get(run_folder=runfolder) #,flowcell_id=fcid)
+          cnfgfile = rec.config_params
+          #match_str = re.compile(r"READ_LENGTH.+$")
+          match_str = re.compile('^READ_LENGTH.+')
+          if not match_str.search(cnfgfile):
+            cnfgfile = generateConfile(fcid)
+            if match_str.search(cnfgfile):
+              rec = DataRun.objects.get(run_folder=runfolder) #,flowcell_id=fcid)
+              rec.config_params = cnfgfile
+              rec.save()
+            else:
+              cnfgfile = 'Failed generating config params for RunFolder = '+runfolder +', Flowcell id = '+ fcid+ ' Config Text:\n'+cnfgfile  
+            
+        except ObjectDoesNotExist:
+          cnfgfile = 'Entry not found for RunFolder = '+runfolder
+
+    return HttpResponse(cnfgfile)
+
+def getLaneLibs(request):
+    fcid = 'none'
+    outputfile = ''
+    if request.has_key('fcid'):
+      fcid = request['fcid']                                                                                                      
+      try:                                
+        rec = FlowCell.objects.get(flowcell_id=fcid)
+        #Ex: 071211
+        year = datetime.today().year.__str__()
+        year = replace(year,'20','')
+        month = datetime.today().month
+        if month < 10: month = "0"+month.__str__()
+        else: month = month.__str__() 
+        day = datetime.today().day
+        if day < 10: day = "0"+day.__str__()
+        else: day = day.__str__()
+        mydate = year+month+day
+        outputfile = '<?xml version="1.0" ?>'
+        outputfile += '\n<SolexaResult Date="'+mydate+'" Flowcell="'+fcid+'">'
+        outputfile += '\n<Lane Index="1" Name="'+rec.lane_1_library.library_name+'" Library="'+rec.lane_1_library.library_id+'" Genome="'+rec.lane_1_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="2" Name="'+rec.lane_2_library.library_name+'" Library="'+rec.lane_2_library.library_id+'" Genome="'+rec.lane_2_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="3" Name="'+rec.lane_3_library.library_name+'" Library="'+rec.lane_3_library.library_id+'" Genome="'+rec.lane_3_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="4" Name="'+rec.lane_4_library.library_name+'" Library="'+rec.lane_4_library.library_id+'" Genome="'+rec.lane_4_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="5" Name="'+rec.lane_5_library.library_name+'" Library="'+rec.lane_5_library.library_id+'" Genome="'+rec.lane_5_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="6" Name="'+rec.lane_6_library.library_name+'" Library="'+rec.lane_6_library.library_id+'" Genome="'+rec.lane_6_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="7" Name="'+rec.lane_7_library.library_name+'" Library="'+rec.lane_7_library.library_id+'" Genome="'+rec.lane_7_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n<Lane Index="8" Name="'+rec.lane_8_library.library_name+'" Library="'+rec.lane_8_library.library_id+'" Genome="'+rec.lane_8_library.library_species.use_genome_build+'"/>'
+        outputfile += '\n</SolexaResult>'
+      except ObjectDoesNotExist:
+        outputfile = 'Flowcell entry not found for: '+fcid
+    else: outputfile = 'Missing input: flowcell id'
+
+    return HttpResponse(outputfile)
diff --git a/gaworkflow/frontend/exp_track/models.py b/gaworkflow/frontend/exp_track/models.py
new file mode 100644 (file)
index 0000000..7bdaff7
--- /dev/null
@@ -0,0 +1,29 @@
+from django.db import models
+from gaworkflow.frontend.fctracker.models import FlowCell 
+
+class DataRun(models.Model):
+  #ConfTemplate = "READ_LENGTH 25\nGENOME_DIR /Volumes/Genomes/hg18\nELAND_GENOME /Volumes/Genomes/hg18\nANALYSIS eland\nGENOME_FILE all_chr.fa\nELAND_MULTIPLE_INSTANCES 8"
+  ConfTemplate = "CONFIG PARAMS WILL BE GENERATED BY THE PIPELINE SCRIPT.\nYOU'LL BE ABLE TO EDIT AFTER IF NEEDED."
+  ##-----
+  run_folder = models.CharField(max_length=50,unique=True, db_index=True)
+  fcid = models.ForeignKey(FlowCell,verbose_name="Flowcell Id") #, null=True)
+  config_params = models.TextField(default=ConfTemplate)
+  run_start_time = models.DateTimeField(core=True)
+  RUN_STATUS_CHOICES = (
+      (0, 'Solexa Pipeline Not Yet Started'),
+      (1, 'Solexa Pipeline Started'),
+      (2, 'Solexa Pipeline Interrupted'),
+      (3, 'Solexa Pipeline Finished'),
+      (4, 'CollectReads Started'),
+      (5, 'CollectReads Finished'),
+    )
+  run_status = models.IntegerField(choices=RUN_STATUS_CHOICES, default=0)
+  run_note = models.CharField(max_length=500,blank=True)
+  
+  #def __unicode__(self):
+  #  return ...
+
+  class Admin:
+    list_display = ('run_folder','fcid','run_start_time','run_status','run_note')
+    list_filter = ('run_status','run_start_time')
+    
diff --git a/gaworkflow/frontend/exp_track/views.py b/gaworkflow/frontend/exp_track/views.py
new file mode 100644 (file)
index 0000000..1d9aa8d
--- /dev/null
@@ -0,0 +1,22 @@
+# Create your views here.
+#from django.template import Context, loader
+#shortcut to the above modules
+from django.shortcuts import render_to_response, get_object_or_404
+from gaworkflow.frontend.exp_track.models import DataRun
+from django.http import HttpResponse
+
+def index(request):
+    all_runs = DataRun.objects.all().order_by('-run_start_time')
+    #t = loader.get_template('exptrack/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}) 
+    
+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})