simplify library report
authorDiane Trout <diane@ghic.org>
Tue, 5 May 2015 23:29:40 +0000 (16:29 -0700)
committerDiane Trout <diane@ghic.org>
Tue, 5 May 2015 23:29:40 +0000 (16:29 -0700)
htsworkflow/templates/samples/library_index.html
samples/views.py

index 6ee9750cd8e0bc282fe57202596fd803cdd4f2f6..4491a09d11cc253b3a7044c1168103348d184a6e 100644 (file)
     </thead>
     <tbody >
       {% for lib in library_list %}
-      <tr typeof="libns:Library" about="{{lib.library.get_absolute_url}}">
-        <td ><a href="{{lib.library.get_absolute_url}}">{{ lib.amplified_from }}</a></td>
-        <td ><a href="{{lib.library.get_absolute_url}}"><span property="libns:library_id">{{ lib.library_id }}</span></a></td>
+      <tr typeof="libns:Library" about="{{lib.get_absolute_url}}">
+        <td >
+          <a href="{{lib.amplified_from_sample.get_absolute_url }}">
+            {{ lib.amplified_from_sample.id }}
+          </a>
+        </td>
+        <td >
+          <a href="{{lib.get_absolute_url}}">
+            <span property="libns:library_id">{{ lib.id }}</span>
+          </a>
+        </td>
         <td rel="libns:species">
           <a typeof="libns:Species"
-             href="{{lib.library.library_species.get_absolute_url}}">
-            <span property="libns:species_name">{{ lib.species_name }}</span>
+             href="{{ lib.library_species.get_absolute_url }}">
+            <span property="libns:species_name">{{ lib.library_species.scientific_name }}</span>
           </a>
         </td>
         <td >
-          <a href="{{ lib.library.get_absolute_url }}">
+          <a href="{{ lib.get_absolute_url }}">
             <span property="libns:name">{{ lib.library_name }}</span>
           </a>
         </td>
-        <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.0 }}</td>
-        <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.1 }}</td>
-        <td  bgcolor="#00BFFF">{{ lib.lanes_run.0.2 }}</td>
-        <td  bgcolor="#66CDAA">{{ lib.lanes_run.1.0 }}</td>
-        <td  bgcolor="#66CDAA">{{ lib.lanes_run.1.1 }}</td>
-        <td  bgcolor="#66CDAA">{{ lib.lanes_run.1.2 }}</td>
+        {% for ended in lib.lanes_sequenced %}
+          {% cycle '#00BFFF' '#66CDAA' as bincolor silent %}
+          {% for bin in ended %}
+          <td bgcolor="{{ bincolor }}">{% if bin %}{{ bin }}{% endif %}</td>
+          {% endfor %}
+        {% endfor %}
         {% if lib.is_archived %}
           <td ><img src="{% static "img/hdd_unmount.png" %}" alt="Archived" /></td>
         {% else %}
index e173b08d5974f193ee7ea27fabbc545f4894973c..3b5ea350e2289e16d7474bec221580d8175311b4 100644 (file)
@@ -35,75 +35,23 @@ SAMPLES_CONTEXT_DEFAULTS = {
 LOGGER = logging.getLogger(__name__)
 
 
-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}
-
-
 def library(request, todo_only=False):
-    queryset = Library.objects.filter(hidden__exact=0)
-    filters = {'hidden__exact': 0}
+    #filters = {'hidden__exact': 0}
     if todo_only:
         filters['lane'] = None
-    # build changelist
+
     fcl = HTSChangeList(request, Library,
                         list_filter=['affiliations', 'library_species'],
                         search_fields=['id', 'library_name', 'amplified_from_sample__id'],
                         list_per_page=200,
                         model_admin=LibraryOptions(Library, None),
-                        extra_filters=filters
                         )
 
-    context = {'cl': fcl, 'title': 'Library Index', 'todo_only': todo_only}
-    context.update(create_library_context(fcl))
+    context = {'cl': fcl,
+               'library_list': fcl.result_list,
+               'title': 'Library Index',
+               'todo_only': todo_only}
+
     t = get_template('samples/library_index.html')
     c = RequestContext(request, context)
     return HttpResponse(t.render(c))