Skip to content

Commit 168ce6c

Browse files
committed
Add new features viewer
1 parent 259f675 commit 168ce6c

File tree

4 files changed

+38
-9
lines changed

4 files changed

+38
-9
lines changed

src/pathme_viewer/constants.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
import os
66

77
from pathme.cli import WIKIPATHWAYS_FILES
8-
from pathme.constants import get_connection
8+
from pathme.constants import get_connection, KEGG, REACTOME, WIKIPATHWAYS
9+
10+
DATABASE_STYLE_DICT = {
11+
KEGG: 'KEGG',
12+
REACTOME: 'Reactome',
13+
WIKIPATHWAYS: 'WikiPathways',
14+
}
915

1016
MODULE_NAME = 'pathme_viewer'
1117
PATHME_DIR = os.environ.get('PATHME_DIRECTORY', os.path.join(os.path.expanduser('~'), '.pathme'))

src/pathme_viewer/models.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
import datetime
66

7-
from pybel import from_bytes
87
from sqlalchemy import Column, DateTime, Integer, String
98
from sqlalchemy import LargeBinary, Text
109
from sqlalchemy.ext.declarative import declarative_base
1110

12-
from .constants import MODULE_NAME
11+
from pybel import from_bytes
12+
from .constants import MODULE_NAME, DATABASE_STYLE_DICT
1313

1414
LONGBLOB = 4294967295
1515

@@ -43,8 +43,19 @@ class Pathway(Base):
4343
blob = Column(LargeBinary(LONGBLOB), doc='A pickled version of this pathway')
4444

4545
def __str__(self):
46-
"""Return Pathway name."""
47-
return self.name
46+
"""Return pathway name."""
47+
return '{} ({})'.format(
48+
self.name,
49+
DATABASE_STYLE_DICT.get(self.resource_name, self.resource_name)
50+
)
51+
52+
@property
53+
def display_name(self):
54+
"""Return pathway name."""
55+
return '{} ({})'.format(
56+
self.name,
57+
DATABASE_STYLE_DICT.get(self.resource_name, self.resource_name)
58+
)
4859

4960
def as_bel(self):
5061
"""Get this network and loads it into a :class:`BELGraph`.

src/pathme_viewer/templates/pathme_viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959

6060
<div class="col-lg-12 col-md-12 col-sm-12">
6161
<div class="row">
62-
<h2 class="title text-center"> {{ subgraph_name_string }}</h2>
62+
<h2 class="title text-center"> {{ pathways_name }}</h2>
6363
</div>
6464
<div class="row" style="margin-right: 0; margin-bottom:20px"><!-- visualization row -->
6565
<div class="panel panel-default"> <!-- / Panel d3 Force -->

src/pathme_viewer/web/views.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
from flask_admin.contrib.sqla import ModelView
1717
from pkg_resources import resource_filename
1818

19-
from ..graph_utils import export_graph, merge_pathways, get_tree_annotations, process_request
20-
from ..models import Pathway
19+
from pathme_viewer.graph_utils import export_graph, merge_pathways, get_tree_annotations, process_request
20+
from pathme_viewer.models import Pathway
2121

2222
log = logging.getLogger(__name__)
2323
time_instantiated = str(datetime.datetime.now())
@@ -106,9 +106,20 @@ def viewer():
106106
"""PathMe page."""
107107
pathways = process_request(request)
108108

109+
# List of all pathway names
110+
pathway_names = []
111+
for pathway_id, resource in pathways.items():
112+
pathway = current_app.pathme_manager.get_pathway_by_id(pathway_id, resource)
113+
114+
if not pathway:
115+
continue
116+
117+
pathway_names.append(pathway.display_name)
118+
109119
return render_template(
110120
'pathme_viewer.html',
111121
pathways=pathways,
122+
pathways_name='+'.join(pathway_names),
112123
pathway_ids=list(pathways.keys())
113124
)
114125

@@ -120,7 +131,8 @@ def get_network():
120131

121132
graph = merge_pathways(pathways)
122133

123-
log.info('Exporting merged graph with {} nodes and {} edges'.format(graph.number_of_nodes(), graph.number_of_edges()))
134+
log.info(
135+
'Exporting merged graph with {} nodes and {} edges'.format(graph.number_of_nodes(), graph.number_of_edges()))
124136

125137
return export_graph(graph, request.args.get('format'))
126138

0 commit comments

Comments
 (0)