Metadata-Version: 2.4
Name: isolaser
Version: 0.0.4
Summary: Exonic Part centered allele-specific splicing analysis
Home-page: https://github.com/gxiaolab/isoLASER
Author: Giovanni Quinones Valdez
Author-email: giovas@ucla.edu
Project-URL: Bug Tracker, https://github.com/gxiaolab/isoLASER/issues
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: scipy>=1.10
Requires-Dist: pandas<3,>=2.0
Requires-Dist: statsmodels>=0.14
Requires-Dist: scikit-learn>=1.5.1
Requires-Dist: networkx>=3.1
Requires-Dist: pysam>=0.21
Requires-Dist: pytabix>=0.1
Requires-Dist: pyfaidx>=0.7
Requires-Dist: biopython>=1.79
Requires-Dist: PyVCF3>=1.0.3
Requires-Dist: HTSeq>=2.0.3
Requires-Dist: psutil
Dynamic: license-file

# **isoLASER**
[![](https://img.shields.io/badge/isoLASER-v0.0.0.4-blue)](https://test.pypi.org/project/isoLASER/)


[Publication](https://www.nature.com/articles/s41467-025-64605-6)

[github](https://github.com/gxiaolab/isoLASER/)



## **About**

IsoLASER performs gene-level variant calls, phasing, and splicing linkage analysis using third-generation RNA sequencing data.

## **Table of contents**
- [Requirements](#requirements)
- [Installation](#installation)
- [Preprocessing](#preprocessing)
  - [Transcript identification](#transcript-identification)
  - [Annotate bam file](#annotate-bam-file)
  - [Extract exonic parts from GTF](#extract-exonic-parts-from-gtf)
- [Run IsoLASER](#run-isolaser)
- [Run IsoLASER joint](#run-isolaser-joint)
- [Make a nigiri plot](#make-a-nigiri-plot)
- [Demo](#demo)
- [Debug](#debug)


## **Requirements**

IsoLASER requires Python 3.9 or newer and supports Python 3.9 – 3.13 (see the note on Python 3.14 below). The Python dependencies below are installed automatically by `pip`.
The required versions match `setup.cfg`. The known-working column is a set of versions verified together on Python 3.11.

| Package | Required version | Known-working |
|---|---|---|
| numpy | >=1.24 | 1.26.4 |
| scipy | >=1.10 | 1.17.1 |
| pandas | >=2.0, <3 | 2.3.3 |
| statsmodels | >=0.14 | 0.15.0 |
| scikit-learn | >=1.5.1 | 1.5.1 |
| networkx | >=3.1 | 3.6.1 |
| pysam | >=0.21 | 0.24.1 |
| pytabix | >=0.1 | 0.1 |
| pyfaidx | >=0.7 | 0.9.4 |
| biopython | >=1.79 | 1.85 |
| PyVCF3 | >=1.0.3 | 1.0.4 |
| HTSeq | >=2.0.3 | 2.1.2 |
| psutil | any | 7.2.2 |

Notes:
- The pre-trained variant-calling models bundled with IsoLASER were saved with scikit-learn 1.5.1. They give the same predictions with newer releases (checked up to scikit-learn 1.9.1 with NumPy 2.5.5), but scikit-learn prints a version-mismatch warning when loading them. Use scikit-learn 1.5.1 to avoid the warning.
- `PyVCF3` is the maintained fork of PyVCF and provides the `vcf` module. The original `PyVCF` package does not install with current versions of setuptools.
- IsoLASER works with both NumPy 1.x and NumPy 2.x.
- pandas is kept below 3, because pandas 3 changes several default behaviors.
- Python 3.14: HTSeq does not yet publish pre-built packages for Python 3.14, so `pip` will compile it from source. This requires `swig` and a C++ compiler.
- HTSeq does not publish macOS wheels. On macOS it has to be compiled from source (requires `swig` and a working C++ toolchain), or installed from bioconda.

IsoLASER has been tested in the following operating systems:
- CentOS Linux 7

External software requirements:
- [GATK](https://gatk.broadinstitute.org/hc/en-us) 
- [samtools](http://www.htslib.org/)
- [minimap2](https://github.com/lh3/minimap2)
- [tabix](http://www.htslib.org/doc/tabix.html)
- [R](https://www.r-project.org/) (only for `nigiri_plot`) with the packages `ggplot2`, `grid`, `gridExtra`, `data.table`, `gtable`, `patchwork` and `RColorBrewer`

## **Installation**

First, it is recommended to install IsoLASER in a virtual environment.

```
conda create -n isolaser_env python=3.11
conda activate isolaser_env
```

You can clone this **GitHub** repository:
```
git clone git@github.com:gxiaolab/isoLASER.git 
cd isoLASER
pip install .
```

Or you can install directly from **PyPI**:

```
pip install isolaser
```

Alternatively, you can also download the **Singularity** container:

```
singularity pull library://giovas/collection/s6
singularity exec s6_latest.sif isolaser
```

If successful, the program is ready to use. The installation incorporates console script entry points to directly call isoLASER:

```
isolaser --help
```

Installation time varies depending on the number of dependencies that need to be installed. 
Assuming all library dependencies are installed already, the installation of IsoLASER should only take a few seconds.  

## *Preprocessing* 

Long-read RNA sequencing is notorious for its high base-calling error rate. As such, it is important to clean and preprocess the data to discard false transcripts resulting from misalignment, bad consensus, truncation, and other technical artifacts.   

Input file requirements:
- The reference fasta file (e.g., `hg38.fa`) must be indexed with `samtools faidx` (`.fai`). The joint analysis also needs a sequence dictionary (`.dict`, made with `gatk CreateSequenceDictionary`).
- The GTF annotation must be sorted, bgzip-compressed and tabix-indexed:

```
(grep "^#" annot.gtf; grep -v "^#" annot.gtf | sort -k1,1 -k4,4n) | bgzip -c > annot.gtf.gz
tabix -p gff annot.gtf.gz
```

- The input bam file must be sorted and indexed.


### Transcript identification

IsoLASER needs a GTF file as input to annotate individual reads with their isoform membership. Ideally, this GTF file is built using a long-read annotation software such as Talon, Clair, Bambu, Espresso, or similar. 

Details of the Talon pipeline can be found on their GitHub repository.[TALON](https://github.com/mortazavilab/TALON).

- The pipeline consists of correcting alignments around splice junctions using `TranscriptClean`, and labeling the reads for internal priming using `talon_label_reads`. 
- The processed bam files are then ready to be annotated by first creating a database with `talon_initialize_database` and then annotating the individual reads with `talon`. 
- Finally, the transcripts are filtered with `talon_filter_transcripts` and a GTF file is constructed with the retained transcripts with the command `talon_create_GTF`.     


### Annotate bam file

From the annotation used in the previous step, use the GTF file to generate a transcriptome reference for alignment.   
This step serves to assign transcript ids to every read of the target bam file.

```
# generate transcriptome reference from GTF
isolaser_convert_gtf_to_fasta -g {annot.gtf.gz} -f {reference.fa} -o {transcriptome.fa}

# convert bam file to fastq for re-alignment
samtools fastq {input.bam} > {input.fq}

# re-align against newly generated transcriptome reference
minimap2 -t 16 -ax splice:hq -uf --MD {transcriptome.fa} {input.fq} > {transcriptome.sam}
```

The output is a sam file where the contigs are transcript ids. 
Next, filter for secondary, supplementary and trans-gene reads whilst annotating with transcript ids. 

```
isolaser_annotate -b {input.bam} -t {transcriptome.sam} -g {annot.gtf.gz} -o {input.annot.bam}

# sort and index the annotated bam file
samtools sort {input.annot.bam} -o {input.annot.sorted.bam}
samtools index {input.annot.sorted.bam}
```
The output bam file has passed basic filtering (secondary and supplementary reads), trans-gene filtering, and carries `ZG` and `ZT` tags with the gene and transcript id of each read. It is written in gene order, so it must be sorted and indexed before running IsoLASER.

If you already have read-to-transcript assignments (e.g., from your transcript identification software), you can pass them with `-a {assignments.tsv}` instead of `-t`. This is a tab-separated file with no header, containing the read name and the transcript id.

Options:
- `--padding` : bases a read can extend beyond its gene boundaries before it is removed as trans-gene [default: 10]

### Extract exonic parts from GTF

IsoLASER uses an exon-centric approach to analyze splicing and exonic-parts are a great granular approach to understand local splicing changes. 

```
mkdir -p {transcript.db}
isolaser_extract_exon_parts -g {annot.gtf.gz} -o {transcript.db}
```

The output directory `transcript.db` must exist before running this step. It will contain a `GeneList.tsv` file and a pickle file per gene (`tx_structure.{gene_id}_{gene_name}.pickle`) encapsulating all the exonic parts and transcripts associated with them.   

## *Run IsoLASER*

IsoLASER requires the sorted and indexed annotated bam file (with ZG and ZT tags), the transcriptome database with exonic parts, and the reference genome (e.g. hg38.fa).  

```
isolaser -b {input.annot.sorted.bam} -o {output.prefix} -t {transcript.db} -f {reference.fa}

# output:
{output.prefix}.gvcf
{output.prefix}.mi_summary.tab
{output.prefix}.haplotagged_reads.tab
```

Main options:
- `-s` : sample name written to the gvcf. If not given, the `SM` field of the bam read group is used, or the bam file path if there is no read group.
- `--platform` : `PacBio` or `Nanopore` [default: PacBio]
- `-n` : number of parallel processes [default: 64, capped at the number of CPUs]
- `-c` : limit the analysis to a region (`CHROM` or `CHROM:start-end`)

Run `isolaser --help` for the full list of filtering and advanced options.

The output is very extensive and includes information that is only relevant for the joint analysis or plotting. 
Compress and index the mi_summary.tab file for downstream analysis and plotting:

```
sort -k1,1V -k2,2n -k3,3n {output.prefix}.mi_summary.tab | bgzip -c -f > {output.prefix}.mi_summary.tab.gz
tabix -f -p bed {output.prefix}.mi_summary.tab.gz
```
To obtain the significant allele-specific events (cis-directed splicing events) use the filter function: 

```
isolaser_filter -m {output.prefix}.mi_summary.tab.gz -o {output.prefix}.mi_summary.filtered.tab
```

The thresholds can be changed with `--AR_min`, `--AR_max`, `--PSI_min`, `--PSI_max`, `--COV_min`, `--delta_PSI_min`, `--exonic_part_len_min` and `--linkage_types` (see `isolaser_filter --help`).

## *Run IsoLASER joint*

The first step is a wrapper of GATK functions (`CombineGVCFs` and `GenotypeGVCFs`) to merge the variant calls from different samples. `gatk` and `tabix` must be in your `PATH`.

The input file `fofn.tsv` is **tab-separated** with no header and three columns: sample name, compressed mi_summary file, and gvcf file.
The sample name must match the sample name in the gvcf (see the `-s` option of `isolaser`).
```
# fofn.tsv
SM1	SM1.mi_summary.tab.gz	SM1.gvcf
SM2	SM2.mi_summary.tab.gz	SM2.gvcf
```
Run the combine vcf step:
```
isolaser_combine_vcf -i {fofn.tsv} -o {output.prefix} -f {reference.fa}

# output:
{output.prefix}.gvcfs.list
{output.prefix}.merged.gvcf.gz
{output.prefix}.merged.genotyped.gvcf.gz
```
Perform joint analysis
```
isolaser_joint -i {fofn.tsv} -o {output.joint.tab} -t {transcript.db} -v {output.prefix}.merged.genotyped.gvcf.gz

# output:
{output.joint.tab}
```

Options:
- `-p` : number of worker processes [default: 1]
- `-c` : only process genes on this chromosome [default: all]

## *Make a nigiri plot*

Parse the compressed `.mi_summary.tab.gz` file to obtain the list of events to plot

```
nigiri_parse --mi {output.prefix}.mi_summary.tab.gz -o {output.plot} -t {transcript.db}

# output:
{output.plot}.cis_events.bed
{output.plot}.cis_genes.tsv
```
`cis_genes.tsv` has one line per gene with the gene id, the best variant (`CHROM:POS:REF>ALT`), the gene region (`CHROM:start-end`) and the delta PSI.

Split the bam file by the alleles of a variant from `cis_genes.tsv`

```
nigiri_split -b {input.annot.sorted.bam} -v {CHROM:POS:REF>ALT} -o {split.fofn} -t {tmpdir}

# output:
{tmpdir}/allele={REF}.sorted.bam
{tmpdir}/allele={ALT}.sorted.bam
{split.fofn}
```
The split bam files are written to `{tmpdir}` (default: `tmp`). The fofn lists them and is the input of the plotting step.

We use an adapted version of [ggsashimi](https://github.com/guigolab/ggsashimi). Use a region from `cis_genes.tsv`:
```
nigiri_plot -b {split.fofn} -c {CHROM:start-end} -g {annot.gtf.gz} --mi {output.plot}.cis_events.bed -o {output.plot}.pdf
```
`-o` is the full name of the output pdf. `-g` and `--mi` are needed to draw the transcript track and to highlight the cis-directed exonic parts. Plotting requires R with the packages listed in [Requirements](#requirements).

<img src="nigiri.FAM221A.png" alt="FAM221A" width="600" heigth="600" class="center" />

## **Demo**

For a complete demo please check the [test_pipeline](test_pipeline) directory.

The complete pipeline is available as a snakemake workflow in `test_pipeline/isolaser_test.smk`.

```
cd test_pipeline
snakemake -s isolaser_test.smk --cores 4
```

## **Debug**
If you experience any issues please submit your question to the *Issues* tab on this website. 
