[views] Fix results file display in GenomicMeasure view.
authorVladimir Popescu <vladimir.popescu@logilab.fr>
Fri, 18 Oct 2013 14:01:14 +0000
changeset 396 3990d3a0e1a8
parent 395 c56d3cceaead
child 398 da90998dea18
[views] Fix results file display in GenomicMeasure view. Also add Gene primary view and CGH and Mutation table views, used in the GenomicMeasure primary view. Add table views on genomic measures and results
views/primary.py
views/secondary.py
views/tableviews.py
--- a/views/primary.py	Mon Sep 30 09:04:33 2013 +0200
+++ b/views/primary.py	Fri Oct 18 14:01:14 2013 +0000
@@ -104,23 +104,6 @@
                 tab.render(self.w)
         w(u'</div>')
 
-###############################################################################
-### GENOMIC MEASURE ###########################################################
-###############################################################################
-class GenomicMeasurePrimaryView(BrainomicsPrimaryView):
-    __select__ = BrainomicsPrimaryView.__select__ & is_instance('GenomicMeasure')
-
-    def iterate_attributes(self, entity):
-        fields = [(self._cw._('Type'), entity.type),
-                  (self._cw._('Format'), entity.format),
-                  (self._cw._('Chip S/N'), entity.formatted_chip_serialnum)]
-        if entity.platform:
-            fields.append((self._cw._('Platform'), entity.platform[0].identifier))
-        return fields
-
-    def display_main_col(self, entity):
-        self.w(entity.view('results-view'))
-
 
 ###############################################################################
 ### SUBJECT ###################################################################
@@ -638,3 +621,72 @@
         if rset:
             self.w(u'<h3>%s</h3>' % self._cw._('External Resources'))
             self.wview('list', rset=rset)
+
+
+###############################################################################
+### GENOMIC MEASURE ###########################################################
+###############################################################################
+class GenomicMeasurePrimaryView(BrainomicsPrimaryView):
+    __select__ = BrainomicsPrimaryView.__select__ & is_instance('GenomicMeasure')
+
+    def iterate_attributes(self, entity):
+        subject = entity.concerns[0]
+        subject = u'<a href="%s">%s</a>' % (subject.absolute_url(), subject.dc_title())
+        fields = [(self._cw._('Type'), entity.type),
+                  (self._cw._('Format'), entity.format),
+                  (self._cw._('File path'), entity.filepath),
+                  (self._cw._('Chip S/N'), entity.formatted_chip_serialnum),
+                  (self._cw._('Subject'), subject),
+                  (self._cw._('Study'), entity.related_study[0].view('outofcontext'))]
+        if entity.platform:
+            fields.append((self._cw._('Platform'), entity.platform[0].view('outofcontext')))
+        return fields
+
+    def display_main_col(self, entity):
+        self.w(entity.view('results-view'))
+        cgh_results = self._cw.execute('Any R WHERE R is CghResult, '
+                                       'R related_measure X, X eid %(e)s',
+                                       {'e': entity.eid})
+        mutation_results = self._cw.execute('Any R WHERE R is Mutation, '
+                                            'R related_measure X, X eid %(e)s',
+                                            {'e': entity.eid})
+        if cgh_results or mutation_results:
+            self.w(u'<div class="span3">')
+            if cgh_results:
+                self.w(u'<h3>%s</h3>' % self._cw._('CGH results'))
+                self.wview('cgh-table-view', rset=cgh_results)
+            if mutation_results:
+                self.w(u'<h3>%s</h3>' % self._cw._('Sequencing results'))
+                self.wview('mutation-table-view', rset=mutation_results)
+            self.w(u'</div>')
+
+
+###############################################################################
+### GENE ######################################################################
+###############################################################################
+class GenePrimaryView(BrainomicsPrimaryView):
+    __select__ = BrainomicsPrimaryView.__select__ & is_instance('Gene')
+
+    def iterate_attributes(self, entity):
+        fields = [(self._cw._('Identifier'), entity.gene_id),
+                  (self._cw._('Start position'), entity.start_position),
+                  (self._cw._('Stop position'), entity.stop_position),
+                  (self._cw._('Chromosome'), entity.chromosome[0].view('outofcontext'))]
+        return fields
+
+    def display_main_col(self, entity):
+        cgh_results = self._cw.execute('Any R WHERE R is CghResult, '
+                                       'R related_gene X, X eid %(e)s',
+                                       {'e': entity.eid})
+        mutation_results = self._cw.execute('Any R WHERE R is Mutation, '
+                                            'R related_gene X, X eid %(e)s',
+                                            {'e': entity.eid})
+        if cgh_results or mutation_results:
+            self.w(u'<div class="span3">')
+            if cgh_results:
+                self.w(u'<h3>%s</h3>' % self._cw._('CGH results'))
+                self.wview('gene-cgh-table-view', rset=cgh_results)
+            if mutation_results:
+                self.w(u'<h3>%s</h3>' % self._cw._('Sequencing results'))
+                self.wview('gene-mutation-table-view', rset=mutation_results)
+            self.w(u'</div>')
--- a/views/secondary.py	Mon Sep 30 09:04:33 2013 +0200
+++ b/views/secondary.py	Fri Oct 18 14:01:14 2013 +0000
@@ -65,11 +65,11 @@
         # Display results file
         w = self.w
         w(u'<div class="span3">')
