Metadata-Version: 2.4
Name: fruitfly4
Version: 0.1.2
Summary: Small dataset of fruit fly chromosome 4
Author-email: Anthony Aylward <anthony.aylward@protonmail.com>
Project-URL: Homepage, https://gitlab.com/aaylward/fruitfly4
Project-URL: Documentation, https://aaylward.gitlab.io/fruitfly4
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: License :: OSI Approved :: MIT License
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: biopython
Requires-Dist: pysradb
Dynamic: license-file

# FruitFly4

## Introduction

This package contains a set of minimal eukaryotic genome and transcriptome datasets from chromosme r of *Drosophila melanogaster*. They may, for example, be useful for rapidly testing a RNA-seq bioinformatics pipeline.

## Installation

Ensure your computing environment includes Python 3.11 or later and the following bioinformatics tools:
- sra-tools
- pigz
- fastp
- kraken2

Conda is useful for setting up this environment. Then, fruitfly4 can be installed with Pip:

```sh
conda create -c conda-forge -c bioconda -n fruitfly4 \
  biopython pysradb sra-tools pigz fastp kraken2
conda activate fruitfly4
pip install fruitfly4
```

## Usage

Run `fruitfly4` without arguments to list the help text of all subcommands

```sh
fruitfly4
```
```
usage: fruitfly4 [-h] [--version] {init,path,metadata,download,sheet,trim,classify} ...

Small dataset of fruit fly chromosome 4

positional arguments:
  {init,path,metadata,download,sheet,trim,classify}
    init                fully initialize the dataset by downloading, trimming, and classifying RNA-seq reads
    path                show paths to data directory and files
    metadata            fetch sra metadata
    download            download RNA-seq reads
    sheet               sample sheet for fruitfly4 rna-seq dataset
    trim                trim downloaded reads
    classify            classify downloaded reads

options:
  -h, --help            show this help message and exit
  --version             show program's version number and exit
```

To download and downsample all RNA-seq data, run:

```sh
fruitfly4 init
```

Use `fruitfly4 path` to get the absolute path for a data file
```sh
fruitfly4 path data-dir
fruitfly4 path genome
fruitfly4 path cds
fruitfly4 path pep
fruitfly4 path gff
fruitfly4 path gtf
fruitfly4 path sheet
```

`fruitfly4 path` can also fetch paths to datasets for the two alternate species:

```sh
fruitfly4 path genome-dmauri
fruitfly4 path genome-dseche
```

To see the sample sheet listing the locations of the RNA-seq reads:
```sh
fruitfly4 sheet
```

If you need the data at another location, you can symbolically link to the fruitfly4 dataset, or copy the contents to another directory
```sh
ln -s `fruitfly4 path data-dir` test_data/
cp -r `fruitfly4 path data-dir` test_data/
```

To see the SRA metadata of the RNA-seq reads:
```sh
fruitfly4 metadata
```

To execute the initialization steps individually:
```sh
fruitfly4 download
fruitfly4 trim
fruitfly4 classify
```

## Datasets
![fruitfly4-datasets.png](docs/source/_static/fruitfly4-datasets.png)

