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 result_fc_cnm_eland_lane(request, fc_id, cnm, lane):
65 returns an eland_file upon calling.
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 erd = d[cnm]['eland_results']
80 return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
84 f = opener.autoopen(filepath, 'r')
86 return HttpResponse(f, mimetype="application/x-elandresult")
89 def bedfile_fc_cnm_eland_lane_ucsc(request, fc_id, cnm, lane):
91 returns a bed file for a given flowcell, CN-M (i.e. C1-33), and lane (ucsc compatible)
93 return bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=True)
96 def bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane, ucsc_compatible=False):
98 returns a bed file for a given flowcell, CN-M (i.e. C1-33), and lane
100 fc_id = flowcellIdStrip(fc_id)
101 d = get_flowcell_result_dict(fc_id)
104 return HttpResponse('<b>Results for Flowcell %s not found.' % (fc_id))
107 return HttpResponse('<b>Results for Flowcell %s; %s not found.' % (fc_id, cnm))
109 erd = d[cnm]['eland_results']
113 return HttpResponse('<b>Results for Flowcell %s; %s; lane %s not found.' % (fc_id, cnm, lane))
118 fi = opener.autoopen(filepath, 'r')
122 name, description = makebed.make_description(settings.DATABASE_NAME,
126 bedgen = makebed.make_bed_from_eland_stream_generator(fi, name, description)
129 return HttpResponse(bedgen)
131 return HttpResponse(bedgen, mimetype="application/x-bedfile")
134 def _files(flowcell_id, lane):
136 Sets up available files for download
138 flowcell_id = flowcellIdStrip(flowcell_id)
139 d = get_flowcell_result_dict(flowcell_id)
146 # c_name == 'CN-M' (i.e. C1-33)
148 erd = d[c_name]['eland_results']
151 output.append('<a href="/results/%s/%s/eland_result/%s">eland_result(%s)</a>' % (flowcell_id, c_name, lane, c_name))
152 output.append('<a href="/results/%s/%s/bedfile/%s">bedfile(%s)</a>' % (flowcell_id, c_name, lane, c_name))
157 return '(' + '|'.join(output) + ')'