# NGSTk API Documentation

## Overview

NGSTk (Next-Generation Sequencing Toolkit) is a toolkit class that provides helper functions for building command strings used in NGS pipelines. It can be configured with a YAML configuration file to specify custom tool paths, or it will use tools from the system PATH.

### Key Features

- **Command Building**: Generate command strings for common NGS tools
- **Configuration Management**: Use custom tool paths via YAML config
- **Tool Integration**: Built-in support for common tools like samtools, bedtools, etc.
- **Pipeline Integration**: Works seamlessly with PipelineManager

### Installation

NGSTk is included with pypiper:

```bash
pip install pypiper
```

### Quick Example

```python
from pypiper.ngstk import NGSTk

# Initialize NGSTk
tk = NGSTk()

# Generate a command
cmd = tk.samtools_index("sample.bam")
# Returns: "samtools index sample.bam"
```

## API Reference

### NGSTk Class

<a id="pypiper.ngstk.NGSTk"></a>

### `NGSTk`

```python
class NGSTk(config_file: str | None = None, pm: Any = None)
```

Build shell command strings for common NGS processing operations.

:::note[Example]
tk = NGSTk()
tk.samtools_index("sample.bam")  # => "samtools index sample.bam"

tk = NGSTk("pipeline_config.yaml")
tk.samtools_index("sample.bam")  # uses configured samtools path
:::

