Usage: Web UI Server

Twitcher Workbench GUI consists of a backend server and a browser-based web UI. The backend server is always needed. It can run on a personal desktop/laptop computer or centrally on a shared server computer.

Tip: It is convenient (but not strictly necessary) to run the server in a ‘screen’ session. On Linux, a new session is started with screen -S twb and detached with Ctrl+a d, i.e. pressing simultaneously the ‘Ctrl’ and ‘a’ keys and then the ‘d’ key. An existing session is reattached with screen -r twb and detached as above. Running sessions can be listed with screen -ls. If ‘screen’ is used, one should start a session as the first step, perform then the necessary commands below, and then detach as the server starts outputting logging information.

Workbench server

Twitcher Workbench server is most easily run in a container. Instructions are provided for Singularity and Docker. It can also be run as a Python app. See Installation for instruction for pulling/building an image or installing the package.

Singularity

See Installation for instructions pulling and building the image. The ref/ directory needs to follow the structure explained in Reference/annotation data.

mkdir -p data
singularity run \
  -B $PWD/ref:/app/ref:ro -B $PWD/data:/data \
  --env TWB_DATA_DIR=/data twb.sif

Docker

See Installation for instructions pulling or building the image. The ref/ directory needs to follow the structure explained in Reference/annotation data.

docker run --rm \
  -p 8000:8000 -v $PWD/ref:/app/ref:ro \
  aryashta/twb:latest

Local / pip install

See Installation for instructions pulling or building the image. The ref/ directory needs to follow the structure explained in Reference/annotation data.

# if using virtual environment, activate it first
source twb_env/bin/activate  

twb serve

Command options

twb serve has the following options:

--host TEXT             Bind address. Default: 0.0.0.0
-p, --port INTEGER      Bind port. Default: 8000
-w, --workers INTEGER   Number of gunicorn worker processes. Ignored with --debug. Default: 2
--timeout INTEGER       Gunicorn worker timeout in seconds. Ignored with --debug. Default: 600
--debug                 Run Flask's built-in dev server with the auto-reloader instead of gunicorn, for active local development. Single-threaded; not for production or multi-user use.
--csv-dir DIRECTORY     Directory of CSV files the server reads directly (searched recursively for *.csv). May be repeated. Alias: --csv_dir
--csv FILE              A CSV on the server to offer in the viewer. An already-processed CSV is loaded before the browser connects. May be repeated; the first file is preloaded.
--bam-dir DIRECTORY     Directory of indexed BAM files the server reads directly (searched recursively for *.bam with a .bai or .bam.bai). May be repeated. Alias: --bam_dir
--bam FILE              A single indexed BAM on the server (needs a .bai or .bam.bai next to it; startup fails without one). Offered in the BAM menu; the first --bam is already selected when the page opens. May be repeated.
--clean-on-exit / --no-clean-on-exit
                        Delete everything this session added to the data directory when the server stops. Default: on

Examples:

# Different port
twb serve --port 9000

# Active development: auto-reload on file changes
twb serve --debug --port 9000

# More gunicorn workers, longer timeout
twb serve --workers 4 --timeout 900

By default this runs the same gunicorn setup the Docker image uses in production: multiple worker processes, no auto-reload.

Working with data that must not leave the server

If the CSV files may not be copied to the machine running the browser, do not use the browser’s file upload. Let the server read them in place and view the page through an SSH tunnel.

singularity run \
  -B $PWD/ref:/app/ref:ro \
  -B $PWD/data:/data \
  -B $PWD/results/twb:/results:ro \
  --env TWB_DATA_DIR=/data twb.sif \
  twb serve --host 127.0.0.1 --csv-dir /results

To also use BAM files for the raw alignment viewer and JBrowse, bind them read-only and add -B $PWD/bams:/bams:ro and --bam-dir /bams.

Then, on your own computer:

ssh -L 8000:127.0.0.1:8000 <login-node-or-compute-node>
# open http://127.0.0.1:8000
  • --csv-dir lists every *.csv below the directory (for example NA12877/filtered/NA12877.filter.loose.csv and ...strict.csv). New files appear after Refresh list in Settings; no restart is needed.
  • In the CSV data card, pick a file from the or a CSV on the server menu and press Start loading (or Start processing for raw Twitcher output). Nothing runs until you press the button.
  • --csv FILE does the same for one file, and an already-processed CSV is loaded before the browser connects, so the page opens with the table ready. A raw Twitcher CSV cannot be preloaded (it needs a reference genome chosen in the UI); it is only listed.
  • The source files are only read, never copied or modified. The directory can be mounted read-only. Processing of a raw CSV writes its derived processed_*.csv into the data directory (/data).
  • The browser sends only an opaque file ID. The server serves only *.csv files below the configured directories (or named with --csv).
  • At startup the log reports how many files each directory yielded, for example --csv-dir /results: 2 CSV file(s) found and --bam-dir /bams: 3 BAM file(s) with an index found (1 .bam without .bai/.bam.bai skipped). A directory with no matching files prints a warning.
  • --bam FILE works like --csv FILE for one BAM: it is listed in the same menu and the first one is selected before you touch anything, so the BAM chip already shows it and the BAM button and JBrowse track work immediately.
  • --bam-dir lists every *.bam below the directory that has an index named <file>.bam.bai or <file>.bai; BAMs without an index are skipped. In the UI, pick one under Settings → Raw alignment viewer → BAM on the server. There is no Start button because nothing is processed: the choice only tells the viewer which BAM to use for the BAM slice and the JBrowse alignments track. The BAM and its index are read in place and never copied. The main page’s status card shows a BAM chip like the reference, genes and repeat mask.
  • Because the source is opened in place, renaming sample labels is not available for such a file (it would rewrite the source).

What /data is

/data (set with TWB_DATA_DIR) is the writable runtime directory, not just temp space. It holds uploads/ (uploaded and processed CSVs, sorted annotation files, exports), output/ (SVGs), job_status/ and jbrowse_configs/. The container image is read-only, so a writable directory has to be bound in. Put it on a filesystem approved for the data.

Clean-on-exit

By default, when the server stops (Ctrl+C or SIGTERM) everything the session added to those four directories is removed. Files that were already there at startup, and any --csv-dir/--csv source, are never touched. Pass --no-clean-on-exit to keep the files. A server killed with SIGKILL, or a crashed machine, cannot clean up: remove leftovers from /data by hand.

Security notes

  • Binding to 0.0.0.0 (the default) makes the port reachable by other users on a shared node. For sensitive data use --host 127.0.0.1 and the SSH tunnel above; twb serve prints a warning otherwise.
  • What you see in the browser (table rows, sequences, plots) is held in the browser’s memory on your computer, and the export buttons can save it. The tunnel cannot prevent that.
  • The page currently loads Tailwind, jQuery, DataTables and Google Fonts from public CDNs, so the browser needs internet access and contacts those hosts. No CSV content is sent to them.