There are two groups of datasets: 
1. The directly included package data of **chromosome r** sequence and annotation from [*D. melanogaster* assembly DM6](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_000001215.4/) at NCBI, including:
    * Genome sequence (FASTA)
    * Coding sequences (FASTA)
    * mRNA transcripts (FASTA)
    * Peptide sequences (FASTA)
    * Gene annotation (GFF3, GTF)
    * Sequences and annotations (chromosome 4) are also included for six other *Drosophila* species:
        - [*D. mauritiana*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_004382145.1/)
        - [*D. sechellia*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_004382195.2/)
        - [*D. santomea*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_016746245.2/)
        - [*D. simulans*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_016746395.2/)
        - [*D. teissieri*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_016746235.2/)
        - [*D. yakuba*](https://www.ncbi.nlm.nih.gov/datasets/genome/GCF_016746365.2/)

2. The RNA-seq reads from [Bajgiran  et al. (2021)](https://pmc.ncbi.nlm.nih.gov/articles/PMC8488473/), which are downloaded from [SRA/NCBI BioProject PRJNA718442](https://www.ncbi.nlm.nih.gov/bioproject/PRJNA718442) and downsampled to include only chromosome 4 reads by running an included script.
    * The study sequenced mRNA from *D. melanogaster* at ages 1 day and 60 days.

## Downsampling RNA-seq
![fruitfly4-init.png](docs/source/_static/fruitfly4-init.png)

During the initialization process, after the RNA-seq reads are downloaded they are downsampled by:
1. Adapter and quality trimming with `fastp`
2. Classification with `kraken2` to filter out all reads that do not match chromosome I

## Configuration
You can configure some fruitfly4 settings using environment variables or a TOML file.

### Environment variables
```sh
export FRUITFLY4_DOWNLOAD_DIR = /absolute/path/to/directory/
export FRUITFLY4_TAXID = <integer>
export FRUITFLY4_SAMPLE_SHEET = /absolute/path/to/sample_sheet.csv
export FRUITFLY4_KRAKEN2_DB /absolute/path/to/kraken2_db/
```

### Config file
By default, fruitfly4 looks for configuration in TOML format at `$HOME/.fruitfly4.toml`

```toml
download_dir = /absolute/path/to/directory/
taxid = <integer>
sample_sheet = /absolute/path/to/sample_sheet.csv
kraken2_db = /absolute/path/to/kraken2_db/
```

The location of the config file can also be set using an environment variable:
```sh
export FRUITFLY4_CONFIG_FILE=/absolute/path/to/alternate/config.toml
```

## Python API

FruitFly4 resources can also be accessed from within python:

```python
import fruitfly4
fruitfly4.init()
fruitfly4.path('genome')
fruitfly4.path('genome-skud')
metadata = fruitfly4.metadata()
sample_sheet = fruitfly4.create_sample_sheet(metadata)
fruitfly4.write_sample_sheet(sample_sheet, 'sample_sheet.csv')
fruitfly4.download()
fruitfly4.trim('reads_1.fastq.gz', 'reads_2.fastq.gz')
fruitfly4.classify('reads_1.fastq.gz', 'reads_2.fastq.gz')
fruitfly4.taxid
fruitfly4.busco
```

## Example usage with nf-core pipelines

### Conda environment
```sh
conda create -c conda-forge -c bioconda -n fruitfly4-nf-core \
  biopython pysradb sra-tools pigz fastp kraken2 nextflow nf-core
conda activate fruitfly4-nf-core
pip install fruitfly4
```

### nf-core/genomeqc
```sh
echo '{"is_plant": false, "skip_busco": false, "skip_tidk": false}' > genomeqc-params.json
fruitfly4 sheet --pipeline nf-core-genomeqc > sample_sheet.csv
nextflow run nf-core/genomeqc -r 1.0.1 \
  -profile <docker/singularity/.../institute> \
  -params-file genomeqc-params.json \
  --input sample_sheet.csv \
  --outdir genomeqc_output_dir/ \
  --busco_lineage `fruitfly4 busco`
```

### nf-core/seqinspector
```sh
fruitfly4 sheet --pipeline nf-core-seqinspector > sample_sheet.csv
nextflow run nf-core/seqinspector \
  -profile <docker/singularity/.../institute> \
  --input sample_sheet.csv \
  --outdir seqinspector_output_dir/
```

### nf-core/seqinspector
```sh
fruitfly4 sheet --pipeline nf-core-seqinspector > sample_sheet.csv
nextflow run nf-core/seqinspector \
  -profile <docker/singularity/.../institute> \
  --input sample_sheet.csv \
  --outdir seqinspector_output_dir/ \
  --fasta `fruitfly4 path genome`
```

### nf-core/rnaseq
```sh
fruitfly4 sheet > sample_sheet.csv
nextflow run nf-core/rnaseq \
  -profile <docker/singularity/.../institute> \
  --input sample_sheet.csv \
  --outdir rnaseq_output_dir/ \
  --fasta `fruitfly4 path genome` \
  --gtf `fruitfly4 path gtf`
```

### nf-core/denovotranscript
```sh
fruitfly4 sheet > sample_sheet.csv
nextflow run nf-core/denovotranscript -r 1.2.1 \
  -profile <docker/singularity/.../institute> \
  --input sample_sheet.csv \
  --outdir denovotranscript_output_dir/ \
  --assemblers rnaspades
```
