1 # Create your views here.
2 from gaworkflow.frontend.fctracker.models import Library
3 from gaworkflow.frontend.fctracker.results import get_flowcell_result_dict, flowcellIdStrip
4 from gaworkflow.frontend import settings
5 from gaworkflow.util import makebed
6 from gaworkflow.util import opener
7 from django.http import HttpResponse
11 #from django.db.models import base
14 library_list = Library.objects.all() #.order_by('-pub_date')
15 rep_string = '<a href="/library/%s/">%s - %s (%s)</a>'
16 output = '<br />\n'.join([rep_string \
20 l.library_species.scientific_name) for l in library_list])
21 return HttpResponse(output)
23 def library_to_flowcells(request, lib_id):
26 lib = Library.objects.get(library_id=lib_id)
28 return HttpResponse("Library %s does not exist" % (lib_id))
32 output.append('<b>Library ID:</b> %s' % (lib.library_id))
33 output.append('<b>Name:</b> %s' % (lib.library_name))
34 output.append('<b>Species:</b> %s' % (lib.library_species.scientific_name))
37 output.append('<b>FLOWCELL - LANE:</b>')
39 output.extend([ '%s - Lane 1 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 1)) for fc in lib.lane_1_library.all() ])
40 output.extend([ '%s - Lane 2 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 2)) for fc in lib.lane_2_library.all() ])
41 output.extend([ '%s - Lane 3 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 3)) for fc in lib.lane_3_library.all() ])
42 output.extend([ '%s - Lane 4 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 4)) for fc in lib.lane_4_library.all() ])
43 output.extend([ '%s - Lane 5 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 5)) for fc in lib.lane_5_library.all() ])
44 output.extend([ '%s - Lane 6 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 6)) for fc in lib.lane_6_library.all() ])
45 output.extend([ '%s - Lane 7 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 7)) for fc in lib.lane_7_library.all() ])
46 output.extend([ '%s - Lane 8 %s' % (fc.flowcell_id, _files(fc.flowcell_id, 8)) for fc in lib.lane_8_library.all() ])
48 record_count = lib.lane_1_library.count() + \
49 lib.lane_2_library.count() + \
50 lib.lane_3_library.count() + \
51 lib.lane_4_library.count() + \
52 lib.lane_5_library.count() + \
53 lib.lane_6_library.count() + \
54 lib.lane_7_library.count() + \
55 lib.lane_8_library.count()
58 output.append("None Found")
60 return HttpResponse('<br />\n'.join(output))
63 def summaryhtm_fc_cnm(request, fc_id, cnm):
65 returns a Summary.htm file if it exists.
67 fc_id = flowcellIdStrip(fc_id)
68 d = get_flowcell_result_dict(fc_id)
71 return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
74 return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
76 summary_filepath = d[cnm]['summary']
78 if summary_filepath is None:
79 return HttpResponse('<b>Summary.htm for Flowcell %s; %s not found.' % (fc_id, cnm))
81 f = open(summary_filepath, 'r')
83 return HttpResponse(f)
86 def result_fc_cnm_eland_lane(request, fc_id, cnm, lane):
88 returns an eland_file upon calling.
90 fc_id = flowcellIdStrip(fc_id)
91 d = get_flowcell_result_dict(fc_id)
94 return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
97 return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
99 erd = d[cnm]['eland_results']
103 return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
107 f = opener.autoopen(filepath, 'r')
109 return HttpResponse(f, mimetype="application/x-elandresult")
112 def bedfile_fc_cnm_eland_lane_ucsc(request, fc_id, cnm, lane):
114 returns a bed file for a given flowcell, CN-M (i.e. C1-33), and lane (ucsc compatible)
116 return bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=True)
119 def bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=False):
121 returns a bed file for a given flowcell, CN-M (i.e. C1-33), and lane
123 fc_id = flowcellIdStrip(fc_id)
124 d = get_flowcell_result_dict(fc_id)
127 return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
130 return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
132 erd = d[cnm]['eland_results']
136 return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
141 fi = opener.autoopen(filepath, 'r')
145 name, description = makebed.make_description(settings.DATABASE_NAME,
149 bedgen = makebed.make_bed_from_eland_stream_generator(fi, name, description)
152 return HttpResponse(bedgen)
154 return HttpResponse(bedgen, mimetype="application/x-bedfile")
157 def _files(flowcell_id, lane):
159 Sets up available files for download
161 flowcell_id = flowcellIdStrip(flowcell_id)
162 d = get_flowcell_result_dict(flowcell_id)
169 # c_name == 'CN-M' (i.e. C1-33)
172 if d[c_name]['summary'] is not None:
173 output.append('<a href="/results/%s/%s/summary/">summary(%s)</a>' \
174 % (flowcell_id, c_name, c_name))
176 erd = d[c_name]['eland_results']
179 output.append('<a href="/results/%s/%s/eland_result/%s">eland_result(%s)</a>' % (flowcell_id, c_name, lane, c_name))
180 output.append('<a href="/results/%s/%s/bedfile/%s">bedfile(%s)</a>' % (flowcell_id, c_name, lane, c_name))
185 return '(' + '|'.join(output) + ')'