Tool paths come from the config's "tools" section; unconfigured tools
default to their name (assuming they're on $PATH).

**Parameters:**

- `config_file` (*str | None*): Path to pipeline YAML config file. (default: `None`)
- `pm` (*Any*): PipelineManager to associate with this toolkit. (default: `None`)

#### Attributes

- <a id="pypiper.ngstk.NGSTk.parameters"></a>**`parameters`**
- <a id="pypiper.ngstk.NGSTk.pm"></a>**`pm`**
- <a id="pypiper.ngstk.NGSTk.tools"></a>**`tools`**
- <a id="pypiper.ngstk.NGSTk.ziptool_cmd"></a>**`ziptool_cmd`**

#### Properties

<a id="pypiper.ngstk.NGSTk.ziptool"></a>

##### `ziptool`

```python
@property
def ziptool -> str
```

Compression command: 'pigz' if available with multiple cores, else 'gzip'.

#### Methods

<a id="pypiper.ngstk.NGSTk.add_track_to_hub"></a>

##### `add_track_to_hub`

```python
def add_track_to_hub(sample_name: str, track_url: str, track_hub: str, colour: str, five_prime: str = '') -> list[str]
```

<a id="pypiper.ngstk.NGSTk.bam2fastq"></a>

##### `bam2fastq`

```python
def bam2fastq(input_bam: str, output_fastq: str, output_fastq2: str | None = None, unpaired_fastq: str | None = None) -> str
```

Build command to convert BAM to FASTQ via Picard SamToFastq.

<a id="pypiper.ngstk.NGSTk.bam_conversions"></a>

##### `bam_conversions`

```python
def bam_conversions(bam_file: str, depth: bool = True) -> str
```

Build command to sort and index a BAM file (optionally with depth).

**Parameters:**

- `bam_file` (*str*): Path to BAM file.
- `depth` (*bool*): Also calculate per-position coverage. (default: `True`)

<a id="pypiper.ngstk.NGSTk.bam_to_bed"></a>

##### `bam_to_bed`

```python
def bam_to_bed(input_bam: str, output_bed: str) -> str
```

<a id="pypiper.ngstk.NGSTk.bam_to_bigwig"></a>

##### `bam_to_bigwig`

```python
def bam_to_bigwig(input_bam: str, output_bigwig: str, genome_sizes: str, genome: str, tagmented: bool = False, normalize: bool = False, norm_factor: int = 1000) -> list[str]
```

Convert a BAM file to a bigWig file.

**Parameters:**

- `input_bam` (*str*): path to BAM file to convert
- `output_bigwig` (*str*): path to which to write file in bigwig format
- `genome_sizes` (*str*): path to file with chromosome size information
- `genome` (*str*): name of genomic assembly
- `tagmented` (*bool*): flag related to read-generating protocol (default: `False`)
- `normalize` (*bool*): whether to normalize coverage (default: `False`)
- `norm_factor` (*int*): number of bases to use for normalization (default: `1000`)

**Returns:**

- *list[str]*: list[str]: sequence of commands to execute

<a id="pypiper.ngstk.NGSTk.bam_to_fastq"></a>

##### `bam_to_fastq`

```python
def bam_to_fastq(bam_file: str, out_fastq_pre: str, paired_end: bool) -> str
```

Build Picard SamToFastq command for BAM to FASTQ conversion.

<a id="pypiper.ngstk.NGSTk.bam_to_fastq_awk"></a>

##### `bam_to_fastq_awk`

```python
def bam_to_fastq_awk(bam_file: str, out_fastq_pre: str, paired_end: bool, zipmode: bool = False) -> tuple[str, str, str | None]
```

Build fast awk-based BAM to FASTQ conversion command.

Faster than Picard/bedtools but assumes paired reads are properly
ordered with no singletons.

<a id="pypiper.ngstk.NGSTk.bam_to_fastq_bedtools"></a>

##### `bam_to_fastq_bedtools`

```python
def bam_to_fastq_bedtools(bam_file: str, out_fastq_pre: str, paired_end: bool) -> tuple[str, str, str | None]
```

Build bedtools bamtofastq command for BAM to FASTQ conversion.

<a id="pypiper.ngstk.NGSTk.bowtie2_map"></a>

##### `bowtie2_map`

```python
def bowtie2_map(input_fastq1: str, output_bam: str, log: str, metrics: str, genome_index: str, max_insert: int | str, cpus: int | str, input_fastq2: str | None = None) -> str
```

<a id="pypiper.ngstk.NGSTk.calc_frip"></a>

##### `calc_frip`

```python
def calc_frip(input_bam: str, input_bed: str, threads: int = 4) -> str
```

Calculate fraction of reads in peaks.

A file of with a pool of sequencing reads and a file with peak call
regions define the operation that will be performed. Thread count
for samtools can be specified as well.

**Parameters:**

- `input_bam` (*str*): sequencing reads file
- `input_bed` (*str*): file with called peak regions
- `threads` (*int*): number of threads samtools may use (default: `4`)

**Returns:**

- `float` (*str*): fraction of reads in peaks defined in given peaks file

<a id="pypiper.ngstk.NGSTk.calculate_frip"></a>

##### `calculate_frip`

```python
def calculate_frip(input_bam: str, input_bed: str, output: str, cpus: int = 4) -> str
```

<a id="pypiper.ngstk.NGSTk.center_peaks_on_motifs"></a>

##### `center_peaks_on_motifs`

```python
def center_peaks_on_motifs(peak_file: str, genome: str, window_width: int, motif_file: str, output_bed: str) -> str
```

<a id="pypiper.ngstk.NGSTk.check_command"></a>

##### `check_command`

```python
def check_command(command: str) -> bool
```

Check if a command is callable on the system.

<a id="pypiper.ngstk.NGSTk.check_fastq"></a>

##### `check_fastq`

```python
def check_fastq(input_files: str | list[str], output_files: str | list[str], paired_end: bool) -> Callable
```

Return a follow function that validates FASTQ conversion read counts.

:::note[Example]
cmd, prefix, out = tk.input_to_fastq(bam, name, pe, folder)
pm.run(cmd, out, follow=tk.check_fastq(bam, out, pe))
:::

**Parameters:**

- `input_files` (*str | list[str]*): Original input file(s) before conversion.
- `output_files` (*str | list[str]*): FASTQ output file(s) from conversion.
- `paired_end` (*bool*): Whether data is paired-end.

**Returns:**

- *Callable*: Callable that compares read counts and reports stats.

<a id="pypiper.ngstk.NGSTk.check_trim"></a>

##### `check_trim`

```python
def check_trim(trimmed_fastq: str, paired_end: bool, trimmed_fastq_R2: str | None = None, fastqc_folder: str | None = None) -> Callable
```

Return a follow function that counts trimmed reads and optionally runs FastQC.

**Parameters:**

- `trimmed_fastq` (*str*): Path to trimmed reads file.
- `paired_end` (*bool*): Whether data is paired-end.
- `trimmed_fastq_R2` (*str | None*): Path to R2 trimmed file for paired-end. (default: `None`)
- `fastqc_folder` (*str | None*): If set, run FastQC and place output here. (default: `None`)

**Returns:**

- *Callable*: Callable for use as pm.run() follow function.

<a id="pypiper.ngstk.NGSTk.count_concordant"></a>

##### `count_concordant`

```python
def count_concordant(aligned_bam: str) -> str
```

Count reads aligned concordantly exactly once (YT:Z:CP flag).

<a id="pypiper.ngstk.NGSTk.count_fail_reads"></a>

##### `count_fail_reads`

```python
def count_fail_reads(file_name: str, paired_end: bool) -> int
```

Count reads that failed platform/vendor quality checks (SAM flag 512).

<a id="pypiper.ngstk.NGSTk.count_flag_reads"></a>

##### `count_flag_reads`

```python
def count_flag_reads(file_name: str, flag: int | str, paired_end: bool) -> str
```

Count reads with a specific SAM flag value.

<a id="pypiper.ngstk.NGSTk.count_lines"></a>

##### `count_lines`

```python
def count_lines(file_name: str) -> str
```

Count lines in a file using wc -l.

<a id="pypiper.ngstk.NGSTk.count_lines_zip"></a>

##### `count_lines_zip`

```python
def count_lines_zip(file_name: str) -> str
```

Count lines in a gzipped file using zcat | wc -l.

<a id="pypiper.ngstk.NGSTk.count_mapped_reads"></a>

##### `count_mapped_reads`

```python
def count_mapped_reads(file_name: str, paired_end: bool) -> str | int
```

Count mapped reads in a BAM/SAM file (excludes unmapped, flag -F4).

<a id="pypiper.ngstk.NGSTk.count_multimapping_reads"></a>

##### `count_multimapping_reads`

```python
def count_multimapping_reads(file_name: str, paired_end: bool) -> int
```

Count reads flagged as multimapping (SAM flag 256).

<a id="pypiper.ngstk.NGSTk.count_reads"></a>

##### `count_reads`

```python
def count_reads(file_name: str, paired_end: bool) -> str | int | float
```

Count reads in a BAM/SAM/FASTQ file.

Paired-end reads count as 2. Assumes paired-end FASTQs are split
into separate R1/R2 files (divides line count by 2 instead of 4).

**Parameters:**

- `file_name` (*str*): Path to BAM/SAM/FASTQ file.
- `paired_end` (*bool*): Whether the file contains paired-end reads.

<a id="pypiper.ngstk.NGSTk.count_unique_mapped_reads"></a>

##### `count_unique_mapped_reads`

```python
def count_unique_mapped_reads(file_name: str, paired_end: bool) -> int
```

Count mapped reads (by name, deduplicated) in a BAM/SAM file.

<a id="pypiper.ngstk.NGSTk.count_unique_reads"></a>

##### `count_unique_reads`

```python
def count_unique_reads(file_name: str, paired_end: bool) -> int
```

Count unique reads (by name) in a BAM/SAM file. Paired-end counts as 2.

<a id="pypiper.ngstk.NGSTk.count_uniquelymapping_reads"></a>

##### `count_uniquelymapping_reads`

```python
def count_uniquelymapping_reads(file_name: str, paired_end: bool) -> str
```

Count reads that mapped to a unique position (exclude flag 256).

<a id="pypiper.ngstk.NGSTk.fastqc"></a>

##### `fastqc`

```python
def fastqc(file: str, output_dir: str) -> str
```

Build FastQC command for a reads file.

<a id="pypiper.ngstk.NGSTk.fastqc_rename"></a>

##### `fastqc_rename`

```python
def fastqc_rename(input_bam: str, output_dir: str, sample_name: str) -> list[str]
```

Build commands to run FastQC and rename output by sample name.

<a id="pypiper.ngstk.NGSTk.filter_peaks_mappability"></a>

##### `filter_peaks_mappability`

```python
def filter_peaks_mappability(peaks: str, alignability: str, filtered_peaks: str) -> str
```

<a id="pypiper.ngstk.NGSTk.filter_reads"></a>

##### `filter_reads`

```python
def filter_reads(input_bam: str, output_bam: str, metrics_file: str, paired: bool = False, cpus: int = 16, Q: int = 30) -> list[str]
```

Build commands to dedup, quality-filter, and remove multimappers.

<a id="pypiper.ngstk.NGSTk.genome_wide_coverage"></a>

##### `genome_wide_coverage`

```python
def genome_wide_coverage(input_bam: str, genome_windows: str, output: str) -> str
```

<a id="pypiper.ngstk.NGSTk.get_chrs_from_bam"></a>

##### `get_chrs_from_bam`

```python
def get_chrs_from_bam(file_name: str) -> list[str]
```

Extract chromosome names from a BAM file header via samtools.

<a id="pypiper.ngstk.NGSTk.get_file_size"></a>

##### `get_file_size`

```python
def get_file_size(filenames: str | list[str]) -> float
```

Get total size of file(s) in megabytes.

<a id="pypiper.ngstk.NGSTk.get_fragment_sizes"></a>

##### `get_fragment_sizes`

```python
def get_fragment_sizes(bam_file: str) -> Any
```

<a id="pypiper.ngstk.NGSTk.get_frip"></a>

##### `get_frip`

```python
def get_frip(sample: Any) -> dict
```

Calculates the fraction of reads in peaks for a given sample.

**Parameters:**

- `sample` (*pipelines.Sample*): Sample object with "peaks" attribute.

<a id="pypiper.ngstk.NGSTk.get_input_ext"></a>

##### `get_input_ext`

```python
def get_input_ext(input_file: str) -> str
```

Detect input file type: ".bam", ".fastq.gz", or ".fastq".

<a id="pypiper.ngstk.NGSTk.get_mitochondrial_reads"></a>

##### `get_mitochondrial_reads`

```python
def get_mitochondrial_reads(bam_file: str, output: str, cpus: int = 4) -> list[str]
```

<a id="pypiper.ngstk.NGSTk.get_peak_number"></a>

##### `get_peak_number`

```python
def get_peak_number(sample: Any) -> Any
```

Counts number of peaks from a sample's peak file.

**Parameters:**

- `sample` (*pipelines.Sample*): Sample object with "peaks" attribute.

<a id="pypiper.ngstk.NGSTk.get_read_type"></a>

##### `get_read_type`

```python
def get_read_type(bam_file: str, n: int = 10) -> tuple[str, int]
```

Gets the read type (single, paired) and length of bam file.

**Parameters:**

- `bam_file` (*str*): Bam file to determine read attributes.
- `n` (*int*): Number of lines to read from bam file. (default: `10`)

**Returns:**

- *tuple[str, int]*: str, int: tuple of read type and read length

<a id="pypiper.ngstk.NGSTk.homer_annotate_pPeaks"></a>

##### `homer_annotate_pPeaks`

```python
def homer_annotate_pPeaks(peak_file: str, genome: str, motif_file: str, output_bed: str) -> str
```

<a id="pypiper.ngstk.NGSTk.homer_find_motifs"></a>

##### `homer_find_motifs`

```python
def homer_find_motifs(peak_file: str, genome: str, output_dir: str, size: int = 150, length: str = '8,10,12,14,16', n_motifs: int = 12) -> str
```

<a id="pypiper.ngstk.NGSTk.htseq_count"></a>

##### `htseq_count`

```python
def htseq_count(input_bam: str, gtf: str, output: str) -> list[str]
```

<a id="pypiper.ngstk.NGSTk.index_bam"></a>

##### `index_bam`

```python
def index_bam(input_bam: str) -> str
```

<a id="pypiper.ngstk.NGSTk.input_to_fastq"></a>

##### `input_to_fastq`

```python
def input_to_fastq(input_file: str | list[str], sample_name: str, paired_end: bool, fastq_folder: str, output_file: str | None = None, multiclass: bool = False, zipmode: bool = False) -> list
```

Build command to convert any input (.bam/.fastq.gz/.fastq) to FASTQ.

**Parameters:**

- `input_file` (*str | list[str]*): Path(s) to input file(s).
- `sample_name` (*str*): Sample name for output file naming.
- `paired_end` (*bool*): Whether data is paired-end.
- `fastq_folder` (*str*): Directory for output FASTQ files.
- `output_file` (*str | None*): Explicit output path (auto-derived if None). (default: `None`)
- `multiclass` (*bool*): Internal flag for recursive R1/R2 handling. (default: `False`)
- `zipmode` (*bool*): Output as .fastq.gz instead of .fastq. (default: `False`)

**Returns:**

- *list*: List of [command, fastq_prefix, output_file].

<a id="pypiper.ngstk.NGSTk.kallisto"></a>

##### `kallisto`

```python
def kallisto(input_fastq: str, output_dir: str, output_bam: str, transcriptome_index: str, cpus: int, input_fastq2: str | None = None, size: int = 180, b: int = 200) -> list[str]
```

<a id="pypiper.ngstk.NGSTk.link_to_track_hub"></a>

##### `link_to_track_hub`

```python
def link_to_track_hub(track_hub_url: str, file_name: str, genome: str) -> None
```

<a id="pypiper.ngstk.NGSTk.macs2_call_peaks"></a>

##### `macs2_call_peaks`

```python
def macs2_call_peaks(treatment_bams: str | Iterable[str], output_dir: str, sample_name: str, genome: str, control_bams: str | Iterable[str] | None = None, broad: bool = False, paired: bool = False, pvalue: float | None = None, qvalue: float | None = None, include_significance: bool | None = None) -> str
```

Use MACS2 to call peaks.

**Parameters:**

- `treatment_bams` (*str | Iterable[str]*): Paths to files with data to
  regard as treatment.
- `output_dir` (*str*): Path to output folder.
- `sample_name` (*str*): Name for the sample involved.
- `genome` (*str*): Name of the genome assembly to use.
- `control_bams` (*str | Iterable[str]*): Paths to files with data to
  regard as control (default: `None`)
- `broad` (*bool*): Whether to do broad peak calling. (default: `False`)
- `paired` (*bool*): Whether reads are paired-end (default: `False`)
- `pvalue` (*float | NoneType*): Statistical significance measure to
  pass as --pvalue to peak calling with MACS (default: `None`)
- `qvalue` (*float | NoneType*): Statistical significance measure to
  pass as --qvalue to peak calling with MACS (default: `None`)
- `include_significance` (*bool | NoneType*): Whether to pass a
  statistical significance argument to peak calling with MACS; if
  omitted, this will be True if the peak calling is broad or if
  either p-value or q-value is specified; default significance
  specification is a p-value of 0.001 if a significance is to be
  specified but no value is provided for p-value or q-value. (default: `None`)

**Returns:**

- *str*: Command to run.

<a id="pypiper.ngstk.NGSTk.macs2_call_peaks_atacseq"></a>

##### `macs2_call_peaks_atacseq`

```python
def macs2_call_peaks_atacseq(treatment_bam: str, output_dir: str, sample_name: str, genome: str) -> str
```

<a id="pypiper.ngstk.NGSTk.macs2_plot_model"></a>

##### `macs2_plot_model`

```python
def macs2_plot_model(r_peak_model_file: str, sample_name: str, output_dir: str) -> list[str]
```

<a id="pypiper.ngstk.NGSTk.make_dir"></a>

##### `make_dir`

```python
def make_dir(path: str) -> None
```

Create directory and all intermediates, no error if exists.

<a id="pypiper.ngstk.NGSTk.make_sure_path_exists"></a>

##### `make_sure_path_exists`

```python
def make_sure_path_exists(path: str) -> None
```

Alias for make_dir

<a id="pypiper.ngstk.NGSTk.mark_duplicates"></a>

##### `mark_duplicates`

```python
def mark_duplicates(aligned_file: str, out_file: str, metrics_file: str, remove_duplicates: str = 'True') -> str
```

<a id="pypiper.ngstk.NGSTk.merge_bams"></a>

##### `merge_bams`

```python
def merge_bams(input_bams: list[str], merged_bam: str, in_sorted: bool | str = 'TRUE', tmp_dir: str | None = None) -> str | int
```

Build Picard MergeSamFiles command to combine BAM files.

<a id="pypiper.ngstk.NGSTk.merge_bams_samtools"></a>

##### `merge_bams_samtools`

```python
def merge_bams_samtools(input_bams: list[str], merged_bam: str) -> str
```

<a id="pypiper.ngstk.NGSTk.merge_fastq"></a>

##### `merge_fastq`

```python
def merge_fastq(inputs: list[str], output: str, run: bool = False, remove_inputs: bool = False) -> str | None
```

Merge multiple FASTQ files into one via cat.

<a id="pypiper.ngstk.NGSTk.merge_or_link"></a>

##### `merge_or_link`

```python
def merge_or_link(input_args: list, raw_folder: str, local_base: str = 'sample') -> str | list[str]
```

Standardize inputs by linking or merging .bam/.fastq/.fastq.gz files.

:::note[Example]
local = tk.merge_or_link([["s1_R1.fq.gz"], ["s1_R2.fq.gz"]], "raw/", "sample1")
:::

For single files, creates a symlink. For multiple files of the same
type, merges them (cat for fastq, samtools merge for bam).

**Parameters:**

- `input_args` (*list*): List of input file paths or list of lists (R1/R2).
- `raw_folder` (*str*): Directory for the merge/link output.
- `local_base` (*str*): Base name for output file (usually sample name). (default: `'sample'`)

<a id="pypiper.ngstk.NGSTk.move_file"></a>

##### `move_file`

```python
def move_file(old: str, new: str) -> str
```

<a id="pypiper.ngstk.NGSTk.parse_bowtie_stats"></a>

##### `parse_bowtie_stats`

```python
def parse_bowtie_stats(stats_file: str) -> dict
```

Parses Bowtie2 stats file, returns dict with values.

**Parameters:**

- `stats_file` (*str*): Bowtie2 output file with alignment statistics.

<a id="pypiper.ngstk.NGSTk.parse_duplicate_stats"></a>

##### `parse_duplicate_stats`

```python
def parse_duplicate_stats(stats_file: str) -> dict
```

Parses sambamba markdup output, returns dict with values.

**Parameters:**

- `stats_file` (*str*): sambamba output file with duplicate statistics.

<a id="pypiper.ngstk.NGSTk.parse_qc"></a>

##### `parse_qc`

```python
def parse_qc(qc_file: str) -> dict
```

Parse phantompeakqualtools (spp) QC table and return quality metrics.

**Parameters:**

- `qc_file` (*str*): Path to phantompeakqualtools output file, which
  contains sample quality measurements.

<a id="pypiper.ngstk.NGSTk.picard_mark_duplicates"></a>

##### `picard_mark_duplicates`

```python
def picard_mark_duplicates(input_bam: str, output_bam: str, metrics_file: str, temp_dir: str = '.') -> list[str]
```

<a id="pypiper.ngstk.NGSTk.plot_atacseq_insert_sizes"></a>

##### `plot_atacseq_insert_sizes`

```python
def plot_atacseq_insert_sizes(bam: str, plot: str, output_csv: str, max_insert: int = 1500, smallest_insert: int = 30) -> None
```

Heavy inspiration from here:
https://github.com/dbrg77/ATAC/blob/master/ATAC_seq_read_length_curve_fitting.ipynb

<a id="pypiper.ngstk.NGSTk.preseq_coverage"></a>

##### `preseq_coverage`

```python
def preseq_coverage(bam_file: str, output_prefix: str) -> str
```

<a id="pypiper.ngstk.NGSTk.preseq_curve"></a>

##### `preseq_curve`

```python
def preseq_curve(bam_file: str, output_prefix: str) -> str
```

<a id="pypiper.ngstk.NGSTk.preseq_extrapolate"></a>

##### `preseq_extrapolate`

```python
def preseq_extrapolate(bam_file: str, output_prefix: str) -> str
```

<a id="pypiper.ngstk.NGSTk.remove_file"></a>

##### `remove_file`

```python
def remove_file(file_name: str) -> str
```

<a id="pypiper.ngstk.NGSTk.run_spp"></a>

##### `run_spp`

```python
def run_spp(input_bam: str, output: str, plot: str, cpus: int) -> str
```

Run the SPP read peak analysis tool.

**Parameters:**

- `input_bam` (*str*): Path to reads file
- `output` (*str*): Path to output file
- `plot` (*str*): Path to plot file
- `cpus` (*int*): Number of processors to use

**Returns:**

- *str*: Command with which to run SPP

<a id="pypiper.ngstk.NGSTk.sam_conversions"></a>

##### `sam_conversions`

```python
def sam_conversions(sam_file: str, depth: bool = True) -> str
```

Build command to convert SAM to sorted/indexed BAM (optionally with depth).

**Parameters:**

- `sam_file` (*str*): Path to SAM file.
- `depth` (*bool*): Also calculate per-position coverage. (default: `True`)

<a id="pypiper.ngstk.NGSTk.sambamba_remove_duplicates"></a>

##### `sambamba_remove_duplicates`

```python
def sambamba_remove_duplicates(input_bam: str, output_bam: str, cpus: int = 16) -> str
```

<a id="pypiper.ngstk.NGSTk.samtools_index"></a>

##### `samtools_index`

```python
def samtools_index(bam_file: str) -> str
```

Index a bam file.

<a id="pypiper.ngstk.NGSTk.samtools_view"></a>

##### `samtools_view`

```python
def samtools_view(file_name: str, param: str, postpend: str = '') -> str
```

Run samtools view with given parameters and optional post-processing pipe.

<a id="pypiper.ngstk.NGSTk.shift_reads"></a>

##### `shift_reads`

```python
def shift_reads(input_bam: str, genome: str, output_bam: str) -> str
```

<a id="pypiper.ngstk.NGSTk.simple_frip"></a>

##### `simple_frip`

```python
def simple_frip(input_bam: str, input_bed: str, threads: int = 4) -> str
```

<a id="pypiper.ngstk.NGSTk.skewer"></a>

##### `skewer`

```python
def skewer(input_fastq1: str, output_prefix: str, output_fastq1: str, log: str, cpus: int | str, adapters: str, input_fastq2: str | None = None, output_fastq2: str | None = None) -> list[str]
```

Build skewer adapter-trimming commands with file renaming.

<a id="pypiper.ngstk.NGSTk.slurm_footer"></a>

##### `slurm_footer`

```python
def slurm_footer() -> str
```

<a id="pypiper.ngstk.NGSTk.slurm_header"></a>

##### `slurm_header`

```python
def slurm_header(job_name: str, output: str, queue: str = 'shortq', n_tasks: int = 1, time: str = '10:00:00', cpus_per_task: int = 8, mem_per_cpu: int = 2000, nodes: int = 1, user_mail: str = '', mail_type: str = 'end') -> str
```

<a id="pypiper.ngstk.NGSTk.slurm_submit_job"></a>

##### `slurm_submit_job`

```python
def slurm_submit_job(job_file: str) -> int
```

<a id="pypiper.ngstk.NGSTk.sort_index_bam"></a>

##### `sort_index_bam`

```python
def sort_index_bam(input_bam: str, output_bam: str) -> list[str]
```

<a id="pypiper.ngstk.NGSTk.spp_call_peaks"></a>

##### `spp_call_peaks`

```python
def spp_call_peaks(treatment_bam: str, control_bam: str, treatment_name: str, control_name: str, output_dir: str, broad: str | bool, cpus: int, qvalue: float | None = None) -> str
```

Build command for R script to call peaks with SPP.

**Parameters:**

- `treatment_bam` (*str*): Path to file with data for treatment sample.
- `control_bam` (*str*): Path to file with data for control sample.
- `treatment_name` (*str*): Name for the treatment sample.
- `control_name` (*str*): Name for the control sample.
- `output_dir` (*str*): Path to folder for output.
- `broad` (*str | bool*): Whether to specify broad peak calling mode.
- `cpus` (*int*): Number of cores the script may use.
- `qvalue` (*float*): FDR, as decimal value (default: `None`)

**Returns:**

- *str*: Command to run.

<a id="pypiper.ngstk.NGSTk.topHat_map"></a>

##### `topHat_map`

```python
def topHat_map(input_fastq: str, output_dir: str, genome: str, transcriptome: str, cpus: int | str) -> str
```

<a id="pypiper.ngstk.NGSTk.trimmomatic"></a>

##### `trimmomatic`

```python
def trimmomatic(input_fastq1: str, output_fastq1: str, cpus: int | str, adapters: str, log: str, input_fastq2: str | None = None, output_fastq1_unpaired: str | None = None, output_fastq2: str | None = None, output_fastq2_unpaired: str | None = None) -> str
```

<a id="pypiper.ngstk.NGSTk.validate_bam"></a>

##### `validate_bam`

```python
def validate_bam(input_bam: str) -> str
```

Build Picard ValidateSamFile command.

<a id="pypiper.ngstk.NGSTk.zinba_call_peaks"></a>

##### `zinba_call_peaks`

```python
def zinba_call_peaks(treatment_bed: str, control_bed: str, cpus: int, tagmented: bool = False) -> str
```
