Ultra-raw output of run_xml data implemented. The sorting of columns
authorBrandon King <kingb@caltech.edu>
Fri, 6 Jun 2008 22:04:32 +0000 (22:04 +0000)
committerBrandon King <kingb@caltech.edu>
Fri, 6 Jun 2008 22:04:32 +0000 (22:04 +0000)
is currently semi-random, but the data is there. I will work on a
better sorting in the near future. Keeping it simple at first.

gaworkflow/frontend/fctracker/results.py
gaworkflow/frontend/fctracker/views.py
gaworkflow/frontend/urls.py
templates/summary_stats.html [new file with mode: 0644]

index 85e1fd752ef74e039a0618783042a570a0bd30f3..08a7259b24fa8c2df38ba946d6c47e838b45bbfd 100644 (file)
@@ -12,8 +12,10 @@ def get_flowcell_result_dict(flowcell_id):
     a given flowcell_id:
     
      
-    d['C1-33']['summary'] = #Summary.htm file path
-    d['C1-33']['eland_results'][5] # C1-33 lane 5 file eland results file path
+    d['C1-33']['summary']           # Summary.htm file path
+    d['C1-33']['eland_results'][5]  # C1-33 lane 5 file eland results file path
+    d['C1-33']['run_xml']           # run_*.xml file path
+    d['C1-33']['scores']            # scores.tar.gz file path
     """
     
     flowcell_id = flowcell_id.strip()
index de7c6c85e7bc73e53167f956d6b5e7cfb85996eb..9c070edbda1cda44c0d342d23b9d38645b675fdb 100644 (file)
@@ -1,10 +1,15 @@
 # Create your views here.
 from gaworkflow.frontend.fctracker.models import Library
 from gaworkflow.frontend.fctracker.results import get_flowcell_result_dict, flowcellIdStrip
+from gaworkflow.pipeline.runfolder import ElementTree
+from gaworkflow.pipeline import runfolder
 from gaworkflow.frontend import settings
 from gaworkflow.util import makebed
 from gaworkflow.util import opener
+
 from django.http import HttpResponse
+from django.template.loader import get_template
+from django.template import Context
 
 import StringIO
 
@@ -21,6 +26,10 @@ def library(request):
     return HttpResponse(output)
 
 def library_to_flowcells(request, lib_id):
+    """
+    Display information about all the flowcells a library has been run on.
+    """
+    t = get_template("summary_stats.html")
     
     try:
       lib = Library.objects.get(library_id=lib_id)
@@ -54,6 +63,35 @@ def library_to_flowcells(request, lib_id):
                     lib.lane_7_library.count() + \
                     lib.lane_8_library.count()
     
+    flowcell_list = []
+    flowcell_list.extend([ (fc.flowcell_id, 1) for fc in lib.lane_1_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 2) for fc in lib.lane_2_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 3) for fc in lib.lane_3_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 4) for fc in lib.lane_4_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 5) for fc in lib.lane_5_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 6) for fc in lib.lane_6_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 7) for fc in lib.lane_7_library.all() ])
+    flowcell_list.extend([ (fc.flowcell_id, 8) for fc in lib.lane_8_library.all() ])
+    flowcell_list.sort()
+    
+    output.append('<br />')
+    
+    data_dict_list = []
+    for fc, lane in flowcell_list:
+        dicts, err_list = _summary_stats(fc, lane)
+        
+        data_dict_list.extend(dicts)
+    
+        for err in err_list:    
+            output.append(err)
+    
+    html = t.render(Context({'data_dict_list': data_dict_list}))
+    output.append('<br />')
+    output.append('<br />')
+    output.append(html)
+    output.append('<br />')
+    output.append('<br />')
+    
     if record_count == 0:
         output.append("None Found")
     
@@ -68,15 +106,15 @@ def summaryhtm_fc_cnm(request, fc_id, cnm):
     d = get_flowcell_result_dict(fc_id)
     
     if d is None:
-        return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
+        return HttpResponse('<b>Results for Flowcell %s not found.</b>' % (fc_id))
     
     if cnm not in d:
-        return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
+        return HttpResponse('<b>Results for Flowcell %s; %s not found.</b>' % (fc_id, cnm))
     
     summary_filepath = d[cnm]['summary']
     
     if summary_filepath is None:
-        return HttpResponse('<b>Summary.htm for Flowcell %s; %s not found.' % (fc_id, cnm))
+        return HttpResponse('<b>Summary.htm for Flowcell %s; %s not found.</b>' % (fc_id, cnm))
     
     f = open(summary_filepath, 'r')
     
@@ -91,16 +129,16 @@ def result_fc_cnm_eland_lane(request, fc_id, cnm, lane):
     d = get_flowcell_result_dict(fc_id)
     
     if d is None:
-        return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
+        return HttpResponse('<b>Results for Flowcell %s not found.</b>' % (fc_id))
     
     if cnm not in d:
-        return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
+        return HttpResponse('<b>Results for Flowcell %s; %s not found.</b>' % (fc_id, cnm))
     
     erd = d[cnm]['eland_results']
     lane = int(lane)
     
     if lane not in erd:
-        return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
+        return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.</b>' % (fc_id, cnm, lane))
     
     filepath = erd[lane]
     
@@ -124,16 +162,16 @@ def bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=False):
     d = get_flowcell_result_dict(fc_id)
     
     if d is None:
-        return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
+        return HttpResponse('<b>Results for Flowcell %s not found.</b>' % (fc_id))
     
     if cnm not in d:
-        return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
+        return HttpResponse('<b>Results for Flowcell %s; %s not found.</b>' % (fc_id, cnm))
     
     erd = d[cnm]['eland_results']
     lane = int(lane)
     
     if lane not in erd:
-        return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
+        return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.</b>' % (fc_id, cnm, lane))
     
     filepath = erd[lane]
     
@@ -153,6 +191,57 @@ def bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=False):
     else:
         return HttpResponse(bedgen, mimetype="application/x-bedfile")
 
+
+def _summary_stats(flowcell_id, lane):
+    """
+    return a dictionary of summary stats for a given flowcell_id & lane.
+    """
+    fc_id = flowcellIdStrip(flowcell_id)
+    d = get_flowcell_result_dict(fc_id)
+    
+    dict_list = []
+    err_list = []
+    
+    if d is None:
+        err_list.append('Results for Flowcell %s not found.' % (fc_id))
+        return (dict_list, err_list)
+    
+    for cnm in d:
+    
+        xmlpath = d[cnm]['run_xml']
+        
+        if xmlpath is None:
+            err_list.append('Run xml for Flowcell %s(%s) not found.' % (fc_id, cnm))
+            continue
+        
+        tree = ElementTree.parse(xmlpath).getroot()
+        results = runfolder.PipelineRun(pathname='', xml=tree)
+        
+        lane_results = results.gerald.summary[str(lane)]
+        lrs = lane_results
+        
+        d = {}
+        
+        d['average_alignment_score'] = lrs.average_alignment_score
+        d['average_first_cycle_intensity'] = lrs.average_first_cycle_intensity
+        d['cluster'] = lrs.cluster
+        d['lane'] = lrs.lane
+        d['flowcell'] = flowcell_id
+        d['percent_error_rate'] = lrs.percent_error_rate
+        d['percent_intensity_after_20_cycles'] = lrs.percent_intensity_after_20_cycles
+        d['percent_pass_filter_align'] = lrs.percent_pass_filter_align
+        d['percent_pass_filter_clusters'] = lrs.percent_pass_filter_clusters
+        
+        #FIXME: function finished, but need to take advantage of
+        #   may need to take in a list of lanes so we only have to
+        #   load the xml file once per flowcell rather than once
+        #   per lane.
+        dict_list.append(d)
+    
+    return (dict_list, err_list)
+    
+    
+
     
 def _files(flowcell_id, lane):
     """
