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

Commit

Permalink
fixed build script - now produces proper build
Browse files Browse the repository at this point in the history
  • Loading branch information
lucast122 committed Oct 31, 2022
1 parent 7b7949b commit ff3dbdf
Show file tree
Hide file tree
Showing 21 changed files with 106 additions and 58 deletions.
18 changes: 13 additions & 5 deletions desktop/build.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,26 @@
from os import pathsep
from os.path import realpath, dirname, join
import shutil
from os.path import realpath, dirname, join
from subprocess import call

ROOT = dirname(realpath(__file__))


def main():
entry_point = join(root, 'src', 'mmonitor', '__main__.py')
placeholder = join(root, 'src', 'resources', 'images', '.placeholder')
entry_point = join(ROOT, 'src', 'mmonitor', '__main__.py')
placeholder = join(ROOT, 'src', 'resources', 'images', '.placeholder')
images_dir_dest = join('resources', 'images')
r_script = join(root, 'src', 'resources', 'r', 'horizon.r')
r_script = join(ROOT, 'src', 'resources', 'r', 'horizon.r')
r_dir_dest = join('resources', 'r')

call(f"pyinstaller -D {entry_point} --name mmonitor --add-data {placeholder}{pathsep}{images_dir_dest} --add-data {r_script}{pathsep}{r_dir_dest}".split())
# call(f"pyinstaller -D {entry_point} --name mmonitor --add-data {placeholder}{pathsep}{images_dir_dest} --add-data {r_script}{pathsep}{r_dir_dest}".split()) #use this for building new spec file
# remove old dist and built for faster rebuilding
try:
shutil.rmtree("/Users/timolucas/PycharmProjects/MMonitor/desktop/build/mmonitor/")
shutil.rmtree("/Users/timolucas/PycharmProjects/MMonitor/desktop/dist/mmonitor/")
except:
call(f"pyinstaller mmonitor.spec".split()) # use this for using edited spec file
call(f"pyinstaller mmonitor.spec".split()) # use this for using edited spec file


if __name__ == '__main__':
Expand Down
Binary file modified desktop/mmonitor.sqlite3
Binary file not shown.
11 changes: 6 additions & 5 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 dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.express as px
from dash import dash_table
from dash import dcc as dcc
from dash import html as html
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 @@ -141,14 +141,15 @@ def _init_layout(self) -> None:
)

# data table and its download element
correlations_tb = DataTable(id='table-correlations', data=[], columns=[])
correlations_tb = dash_table.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'
'margin-bottom': '200px',
'font-size': '25px'
}

