library view: eland_result files accessible now
authorBrandon King <kingb@caltech.edu>
Sat, 24 May 2008 00:18:32 +0000 (00:18 +0000)
committerBrandon King <kingb@caltech.edu>
Sat, 24 May 2008 00:18:32 +0000 (00:18 +0000)
 * Added links in the library view to get access to "accessable" data.
   If the data is not "accessable", no link will be provided.

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

diff --git a/gaworkflow/frontend/fctracker/results.py b/gaworkflow/frontend/fctracker/results.py
new file mode 100644 (file)
index 0000000..85e1fd7
--- /dev/null
@@ -0,0 +1,128 @@
+from gaworkflow.frontend import settings
+
+import glob
+import os
+import re
+
+s_paren = re.compile("^\w+")
+
+def get_flowcell_result_dict(flowcell_id):
+    """
+    returns a dictionary following the following pattern for
+    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
+    """
+    
+    flowcell_id = flowcell_id.strip()
+    
+    d = {}
+    
+    ################################
+    # Flowcell Directory
+    fc_dir = glob.glob(os.path.join(settings.RESULT_HOME_DIR, flowcell_id))
+    
+    # Not found
+    if len(fc_dir) == 0:
+        return None
+    
+    # No duplicates!
+    assert len(fc_dir) <= 1
+    
+    # Found fc dir
+    fc_dir = fc_dir[0]
+    
+    ################################
+    # C#-## dirs
+    c_dir_list = glob.glob(os.path.join(fc_dir, 'C*'))
+    
+    # Not found
+    if len(c_dir_list) == 0:
+        return d
+    
+    for c_dir_path in c_dir_list:
+        summary_file = glob.glob(os.path.join(c_dir_path, 'Summary.htm'))
+        pathdir, c_dir = os.path.split(c_dir_path)
+        
+        # Create sub-dictionary
+        d[c_dir] = {}
+        
+        
+        ###############################
+        # Summary.htm file
+        
+        # Not found
+        if len(summary_file) == 0:
+            d[c_dir]['summary'] = None
+            
+        # Found
+        else:
+            # No duplicates!
+            assert len(summary_file) == 1
+            
+            summary_file = summary_file[0]
+            d[c_dir]['summary'] = summary_file
+            
+        ###############################
+        # Result files
+        
+        d[c_dir]['eland_results'] = {}
+        
+        result_filepaths = glob.glob(os.path.join(c_dir_path, 's_*_eland_result.txt*'))
+        
+        for filepath in result_filepaths:
+            
+            junk, result_name = os.path.split(filepath)
+            
+            #lanes 1-8, single digit, therefore s_#; # == index 2
+            lane = int(result_name[2])
+            d[c_dir]['eland_results'][lane] = filepath
+            
+        ###############################
+        # run*.xml file
+        run_xml_filepath = glob.glob(os.path.join(c_dir_path, 'run_*.xml'))
+        
+        if len(run_xml_filepath) == 0:
+            d[c_dir]['run_xml'] = None
+        else:
+            # No duplicates
+            assert len(run_xml_filepath) == 1
+            
+            d[c_dir]['run_xml'] = run_xml_filepath[0]
+            
+        ###############################
+        # scores.tar.gz
+        scores_filepath = glob.glob(os.path.join(c_dir_path, 'scores*'))
+        
+        if len(scores_filepath) == 0:
+            d[c_dir]['scores'] = None
+        else:
+            # No duplicates
+            assert len(scores_filepath) == 1
+            
+            d[c_dir]['scores'] = scores_filepath[0]
+        
+    return d
+
+    
+def cn_mTobp(cn_m):
+    """
+    Converts CN-M (i.e. C1-33, C1-26, C4-28) cycle information into
+    number of base pairs.
+    """
+    pass
+
+
+def flowcellIdStrip(flowcell_id):
+    """
+    Removes (<words>) from flowcell id
+    """
+    mo = s_paren.search(flowcell_id)
+    
+    if mo:
+        return flowcell_id[mo.start():mo.end()]
+    else:
+        return flowcell_id
+    
\ No newline at end of file
index 6f67bec5aaf5b65f7b0d802d6d15af4489d555a4..7f117c9c3fc2988df0c172c2f7b6a73cbdaa2a49 100644 (file)
@@ -1,5 +1,7 @@
 # Create your views here.
 from gaworkflow.frontend.fctracker.models import Library
+from gaworkflow.frontend.fctracker.results import get_flowcell_result_dict, flowcellIdStrip
+from gaworkflow.util import opener
 from django.http import HttpResponse
 
 #from django.db.models import base 
@@ -30,14 +32,14 @@ def library_to_flowcells(request, lib_id):
     
     output.append('<b>FLOWCELL - LANE:</b>')
     
