Metadata-Version: 2.4
Name: apscale_nanopore
Version: 2.1.1
Summary: Advanced Pipeline for Simple yet Comprehensive AnaLysEs of DNA metabarcoding data - Nanopore application
Home-page: https://github.com/TillMacher/apscale_nanopore
Author: Till-Hendrik Macher
Author-email: macher@uni-trier.de
License: MIT
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: biopython>=1.85
Requires-Dist: cutadapt>=5.0
Requires-Dist: joblib>=1.4.2
Requires-Dist: ete3>=3.1.3
Requires-Dist: numpy>=1.26.4
Requires-Dist: pandas>=2.2.3
Requires-Dist: openpyxl>=3.1.5
Requires-Dist: pyarrow>=19.0.0
Requires-Dist: xmltodict>=0.14.2
Requires-Dist: plotly>=6.1.1
Requires-Dist: tqdm>=4.67.1
Requires-Dist: apscale_blast>=3.0.2
Requires-Dist: pygbif>=0.6.4
Requires-Dist: pycountry>=24.6.1
Requires-Dist: boldigger3>=3.0.3
Requires-Dist: lxml_html_clean>=0.4.2
Requires-Dist: stqdm>=0.0.5
Requires-Dist: streamlit>=1.48.1
Requires-Dist: playwright>=1.54.0
Requires-Dist: update-checker>=0.18.0
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: home-page
Dynamic: license
Dynamic: license-file
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# APSCALE-Nanopore

