# Bonus tips

### 🌈 Colored Logs with Batch Systems

<div><figure><img src="https://627844163-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgZ3I0-6juLK-X9gb1Z%2Fuploads%2FEpBHmQrxRb8NXgcR5MgQ%2FScreenshot%202024-10-21%20at%202.18.41%E2%80%AFPM.png?alt=media&#x26;token=55eabe53-38ec-423d-8169-f4e0340060f3" alt=""><figcaption><p>Default: No colored logs </p></figcaption></figure> <figure><img src="https://627844163-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgZ3I0-6juLK-X9gb1Z%2Fuploads%2F6Go4EZdtHmFNX0RhnaVC%2FScreenshot%202024-10-21%20at%202.17.20%E2%80%AFPM.png?alt=media&#x26;token=1da4626f-af75-409d-ba65-cf7ccddc8ea1" alt=""><figcaption><p>Colored unbuffered logs</p></figcaption></figure></div>

When running jobs using batch systems like LSF or Slurm, many programs detect whether their output is being sent to a terminal (`TTY`) or a file and may disable features like color formatting or progress bars if they detect non-interactive output.

One workaround, using it carefully, is to use the [`unbuffer`](https://manpages.debian.org/stretch/expect/unbuffer.1.en.html) utility from the `expect` package. `unbuffer` simulates a terminal by running the program in a pseudo-terminal (PTY), tricking the program into thinking it is running interactively in a terminal, so it continues to produce colored output.

{% hint style="success" %}
**Requirements:**&#x20;

* Have **`unbuffer`** available. See tips on [how to install on an HPC](#bonus-tip-install-unbuffer-in-an-hpc-with-miniconda).
* **`unbuffer: True`,** in your `isabl_cli`s **`SUBMIT_CONFIGURATION`**.
* **`>=0.3.28`** version of **`@papaemmelab/isabl_web`**
* [8c8ad75](https://github.com/papaemmelab/isabl_cli/commit/8c8ad75c85b6c86f291787fcfbf4a51532930154) commit of **`isabl_cli`**
  {% endhint %}

{% hint style="warning" %}
Unbuffered output will redirect both stdout/stderr to the same`head_job.log`file,  causing the file `head_job.err` output to be empty from errors of the running application.
{% endhint %}

{% hint style="danger" %}
By simulating a pseudo-PTY, you can gain desired colored outputs, but some outputs like progress bars print undesired characters that can clutter your logs. Be aware to disable those if possible (i.e. `toil ... --disableProgress),`or for specific applications add a dummy env`TERM=dumb` to tell the program there's no effective terminal attached.
{% endhint %}

#### **➕ Bonus tip**: **Install `unbuffer` in an HPC with miniconda.**&#x20;

```bash
conda create -n myenv
conda activate myenv
conda install -c conda-forge expect
```

Having `$OPT_DIR` where you install your packages and `$BIN_DIR` where you add your executable binaries, create a runnable script called `unbuffer`, where you add your miniconda env's `unbuffer` executable and add its shared libraries:

{% code title="${BIN\_DIR}/unbuffer" %}

```bash
#!/bin/bash

OPT_DIR=<your-installation-dir>
export LD_LIBRARY_PATH="${OPT_DIR}/miniconda3/envs/myenv/lib:$LD_LIBRARY_PATH"
${OPT_DIR}/miniconda3/envs/myenv/bin/unbuffer "$@"
```

{% endcode %}

Test it works:&#x20;

```bash
$ unbuffer echo "Hello World!" 
Hello World
```

### :dna:  Use IGV links to be 1-click away to visualize your mutation calls

\
The frontend allows the user to visualize alignment files (`bam`/ `cram`) through IGV, by using the API's `igv` endpoints in 2 cases:

* `/api/v1/experiments/igv/{system_id}?assembly={assembly}&locus={locus}`: To visualize an aligned file stored in the`Experiment.bam_files`&#x20;
* `/api/v1/analyses/igv/{pk}?result={result}&result_index={result_index}&locus={locus}`: to visualize an analysis result whose `frontend_type` is `igv_<result><result-index>. See` [`Frontend Result Types`](https://docs.isabl.io/writing-applications#frontend-result-types)&#x20;

But you can also use these endpoints widely to dynamically create your own **igv links**, when doing data analyses or creating reports!

#### Demo time

This is a cool example where you can generate clickable links in jupyter to visualize fusions events. The idea is to be 1-click away to visualize the reads of a specific sample in the locus of interest to see if a mutation is a real event or not.  Taking into account that the param variable `locus` supports multiple locus for example to visualize the 2 breakpoints of the fusion. Each locus, creates a new igv view in a tab. The locus can be defined by adding multiple ones separated by a space.

<figure><img src="https://627844163-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgZ3I0-6juLK-X9gb1Z%2Fuploads%2FuizTEuYEgsB1jzoZDLsf%2FScreenshot%202025-02-26%20at%201.38.40%E2%80%AFPM.png?alt=media&#x26;token=bf0f031d-639f-4116-9959-eadbc9cfdc6d" alt=""><figcaption><p>Create IGV links in a Jupyter Notebook</p></figcaption></figure>

Here you have an **IGV link** for each event. For example, clicking in the `GTF2I::GTF2IRD1`fusion link, will open an IGV where you can visualize the 2 breakpoints:\
\
`https://{my-instance}/api/v1/experiments/igv/{system_id}?assembly={assembly}&locus={locus1}%20{locus2}`

{% hint style="info" %}
`%20` is the safe url encoding for a `space` character, needed to append multiple locus.
{% endhint %}

<figure><img src="https://627844163-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LgZ3I0-6juLK-X9gb1Z%2Fuploads%2FW4ibAmLKUX9Mjuh6woqj%2FScreenshot%202025-02-26%20at%201.39.20%E2%80%AFPM.png?alt=media&#x26;token=dedaf527-d79f-4d2b-a1f2-d347a14896aa" alt=""><figcaption><p>Visualize events pointing to the desired locus. Example showing a<strong><code>GTF2I::GTF2IRD1</code></strong>fusion in 2 locus at <strong><code>7:74125440</code></strong>and  <strong><code>7:74015371</code></strong></p></figcaption></figure>

This feature is extremely powerful and useful, especially for generating reports with tens or thousands of variants. You can click on any variant to visualize it in IGV!
