-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
- """
- 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
- if lib.amplified_from_sample is not None:
- summary['amplified_from'] = lib.amplified_from_sample.id
- else:
- summary['amplified_from'] = ''
- lanes_run = count_lanes(lib.lane_set)
- # suppress zeros
- for row_index, row in enumerate(lanes_run):
- for col_index, cell in enumerate(row):
- if lanes_run[row_index][col_index] == 0:
- lanes_run[row_index][col_index] = ''
- summary['lanes_run'] = lanes_run
- summary['is_archived'] = lib.is_archived()
- records.append(summary)
- cl.result_count = str(cl.paginator._count)
- return {'library_list': records}
-
-