-        rset = self._cw.execute('(Any F LIMIT 1 WHERE X results_file F, X eid %(e)s)',
+        rset = self._cw.execute('Any F WHERE X results_file F, X eid %(e)s',
                                 {'e': entity.eid})
         if rset:
             w(u'<h3>%s</h3>' % self._cw._('Results file'))
-            self.wview('downloadlink', rset=rset)
+            self.wview('list', rset=rset)
         w(u'</div>')
 
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/views/tableviews.py	Fri Oct 18 14:01:14 2013 +0000
@@ -0,0 +1,75 @@
+# -*- coding: utf-8 -*-
+# copyright 2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2013 CEA (Saclay, FRANCE), all rights reserved.
+# contact http://www.logilab.fr -- mailto:contact@logilab.fr
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Lesser General Public License as published by the Free
+# Software Foundation, either version 2.1 of the License, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Lesser General Public License along
+# with this program. If not, see <http://www.gnu.org/licenses/>.
+
+"""cubicweb-suivimp views/forms/actions/components for web ui"""
+from cubicweb.selectors import is_instance
+from cubicweb.web.views.tableview import EntityTableView, RelationColRenderer
+
+
+###############################################################################
+### GENOMIC MEASURE - CGH #####################################################
+###############################################################################
+class AbstractCghTableView(EntityTableView):
+    __abtract__ = True
+    __select__ = EntityTableView.__select__ & is_instance('CghResult')
+
+
+class CghTableView(AbstractCghTableView):
+    __regid__ = 'cgh-table-view'
+    columns = ['related_gene', 'cgh_ratio']
+    column_renderers = {'related_gene': RelationColRenderer(role='subject')}
+
+
+class GeneCghTableView(AbstractCghTableView):
+    __regid__ = 'gene-cgh-table-view'
+    columns = ['related_measure', 'cgh_ratio']
+    column_renderers = {'related_measure': RelationColRenderer(role='subject', vid='incontext')}
+
+
+###############################################################################
+### GENOMIC MEASURE - SEQUENCAGE ##############################################
+###############################################################################
+class AbstractMutationTableView(EntityTableView):
+    __abstract__ = True
+    __select__ = EntityTableView.__select__ & is_instance('Mutation')
+
+    columns = ['histology_number', 'biopsy_date', 'percent_tumoral',
+               'valid', 'mutation_id', 'mutation_type', 'ploidy',
+               'reference_base', 'variant_base', 'variant_frequency', 'p_value',
+               'coverage', 'reference_coverage', 'variant_coverage',
+               'hotspot_id', 'reference_id', 'comment',
+               'protein', 'biological_classification', 'classification_type',
+               'locus_version', 'nucl', 'polyphen', 'sift', 'gvd_alignment',
+               'base', 'conclusions', 'reception_date', 'result_date',
+               'block', 'medical_coverage', 'transfert']
+
+
+class MutationTableView(AbstractMutationTableView):
+    __regid__ = 'mutation-table-view'
+
+    column_renderers = {'related_gene': RelationColRenderer(role='subject')}
+
+    columns = ['related_gene',] + AbstractMutationTableView.columns
+
+
+class GeneMutationTableView(AbstractMutationTableView):
+    __regid__ = 'gene-mutation-table-view'
+
+    column_renderers = {'related_measure': RelationColRenderer(role='subject', vid='incontext')}
+
+    columns = ['related_measure',] + AbstractMutationTableView.columns