index 926a7c4cc2d1922d1b7e07503beae447ff308219..3ea807308bd710f6dbc0c99cbad36de8786a807a 100644 (file)
@@ -13,7 +13,7 @@ urlpatterns = patterns('',
      (r'^admin/', include('django.contrib.admin.urls')),
     # Databrowser:
      #(r'^databrowse/(.*)', databrowse.site.root),
-     (r'^library/$', 'gaworkflow.frontend.fctracker.views.library'),
+     (r'^library/$', 'gaworkflow.frontend.fctracker.views.library'), 
      (r'^library/(?P<lib_id>\w+)/$', 'gaworkflow.frontend.fctracker.views.library_to_flowcells'),
      (r'^results/(?P<fc_id>\w+)/(?P<cnm>C[1-9]-[0-9]+)/summary/','gaworkflow.frontend.fctracker.views.summaryhtm_fc_cnm'),
      (r'^results/(?P<fc_id>\w+)/(?P<cnm>C[1-9]-[0-9]+)/eland_result/(?P<lane>[1-8])','gaworkflow.frontend.fctracker.views.result_fc_cnm_eland_lane'),
diff --git a/templates/summary_stats.html b/templates/summary_stats.html
new file mode 100644 (file)
index 0000000..78a909e
--- /dev/null
@@ -0,0 +1,23 @@
+
+{% block summary_stats %}
+
+<table border="1">
+{% for d in data_dict_list %}
+    {# Header row for table #}
+    {% if forloop.first %}
+        <tr>
+        {% for key, value in d.items %}
+            <td><b>{{ key }}</b></td>
+        {% endfor %}
+        </tr>
+    {% endif %}
+    {# Main contents of table #}
+    <tr>
+    {% for key, value in d.items %}
+        <td>{{ value }}</td>
+    {% endfor %}
+    </tr>
+{% endfor %}
+</table>
+
+{% endblock %}