Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
added pipeline for functional analysis (assembly, correction, binning…
Browse files Browse the repository at this point in the history
…, annotation, kegg mapping)

added dash app for viewing kegg pathways. for each kegg pathway the user can view all microbes that have the respective enzymes in their genome
improved view (visual enhancements, added pipeline to view)
  • Loading branch information
lucast122 committed May 16, 2022
1 parent cf3bb5d commit 7b7949b
Show file tree
Hide file tree
Showing 11 changed files with 441 additions and 41 deletions.
7 changes: 4 additions & 3 deletions desktop/build.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from subprocess import call
from os.path import realpath, dirname, join
from os import pathsep
from os.path import realpath, dirname, join
from subprocess import call

ROOT = dirname(realpath(__file__))


def main():
root = dirname(realpath(__file__))
entry_point = join(root, 'src', 'mmonitor', '__main__.py')
placeholder = join(root, 'src', 'resources', 'images', '.placeholder')
images_dir_dest = join('resources', 'images')
Expand Down
Empty file modified desktop/mmonitor.sqlite3
100644 → 100755
Empty file.
9 changes: 7 additions & 2 deletions desktop/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ pandas==1.3.5
numpy==1.22.1
scipy==1.7.3
plotly==5.5.0
dash==1.20.0
dash~=2.4.1
Flask==2.0.2
future==0.18.2
mysql-connector-python==8.0.27
requests==2.27.1
requests==2.27.1
setuptools~=57.0.0
matplotlib~=3.5.2
tqdm~=4.63.0
Pillow~=9.0.1
conda~=4.1.6
16 changes: 12 additions & 4 deletions desktop/src/mmonitor/dashapp/apps/correlations.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Tuple, Any, List, Iterable, Dict, Union

import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash_table import DataTable
import plotly.express as px
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from dash_table import DataTable
from pandas import DataFrame
from plotly.graph_objects import Figure

Expand Down Expand Up @@ -52,6 +52,7 @@ def _init_layout(self) -> None:

# graph dropdown menus in a flex box
header = html.H1('Correlations of abundances and metadata')

taxonomy_dd = dcc.Dropdown(
id='taxonomy-dd',
options=[{'label': t, 'value': t} for t in self._taxonomies],
Expand Down Expand Up @@ -143,11 +144,18 @@ def _init_layout(self) -> None:
correlations_tb = DataTable(id='table-correlations', data=[], columns=[])
download_tb = dcc.Download(id='download-tb')

CONTENT_STYLE = {

"margin-right": "2rem",
"padding": "2rem 1rem",
'margin-bottom': '200px', 'background-color': 'gainsboro'
}

container = html.Div(
[header, dropdowns, graph_score, graph_test, header_tb, dropdowns_tb,
selections_tb, correlations_tb, download_tb],
style={'margin-bottom': '200px'}
)
style=CONTENT_STYLE)

self.layout = container

def _init_callbacks(self) -> None:
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/mmonitor/dashapp/apps/horizon.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid

import dash_html_components as html
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from flask import send_from_directory
Expand All @@ -28,7 +28,7 @@ def serve_image(cache_bust):
class Horizon(BaseApp):
"""
App to display the taxonomy abundances in a horizon plot.
Calls an R script and uploads the generated image.
Calls an R script and uploads the pipeline_out image.
"""

def __init__(self, sql: MMonitorDBInterface):
Expand Down
71 changes: 71 additions & 0 deletions desktop/src/mmonitor/dashapp/apps/kegg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import base64
import glob

import dash
import dash_core_components as dcc
import dash_html_components as html

from mmonitor.dashapp.app import app
from mmonitor.dashapp.base_app import BaseApp


class Kegg(BaseApp):

def __init__(self):
self._init_layout()
self._init_callbacks()

# @app.server.route('/horizon.png<cache_bust>')
# def serve_image(cache_bust):
# """
# Allows dash to display png images from ../resources/images/
#
# The cache_bust is a way to make the url unique.
# This is necessary to force the browser to reload the
# presumably 'static' image file that it had previously cached.
# """
# return send_from_directory(images_path, 'horizon.png')

def _init_layout(self) -> None:
self._static_image_route = "/static/"
self._samples = glob.glob("/resources/pipeline_out/*/")
print(self._samples)
header = html.H1("Functional mapping of annotated genomes to KEGG pathways")
print(self._samples)
sample_dropdown = dcc.Dropdown(id="sample-dropdown", options=[{'label': t, 'value': t} for t in self._samples],
value=self._samples[0])
pathway_dropdown = dcc.Dropdown(id="pathway-dropdown")
dd = html.Div(id='dd-output-container')

