MAGECK TEST

https://img.shields.io/badge/wrapper_version-v9.14.0-10785b https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/mageck/test?label=version%20update%20pull%20requests&color=1cb481

Search positively and negatively selected genes with MAGeCK.

URL: https://sourceforge.net/p/mageck/wiki/demo/#h-step-5-compare-samples-using-mageck-test-subcommand

Example

This wrapper can be used in the following way:

rule test_mageck_test:
    input:
        counts="counts.tsv",
        # Optional path to CNV matrix
        cnv="short_cnv.tsv",
    output:
        # Path to positively/negatively selected genes
        rra="RRA.tsv",
        r_script="mageck.R",
        rmd_report="mageck.Rmd",
        sgrna_summary="sgrna.tsv",
        sweave="mageck.Rnw",
        logs="additional_logs.log",
        # Optional path to PDF report
        pdf="RRA.pdf",
        # Optional path to normalized counts
        normalized="Normalized_counts.tsv",
    log:
        "test_mageck_test.log",
    threads: 1
    params:
        extra="--treatment-id HL60.final,KBM7.final --control-id HL60.initial,KBM7.initial --cell-line HL60_HAEMATOPOIETIC_AND_LYMPHOID_TISSUE",
    wrapper:
        "v9.14.0/bio/mageck/test"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • mageck=0.5.9.5

  • snakemake-wrapper-utils=0.8.0

Input/Output

Input:

  • counts: Path to file holding read counts.

  • cnv: Optional path to CNV data.

Output:

  • rra: Path to selected genes

  • r_script: Path to RScript used to perform end-analysis

  • rmd_report: Path to ready-to-use RMarkdown report

  • sgrna_summary: Path to sgRNA score ranking

  • sweave: Path to ready-to-use sweave report

  • logs: Path to internal logs file

  • pdf: Optional path to PDF report

  • normalized: Optional path to normalized read count file

Params

  • extra: Optional parameters besides –cnv-norm, –normcounts-to-file, -n|–output-prefix, –pdf-report, or –count-table.

Authors

  • Thibault Dayris

Code

# coding: utf-8

"""Snakemake wrapper for MaGeCK Test"""

__author__ = "Thibault Dayris"
__copyright__ = "Copyright 2026, Thibault Dayris"
__email__ = "thibault.dayris@gustaveroussy.fr"
__license__ = "MIT"

from pathlib import Path
from tempfile import TemporaryDirectory
from snakemake.shell import shell
from snakemake_wrapper_utils.snakemake import move_files

extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True)

cnv = snakemake.input.get("cnv", "")
if cnv:
    cnv = f"--cnv-norm {cnv} "

with TemporaryDirectory() as tempdir:
    outfile_mapping = {
        "rra": f"{tempdir}.gene_summary.txt",
        "r_script": f"{tempdir}.R",
        "rmd_report": f"{tempdir}.report.Rmd",
        "sgrna_summary": f"{tempdir}.sgrna_summary.txt",
        "sweave": f"{tempdir}_summary.Rnw",
        "logs": f"{tempdir}.log",
    }

    pdf = snakemake.output.get("pdf")
    if pdf:
        extra += " --pdf-report "
        outfile_mapping["pdf"] = f"{tempdir}.pdf"

    normalized = snakemake.output.get("normalized")
    if normalized:
        extra += " --normcounts-to-file "
        outfile_mapping["normalized"] = f"{tempdir}.normalized.txt"

    shell(
        "mageck test {extra} --count-table {snakemake.input.counts} "
        "--output-prefix {tempdir} {cnv} {log} "
    )

    for move_cmd in move_files(snakemake, outfile_mapping):
        shell("{move_cmd} {log}")