[![Downloads](https://static.pepy.tech/badge/apscale-nanopore)](https://pepy.tech/project/apscale-nanopore)

Metabarcoding pipeline for **Oxford Nanopore** data, based on [APSCALE](https://github.com/DominikBuchner/apscale). APSCALE-Nanopore takes you from the raw Nanopore reads to the read table and the taxonomic assignment: index demultiplexing, primer trimming, quality filtering, clustering/denoising, read table and taxonomic assignment with [APSCALE-blast](https://github.com/TillMacher/apscale_blast). It can be used with a graphical user interface (runs in your browser) or from the command line, and also supports live processing during sequencing.

* **Input:** Nanopore sequencing data (`.fastq` or `.fastq.gz`), demultiplexed or not
* **Output:** read table (`.xlsx`/`.parquet`), OTU/ESV sequences (`.fasta`), taxonomy table (`.xlsx`) and quality/summary reports (`.html`) in your project folder. The read table and taxonomy table have the same format as in APSCALE, so they can be imported directly into [TaxonTableTools2](https://github.com/TillMacher/TaxonTableTools2) (import format "APSCALE")

## Installation

The easiest way is the conda environment of the [APSCALE installer](https://github.com/TillMacher/apscale_installer), which installs APSCALE-Nanopore and all its dependencies (APSCALE-blast, cutadapt, VSEARCH, SWARM, BLAST+).

Alternatively, install via pip (Python ≥ 3.10):

```
pip install apscale_nanopore
```

With pip, [VSEARCH](https://github.com/torognes/vsearch), [SWARM](https://github.com/torognes/swarm) and [BLAST+](https://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/) must be installed separately and be available in your PATH. APSCALE-Nanopore checks whether they are installed and tells you what is missing.

To download all databases at once from the GUI, the browser used for the download must be installed once:

```
playwright install chromium
```

To update:

```
pip install --upgrade apscale_nanopore
```

## Graphical user interface

```
conda activate apscale4
apscale_nanopore gui
```

The graphical interface opens in your browser. Enter the path to your projects folder (e.g. an empty folder named `APSCALE_projects`) in the sidebar, create the database folder, and create or select a project. Click **"🔄 Refresh files and folders"** at the top of each page when you have added new files.

### Pages

**Start**
* **Home:** overview of the active project (raw files, demultiplexed files, FASTA files, databases), installed tools and package versions, links and citations

**Raw Data Processing**
* **APSCALE-Nanopore:** download databases, adjust the settings (index demultiplexing, primer trimming, quality filtering, clustering/denoising, read table, taxonomic assignment) and run the selected steps. The settings are saved to the project's settings file when the analysis starts. For demultiplexed data, the raw files can be imported into the Demultiplexing sheet with one click. The taxonomic assignment of the pipeline uses the standard settings of APSCALE-blast

**Taxonomic Assignment** (same as in [APSCALE-GUI](https://github.com/TillMacher/apscale_gui))
* **Database Finder:** find a suitable reference database for your taxonomic group and marker, check whether it is already in your database folder, or build it with the APSCALE-blast Database Creator
* **APSCALE-BLAST:** BLAST your OTUs/ESVs with all APSCALE-blast options: database-specific thresholds (`db_thresholds.xlsx`, calculated with the Database Optimiser) or custom thresholds, filter mode, minimum query coverage, re-BLAST against a second database. Optional: validate the species assignments with GBIF occurrences in your study area. The results are written to `7_taxonomic_assignment/blastn_...`

**Reports**
* **Quality Report:** create and view quality plots (mean PHRED score, read length, quality vs. length) for the raw, demultiplexed or primer-trimmed data
* **Summary Report:** reads and OTUs/ESVs per sample, created automatically after each run

**Downstream**
* **Data Analysis:** shows which read table and taxonomy table to import into [TaxonTableTools2](https://github.com/TillMacher/TaxonTableTools2)

Live processing during sequencing is only available from the command line (see below).

## Command line

### Create a project

```
apscale_nanopore create -p PATH/TO/My_project
```

A new project folder (`My_project_apscale_nanopore`) is created. You are asked whether your data is already demultiplexed, and the matching settings file is created. Existing projects are never overwritten.

### Run APSCALE-Nanopore

APSCALE-Nanopore can be run in four different ways:

**1) Non-demultiplexed data**

Copy your non-demultiplexed `.fastq(.gz)` files to `1_raw_data/data`. All files are demultiplexed according to the Demultiplexing sheet.

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore
```

**2) Demultiplexed data**

Copy your demultiplexed `.fastq(.gz)` files to `1_raw_data/data` (one file per sample) and add them to the Demultiplexing sheet:

```
apscale_nanopore import_raw_data -p PATH/TO/My_project_apscale_nanopore
```

This writes one row per file (the file name is the sample ID) and copies the primers and lengths of the first row to all samples. Check the sheet, then run with `-sd` (skip demultiplexing):

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -sd
```

**3) Live processing of non-demultiplexed data**

Let the sequencer write your `.fastq(.gz)` files to `1_raw_data/data`. APSCALE-Nanopore scans the folder for new files and processes them automatically. Press `Ctrl+C` to stop.

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -live
```

**4) Live processing of demultiplexed data**

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -live -sd
```

### Run individual steps

Run a single step (`-step X`) or all steps from a specific step onwards (`-steps X`):

* 1 = Index demultiplexing
* 2 = Primer trimming
* 3 = Quality filtering
* 4 = Clustering/denoising
* 5 = Read table
* 6 = Taxonomic assignment

Example: run only the clustering/denoising

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -step 4
```

Example: run all steps from the quality filtering onwards

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -steps 3
```

Re-running the index demultiplexing replaces the previous results (reads are not added twice).

### Change settings on the fly

Settings can be changed for a single run without editing the settings file:

| Option | Setting |
|---|---|
| `-e1` | allowed errors index |
| `-e2` | allowed errors primer |
| `-minlen` / `-maxlen` | minimum / maximum length (for all samples) |
| `-minq` | minimum quality |
| `-mode` | clustering/denoising mode |
| `-percid` | vsearch clustering percentage identity |
| `-alpha` | vsearch denoising alpha |
| `-d` | swarm's d value |
| `-rep` | representative sequence (centroid or consensus) |
| `-minreads` | read filter threshold |

Example:

```
apscale_nanopore run -p PATH/TO/My_project_apscale_nanopore -steps 4 -mode "Swarm OTUs" -percid 0.98
```

### Quality control

Create quality plots for the raw, demultiplexed or primer-trimmed data (you are asked which folder):

```
apscale_nanopore qc -p PATH/TO/My_project_apscale_nanopore
```

## Project folder

```
APSCALE_projects/
├── APSCALE_databases/
└── My_project_apscale_nanopore/
    ├── 1_raw_data/data                <- raw data (non-demultiplexed or demultiplexed)
    ├── 2_index_demultiplexing/data
    ├── 3_primer_trimming/data
    ├── 4_quality_filtering/data
    ├── 5_clustering_denoising/data
    ├── 6_read_table                   <- read table (My_project_read_table.xlsx/.parquet.snappy)
    │   └── data                       <- OTU/ESV sequences (My_project_reads.fasta)
    ├── 7_taxonomic_assignment
    │   ├── My_project                 <- taxonomy table of the pipeline (My_project_taxonomy.xlsx)
    │   └── blastn_My_project_reads    <- taxonomy table of the APSCALE-BLAST page
    ├── 8_nanopore_report              <- quality reports (data) and summary report (main)
    └── My_project_settings.xlsx
```

## Settings file

The settings file has two sheets.

### Demultiplexing sheet

One row per sample. The index columns are only required for non-demultiplexed data and can be left empty otherwise. The minimum and maximum length are set per sample, so different markers can be processed in the same run.

| Forward index 5-3 | Forward primer 5-3 | Reverse index 5-3 | Reverse primer 5-3 | ID | Minimum length | Maximum length |
|---|---|---|---|---|---|---|
| AGAACGACTTCCATACTCGTGTGA | AAACTCGTGCCAGCCACC | AGAACGACTTCCATACTCGTGTGA | GGGTATCTAATCCCAGTTTG | Sample_1 | 157 | 177 |
| AACGAGTCTCTTGGGACCCATAGA | AAACTCGTGCCAGCCACC | AACGAGTCTCTTGGGACCCATAGA | GGGTATCTAATCCCAGTTTG | Sample_2 | 157 | 177 |

### Settings sheet (defaults)

| Category | Default | Comment |
|---|---|---|
| cpu count | auto | Number of cores to use (auto = all cores minus two) |
| allowed errors index | 3 | Allowed errors during index demultiplexing |
| allowed errors primer | 3 | Allowed errors during primer trimming |
| minimum quality | 20 | Reads below this average PHRED quality score are discarded |
| mode | denoised OTUs | ESVs, Swarms, denoised OTUs or Swarm OTUs |
| percid | 0.97 | vsearch clustering percentage identity |
| alpha | 1 | vsearch denoising alpha value |
| d | 1 | swarm's d value |
| representative | centroid | Representative sequence of OTUs: centroid or consensus |
| minimum reads | 0.0001 | Read filter per sample: < 1 = relative (0.0001 = 0.01% of the sample's reads), ≥ 1 = absolute number of reads |
| apscale blast | Yes | Run the taxonomic assignment (Yes or No) |
| task | megablast | BLAST task (megablast, blastn, dc-megablast) |
| apscale db | | Path to the APSCALE database (selected automatically in the GUI) |

## Bioinformatic workflow

**1) Index demultiplexing** (`cutadapt`) – sorts the reads into samples by their index combination. Reads are searched in both orientations (5'-3' and 3'-5').

**2) Primer trimming** (`cutadapt`) – removes the primers (both orientations); reads without primers are discarded.

**3) Quality filtering** (`python`, `vsearch`) – removes reads below the minimum mean PHRED score and outside the length range of the sample, then dereplicates the reads.

**4) Clustering/denoising** (`vsearch`, `swarm`) – per sample, followed by de novo chimera removal (`vsearch --uchime3_denovo`):
* **ESVs:** denoising (UNOISE3) to exact sequence variants
* **Swarms:** SWARM clustering; the seed (= centroid) is always used as representative
* **denoised OTUs:** denoising followed by similarity clustering
* **Swarm OTUs:** SWARM clustering followed by similarity clustering

The read count of each OTU/ESV includes the reads of all its cluster members.

**5) Read table** (`python`) – builds the read table (OTUs/ESVs × samples) and removes low-abundance OTUs/ESVs per sample (minimum reads). The format is the same as in APSCALE: columns `hash`, `sequence` and one column per sample; the hash is the SHA3-256 hash of the sequence; OTUs/ESVs are sorted by their total reads.

**6) Taxonomic assignment** (`BLASTn` via [APSCALE-blast](https://github.com/TillMacher/apscale_blast) v3) – assigns taxonomy using a local reference database. The pipeline uses the standard settings of APSCALE-blast (database-specific thresholds of `db_thresholds.xlsx`, if available); all other options are available on the APSCALE-BLAST page of the GUI or with `apscale_blast` directly.

**Data analysis** – import the read table and the taxonomy table into [TaxonTableTools2](https://github.com/TillMacher/TaxonTableTools2) with the import format "APSCALE".

**7) Reports** (`python`, `plotly`) – summary report after each run and optional quality reports.

## Databases

Pre-compiled databases for APSCALE-blast are [available here](https://seafile.rlp.net/d/c172d076de1e4c45b594/) and are updated regularly (the same databases as in [APSCALE-GUI](https://github.com/TillMacher/apscale_gui)). They are stored in `APSCALE_projects/APSCALE_databases` and can be downloaded directly in the GUI. Each database folder contains a `citation.txt`. The database path must not contain spaces.

## Citation

APSCALE-Nanopore: coming soon. Until then, please cite APSCALE:

* **APSCALE:** Buchner, Macher & Leese (2022) Bioinformatics 38: 4817–4819. https://doi.org/10.1093/bioinformatics/btac588

Please also cite the programs and data you used:

* **cutadapt:** Martin (2011) EMBnet.journal 17: 10–12. https://doi.org/10.14806/ej.17.1.200
* **VSEARCH:** Rognes et al. (2016) PeerJ 4: e2584. https://doi.org/10.7717/peerj.2584
* **SWARM:** Mahé et al. (2022) Bioinformatics 38: 267–269. https://doi.org/10.1093/bioinformatics/btab493
* **BLAST+:** Camacho et al. (2009) BMC Bioinformatics 10: 421. https://doi.org/10.1186/1471-2105-10-421
* **Databases:** see the `citation.txt` in the database folder and the [APSCALE-blast citations](https://github.com/TillMacher/apscale_blast#citation)

## Reporting issues

Please open an [issue](https://github.com/TillMacher/apscale_nanopore/issues) or contact me via email (macher@uni-trier.de).