dropdowns = html.Div(
[sample_dropdown, pathway_dropdown]
)

image = html.Img(
id='kegg-plot',
alt='Please select a kegg plot',
style={'display': 'block', 'margin-left': 'auto', 'margin-right': 'auto', 'padding': '20px'}
)

container = html.Div([header, dropdowns, dd, image])

self._layout = container

def _init_callbacks(self) -> None:
@app.callback(
dash.dependencies.Output('pathway-dropdown', 'options'),
[dash.dependencies.Input('sample-dropdown', 'value')]
)
def update_pathway_dropdown(sample):
return [{'label': i.split("/")[-1].removesuffix(".png"), 'value': i} for i in glob.glob(f"{sample}/*.png")]

@app.callback(
dash.dependencies.Output('kegg-plot', 'src'),
dash.dependencies.Input('pathway-dropdown', 'value')
)
def update_image_src(image_path):
print('current image_path = {}'.format(image_path))
encoded_image = base64.b64encode(open(image_path, 'rb').read())
return 'data:image/png;base64,{}'.format(encoded_image.decode())

return value
8 changes: 4 additions & 4 deletions desktop/src/mmonitor/dashapp/apps/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from io import StringIO
from typing import List, Tuple, Set

import pandas as pd
import plotly.express as px
import dash
import dash_core_components as dcc
import dash_html_components as html
import pandas as pd
import plotly.express as px
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from plotly.graph_objects import Figure
Expand Down Expand Up @@ -52,7 +52,7 @@ def _init_layout(self) -> None:
multiple=True
)

# generated content
# pipeline_out content
graph = dcc.Graph(id='kraken-graph')

# slider to adjust entities per bar
Expand Down Expand Up @@ -96,7 +96,7 @@ def _init_callbacks(self) -> None:
)
def _update_output(contents, slider_value, tax_rank, filenames, tax_rank_options, content_style):
"""
Read the uploaded files and display the generated plot.
Read the uploaded files and display the pipeline_out plot.
The plot is a stacked bar chart with abundances
projected to 100%. The number of entities per bar
is adjustable with different elements.
Expand Down
28 changes: 17 additions & 11 deletions desktop/src/mmonitor/dashapp/index.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dash_html_components as html
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
from dash.exceptions import PreventUpdate
from flask import request

from mmonitor.dashapp.app import app
from mmonitor.dashapp.apps import correlations, taxonomy, kraken, horizon
from mmonitor.dashapp.apps import correlations, taxonomy, kraken, horizon, kegg
from mmonitor.dashapp.base_app import BaseApp
from mmonitor.database.mmonitor_db import MMonitorDBInterface

Expand All @@ -31,22 +31,28 @@ def _init_apps(self) -> None:
"""

self._apps = {
'/apps/correlations': {
'name': 'Correlations',
'app': correlations.Correlations(self._sql)
},
'/apps/taxonomy': {
'name': 'Taxonomy',
'app': taxonomy.Taxonomy(self._sql)
},
'/apps/kraken2': {
'name': 'Kraken2',
'app': kraken.Kraken(self._sql)
},

'/apps/horizon': {
'name': 'Horizon',
'app': horizon.Horizon(self._sql)
},

'/apps/correlations': {
'name': 'Correlations',
'app': correlations.Correlations(self._sql)
},
'/apps/kraken2': {
'name': 'Kraken2',
'app': kraken.Kraken(self._sql)
},
'/apps/kegg': {
'name': 'kegg',
'app': kegg.Kegg()
}
}

def _init_layout(self) -> None:
Expand All @@ -57,7 +63,7 @@ def _init_layout(self) -> None:

location = dcc.Location(id='url', refresh=False)
navigation = html.Div([
dcc.Link(values['name'], href=url, style={'padding': '10px'})
dcc.Link(values['name'], href=url, style={'padding': '10px', 'font-size': "30px"})
for url, values in self._apps.items()
], className="row")
page_content = html.Div(id='page-content', children=[])
Expand Down
3 changes: 2 additions & 1 deletion desktop/src/mmonitor/database/mmonitor_db.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sqlite3
from json import loads, dumps
from typing import List, Tuple, Any

import pandas as pd
from json import loads, dumps


def _parse_dict(x):
Expand Down Expand Up @@ -97,6 +97,7 @@ def create_db(self, db_name):
abundance INTEGER,
sample_id INTEGER,
project_id INTEGER,
sample_date TEXT,
PRIMARY KEY ("read_id")
)"""

Expand Down
Loading

0 comments on commit 7b7949b

Please sign in to comment.