Skip to content

Commit

Permalink
forgot to include all files
Browse files Browse the repository at this point in the history
  • Loading branch information
maximilianmordig committed Nov 1, 2023
1 parent eec3176 commit f71e34d
Show file tree
Hide file tree
Showing 9 changed files with 229 additions and 784 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ jobs:
ln -s ../configs/chr202122_run/sampler_per_window configs
python ~/ont_project_all/ont_project/usecases/enrich_usecase.py
tar -cvzf figures.tar.gz readfish_run/figures
tar -cvzf figures.tar.gz simulator_run/figures
-
name: Archive figures
uses: actions/upload-artifact@v3
Expand Down
695 changes: 21 additions & 674 deletions LICENSE

Large diffs are not rendered by default.

95 changes: 48 additions & 47 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,53 @@ This repository provides a simulator for an ONT device controlled by the ReadUnt
The code is well-tested with `pytest` and an example usecase combining the simulator with ReadFish and NanoSim is provided.
Access the documentation [here](https://ratschlab.github.io/sim_read_until/).

See below for a [quick start](#quick-start).
A video for the CLI interface of the simulator (as described in [usecases](usecases/README.md)) is available here: [CLI interface Youtube](https://youtu.be/8GDTD4Memes)
See below for an [overview](#overview).

## Quick Start

Clone the repository, install the virtual environment and run the usecase, as explained below.

### Installation and Setup

We have tested the code with python3.10 and python3.8 on Linux and Mac OS X, so try to use it:
```{bash}
# create a shared directory:
mkdir ~/ont_project_all
cd ~/ont_project_all
git clone --depth 1 [email protected]:ratschlab/sim_read_until.git ont_project
# the NanoSim repository (integrated as a submodule here) is quite large (2Gb) due to pre-computed models, so we omit it here
# if you want it, do: git clone --recurse-submodules [email protected]:ratschlab/sim_read_until.git ont_project
# conda deactivate # if you have a conda environment activated, including base env
python3.10 -m venv ont_project_venv
source ~/ont_project_all/ont_project_venv/bin/activate
pip install --upgrade pip
pip install ont_project/
pip install --upgrade seaborn
```

Take a look at the directory [usecase](usecases/) to run some example usecases.

If the installation fails due to dependency issues, you can alternatively run it as a Docker image that comes with the dependencies and runs Jupyter lab:
```{bash}
# to update the Docker image if a new one was published
# note: it may not always be up-to-date with the main branch, check the release date online
docker pull ghcr.io/ratschlab/sim_read_until:main_dev
cd ~/ont_project_all
./ont_project/start_docker_container.sh
# to see the options
# ./ont_project/start_docker_container.sh -h
```
Several Docker containers can run in parallel, provided you modify the port and container name via the options `-n` and `-p`.

**Note**: Conda is not officially supported, but you can set up your environment with:
```{bash}
conda create -y -n ont_project_venv python=3.10 pip
```
Some scripts activate the virtual environment, so you have to change it to `conda activate ont_project_venv`.

## Overview

Expand Down Expand Up @@ -57,52 +103,7 @@ The repository contains the following directories (as submodules):
- `runs`: for local runs; in `.gitignore`
- `apidocs`: location for API docs; in `.gitignore`

## Quick Start

Clone the repository, install the virtual environment and run the usecase, as explained below.

### Installation and Setup

We have tested the code with python3.10 and python3.8, so try to use it:
```{bash}
# create a shared directory:
mkdir ~/ont_project_all
cd ~/ont_project_all
git clone --depth 1 [email protected]:ratschlab/sim_read_until.git ont_project
# the NanoSim repository (integrated as a submodule here) is quite large (2Gb) due to pre-computed models, so we omit it here
# if you want it, do: git clone --recurse-submodules [email protected]:ratschlab/sim_read_until.git ont_project
# conda deactivate # if you have a conda environment activated, including base env
python3.10 -m venv ont_project_venv
source ~/ont_project_all/ont_project_venv/bin/activate
pip install --upgrade pip
pip install ont_project/
pip install --upgrade seaborn
```

Take a look at the directory [usecase](usecases/) to run some example usecases.

If the installation fails due to dependency issues, you can alternatively run it as a Docker image that comes with the dependencies and runs Jupyter lab:
```{bash}
# to update the Docker image if a new one was published
# note: it may not always be up-to-date with the main branch, check the release date online
docker pull ghcr.io/ratschlab/sim_read_until:main_dev
cd ~/ont_project_all
./ont_project/start_docker_container.sh
# to see the options
# ./ont_project/start_docker_container.sh -h
```
Several Docker containers can run in parallel, provided you modify the port and container name via the options `-n` and `-p`.

**Note**: Conda is not officially supported, but you can set up your environment with:
```{bash}
conda create -y -n ont_project_venv python=3.10 pip
```
Some scripts activate the virtual environment, so you have to change it to `conda activate ont_project_venv`.

### Comparison with UNCALLED
## Comparison with UNCALLED

We tried comparing with UNCALLED, but it didn't work due to a segmentation fault without any useful error message, see [uncalled_comparison](uncalled_comparison.md) for details.
According to the authors, the UNCALLED simulator is superseeded by the recent tool Icarust, which is a tool that addresses a similar setting as we do.
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ usecase_generate_random_reads = "simreaduntil.usecase_helpers.cli_usecase.genera
simulator_server_cli = "simreaduntil.usecase_helpers.cli_usecase.simulator_server_cli:main"
usecase_simulator_client_cli = "simreaduntil.usecase_helpers.cli_usecase.simulator_client_cli:main"
sim_plots_cli = "simreaduntil.usecase_helpers.cli_usecase.sim_plots_cli:main"
usecase_make_html_report = "simreaduntil.usecase_helpers.cli_usecase.make_html_report:main"


[project.urls]
Expand Down
Binary file modified simulator_example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
102 changes: 102 additions & 0 deletions src/simreaduntil/usecase_helpers/cli_usecase/make_html_report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
"""
Make an overview page from all figures in the directory
"""
import argparse
import logging
from pathlib import Path
import sys
from simreaduntil.shared_utils.logging_utils import add_comprehensive_stream_handler_to_logger, setup_logger_simple
from simreaduntil.shared_utils.utils import print_args

logger = setup_logger_simple(__name__)
"""module logger"""

mainpage_template = r"""
<!DOCTYPE html>
<html>
<head>
<title>Generated Figures</title>
</head>
<style>
img {
display: inline-block;
margin: 5px;
max-width: 100%;
max-height: 400px;
text-align: center;
}
</style>
<body>
<h1>Generated Figures</h1>
{FIGURES_HTML}
</body>
</html>
"""
figure_template = r"""
<h2 class="image-name">{figure_name}</h2>
<div class="photo">
<img src="{figure_filename}">
</div>
<hr style="height:2px;border-width:0;color:gray;background-color:gray">
"""

def parse_args(args=None):
parser = argparse.ArgumentParser(description="Combine images into html report")
parser.add_argument("figure_dir", type=Path, help="Directory containing figures (.png files)")

args = parser.parse_args(args)
print_args(args, logger=logger)
return args

def main():
log_level = logging.DEBUG
logging.getLogger(__name__).setLevel(log_level) # log level of this script (running as __main__)
add_comprehensive_stream_handler_to_logger(None, level=log_level)

args = parse_args()

figure_dir = args.figure_dir
assert figure_dir.exists(), f"figure_dir '{figure_dir}' does not exist"

figure_htmls = ""
for filename in figure_dir.glob("*.png"):
logger.info(f"Adding '{filename}'")
# using relative path wrt to final file!
figure_htmls += figure_template.format(figure_name=filename.name, figure_filename=filename.name)

html_filename = figure_dir / "figures.html"
with open(html_filename, "w") as f:
f.write(mainpage_template.replace("{FIGURES_HTML}", figure_htmls))


# template
# <!DOCTYPE html>
# <html>
# <head>
# <title>Generated Figures</title>
# </head>
# <style>
# img {
# display: inline-block;
# margin: 5px;
# width: 100%;
# max-height: 400px;
# text-align: center;
# }

# </style>
# <body>
# <h1>Generated Figures</h1>

# <h2 class="image-name">nb_basepairs_recrej_per_channel.png</h2>
# <div class="photo">
# <img src="figures/nb_basepairs_recrej_per_channel.png">
# </div>
# <hr style="height:2px;border-width:0;color:gray;background-color:gray">

# </body>
# </html>
4 changes: 3 additions & 1 deletion tests/simulator/test_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import numpy as np
import matplotlib.pyplot as plt
import dill
from simreaduntil.shared_utils.merge_axes import save_fig_and_pickle

from simreaduntil.shared_utils.timing import cur_ns_time
from simreaduntil.simulator import channel
Expand Down Expand Up @@ -215,6 +216,7 @@ def test_random_ops_synchronous(simulator, async_mode, channel_write_zero_length
# make all elements roughly the same length, reads have length 8-17 -> take about 1.2s
sim_params = SimParams(
gap_samplers={f"channel_{i}": ConstantGapsUntilBlocked(short_gap_length=1.2, long_gap_length=1.2, prob_long_gap=0.35, time_until_blocked=200, read_delay=0) for i in range(2)},
# gap_samplers={f"channel_{i}": ConstantGapsUntilBlocked(short_gap_length=1.2, long_gap_length=5.2, prob_long_gap=0.25, time_until_blocked=200, read_delay=0) for i in range(2)},
bp_per_second=10, chunk_size=4, default_unblock_duration=1.2, seed=0,
)

Expand Down Expand Up @@ -249,7 +251,7 @@ def get_read_and_save_id():
if nb_actions["forward"] > 0:
pass
# print(1)
# ax = simulator.plot_channels(); import matplotlib.pyplot as plt; plt.show(block=True); save_fig_and_pickle(ax.figure, "simulator_example.png"); #note: for README.md figure, zoom into appropriate region, then save the figure, keep it commented out
# ax = simulator.plot_channels(); import matplotlib.pyplot as plt; plt.show(block=True); #save_fig_and_pickle(ax.figure, "simulator_example.png"); #note: for README.md figure, zoom into appropriate region, then save the figure, keep it commented out

simulator.stop() if async_mode else simulator.sync_stop()
check_simulator_actions_agree_with_reads_writer(simulator, cum_nb_actions, check_nb_rejected=(j==0))
Expand Down
2 changes: 1 addition & 1 deletion tests/simulator/test_simulator_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def test_launchable_device_grpc_server():

stub.GetActionResults(ont_device_pb2.ActionResultsRequest(clear=True))

assert stub.StartSim(ont_device_pb2.StartRequest(acceleration_factor=2)).value
assert stub.StartSim(ont_device_pb2.StartRequest(acceleration_factor=2, update_method="realtime", log_interval=10)).value

# unblocking inexistent read
assert not stub.PerformActions(ont_device_pb2.ReadActionsRequest(actions=[
Expand Down
Loading

0 comments on commit f71e34d

Please sign in to comment.