import simplejson as json
from htsworkflow.frontend.auth import require_api_key
-from htsworkflow.frontend.experiments.models import FlowCell
+from htsworkflow.frontend.experiments.models import FlowCell, Lane, LANE_STATUS_MAP
from htsworkflow.frontend.samples.changelist import ChangeList
-from htsworkflow.frontend.samples.models import Library
+from htsworkflow.frontend.samples.models import Library, Species, HTSUser
from htsworkflow.frontend.samples.results import get_flowcell_result_dict, parse_flowcell_id
from htsworkflow.frontend.bcmagic.forms import BarcodeMagicForm
from htsworkflow.pipelines.runfolder import load_pipeline_run_xml
from django.core.exceptions import ObjectDoesNotExist
from django.http import HttpResponse, HttpResponseRedirect, Http404
-from django.shortcuts import render_to_response
+from django.shortcuts import render_to_response, get_object_or_404
from django.template import RequestContext
from django.template.loader import get_template
from django.contrib.auth.decorators import login_required
'bcmagic': BarcodeMagicForm()
}
+def count_lanes(lane_set):
+ single = 0
+ paired = 1
+ short_read = 0
+ medium_read = 1
+ long_read = 2
+ counts = [[0,0,0,],[0,0,0]]
+
+ for lane in lane_set.all():
+ if lane.flowcell.paired_end:
+ lane_type = paired
+ else:
+ lane_type = single
+ if lane.flowcell.read_length < 40:
+ read_type = short_read
+ elif lane.flowcell.read_length < 100:
+ read_type = medium_read
+ else:
+ read_type = long_read
+ counts[lane_type][read_type] += 1
+
+ return counts
+
def create_library_context(cl):
"""
- Create a list of libraries that includes how many lanes were run
+ Create a list of libraries that includes how many lanes were run
"""
records = []
#for lib in library_items.object_list:
for lib in cl.result_list:
summary = {}
+ summary['library'] = lib
summary['library_id'] = lib.id
summary['library_name'] = lib.library_name
summary['species_name' ] = lib.library_species.scientific_name
summary['amplified_from'] = lib.amplified_from_sample.id
else:
summary['amplified_from'] = ''
- lanes_run = 0
- #for lane_id in LANE_LIST:
- # lane = getattr(lib, 'lane_%d_library' % (lane_id,))
- # lanes_run += len( lane.all() )
- lanes_run = lib.lane_set.count()
+ lanes_run = count_lanes(lib.lane_set)
+ # suppress zeros
+ for row in xrange(len(lanes_run)):
+ for col in xrange(len(lanes_run[row])):
+ if lanes_run[row][col] == 0:
+ lanes_run[row][col] = ''
summary['lanes_run'] = lanes_run
summary['is_archived'] = lib.is_archived()
records.append(summary)
- cl.result_count = unicode(cl.paginator._count) + u" libraries"
+ cl.result_count = unicode(cl.paginator._count)
return {'library_list': records }
def library(request):
- # build changelist
+ # build changelist
fcl = ChangeList(request, Library,
list_filter=['affiliations', 'library_species'],
search_fields=['id', 'library_name', 'amplified_from_sample__id'],
context.update(create_library_context(fcl))
t = get_template('samples/library_index.html')
c = RequestContext(request, context)
+ return HttpResponse( t.render(c) )
- app_context = {
- 'page_name': 'Library Index',
- 'east_region_config_div': 'changelist-filter',
- 'body': t.render(c)
- }
- app_context.update(SAMPLES_CONTEXT_DEFAULTS)
-
- app_t = get_template('flowcell_libraries_app.html')
- app_c = RequestContext(request, app_context)
- return HttpResponse( app_t.render(app_c) )
def library_to_flowcells(request, lib_id):
"""
context,
context_instance = RequestContext(request))
+def lanes_for(request, username=None):
+ """
+ Generate a report of recent activity for a user
+ """
+ query = {}
+ if username is not None:
+ user = HTSUser.objects.get(username=username)
+ query.update({'library__affiliations__users__id':user.id})
+ fcl = ChangeList(request, Lane,
+ list_filter=[],
+ search_fields=['flowcell__flowcell_id', 'library__id', 'library__library_name'],
+ list_per_page=200,
+ queryset=Lane.objects.filter(**query)
+ )
+
+ context = { 'lanes': fcl, 'title': 'Lane Index'}
+
+ return render_to_response(
+ 'samples/lanes_for.html',
+ context,
+ context_instance = RequestContext(request)
+ )
+
+
def summaryhtm_fc_cnm(request, flowcell_id, cnm):
"""
returns a Summary.htm file if it exists.
else:
return 'unknown'
-def _make_eland_results(flowcell_id, lane, interesting_flowcells):
+def _make_eland_results(flowcell_id, lane_number, interesting_flowcells):
fc_id, status = parse_flowcell_id(flowcell_id)
cur_fc = interesting_flowcells.get(fc_id, None)
if cur_fc is None:
return []
flowcell = FlowCell.objects.get(flowcell_id=flowcell_id)
+ lane = flowcell.lane_set.get(lane_number=lane_number)
# Loop throw storage devices if a result has been archived
storage_id_list = []
if cur_fc is not None:
result_path = cur_fc[cycle]['eland_results'].get(lane, None)
result_link = make_result_link(fc_id, cycle, lane, result_path)
results.append({'flowcell_id': fc_id,
+ 'flowcell': flowcell,
'run_date': flowcell.run_date,
'cycle': cycle,
'lane': lane,
lane_info = []
for lane in lib.lane_set.all():
lane_info.append( {'flowcell':lane.flowcell.flowcell_id,
- 'lane_number': lane.lane_number} )
+ 'lane_number': lane.lane_number,
+ 'paired_end': lane.flowcell.paired_end,
+ 'read_length': lane.flowcell.read_length,
+ 'status_code': lane.status,
+ 'status': LANE_STATUS_MAP[lane.status]} )
info = {
# 'affiliations'?
#'amplified_from_sample_id': lib.amplified_from_sample,
#'antibody_name': lib.antibody_name(), # we have no antibodies.
'antibody_id': lib.antibody_id,
- 'avg_lib_size': lib.avg_lib_size,
'cell_line_id': lib.cell_line_id,
'cell_line': unicode_or_none(lib.cell_line),
'experiment_type': lib.experiment_type.name,
'experiment_type_id': lib.experiment_type_id,
+ 'gel_cut_size': lib.gel_cut_size,
+ 'hidden': lib.hidden,
'id': lib.id,
+ 'insert_size': lib.insert_size,
'lane_set': lane_info,
'library_id': lib.id,
'library_name': lib.library_name,
Return information about a species.
"""
raise Http404
+
+def species(request, species_id):
+ species = get_object_or_404(Species, id=species_id)
+ context = RequestContext(request,
+ { 'species': species })
+
+ return render_to_response("samples/species_detail.html", context)
+
@login_required
def user_profile(request):
"""