-    output.extend([ '%s - Lane 1' % (fc.flowcell_id) for fc in lib.lane_1_library.all() ])
-    output.extend([ '%s - Lane 2' % (fc.flowcell_id) for fc in lib.lane_2_library.all() ])
-    output.extend([ '%s - Lane 3' % (fc.flowcell_id) for fc in lib.lane_3_library.all() ])
-    output.extend([ '%s - Lane 4' % (fc.flowcell_id) for fc in lib.lane_4_library.all() ])
-    output.extend([ '%s - Lane 5' % (fc.flowcell_id) for fc in lib.lane_5_library.all() ])
-    output.extend([ '%s - Lane 6' % (fc.flowcell_id) for fc in lib.lane_6_library.all() ])
-    output.extend([ '%s - Lane 7' % (fc.flowcell_id) for fc in lib.lane_7_library.all() ])
-    output.extend([ '%s - Lane 8' % (fc.flowcell_id) for fc in lib.lane_8_library.all() ])
+    output.extend([ '%s - Lane 1 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 1)) for fc in lib.lane_1_library.all() ])
+    output.extend([ '%s - Lane 2 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 2)) for fc in lib.lane_2_library.all() ])
+    output.extend([ '%s - Lane 3 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 3)) for fc in lib.lane_3_library.all() ])
+    output.extend([ '%s - Lane 4 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 4)) for fc in lib.lane_4_library.all() ])
+    output.extend([ '%s - Lane 5 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 5)) for fc in lib.lane_5_library.all() ])
+    output.extend([ '%s - Lane 6 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 6)) for fc in lib.lane_6_library.all() ])
+    output.extend([ '%s - Lane 7 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 7)) for fc in lib.lane_7_library.all() ])
+    output.extend([ '%s - Lane 8 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 8)) for fc in lib.lane_8_library.all() ])
     
     record_count = lib.lane_1_library.count() + \
                     lib.lane_2_library.count() + \
@@ -52,3 +54,55 @@ def library_to_flowcells(request, lib_id):
         output.append("None Found")
     
     return HttpResponse('<br />\n'.join(output))
+
+
+def result_fc_cnm_eland_lane(request, fc_id, cnm, lane):
+    """
+    returns an eland_file upon calling.
+    """
+    fc_id = flowcellIdStrip(fc_id)
+    d = get_flowcell_result_dict(fc_id)
+    
+    if d is None:
+        return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
+    
+    if cnm not in d:
+        return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (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))
+    
+    filepath = erd[lane]
+    
+    f = opener.autoopen(filepath, 'r')
+    
+    return HttpResponse(f)
+    
+
+def _files(flowcell_id, lane):
+    """
+    Sets up available files for download
+    """
+    flowcell_id = flowcellIdStrip(flowcell_id)
+    d = get_flowcell_result_dict(flowcell_id)
+    
+    if d is None:
+        return ''
+    
+    output = []
+    
+    # c_name == 'CN-M' (i.e. C1-33)
+    for c_name in d:
+        erd = d[c_name]['eland_results']
+        
+        if int(lane) in erd:
+            output.append('<a href="/results/%s/%s/eland_result/%s">eland_result(%s)</a>' % (flowcell_id, c_name, lane, c_name))
+    
+    if len(output) == 0:
+        return ''
+    
+    return '(' + '|'.join(output) + ')'
+            
\ No newline at end of file
index 853cc1e40de4f96b7c63b63199afda984f1a0679..9980c8068b29a032ccd0984767cfd3de7869234f 100644 (file)
@@ -92,3 +92,4 @@ UPLOADTO_CONFIG_FILE = os.path.join(UPLOADTO_HOME, 'eland_config')
 UPLOADTO_ELAND_RESULT_PACKS = os.path.join(UPLOADTO_HOME, 'eland_results')
 UPLOADTO_BED_PACKS = os.path.join(UPLOADTO_HOME, 'bed_packs')
 
+RESULT_HOME_DIR = os.path.abspath('../../results')
index af875b25afeeb80795f43bb124bde6bf54bc08ef..b359c33e4d97d9a0b8b3ed7b2972e62ba1a1237c 100644 (file)
@@ -3,8 +3,8 @@ from django.conf.urls.defaults import *
 # Databrowser:
 from django.contrib import databrowse
 from fctracker.models import Library, FlowCell
-databrowse.site.register(Library)
-databrowse.site.register(FlowCell)
+#databrowse.site.register(Library)
+#databrowse.site.register(FlowCell)
 
 urlpatterns = patterns('',
     # Base:
@@ -12,7 +12,8 @@ urlpatterns = patterns('',
     # Admin:
      (r'^admin/', include('django.contrib.admin.urls')),
     # Databrowser:
-     (r'^databrowse/(.*)', databrowse.site.root),
+     #(r'^databrowse/(.*)', databrowse.site.root),
      (r'^library/$', 'gaworkflow.frontend.fctracker.views.library'),
-     (r'^library/(?P<lib_id>\w+)/$', 'gaworkflow.frontend.fctracker.views.library_to_flowcells')
+     (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]+)/eland_result/(?P<lane>[1-8])','gaworkflow.frontend.fctracker.views.result_fc_cnm_eland_lane')
 )