container = html.Div(
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_core_components as dcc
import dash_html_components as html
from dash import dcc
from dash import html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from flask import send_from_directory
Expand Down
6 changes: 3 additions & 3 deletions desktop/src/mmonitor/dashapp/apps/kegg.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import glob

import dash
import dash_core_components as dcc
import dash_html_components as html
from dash import dcc
from dash import html

from mmonitor.dashapp.app import app
from mmonitor.dashapp.base_app import BaseApp
Expand All @@ -28,7 +28,7 @@ def __init__(self):

def _init_layout(self) -> None:
self._static_image_route = "/static/"
self._samples = glob.glob("/resources/pipeline_out/*/")
self._samples = glob.glob("/Users/timolucas/PycharmProjects/MMonitor/desktop/src/resources/pipeline_out/*/")
print(self._samples)
header = html.H1("Functional mapping of annotated genomes to KEGG pathways")
print(self._samples)
Expand Down
4 changes: 2 additions & 2 deletions desktop/src/mmonitor/dashapp/apps/kraken.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from typing import List, Tuple, Set

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 import dcc
from dash import html
from dash.dependencies import Input, Output, State
from dash.exceptions import PreventUpdate
from plotly.graph_objects import Figure
Expand Down
8 changes: 4 additions & 4 deletions desktop/src/mmonitor/dashapp/apps/taxonomy.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import Tuple, List, Any, Dict

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

Expand Down Expand Up @@ -70,7 +70,7 @@ def _init_layout(self) -> None:
# data table for debugging
db_header = html.H4(children='SQLite Database')
data, columns = self._generate_table_data_cols()
data_tb = DataTable(id='table-correlations', data=data, columns=columns)
data_tb = dash_table.DataTable(id='table-correlations', data=data, columns=columns)

container = html.Div([maira_header, demo_dd, graph1, graph2, pie_chart_input, db_header, data_tb])
self.layout = container
Expand Down
2 changes: 1 addition & 1 deletion desktop/src/mmonitor/dashapp/base_app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import dash_html_components as html
from dash import html

from mmonitor.database.mmonitor_db import MMonitorDBInterface

Expand Down
16 changes: 8 additions & 8 deletions desktop/src/mmonitor/dashapp/index.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import dash_core_components as dcc
import dash_html_components as html
from dash import dcc
from dash import 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, kegg
from mmonitor.dashapp.apps import correlations, taxonomy, horizon, kegg
from mmonitor.dashapp.base_app import BaseApp
from mmonitor.database.mmonitor_db import MMonitorDBInterface

Expand Down Expand Up @@ -44,13 +44,13 @@ def _init_apps(self) -> None:
'/apps/correlations': {
'name': 'Correlations',
'app': correlations.Correlations(self._sql)
},
'/apps/kraken2': {
'name': 'Kraken2',
'app': kraken.Kraken(self._sql)
# },
# '/apps/kraken2': {
# 'name': 'Kraken2',
# 'app': kraken.Kraken(self._sql)
},
'/apps/kegg': {
'name': 'kegg',
'name': 'KEGG',
'app': kegg.Kegg()
}
}
Expand Down
15 changes: 7 additions & 8 deletions desktop/src/mmonitor/database/mmonitor_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,14 @@ def create_db(self, db_name):
taxonomy TEXT,
abundance INTEGER,
sample_id INTEGER,
project_id INTEGER,
sample_date TEXT,
PRIMARY KEY ("read_id")
project_id INTEGER
)"""

# sample metadata
cursor.execute(create_command)
create_command = f"""CREATE TABLE IF NOT EXISTS metadata (
"sample_id" INTEGER PRIMARY KEY,
"data" TEXT,
PRIMARY KEY("sample_id")
"data" TEXT
)"""

cursor.execute(create_command)
Expand All @@ -115,7 +112,7 @@ def create_db(self, db_name):
self._db_path = db_name

def update_table_with_kraken_out(self, kraken_out_path: str, tax_rank: str, sample_name: str,
project_name: str) -> None:
project_name: str, sample_date):
"""
Update MMonitor data from a file containing kraken output
"""
Expand All @@ -131,9 +128,11 @@ def update_table_with_kraken_out(self, kraken_out_path: str, tax_rank: str, samp
)
df = df.sort_values('Count', ascending=False)
# format name
df['Name'] = df['Name'].apply(lambda s: s.strip())

# df['Name'] = df['Name'].apply(lambda s: s.strip())
# add sample name
df['Sample'] = sample_name
df['Sample_date'] = sample_date
df = df[df['Rank'] == tax_rank]
df = df.drop(columns='Rank')
for index, row in df.iterrows():
Expand All @@ -145,7 +144,7 @@ def update_table_with_kraken_out(self, kraken_out_path: str, tax_rank: str, samp
# the same sample while sequencing) then add the abundance to the value in the database
if name_exists == 0:
insert_query = f"""INSERT INTO mmonitor
(taxonomy, abundance, sample_id, project_id)
(taxonomy, abundance, sample_id, project_id, sample_date)
VALUES
('{row['Name']}', {row['Count']}, '{sample_name}', '{project_name}')"""
cursor.execute(insert_query)
Expand Down
14 changes: 7 additions & 7 deletions desktop/src/mmonitor/userside/centrifuge.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import os
import logging
import subprocess
import multiprocessing
import pathlib
import os
import subprocess


class CentrifugeRunner:
Expand Down Expand Up @@ -32,15 +31,16 @@ def check_centrifuge(self):
def run_centrifuge(self, sequence_list, centrifuge_index, sample_name):
print(sequence_list)
if sequence_list[0].lower().endswith(('.fq', '.fastq', '.fastq.gz', '.fq.gz')):
self.cent_out = f"/Users/timolucas/PycharmProjects/MMonitor/desktop/src/resources/pipeline_out/{sample_name}_cent_out"
# if ".fastq" in sequence_list[0] or ".fq" in sequence_list[0] or ".fastq.gz" in sequence_list[0]:
self.cent_out = f"{pathlib.Path(__file__).parent.resolve()}/classifier_out/{sample_name}_cent_out"
cmd = f'centrifuge -x {centrifuge_index} -U {self.unpack_fastq_list(sequence_list)} -p {multiprocessing.cpu_count()} -S {pathlib.Path(__file__).parent.resolve()}/classifier_out/{sample_name}_cent_out'

cmd = f'centrifuge -x {centrifuge_index} -U {self.unpack_fastq_list(sequence_list)} -p {multiprocessing.cpu_count()} -S {self.cent_out}'
print(cmd)
os.system(cmd)
return
if ".fasta" in sequence_list[0] or ".fa" in sequence_list[0]:
self.cent_out = f"{pathlib.Path(__file__).parent.resolve()}/classifier_out/{sample_name}_cent_out"
cmd = f'centrifuge -x {centrifuge_index} -f {self.unpack_fastq_list(sequence_list)} -p {multiprocessing.cpu_count()} -S {pathlib.Path(__file__).parent.resolve()}/classifier_out/{sample_name}_cent_out'
self.cent_out = f"/Users/timolucas/PycharmProjects/MMonitor/desktop/src/resources/pipeline_out/{sample_name}_cent_out"
cmd = f'centrifuge -x {centrifuge_index} -f {self.unpack_fastq_list(sequence_list)} -p {multiprocessing.cpu_count()} -S {self.cent_out}'
print(cmd)
os.system(cmd)
return
Expand Down
1 change: 0 additions & 1 deletion desktop/src/mmonitor/userside/functional_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import zipfile
from os import path

import pandas as pd
import requests

from build import ROOT
Expand Down
61 changes: 51 additions & 10 deletions desktop/src/mmonitor/userside/view.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import tkinter as tk
# from tkcalendar import Calendar
from datetime import date
from threading import Thread
from time import sleep
from tkinter import filedialog
Expand Down Expand Up @@ -33,22 +35,55 @@ def func_wrapper(*args):

def require_centrifuge(func):
"""Decorator that ensures that a centrifuge index was selected by the user."""

def func_wrapper(*args):
obj: GUI = args[0]
if obj.centrifuge_index is not None and len(obj.centrifuge_index) > 0:
return func(*args)
else:
obj.open_popup("Please first select a centrifuge index before analyzing files.", "Centrifuge error")

return func_wrapper


def calendar_picker(but_exit=None):
tkobj = tk.Tk()
# setting up the geomentry
tkobj.geometry("400x400")
tkobj.title("Calendar picker")
# creating a calender object
tkc = Calendar(tkobj, selectmode="day", year=2022, month=1, date=1)
# display on main window
tkc.pack(pady=40)

# getting date from the calendar
def fetch_date():
date.config(text="Selected Date is: " + tkc.get_date())

# add button to load the date clicked on calendar
but = tk.Button(tkobj, text="Select Date", command=fetch_date, bg="black", fg='white')
# displaying button on the main display
but.pack()

but_exit = tk.Button(tkobj, text="Exit", command=tkobj.destroy, bg="black", fg='white')
# displaying button on the main display
but_exit.pack()

# Label for showing date on main display
date = tk.Label(tkobj, text="", bg='black', fg='white')
date.pack(pady=20)
# starting the object
tkobj.mainloop()
return tkc.get_date()


class GUI:

def __init__(self):
# declare data base class variable, to be chosen by user with choose_project()
self.db: MMonitorDBInterface = None
self.db_path = None
self.centrifuge_index = None
self.centrifuge_index = "/Users/timolucas/Downloads/p_compressed_2018_4_15_2/p_compressed"
self.cent = CentrifugeRunner()
self.func = FunctionalAnalysisRunner()
self.dashapp = None
Expand All @@ -65,28 +100,28 @@ def __init__(self):
def init_layout(self):

self.root.geometry("350x250")
self.root.title("MMonitor v0.1.0. alpha")
self.root.title("MMonitor v0.1.0 alpha")
self.root.resizable(width=False, height=True)
self.width = 20
self.height = 1
# create buttons
tk.Button(self.root, text="Create Project", command=self.create_project,
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25').pack()
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='white').pack()
tk.Button(self.root, text="Choose Project", command=self.choose_project,
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25').pack()
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='#254D25').pack()
# tk.Button(self.root, text="Choose centrifuge index", command=self.choose_index,
# padx=10, pady=5, width=self.width,height=self.height, fg='white', bg='#254D25').pack()
# # tk.Button(self.root, text="Analyze fastq in folder", command=self.analyze_fastq_in_folder,
# padx=10, pady=5, width=self.width,height=self.height, fg='white', bg='#254D25').pack()
tk.Button(self.root, text="Add metadata from CSV", command=self.append_metadata,
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25').pack()
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='#254D25').pack()
tk.Button(self.root, text="Run analysis pipeline", command=self.checkbox_popup,
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25').pack()
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='#254D25').pack()

tk.Button(self.root, text="Start monitoring", command=self.start_monitoring,
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25').pack()
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='#254D25').pack()
tk.Button(self.root, text="Quit",
padx=10, pady=5, width=self.width, height=self.height, fg='white', bg='#254D25',
padx=10, pady=5, width=self.width, height=self.height, fg='black', bg='#254D25',
command=self.stop_app).pack()

def open_popup(self, text, title):
Expand Down Expand Up @@ -149,12 +184,18 @@ def analyze_fastq_in_folder(self):
"What should the sample be called?",
parent=self.root
)
self.cent.run_centrifuge(files, self.centrifuge_index, sample_name)

# sample_date = calendar_picker()
sample_date = date.today()
self.cent.run_centrifuge(files, self.centrifuge_index, sample_name)
self.cent.make_kraken_report(self.centrifuge_index)
self.db.update_table_with_kraken_out(f"classifier_out/{sample_name}_kraken_out", "S", sample_name, "project")

self.db.update_table_with_kraken_out(
f"/Users/timolucas/PycharmProjects/MMonitor/desktop/src/resources/pipeline_out/{sample_name}_kraken_out",
"S", sample_name, "project", sample_date)

def checkbox_popup(self):

# open checkbox to ask what the user wants to run (in case of rerunning)
top = tk.Toplevel(self.root)
top.geometry("400x300")
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions desktop/src/resources/r/horizon.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ bandwidth <- strtoi(Sys.getenv("HORI_BANDWIDTH"))
library("latticeExtra")
png(Sys.getenv("HORI_IMAGE"), width = width, height = height)
horizonplot(ts(abundances), colorkey = TRUE, layout = c(1, ncol(abundances)),
strip.left = FALSE, xlab = "Sample ID", ylab = list(rev(colnames(abundances)), rot = 0, cex = 1.35),
horizonscale = bandwidth, origin = 0)
strip.left = FALSE, xlab = "Sample Date", ylab = list(rev(colnames(abundances)), rot = 0, cex = 1.35),
horizonscale = bandwidth, origin = 0, col.regions = hcl.colors(14, palette = "RdYlBu"),)

dev.off()
Binary file modified server/db.sqlite3
100644 → 100755
Binary file not shown.
Binary file modified server/mmonitor.sqlite3
100644 → 100755
Binary file not shown.
Empty file modified server/static/dashboard/1/horizon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified server/static/dashboard/horizon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ff3dbdf

Please sign in to comment.