# Create your views here.
from gaworkflow.frontend.fctracker.models import Library
from gaworkflow.frontend.fctracker.results import get_flowcell_result_dict, flowcellIdStrip
+from gaworkflow.frontend import settings
+from gaworkflow.util import makebed
from gaworkflow.util import opener
from django.http import HttpResponse
+import StringIO
+
#from django.db.models import base
def library(request):
f = opener.autoopen(filepath, 'r')
return HttpResponse(f)
+
+
+def bedfile_fc_cnm_eland_lane(request, fc_id, cnm, lane):
+ """
+ returns a bed file for a given flowcell, CN-M (i.e. C1-33), and lane
+ """
+ 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]
+
+ # Eland result file
+ fi = open(filepath, 'r')
+ # output memory file
+
+
+ name, description = makebed.make_description(settings.DATABASE_NAME,
+ fc_id,
+ lane)
+
+ bedgen = makebed.make_bed_from_eland_stream_generator(fi, name, description)
+
+ return HttpResponse(bedgen)
+
def _files(flowcell_id, lane):
"""
Sets up available files for download
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))
+ output.append('<a href="/results/%s/%s/bedfile/%s">bedfile(%s)</a>' % (flowcell_id, c_name, lane, c_name))
if len(output) == 0:
return ''
#(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'^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')
+ (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'),
+ (r'^results/(?P<fc_id>\w+)/(?P<cnm>C[1-9]-[0-9]+)/bedfile/(?P<lane>[1-8])','gaworkflow.frontend.fctracker.views.bedfile_fc_cnm_eland_lane'),
)
sense_color[fields[SENSE]],
os.linesep
))
+
+def make_bed_from_eland_stream_generator(instream, name, description, chromosome_prefix='chr'):
+ """
+ read an eland result file from instream and output it as a generator (iterator)
+ """
+ # indexes into fields in eland_result.txt file
+ SEQ = 1
+ CHR = 6
+ START = 7
+ SENSE = 8
+ # map eland_result.txt sense
+ sense_map = { 'F': '+', 'R': '-'}
+ sense_color = { 'F': '0,0,255', 'R': '255,255,0' }
+ # provide default track names
+ if name is None: name = "track"
+ if description is None: description = "eland result file"
+ bed_header = 'track name="%s" description="%s" visibility=4 itemRgb="ON"'
+ bed_header += os.linesep
+ yield bed_header % (name, description)
+
+ for line in instream:
+ fields = line.split()
+ # we need more than the CHR field, and it needs to match a chromosome
+ if len(fields) <= CHR or \
+ (chromosome_prefix is not None and \
+ fields[CHR][:3] != chromosome_prefix):
+ continue
+ start = fields[START]
+ stop = int(start) + len(fields[SEQ])
+ chromosome, extension = fields[CHR].split('.')
+ assert extension == "fa"
+ yield '%s %s %d read 0 %s - - %s%s' % (
+ chromosome,
+ start,
+ stop,
+ sense_map[fields[SENSE]],
+ sense_color[fields[SENSE]],
+ os.linesep
+ )
def make_description(database, flowcell_id, lane):
"""
from gaworkflow.util.fctracker import fctracker
fc = fctracker(database)
- cells = fc._get_flowcells("where flowcell_id='%s'" % (flowcell_id))
+ cells = fc._get_flowcells("where flowcell_id LIKE '%s%%'" % (flowcell_id))
if len(cells) != 1:
raise RuntimeError("couldn't find flowcell id %s" % (flowcell_id))
lane = int(lane)
name = "%s-%s" % (flowcell_id, lane)
cell_id, cell = cells.items()[0]
- assert cell_id == flowcell_id
+
+ #The assertion is no longer true after I changed
+ # the where statement to include the LIKE command.
+ # because flowcells are being renamed to 'FC12269 (deleted)'
+ #assert cell_id == flowcell_id
cell_library_id = cell['lane_%d_library_id' %(lane,)]
cell_library = cell['lane_%d_library' %(lane,)]