Skip to content

Commit

Permalink
Merge pull request #52 from compomics/update-streamlit
Browse files Browse the repository at this point in the history
Fix Streamlit web server
  • Loading branch information
RobbinBouwmeester authored May 16, 2023
2 parents c0b9c98 + fb926ab commit 34bf725
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 77 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ name: Publish to PyPI and GitHub release

on:
push:
# tags:
# - 'v*'
tags:
- 'v*'

jobs:
python-package:
Expand Down Expand Up @@ -83,6 +83,7 @@ jobs:
build-streamlit-image:
runs-on: ubuntu-latest
needs: python-package
steps:
- uses: actions/checkout@v2
- id: latest_release
Expand Down
40 changes: 20 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,25 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ['3.9', '3.10']
python-version: ["3.9", "3.10"]
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install --editable .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
pip install --editable .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
18 changes: 3 additions & 15 deletions streamlit/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
FROM continuumio/miniconda3:4.9.2 AS build
COPY environment.yml /
RUN conda env create -f environment.yml && \
conda install -c conda-forge conda-pack && \
conda-pack -n deeplc-streamlit -o /tmp/env.tar && \
mkdir /venv && cd /venv && tar xf /tmp/env.tar && \
rm /tmp/env.tar && \
/venv/bin/conda-unpack

FROM debian:buster-slim AS runtime
WORKDIR /deeplc
COPY --from=build /venv /venv
ENV VIRTUAL_ENV=/venv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
FROM python:3.10-slim-buster
COPY . /deeplc
RUN pip install "deeplc>=0.1.29"
WORKDIR /deeplc
RUN pip install --upgrade pip && pip install -r requirements.txt
ENV DEEPLC_LIBRARY_PATH="/tmp/deeplc_library.txt"
EXPOSE 8501
CMD ["streamlit", "run", "deeplc_streamlit.py"]
43 changes: 24 additions & 19 deletions streamlit/deeplc_streamlit.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import pandas as pd
import plotly.express as px
from deeplc import DeepLC
from streamlit_utils import hide_streamlit_menu, save_dataframe

import streamlit as st
from streamlit_utils import hide_streamlit_menu, save_dataframe
from deeplc import DeepLC

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -101,7 +101,10 @@ def _main_page(self):
help=self.texts.Help.dict_cal_divider,
)
self.user_input["split_cal"] = st.number_input(
"Split calibration", step=1, value=25, help=self.texts.Help.split_cal
"Split calibration",
step=1,
value=25,
help=self.texts.Help.split_cal,
)

st.subheader("Prediction speed boost")
Expand Down Expand Up @@ -145,7 +148,10 @@ def _run_deeplc(self):

logger.info(
"Run requested // %s // peptides %i / use_library %r / calibrate %r",
datetime.now(), len(config["input_df"]), use_lib, calibrate
datetime.now(),
len(config["input_df"]),
use_lib,
calibrate,
)

# Run DeepLC
Expand All @@ -161,9 +167,7 @@ def _run_deeplc(self):
reload_library=True if use_lib else False,
)
if calibrate:
config["input_df_calibration"]["modifications"].fillna(
"", inplace=True
)
config["input_df_calibration"]["modifications"].fillna("", inplace=True)
dlc.calibrate_preds(seq_df=config["input_df_calibration"])
config["input_df"]["modifications"].fillna("", inplace=True)
preds = dlc.make_preds(seq_df=config["input_df"], calibrate=calibrate)
Expand Down Expand Up @@ -191,7 +195,7 @@ def _run_deeplc(self):
label="Download",
data=save_dataframe(result_df),
file_name="deeplc_predictions.csv",
mime="text/csv"
mime="text/csv",
)

def _set_library_path(self):
Expand Down Expand Up @@ -241,7 +245,7 @@ def _parse_user_config(self, user_input):
try:
config["input_df"] = pd.read_csv(user_input["input_csv"])
except (ValueError, pd.errors.ParserError) as e:
raise InvalidPeptideCSV(e)
raise InvalidPeptideCSV(e) from e
else:
raise MissingPeptideCSV

Expand All @@ -260,7 +264,7 @@ def _parse_user_config(self, user_input):
user_input["input_csv_calibration"]
)
except (ValueError, pd.errors.ParserError) as e:
raise InvalidPeptideCSV(e)
raise InvalidPeptideCSV(e) from e

return config

Expand Down Expand Up @@ -306,7 +310,7 @@ class Sidebar:
badges = """
[![GitHub release](https://img.shields.io/github/release-pre/compomics/deeplc.svg?style=flat-square)](https://github.com/compomics/deeplc/releases)
[![GitHub](https://img.shields.io/github/license/compomics/deeplc.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0)
[![Twitter](https://flat.badgen.net/twitter/follow/compomics?icon=twitter)](https://twitter.com/compomics)
[![Twitter](https://img.shields.io/twitter/follow/compomics?style=flat-square)](https://twitter.com/compomics)
"""

about = f"""
Expand All @@ -323,18 +327,19 @@ class Sidebar:
If you use DeepLC for your research, please use the following citation:
>**DeepLC can predict retention times for peptides that carry as-yet unseen
modifications**<br>
>Robbin Bouwmeester, Ralf Gabriels, Niels Hulstaert, Lennart Martens, Sven
Degroeve<br>
>_bioRxiv (2020)_<br>
>[doi:10.1101/2020.03.28.013003](https://doi.org/10.1101/2020.03.28.013003)
>Robbin Bouwmeester, Ralf Gabriels, Niels Hulstaert, Lennart Martens, Sven Degroeve<br>
>_Nature Methods 18, 1363–1369 (2021)_<br>
>[doi:10.1038/s41592-021-01301-5](https://doi.org/10.1038/s41592-021-01301-5)
---
Currently using the following package versions:
Currently using the following package versions: <br />
[![DeepLC](https://img.shields.io/badge/deeplc-{version('deeplc')}-blue?style=flat-square&logoColor=white&logo=pypi)](https://github.com/compomics/deeplc)
[![Tensorflow](https://img.shields.io/badge/tensorflow-{version('tensorflow')}-blue?style=flat-square&logoColor=white&logo=pypi)](https://github.com/tensorflow/tensorflow)
[![Streamlit](https://img.shields.io/badge/streamlit-{version('streamlit')}-blue?style=flat-square&logoColor=white&logo=pypi)](https://github.com/streamlit/streamlit)
[![DeepLC](https://flat.badgen.net/badge/deeplc/{version('deeplc')}/grey?icon=pypi)](https://github.com/compomics/deeplc)
[![Tensorflow](https://flat.badgen.net/badge/tensorflow/{version('tensorflow')}/grey?icon=pypi)](https://github.com/tensorflow/tensorflow)
[![Streamlit](https://flat.badgen.net/badge/streamlit/{version('streamlit')}/grey?icon=pypi)](https://github.com/streamlit/streamlit)
Latest DeepLC version:<br />
![PyPI](https://img.shields.io/pypi/v/deeplc?style=flat-square&logoColor=white&logo=pypi)
"""

class Help:
Expand Down
11 changes: 0 additions & 11 deletions streamlit/environment.yml

This file was deleted.

5 changes: 5 additions & 0 deletions streamlit/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
plotly
pandas
statsmodels
streamlit>=0.88
deeplc
10 changes: 0 additions & 10 deletions streamlit/streamlit_utils.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
"""Streamlit utils."""

import base64
import io
import logging
import os
import re
import tempfile
import uuid
import zipfile
from typing import BinaryIO

from typing_extensions import get_origin

import streamlit as st

Expand Down

0 comments on commit 34bf725

Please sign in to comment.