[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CTXYXYF47W1SZZ5EEC0WC6":3,"skill-same:01M7CTXYXYF47W1SZZ5EEC0WC6":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":29,"repositoryHtmlUrl":30,"repositoryHomepageUrl":6,"ownerHtmlUrl":31,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":32,"install":33,"resources":46},"01M7CTXYXYF47W1SZZ5EEC0WC6","bio-crispr-screens-bagel-essentiality",null,"Identifies essential genes from CRISPR-Cas9 fitness screens using BAGEL2 (Kim & Hart 2021 Genome Med), a Bayesian classifier scoring per-gene Bayes Factors via log-likelihood ratios over per-sgRNA fold changes, calibrated against CEGv2 core-essentials (Hart 2017 G3, ~684 genes) and NEGv1 non-essentials (Hart 2014, ~927 genes). Covers the fc + bf + pr workflow, the linear-extrapolation improvement over BAGEL1 truncation, multi-target off-target correction, tumor-suppressor sensitivity (BAGEL2 detects enrichment), and BF calibration (BF >6 ≈ 90% posterior per Hart 2017; ~5% FDR by BAGEL convention). Use when classifying essential vs non-essential genes, calibrating BAGEL2 thresholds against PR curves, identifying tumor suppressors alongside essentials, comparing BAGEL2 hits to MAGeCK \u002F drugZ, or generating publication-quality essentiality calls.","mrsonord2240\u002Fopenscience-specialists","mrsonord2240","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F76487430?v=4","01M7CTEM40S43GSJZ9A3YCCXZK","Samuel Nord","01M7CTEM4K69JD1GBYNHVJ9ZP4",2,"Apache-2.0","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fcrispr-screen-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-crispr-screens-bagel-essentiality\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: bio-crispr-screens-bagel-essentiality\ndescription: Identifies essential genes from CRISPR-Cas9 fitness screens using BAGEL2 (Kim & Hart 2021 Genome Med), a Bayesian classifier scoring per-gene Bayes Factors via log-likelihood ratios over per-sgRNA fold changes, calibrated against CEGv2 core-essentials (Hart 2017 G3, ~684 genes) and NEGv1 non-essentials (Hart 2014, ~927 genes). Covers the fc + bf + pr workflow, the linear-extrapolation improvement over BAGEL1 truncation, multi-target off-target correction, tumor-suppressor sensitivity (BAGEL2 detects enrichment), and BF calibration (BF >6 ≈ 90% posterior per Hart 2017; ~5% FDR by BAGEL convention). Use when classifying essential vs non-essential genes, calibrating BAGEL2 thresholds against PR curves, identifying tumor suppressors alongside essentials, comparing BAGEL2 hits to MAGeCK \u002F drugZ, or generating publication-quality essentiality calls.\ntool_type: cli\nprimary_tool: BAGEL2\n---\n\n## Version Compatibility\n\nReference examples tested with: BAGEL2 2.0 (hart-lab\u002Fbagel, build 115), pandas 2.2+, numpy 1.26+, scipy 1.12+, matplotlib 3.8+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- CLI: `BAGEL.py fc --help`; `BAGEL.py bf --help`; `BAGEL.py pr --help`\n- Python: BAGEL2 is distributed via `git clone` (no canonical PyPI release); confirm `BAGEL.py version` after checkout.\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.\n\n## BAGEL2 Essentiality Analysis\n\n**\"Identify essential genes from my CRISPR fitness screen using BAGEL2\"** -> Compute per-sgRNA fold changes from counts, derive per-gene log-likelihood ratios against reference essential and non-essential gene sets, sum to Bayes Factor, and apply BF threshold calibrated by precision-recall against the reference.\n\n- CLI: `BAGEL.py fc` to compute fold changes\n- CLI: `BAGEL.py bf` to compute Bayes Factors\n- CLI: `BAGEL.py pr` for precision-recall curves\n- Reference sets: CEGv2 (essentials) and NEGv1 (non-essentials); both at https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel\n\n## The BAGEL2 Bayesian Framework (under the hood)\n\n**Why this matters for postdoc-level use:** BAGEL2 uses a Bayes-factor classifier trained on known essential and non-essential genes. The chain:\n\n1. For each sgRNA, compute log-fold-change (LFC) treatment vs control.\n2. For each gene, look up per-sgRNA LFCs.\n3. For each sgRNA, compute the log-likelihood ratio: `log( P(LFC | gene is essential) \u002F P(LFC | gene is non-essential) )`. The numerator and denominator are KDEs (kernel density estimates) of LFC distributions from CEGv2 and NEGv1 reference sgRNAs.\n4. Sum per-gene log-likelihood ratios across all sgRNAs targeting the gene -> per-gene Bayes Factor.\n5. Resampling for the confidence interval (default: 10-fold cross-validation; `-b` switches to bootstrapping with `-NB`, default 1000); BF >6 corresponds to ~90% posterior probability (Hart 2017 G3); ~5% FDR by BAGEL convention.\n6. **Resampling is randomized and BAGEL.py seeds it from the clock by default -- always pass `-s \u003Cfixed-int>`.** See \"Reproducibility: Fixing the Random Seed\" below; this is required for any result described as publication- or clinical-grade.\n\n**Critical BAGEL2 improvements over BAGEL1:**\n\n- **Linear extrapolation**: BAGEL1 truncated the LLR at the edges of its KDE; BAGEL2 fits a linear regression in the stable region and extrapolates, giving wider dynamic range. This recovers tumor suppressors (highly positive LFC) that BAGEL1 missed.\n- **Multi-target correction**: For sgRNAs targeting multiple genomic loci (off-targets), BAGEL2 discards them and regresses out their BF contribution, but only when `-m\u002F--filter-multi-target` is given together with `--align-info`. The original BAGEL counted off-target hits as essentiality signal.\n- **Tumor suppressor sensitivity**: BAGEL2 correctly identifies positive selection (enrichment) genes -- not possible in BAGEL1.\n\n## Calibration to CEGv2 \u002F NEGv1\n\n**Why these reference sets matter:** BAGEL2's discriminative power depends on KDEs of LFCs from known essential vs known non-essential genes. CEGv2 (Hart 2017) is 684 core essential genes shared across cell lines; NEGv1 (Hart 2014) is 927 non-essential genes verified across multiple screens. These act as positive and negative controls within every screen.\n\nReference set integrity:\n- CEGv2: pan-cancer essentials -- common dropouts across most cancer cell lines\n- NEGv1: confidently non-essential -- genes without expression or genes with verified neutral status\n\n**Critical pitfall:** Using a custom essentiality reference (e.g., a single-cell-line CRISPR screen) instead of CEGv2 biases the BAGEL2 model toward that line's specific biology. Always use the standardized references unless there is a specific reason for custom training.\n\n## Compute Per-Sample Fold Changes\n\n**Goal:** Generate per-sgRNA fold-change matrix as input for Bayes-factor calculation.\n\n**Approach:** Take normalized counts, compute log-fold-change vs a control (Day 0 or plasmid baseline) per sgRNA.\n\n```bash\n# BAGEL2 installation: distributed via git clone (no canonical PyPI release).\ngit clone https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel\ncd bagel\n\n# Inputs:\n# counts.txt: tab-separated with columns: sgRNA, GENE, Sample1, Sample2, ...\n# Control column(s): typically Day 0 or plasmid sample(s)\n# Treatment column(s): screen endpoint\n\nBAGEL.py fc \\\n    -i counts.txt \\\n    -o foldchange \\\n    -c Plasmid \\\n    --min-reads 30\n# -o is a LABEL for fc, not a file path; writes foldchange.foldchange\n# -c: control sample (or Day 0); --min-reads: default is 0, 30 is a common convention\n# Output: foldchange.foldchange (per-sgRNA LFCs) and foldchange.normed_readcount\n```\n\n**Trap, verified directly: a trailing `# comment` after a line-continuation `\\` breaks\nthe shell.** Comments must go on their own line (as above), not appended after a `\\`\nthat continues to another `-flag` line -- `bash` stops treating the rest of the\npipeline as one command as soon as a `#` follows the escaped space, and every\nsubsequent `-flag` line then runs as its own (nonexistent) command.\n\n## Compute Bayes Factors\n\n**Goal:** Score per-gene essentiality as a Bayes Factor.\n\n**Approach:** Run `BAGEL.py bf` with the fold-change matrix and reference gene sets. Resampling defaults to 10-fold cross-validation; add `-b -NB N` to bootstrap instead.\n\n```bash\nBAGEL.py bf \\\n    -i foldchange.foldchange \\\n    -o bayes_factor.txt \\\n    -e CEGv2.txt \\\n    -n NEGv1.txt \\\n    -c Sample1,Sample2,Sample3 \\\n    -s 42 \\\n    -b -NB 1000\n# -e\u002F-n: essentials\u002Fnon-essentials reference; -c: treatment samples to score\n# -s: fixed seed -- required for reproducible calls, see \"Reproducibility\" below\n# -b -NB 1000: opt into bootstrapping (default is 10-fold cross-validation)\n# Output: bayes_factor.txt - per-gene Bayes Factor + CI\n```\n\n**Output columns:**\n\n| Column | Meaning |\n|--------|---------|\n| `GENE` | Gene symbol |\n| `BF` | Per-gene Bayes Factor (log-likelihood ratio summed across sgRNAs) |\n| `STD` | Standard deviation across the 10 cross-validation folds (or bootstrap iterations with `-b`) -- **only present when `-b` is given** |\n| `NumObs` | Number of sgRNAs contributing -- **only present when `-b` is given** |\n\nVerified directly (build 115): a CV-default run (no `-b`) writes a 2-column `GENE\\tBF`\nfile; only `-b` adds `STD`\u002F`NumObs`. If you need the STD diagnostic for guide-quality\ntriage, you must opt into bootstrap -- `-b -NB 1000` takes roughly 20-25 minutes at\ngenome scale (18k+ genes); the CV default runs in well under a minute but has no STD\ncolumn.\n\n**Interpretation rule:** BF >6 corresponds to ~90% posterior probability of essentiality against CEGv2 (Hart 2017; FDR ≤3% in that calibration, with ~5% a looser BAGEL convention); higher BF = stronger evidence the gene is essential. BAGEL2 also reports negative BFs which can indicate tumor suppressors (positive selection) -- see \"Interpret BAGEL2 Results\" below for when that call is actually defensible.\n\n## Reproducibility: Fixing the Random Seed\n\n**BAGEL.py's resampling (both cross-validation and bootstrap) is seeded from the clock\nby default** (`-s` defaults to `int(time.time()*100000 % 100000)`, undocumented in\nSKILL.md, usage-guide.md or `run_bagel2.sh` before this fix) -- every unseeded run\nproduces different Bayes Factors. Verified on real HAP1 TKOv3 data (build 115): two\nidentical, unseeded `bf` invocations differed by up to 26.7 BF and **flipped 33 of\n18,053 genes across the BF>6 essential\u002Fnon-essential threshold**; re-running the\ncomparison with `sort`+`diff`, 18,026\u002F18,053 rows differed between the two runs.\n\n**Fix:** always pass `-s \u003Cfixed-integer>` and record the value used for any\npublication- or clinical-grade call.\n\n```bash\nBAGEL.py bf -i foldchange.foldchange -o bayes_factor.txt \\\n    -e CEGv2.txt -n NEGv1.txt -c Sample1,Sample2,Sample3 \\\n    -s 42                                   # fixed seed -- record this value\n```\n\nVerified directly: two `bf` runs against identical inputs with `-s 42` produced a\nbyte-identical `bayes_factor.txt` (`diff` clean across all 18,053 genes).\n\n**Trap, verified against build 115: `-s` is declared twice in BAGEL.py's own CLI** --\nonce for `-s\u002F--use-small-sample` (a flag) and once for `-s\u002F--seed` (an integer).\n`BAGEL.py bf --help` prints both and warns `The parameter -s is used more than once`;\npassing `-s \u003Cint>` binds to `--seed` (the later-declared option wins in Click's\nparser) -- confirmed by running `-s 42` and inspecting the resulting fold-assignment\nlog and byte-identical rerun, not just by reading `--help`. This is BAGEL.py's own\nbug, not this Skill's; verify with `--help` before relying on it in an environment\nrunning a different BAGEL2 build.\n\n## Precision-Recall Curve\n\n**Goal:** Empirically select BF threshold for a given precision\u002Frecall tradeoff.\n\n**Approach:** Run `BAGEL.py pr` to compute precision and recall at every BF level against CEGv2; pick the BF that gives desired precision.\n\n```bash\nBAGEL.py pr \\\n    -i bayes_factor.txt \\\n    -o precision_recall.txt \\\n    -e CEGv2.txt \\\n    -n NEGv1.txt\n# Output: precision_recall.txt - precision\u002Frecall at each BF threshold\n```\n\n**Practical BF ladder (regenerate precision and recall per screen with `BAGEL.py pr`):**\n\n| BF threshold | Use case |\n|--------------|----------|\n| 0 | Exploratory; highest recall |\n| 6 | Standard call (~90% posterior, Hart 2017) |\n| 12 | High-confidence |\n| 30 | Ultra-stringent; near-certain essentials |\n\n**Pick threshold based on application:** For exploratory hit calling, BF >0 with low precision is acceptable; for clinical-grade essentiality calls, BF >12 or higher.\n\n## Interpret BAGEL2 Results\n\n**Goal:** Stratify genes into essential, non-essential, and tumor-suppressor categories.\n\n**Approach:** Apply BF threshold to classify essentials; only classify negative-BF genes as tumor suppressors when the screen design actually expects enrichment (see Failure Modes below) -- verified on real HAP1 TKOv3 data (a dropout screen) that skipping this guard flags **86.5% of the genome** as tumor-suppressor, with three assay-control pseudo-genes (`LacZ`, `luciferase`, `EGFP`) as the top hits.\n\n```python\nimport pandas as pd\nimport warnings\n\n# Assay-control pseudo-genes spiked into CRISPR libraries (never real biology) --\n# verified present and dominating the naive tumor-suppressor call on real HAP1 TKOv3\n# output; extend this set to match your library's own controls.\nASSAY_CONTROLS = {'LacZ', 'luciferase', 'EGFP'}\n\ndef interpret_bagel(bf_path, bf_essential=6, bf_tumor_suppressor=-6,\n                     screen_type='dropout', control_genes=ASSAY_CONTROLS,\n                     tumor_suppressor_frac_warn=0.05):\n    '''Classify genes from BAGEL2 BF output.\n\n    screen_type: 'dropout' (default) only calls `essential`. Tumor-suppressor calls\n    require screen_type='enrichment' or 'both' -- per the Failure Modes section below,\n    a pure dropout screen's negative-BF genes are noise, not tumor suppressors.\n    '''\n    df = pd.read_csv(bf_path, sep='\\t')\n    df = df[~df['GENE'].isin(control_genes)].copy()   # drop assay-control pseudo-genes\n    df['call'] = 'neutral'\n    df.loc[df['BF'] > bf_essential, 'call'] = 'essential'\n    if screen_type in ('enrichment', 'both'):\n        df.loc[df['BF'] \u003C bf_tumor_suppressor, 'call'] = 'tumor_suppressor'\n        frac = (df['call'] == 'tumor_suppressor').mean()\n        if frac > tumor_suppressor_frac_warn:\n            warnings.warn(\n                f\"{frac:.1%} of genes flagged tumor_suppressor -- implausibly high; \"\n                \"this usually means a dropout-only screen is being scored for \"\n                \"enrichment. Re-check screen_type and BF\u003C-6 calls against literature \"\n                \"before reporting.\"\n            )\n    return df.sort_values('BF', ascending=False)\n```\n\nVerified on real HAP1 TKOv3 data (a T0-vs-T18 dropout screen): the default\n(`screen_type='dropout'`) returns 0 tumor-suppressor calls and excludes the 3 control\npseudo-genes; explicit `screen_type='enrichment'` still surfaces the true tumor\nsuppressors TSC1\u002FTSC2 as the two most-negative-BF entries (now that the control genes\nthat previously masked them are excluded) but raises the 86.6%-flagged warning so the\ncaller doesn't report it uncritically.\n\n**Tumor suppressor identification:** Genes with significantly negative BF (e.g., \u003C-6) in a screen actually designed to detect enrichment (drug-resistance, GoF) indicate fitness advantage from their loss. This is biologically distinct from \"non-essential\" and may indicate tumor-suppressor function. BAGEL1 could not detect this; BAGEL2's linear extrapolation enables it. **Do not call tumor suppressors from a pure dropout screen** -- see Failure Modes.\n\n## Bayesian Reasoning Per Sgrna\n\n**Why this matters:** BAGEL2 computes per-sgRNA contributions; a gene with 4 sgRNAs each contributing +5 to BF gets +20 total. A gene with 3 sgRNAs contributing +5 and 1 sgRNA contributing -3 (off-target or low-efficacy) gets +12 net.\n\n**Approach:** Add `-r\u002F--sgrna-bayes-factors` to the `bf` command -- this flag is not\nmentioned elsewhere in this Skill but is required to get per-sgRNA output; found via\n`BAGEL.py bf --help`, not documented upstream either.\n\n```bash\nBAGEL.py bf \\\n    -i foldchange.foldchange \\\n    -o bayes_factor_sgrna.txt \\\n    -e CEGv2.txt -n NEGv1.txt \\\n    -c Sample1,Sample2,Sample3 \\\n    -s 42 -r                               # -r: per-sgRNA BF contributions\n# Output columns: RNA  GENE  \u003Csample columns>  BF  (one row per sgRNA)\n```\n\nVerified on real HAP1 TKOv3 data: for RPS3 (the example gene below), the 4 per-sgRNA\nBF values summed to 78.9 against a gene-level BF of 80.8 (within 2.4%), confirming the\nadditive-LLR model this section describes.\n\n**Critical:** When per-sgRNA contributions are very heterogeneous (one sgRNA dominates BF), the gene is \"guide-of-one\"; verify with JACKS efficiency analysis or apply the second-best-sgRNA rule from [[hit-calling]].\n\n## Comparing BAGEL2, MAGeCK, drugZ\n\n| Property | BAGEL2 | MAGeCK | drugZ |\n|----------|--------|--------|-------|\n| Statistical framework | Bayes factor with reference sets | NB GLM | Bidirectional Z-score |\n| Calibrated against | CEGv2 \u002F NEGv1 | Internal null | Vehicle distribution |\n| Tumor suppressor detection | YES | Limited (RRA positive-selection score) | YES |\n| Best for | Essentiality classification | General hit calling | Chemogenomic drug screens |\n| Output | Bayes factor + CI | FDR + LFC | Z-score + FDR per direction |\n| Hit threshold | BF >6 | FDR \u003C0.05 | FDR \u003C0.05 |\n| Library calibration | Indirect (reference set) | None | None |\n\n**Reconciliation:** BF >6 ≈ 90% posterior probability (Hart 2017 G3); commonly treated as roughly MAGeCK FDR 0.05 by convention. BAGEL2 hits absent from MAGeCK suggest weak signal that BAGEL2's reference anchoring detects but MAGeCK's null-based test misses; verify by inspecting per-sgRNA contributions.\n\n## Failure Modes\n\n### BAGEL2 returns no hits, crashes, or silently corrupts output on a bad reference set\n\n**Trigger:** Wrong reference gene set file -- species mismatch, thin\u002Funrepresentative reference, or `-e`\u002F`-n` swapped.\n**Mechanism:** The actual failure mode depends on *how* the reference is wrong, verified directly against three concrete misconfigurations (not one uniform symptom):\n- **Species mismatch** (e.g., a mouse CEG file against a human screen): hard crash, `ValueError: dataset input should have multiple elements` (`scipy.stats.gaussian_kde`) -- not a silent \"no hits\" run.\n- **`-e`\u002F`-n` arguments swapped** (an easy transcription mistake, not covered anywhere else in this Skill): `BAGEL.py bf` exits 0 and writes a complete-looking `bayes_factor.txt`, but **every gene's `BF` is the literal string `nan`** -- verified across all 18,053 genes on real data, no warning surfaced to the user.\n- **Genuinely thin\u002Funrepresentative reference** (too few genes, weak KDE separation): the \"median BF near zero, no genes >6\" symptom below does apply here.\n**Symptom:** Depends on failure type -- hard crash (species mismatch), all-`nan` BF column (swapped `-e`\u002F`-n`), or median BF near zero with no genes >6 (thin\u002Funrepresentative reference).\n**Fix:** Re-download CEGv2 \u002F NEGv1 from https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel. Verify gene symbols match the screen's annotation. Before trusting a \"no hits\" reading, check `bayes_factor.txt` for an all-`nan` `BF` column -- that means `-e`\u002F`-n` were swapped, not that the screen is flat.\n\n### BAGEL2 calls negative-LFC genes \"tumor suppressors\"\n\n**Trigger:** Heavy dropout screen where many genes drop out; the dropout signal is captured as positive BF but the *enriched* genes (negative BF) are noise.\n**Mechanism:** BAGEL2's symmetric distribution treats deeply enriched genes as significant; in a dropout-only screen, the enrichment signal is purely noise.\n**Symptom:** Many genes with negative BF; these don't validate as tumor suppressors.\n**Fix:** Restrict tumor-suppressor calling to screens specifically expecting enrichment (e.g., drug-resistance, GoF screens); for dropout screens, only interpret positive BF.\n\n### Bootstrap CI is wide; BF estimates unstable\n\n**Trigger:** Per-gene number of sgRNAs too low (e.g., \u003C4 in some libraries).\n**Mechanism:** Bootstrap of LLR over very few sgRNAs creates wide CI.\n**Symptom:** STD column larger than BF; many genes have CI spanning zero.\n**Fix:** Use a library with at least 4-6 sgRNAs\u002Fgene; or switch to bootstrapping (`-b -NB 5000`); or filter out genes with \u003C3 sgRNAs.\n\n### Low BF for known essential despite high LFC\n\n**Trigger:** One sgRNA per gene is contributing very low LLR (off-target or low-efficacy).\n**Mechanism:** BAGEL2 sums LLR; one weak guide drags total down.\n**Symptom:** Known essential like RPS3 has BF \u003C6 despite 3 of 4 guides showing -5 LFC.\n**Fix:** Inspect per-sgRNA LLR; identify the dragging guide; verify whether to exclude or to use JACKS for efficacy-aware analysis.\n\n### Non-cancer cell-line screen with custom essentials\n\n**Trigger:** Human embryonic kidney HEK293T or iPSC-derived neurons where standard essentials may not be essential.\n**Mechanism:** CEGv2 is calibrated for cancer cell lines; some essentials in tumor cells are not essential in iPSC.\n**Symptom:** PR curve against CEGv2 shows poor separation; many CEGv2 essentials don't drop out.\n**Fix:** Use a cell-type-specific essentialome derived for the relevant lineage; or use MAGeCK \u002F Chronos which doesn't depend on reference sets.\n\n## Quantitative Thresholds\n\n| Threshold | Value | Source \u002F Rationale |\n|-----------|-------|--------------------|\n| Standard essentiality call | BF >6 | Hart 2017: BF>=6 ~ 90% posterior |\n| Stricter essentiality call | BF >12 | BAGEL convention; regenerate precision\u002Frecall per screen with `BAGEL.py pr` |\n| Ultra-stringent call | BF >30 | BAGEL convention |\n| BF for tumor-suppressor candidate | \u003C-6 | Empirical; verify with orthogonal screen |\n| Resampling | 10-fold cross-validation (default); `-b -NB 1000` to bootstrap | BAGEL2 default |\n| Seed for reproducible\u002Fpublication-grade calls | `-s \u003Cfixed-int>`, always | Unseeded runs flip up to 33\u002F18,053 gene calls at BF>6 (verified on HAP1 TKOv3, build 115) |\n| Min reads per sgRNA in control | 30 | Convention; the BAGEL2 default is 0 |\n| Min sgRNAs per gene for stable BF | 4-6 | Wider with library convention |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| No hits despite essentials present | Wrong reference set | Re-verify CEGv2 \u002F NEGv1 files |\n| Every gene's `BF` is `nan` | `-e`\u002F`-n` arguments swapped | Check argument order against the Output columns example; re-run |\n| Different BF\u002Fhit list on a rerun with identical inputs | No `-s` seed given (BAGEL.py defaults to a clock-based seed) | Always pass `-s \u003Cfixed-int>`, see Reproducibility section |\n| Wide resampling CI | Too few sgRNAs\u002Fgene | Increase library coverage; bootstrap with more iterations |\n| Negative BF for known essentials | Confounding factor (e.g., CN amplification) | Pre-correct with CRISPRcleanR \u002F Chronos |\n| Tumor suppressor calls don't validate | Pure dropout screen; enrichment is noise | Only call `interpret_bagel(..., screen_type='enrichment')` on screens actually expecting enrichment |\n| Per-sgRNA LLR dominated by one guide | Outlier or off-target | Apply second-best-sgRNA rule |\n\n## References\n\n- Kim E & Hart T. 2021. *Genome Medicine* 13:2. BAGEL2 algorithm and improvements.\n- Hart T & Moffat J. 2016. *BMC Bioinformatics* 17:164. BAGEL Bayes factor framework.\n- Hart T et al. 2017. *G3* 7:2719. CEGv2 core-essential reference set; BF posterior calibration.\n- Hart T et al. 2014. *Mol Syst Biol* 10:733. Gold-standard essential and non-essential reference sets; source of NEGv1.\n- Pacini C et al. 2021. *Nat Commun* 12:1661. Integrated cross-study dependencies; reference essentiality benchmarks.\n\n## Related Skills\n\n- crispr-screens\u002Fmageck-analysis - MAGeCK RRA\u002FMLE alternative\n- crispr-screens\u002Fjacks-analysis - JACKS for per-guide efficacy\n- crispr-screens\u002Fdrugz-chemogenomic - drugZ for drug screens\n- crispr-screens\u002Fhit-calling - Cross-method decision tree\n- crispr-screens\u002Fscreen-qc - Pre-BAGEL QC including CEGv2 PR-AUC\n- crispr-screens\u002Flibrary-design - 4-6 sgRNAs\u002Fgene library standard\n- crispr-screens\u002Fcopy-number-correction - Pre-correction for cancer-line screens\n- pathway-analysis\u002Fgo-enrichment - Downstream functional analysis\n","## Version Compatibility\n\nReference examples tested with: BAGEL2 2.0 (hart-lab\u002Fbagel, build 115), pandas 2.2+, numpy 1.26+, scipy 1.12+, matplotlib 3.8+.\n\nBefore using code patterns, verify installed versions match. If versions differ:\n- CLI: `BAGEL.py fc --help`; `BAGEL.py bf --help`; `BAGEL.py pr --help`\n- Python: BAGEL2 is distributed via `git clone` (no canonical PyPI release); confirm `BAGEL.py version` after checkout.\n\nIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.\n\n## BAGEL2 Essentiality Analysis\n\n**\"Identify essential genes from my CRISPR fitness screen using BAGEL2\"** -> Compute per-sgRNA fold changes from counts, derive per-gene log-likelihood ratios against reference essential and non-essential gene sets, sum to Bayes Factor, and apply BF threshold calibrated by precision-recall against the reference.\n\n- CLI: `BAGEL.py fc` to compute fold changes\n- CLI: `BAGEL.py bf` to compute Bayes Factors\n- CLI: `BAGEL.py pr` for precision-recall curves\n- Reference sets: CEGv2 (essentials) and NEGv1 (non-essentials); both at https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel\n\n## The BAGEL2 Bayesian Framework (under the hood)\n\n**Why this matters for postdoc-level use:** BAGEL2 uses a Bayes-factor classifier trained on known essential and non-essential genes. The chain:\n\n1. For each sgRNA, compute log-fold-change (LFC) treatment vs control.\n2. For each gene, look up per-sgRNA LFCs.\n3. For each sgRNA, compute the log-likelihood ratio: `log( P(LFC | gene is essential) \u002F P(LFC | gene is non-essential) )`. The numerator and denominator are KDEs (kernel density estimates) of LFC distributions from CEGv2 and NEGv1 reference sgRNAs.\n4. Sum per-gene log-likelihood ratios across all sgRNAs targeting the gene -> per-gene Bayes Factor.\n5. Resampling for the confidence interval (default: 10-fold cross-validation; `-b` switches to bootstrapping with `-NB`, default 1000); BF >6 corresponds to ~90% posterior probability (Hart 2017 G3); ~5% FDR by BAGEL convention.\n6. **Resampling is randomized and BAGEL.py seeds it from the clock by default -- always pass `-s \u003Cfixed-int>`.** See \"Reproducibility: Fixing the Random Seed\" below; this is required for any result described as publication- or clinical-grade.\n\n**Critical BAGEL2 improvements over BAGEL1:**\n\n- **Linear extrapolation**: BAGEL1 truncated the LLR at the edges of its KDE; BAGEL2 fits a linear regression in the stable region and extrapolates, giving wider dynamic range. This recovers tumor suppressors (highly positive LFC) that BAGEL1 missed.\n- **Multi-target correction**: For sgRNAs targeting multiple genomic loci (off-targets), BAGEL2 discards them and regresses out their BF contribution, but only when `-m\u002F--filter-multi-target` is given together with `--align-info`. The original BAGEL counted off-target hits as essentiality signal.\n- **Tumor suppressor sensitivity**: BAGEL2 correctly identifies positive selection (enrichment) genes -- not possible in BAGEL1.\n\n## Calibration to CEGv2 \u002F NEGv1\n\n**Why these reference sets matter:** BAGEL2's discriminative power depends on KDEs of LFCs from known essential vs known non-essential genes. CEGv2 (Hart 2017) is 684 core essential genes shared across cell lines; NEGv1 (Hart 2014) is 927 non-essential genes verified across multiple screens. These act as positive and negative controls within every screen.\n\nReference set integrity:\n- CEGv2: pan-cancer essentials -- common dropouts across most cancer cell lines\n- NEGv1: confidently non-essential -- genes without expression or genes with verified neutral status\n\n**Critical pitfall:** Using a custom essentiality reference (e.g., a single-cell-line CRISPR screen) instead of CEGv2 biases the BAGEL2 model toward that line's specific biology. Always use the standardized references unless there is a specific reason for custom training.\n\n## Compute Per-Sample Fold Changes\n\n**Goal:** Generate per-sgRNA fold-change matrix as input for Bayes-factor calculation.\n\n**Approach:** Take normalized counts, compute log-fold-change vs a control (Day 0 or plasmid baseline) per sgRNA.\n\n```bash\n# BAGEL2 installation: distributed via git clone (no canonical PyPI release).\ngit clone https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel\ncd bagel\n\n# Inputs:\n# counts.txt: tab-separated with columns: sgRNA, GENE, Sample1, Sample2, ...\n# Control column(s): typically Day 0 or plasmid sample(s)\n# Treatment column(s): screen endpoint\n\nBAGEL.py fc \\\n    -i counts.txt \\\n    -o foldchange \\\n    -c Plasmid \\\n    --min-reads 30\n# -o is a LABEL for fc, not a file path; writes foldchange.foldchange\n# -c: control sample (or Day 0); --min-reads: default is 0, 30 is a common convention\n# Output: foldchange.foldchange (per-sgRNA LFCs) and foldchange.normed_readcount\n```\n\n**Trap, verified directly: a trailing `# comment` after a line-continuation `\\` breaks\nthe shell.** Comments must go on their own line (as above), not appended after a `\\`\nthat continues to another `-flag` line -- `bash` stops treating the rest of the\npipeline as one command as soon as a `#` follows the escaped space, and every\nsubsequent `-flag` line then runs as its own (nonexistent) command.\n\n## Compute Bayes Factors\n\n**Goal:** Score per-gene essentiality as a Bayes Factor.\n\n**Approach:** Run `BAGEL.py bf` with the fold-change matrix and reference gene sets. Resampling defaults to 10-fold cross-validation; add `-b -NB N` to bootstrap instead.\n\n```bash\nBAGEL.py bf \\\n    -i foldchange.foldchange \\\n    -o bayes_factor.txt \\\n    -e CEGv2.txt \\\n    -n NEGv1.txt \\\n    -c Sample1,Sample2,Sample3 \\\n    -s 42 \\\n    -b -NB 1000\n# -e\u002F-n: essentials\u002Fnon-essentials reference; -c: treatment samples to score\n# -s: fixed seed -- required for reproducible calls, see \"Reproducibility\" below\n# -b -NB 1000: opt into bootstrapping (default is 10-fold cross-validation)\n# Output: bayes_factor.txt - per-gene Bayes Factor + CI\n```\n\n**Output columns:**\n\n| Column | Meaning |\n|--------|---------|\n| `GENE` | Gene symbol |\n| `BF` | Per-gene Bayes Factor (log-likelihood ratio summed across sgRNAs) |\n| `STD` | Standard deviation across the 10 cross-validation folds (or bootstrap iterations with `-b`) -- **only present when `-b` is given** |\n| `NumObs` | Number of sgRNAs contributing -- **only present when `-b` is given** |\n\nVerified directly (build 115): a CV-default run (no `-b`) writes a 2-column `GENE\\tBF`\nfile; only `-b` adds `STD`\u002F`NumObs`. If you need the STD diagnostic for guide-quality\ntriage, you must opt into bootstrap -- `-b -NB 1000` takes roughly 20-25 minutes at\ngenome scale (18k+ genes); the CV default runs in well under a minute but has no STD\ncolumn.\n\n**Interpretation rule:** BF >6 corresponds to ~90% posterior probability of essentiality against CEGv2 (Hart 2017; FDR ≤3% in that calibration, with ~5% a looser BAGEL convention); higher BF = stronger evidence the gene is essential. BAGEL2 also reports negative BFs which can indicate tumor suppressors (positive selection) -- see \"Interpret BAGEL2 Results\" below for when that call is actually defensible.\n\n## Reproducibility: Fixing the Random Seed\n\n**BAGEL.py's resampling (both cross-validation and bootstrap) is seeded from the clock\nby default** (`-s` defaults to `int(time.time()*100000 % 100000)`, undocumented in\nSKILL.md, usage-guide.md or `run_bagel2.sh` before this fix) -- every unseeded run\nproduces different Bayes Factors. Verified on real HAP1 TKOv3 data (build 115): two\nidentical, unseeded `bf` invocations differed by up to 26.7 BF and **flipped 33 of\n18,053 genes across the BF>6 essential\u002Fnon-essential threshold**; re-running the\ncomparison with `sort`+`diff`, 18,026\u002F18,053 rows differed between the two runs.\n\n**Fix:** always pass `-s \u003Cfixed-integer>` and record the value used for any\npublication- or clinical-grade call.\n\n```bash\nBAGEL.py bf -i foldchange.foldchange -o bayes_factor.txt \\\n    -e CEGv2.txt -n NEGv1.txt -c Sample1,Sample2,Sample3 \\\n    -s 42                                   # fixed seed -- record this value\n```\n\nVerified directly: two `bf` runs against identical inputs with `-s 42` produced a\nbyte-identical `bayes_factor.txt` (`diff` clean across all 18,053 genes).\n\n**Trap, verified against build 115: `-s` is declared twice in BAGEL.py's own CLI** --\nonce for `-s\u002F--use-small-sample` (a flag) and once for `-s\u002F--seed` (an integer).\n`BAGEL.py bf --help` prints both and warns `The parameter -s is used more than once`;\npassing `-s \u003Cint>` binds to `--seed` (the later-declared option wins in Click's\nparser) -- confirmed by running `-s 42` and inspecting the resulting fold-assignment\nlog and byte-identical rerun, not just by reading `--help`. This is BAGEL.py's own\nbug, not this Skill's; verify with `--help` before relying on it in an environment\nrunning a different BAGEL2 build.\n\n## Precision-Recall Curve\n\n**Goal:** Empirically select BF threshold for a given precision\u002Frecall tradeoff.\n\n**Approach:** Run `BAGEL.py pr` to compute precision and recall at every BF level against CEGv2; pick the BF that gives desired precision.\n\n```bash\nBAGEL.py pr \\\n    -i bayes_factor.txt \\\n    -o precision_recall.txt \\\n    -e CEGv2.txt \\\n    -n NEGv1.txt\n# Output: precision_recall.txt - precision\u002Frecall at each BF threshold\n```\n\n**Practical BF ladder (regenerate precision and recall per screen with `BAGEL.py pr`):**\n\n| BF threshold | Use case |\n|--------------|----------|\n| 0 | Exploratory; highest recall |\n| 6 | Standard call (~90% posterior, Hart 2017) |\n| 12 | High-confidence |\n| 30 | Ultra-stringent; near-certain essentials |\n\n**Pick threshold based on application:** For exploratory hit calling, BF >0 with low precision is acceptable; for clinical-grade essentiality calls, BF >12 or higher.\n\n## Interpret BAGEL2 Results\n\n**Goal:** Stratify genes into essential, non-essential, and tumor-suppressor categories.\n\n**Approach:** Apply BF threshold to classify essentials; only classify negative-BF genes as tumor suppressors when the screen design actually expects enrichment (see Failure Modes below) -- verified on real HAP1 TKOv3 data (a dropout screen) that skipping this guard flags **86.5% of the genome** as tumor-suppressor, with three assay-control pseudo-genes (`LacZ`, `luciferase`, `EGFP`) as the top hits.\n\n```python\nimport pandas as pd\nimport warnings\n\n# Assay-control pseudo-genes spiked into CRISPR libraries (never real biology) --\n# verified present and dominating the naive tumor-suppressor call on real HAP1 TKOv3\n# output; extend this set to match your library's own controls.\nASSAY_CONTROLS = {'LacZ', 'luciferase', 'EGFP'}\n\ndef interpret_bagel(bf_path, bf_essential=6, bf_tumor_suppressor=-6,\n                     screen_type='dropout', control_genes=ASSAY_CONTROLS,\n                     tumor_suppressor_frac_warn=0.05):\n    '''Classify genes from BAGEL2 BF output.\n\n    screen_type: 'dropout' (default) only calls `essential`. Tumor-suppressor calls\n    require screen_type='enrichment' or 'both' -- per the Failure Modes section below,\n    a pure dropout screen's negative-BF genes are noise, not tumor suppressors.\n    '''\n    df = pd.read_csv(bf_path, sep='\\t')\n    df = df[~df['GENE'].isin(control_genes)].copy()   # drop assay-control pseudo-genes\n    df['call'] = 'neutral'\n    df.loc[df['BF'] > bf_essential, 'call'] = 'essential'\n    if screen_type in ('enrichment', 'both'):\n        df.loc[df['BF'] \u003C bf_tumor_suppressor, 'call'] = 'tumor_suppressor'\n        frac = (df['call'] == 'tumor_suppressor').mean()\n        if frac > tumor_suppressor_frac_warn:\n            warnings.warn(\n                f\"{frac:.1%} of genes flagged tumor_suppressor -- implausibly high; \"\n                \"this usually means a dropout-only screen is being scored for \"\n                \"enrichment. Re-check screen_type and BF\u003C-6 calls against literature \"\n                \"before reporting.\"\n            )\n    return df.sort_values('BF', ascending=False)\n```\n\nVerified on real HAP1 TKOv3 data (a T0-vs-T18 dropout screen): the default\n(`screen_type='dropout'`) returns 0 tumor-suppressor calls and excludes the 3 control\npseudo-genes; explicit `screen_type='enrichment'` still surfaces the true tumor\nsuppressors TSC1\u002FTSC2 as the two most-negative-BF entries (now that the control genes\nthat previously masked them are excluded) but raises the 86.6%-flagged warning so the\ncaller doesn't report it uncritically.\n\n**Tumor suppressor identification:** Genes with significantly negative BF (e.g., \u003C-6) in a screen actually designed to detect enrichment (drug-resistance, GoF) indicate fitness advantage from their loss. This is biologically distinct from \"non-essential\" and may indicate tumor-suppressor function. BAGEL1 could not detect this; BAGEL2's linear extrapolation enables it. **Do not call tumor suppressors from a pure dropout screen** -- see Failure Modes.\n\n## Bayesian Reasoning Per Sgrna\n\n**Why this matters:** BAGEL2 computes per-sgRNA contributions; a gene with 4 sgRNAs each contributing +5 to BF gets +20 total. A gene with 3 sgRNAs contributing +5 and 1 sgRNA contributing -3 (off-target or low-efficacy) gets +12 net.\n\n**Approach:** Add `-r\u002F--sgrna-bayes-factors` to the `bf` command -- this flag is not\nmentioned elsewhere in this Skill but is required to get per-sgRNA output; found via\n`BAGEL.py bf --help`, not documented upstream either.\n\n```bash\nBAGEL.py bf \\\n    -i foldchange.foldchange \\\n    -o bayes_factor_sgrna.txt \\\n    -e CEGv2.txt -n NEGv1.txt \\\n    -c Sample1,Sample2,Sample3 \\\n    -s 42 -r                               # -r: per-sgRNA BF contributions\n# Output columns: RNA  GENE  \u003Csample columns>  BF  (one row per sgRNA)\n```\n\nVerified on real HAP1 TKOv3 data: for RPS3 (the example gene below), the 4 per-sgRNA\nBF values summed to 78.9 against a gene-level BF of 80.8 (within 2.4%), confirming the\nadditive-LLR model this section describes.\n\n**Critical:** When per-sgRNA contributions are very heterogeneous (one sgRNA dominates BF), the gene is \"guide-of-one\"; verify with JACKS efficiency analysis or apply the second-best-sgRNA rule from [[hit-calling]].\n\n## Comparing BAGEL2, MAGeCK, drugZ\n\n| Property | BAGEL2 | MAGeCK | drugZ |\n|----------|--------|--------|-------|\n| Statistical framework | Bayes factor with reference sets | NB GLM | Bidirectional Z-score |\n| Calibrated against | CEGv2 \u002F NEGv1 | Internal null | Vehicle distribution |\n| Tumor suppressor detection | YES | Limited (RRA positive-selection score) | YES |\n| Best for | Essentiality classification | General hit calling | Chemogenomic drug screens |\n| Output | Bayes factor + CI | FDR + LFC | Z-score + FDR per direction |\n| Hit threshold | BF >6 | FDR \u003C0.05 | FDR \u003C0.05 |\n| Library calibration | Indirect (reference set) | None | None |\n\n**Reconciliation:** BF >6 ≈ 90% posterior probability (Hart 2017 G3); commonly treated as roughly MAGeCK FDR 0.05 by convention. BAGEL2 hits absent from MAGeCK suggest weak signal that BAGEL2's reference anchoring detects but MAGeCK's null-based test misses; verify by inspecting per-sgRNA contributions.\n\n## Failure Modes\n\n### BAGEL2 returns no hits, crashes, or silently corrupts output on a bad reference set\n\n**Trigger:** Wrong reference gene set file -- species mismatch, thin\u002Funrepresentative reference, or `-e`\u002F`-n` swapped.\n**Mechanism:** The actual failure mode depends on *how* the reference is wrong, verified directly against three concrete misconfigurations (not one uniform symptom):\n- **Species mismatch** (e.g., a mouse CEG file against a human screen): hard crash, `ValueError: dataset input should have multiple elements` (`scipy.stats.gaussian_kde`) -- not a silent \"no hits\" run.\n- **`-e`\u002F`-n` arguments swapped** (an easy transcription mistake, not covered anywhere else in this Skill): `BAGEL.py bf` exits 0 and writes a complete-looking `bayes_factor.txt`, but **every gene's `BF` is the literal string `nan`** -- verified across all 18,053 genes on real data, no warning surfaced to the user.\n- **Genuinely thin\u002Funrepresentative reference** (too few genes, weak KDE separation): the \"median BF near zero, no genes >6\" symptom below does apply here.\n**Symptom:** Depends on failure type -- hard crash (species mismatch), all-`nan` BF column (swapped `-e`\u002F`-n`), or median BF near zero with no genes >6 (thin\u002Funrepresentative reference).\n**Fix:** Re-download CEGv2 \u002F NEGv1 from https:\u002F\u002Fgithub.com\u002Fhart-lab\u002Fbagel. Verify gene symbols match the screen's annotation. Before trusting a \"no hits\" reading, check `bayes_factor.txt` for an all-`nan` `BF` column -- that means `-e`\u002F`-n` were swapped, not that the screen is flat.\n\n### BAGEL2 calls negative-LFC genes \"tumor suppressors\"\n\n**Trigger:** Heavy dropout screen where many genes drop out; the dropout signal is captured as positive BF but the *enriched* genes (negative BF) are noise.\n**Mechanism:** BAGEL2's symmetric distribution treats deeply enriched genes as significant; in a dropout-only screen, the enrichment signal is purely noise.\n**Symptom:** Many genes with negative BF; these don't validate as tumor suppressors.\n**Fix:** Restrict tumor-suppressor calling to screens specifically expecting enrichment (e.g., drug-resistance, GoF screens); for dropout screens, only interpret positive BF.\n\n### Bootstrap CI is wide; BF estimates unstable\n\n**Trigger:** Per-gene number of sgRNAs too low (e.g., \u003C4 in some libraries).\n**Mechanism:** Bootstrap of LLR over very few sgRNAs creates wide CI.\n**Symptom:** STD column larger than BF; many genes have CI spanning zero.\n**Fix:** Use a library with at least 4-6 sgRNAs\u002Fgene; or switch to bootstrapping (`-b -NB 5000`); or filter out genes with \u003C3 sgRNAs.\n\n### Low BF for known essential despite high LFC\n\n**Trigger:** One sgRNA per gene is contributing very low LLR (off-target or low-efficacy).\n**Mechanism:** BAGEL2 sums LLR; one weak guide drags total down.\n**Symptom:** Known essential like RPS3 has BF \u003C6 despite 3 of 4 guides showing -5 LFC.\n**Fix:** Inspect per-sgRNA LLR; identify the dragging guide; verify whether to exclude or to use JACKS for efficacy-aware analysis.\n\n### Non-cancer cell-line screen with custom essentials\n\n**Trigger:** Human embryonic kidney HEK293T or iPSC-derived neurons where standard essentials may not be essential.\n**Mechanism:** CEGv2 is calibrated for cancer cell lines; some essentials in tumor cells are not essential in iPSC.\n**Symptom:** PR curve against CEGv2 shows poor separation; many CEGv2 essentials don't drop out.\n**Fix:** Use a cell-type-specific essentialome derived for the relevant lineage; or use MAGeCK \u002F Chronos which doesn't depend on reference sets.\n\n## Quantitative Thresholds\n\n| Threshold | Value | Source \u002F Rationale |\n|-----------|-------|--------------------|\n| Standard essentiality call | BF >6 | Hart 2017: BF>=6 ~ 90% posterior |\n| Stricter essentiality call | BF >12 | BAGEL convention; regenerate precision\u002Frecall per screen with `BAGEL.py pr` |\n| Ultra-stringent call | BF >30 | BAGEL convention |\n| BF for tumor-suppressor candidate | \u003C-6 | Empirical; verify with orthogonal screen |\n| Resampling | 10-fold cross-validation (default); `-b -NB 1000` to bootstrap | BAGEL2 default |\n| Seed for reproducible\u002Fpublication-grade calls | `-s \u003Cfixed-int>`, always | Unseeded runs flip up to 33\u002F18,053 gene calls at BF>6 (verified on HAP1 TKOv3, build 115) |\n| Min reads per sgRNA in control | 30 | Convention; the BAGEL2 default is 0 |\n| Min sgRNAs per gene for stable BF | 4-6 | Wider with library convention |\n\n## Common Errors\n\n| Error \u002F symptom | Cause | Solution |\n|-----------------|-------|----------|\n| No hits despite essentials present | Wrong reference set | Re-verify CEGv2 \u002F NEGv1 files |\n| Every gene's `BF` is `nan` | `-e`\u002F`-n` arguments swapped | Check argument order against the Output columns example; re-run |\n| Different BF\u002Fhit list on a rerun with identical inputs | No `-s` seed given (BAGEL.py defaults to a clock-based seed) | Always pass `-s \u003Cfixed-int>`, see Reproducibility section |\n| Wide resampling CI | Too few sgRNAs\u002Fgene | Increase library coverage; bootstrap with more iterations |\n| Negative BF for known essentials | Confounding factor (e.g., CN amplification) | Pre-correct with CRISPRcleanR \u002F Chronos |\n| Tumor suppressor calls don't validate | Pure dropout screen; enrichment is noise | Only call `interpret_bagel(..., screen_type='enrichment')` on screens actually expecting enrichment |\n| Per-sgRNA LLR dominated by one guide | Outlier or off-target | Apply second-best-sgRNA rule |\n\n## References\n\n- Kim E & Hart T. 2021. *Genome Medicine* 13:2. BAGEL2 algorithm and improvements.\n- Hart T & Moffat J. 2016. *BMC Bioinformatics* 17:164. BAGEL Bayes factor framework.\n- Hart T et al. 2017. *G3* 7:2719. CEGv2 core-essential reference set; BF posterior calibration.\n- Hart T et al. 2014. *Mol Syst Biol* 10:733. Gold-standard essential and non-essential reference sets; source of NEGv1.\n- Pacini C et al. 2021. *Nat Commun* 12:1661. Integrated cross-study dependencies; reference essentiality benchmarks.\n\n## Related Skills\n\n- crispr-screens\u002Fmageck-analysis - MAGeCK RRA\u002FMLE alternative\n- crispr-screens\u002Fjacks-analysis - JACKS for per-guide efficacy\n- crispr-screens\u002Fdrugz-chemogenomic - drugZ for drug screens\n- crispr-screens\u002Fhit-calling - Cross-method decision tree\n- crispr-screens\u002Fscreen-qc - Pre-BAGEL QC including CEGv2 PR-AUC\n- crispr-screens\u002Flibrary-design - 4-6 sgRNAs\u002Fgene library standard\n- crispr-screens\u002Fcopy-number-correction - Pre-correction for cancer-line screens\n- pathway-analysis\u002Fgo-enrichment - Downstream functional analysis\n",{"name":5,"tool_type":24,"description":7,"primary_tool":25},"cli","BAGEL2","main","e0956dc9606356ab78468936b502e55a365282e2","specialists\u002Fcrispr-screen-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-crispr-screens-bagel-essentiality",0,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists","https:\u002F\u002Fgithub.com\u002Fmrsonord2240","2026-10-12 03:19:04",{"source":8,"skillName":5,"commands":34,"prompt":44,"zipAvailable":45},[35,38,41],{"tool":36,"command":37},"npx","npx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-crispr-screens-bagel-essentiality",{"tool":39,"command":40},"bunx","bunx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-crispr-screens-bagel-essentiality",{"tool":42,"command":43},"pnpm","pnpm dlx skills add mrsonord2240\u002Fopenscience-specialists --skill bio-crispr-screens-bagel-essentiality","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fcrispr-screen-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-crispr-screens-bagel-essentiality\u002FSKILL.md",true,[47,53],{"path":48,"resourceType":49,"resourceTypeDesc":50,"sizeBytes":51,"sourceHtmlUrl":52},"examples\u002Frun_bagel2.sh","SCRIPT","脚本",2981,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fcrispr-screen-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-crispr-screens-bagel-essentiality\u002Fexamples\u002Frun_bagel2.sh",{"path":54,"resourceType":55,"resourceTypeDesc":56,"sizeBytes":57,"sourceHtmlUrl":58},"usage-guide.md","REFERENCE","参考文档",8522,"https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Fcrispr-screen-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-crispr-screens-bagel-essentiality\u002Fusage-guide.md",[60,67,74,81,88,95],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":19},"01M7CW36A6QAGWFE2C008M1XPG","bio-workflows-metabolomics-pipeline","Orchestrates the untargeted LC-MS metabolomics pipeline end-to-end (xcms 4.x feature extraction, QC\u002Fdrift\u002Fnormalization, confidence-stratified annotation, permutation-validated statistics, background-aware pathway mapping), naming what each stage decides and where it silently fails. Use when running a full LC-MS metabolomics study from raw mzML to enriched pathways and needing the honest handoffs between stages. Each stage defers to its component skill for parameters and traps; for stable-isotope flux (a separate branch, not this untargeted flow) see metabolomics\u002Fisotope-tracing.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-workflows-metabolomics-pipeline\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M7CW2Y18623NA2S1Y30FRQW1","bio-metabolomics-xcms-preprocessing","Programmatic untargeted LC-MS feature extraction in R with the modern xcms 4.x MsExperiment\u002FXcmsExperiment API, taking raw mzML to a feature table via CentWave peak detection, retention-time alignment, peak-density correspondence, gap-filling, CAMERA redundancy collapse, and built-in QC feature filtering. Use when converting centroided LC-MS runs into a features-by-samples matrix and deciding centWave\u002Fgrouping\u002Falignment parameters. For drift correction and QC\u002FCV filtering execution see metabolomics\u002Fnormalization-qc; for metabolite identification see metabolomics\u002Fmetabolite-annotation; for the MS-DIAL GUI alternative with MS2Dec deconvolution see metabolomics\u002Fmsdial-preprocessing; for downstream statistics see metabolomics\u002Fstatistical-analysis.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-xcms-preprocessing\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M7CW2M364HVWPNQEKE2WP4PP","bio-metabolomics-statistical-analysis","Decision-grade statistical analysis for metabolomics intensity tables. Covers transformation and scaling (Pareto vs unit-variance as a hidden hypothesis), unsupervised structure (PCA\u002FHCA for QC), permutation-validated PLS-DA\u002FOPLS-DA (R2 vs Q2, double CV, VIP as heuristic), univariate testing (Welch\u002FMann-Whitney\u002FANOVA\u002FLMM with covariate adjustment), and dependence-aware multiple testing. Use when testing which metabolites differ, building or validating a discriminant model, choosing a scaling, or correcting many correlated tests. For sample-wise normalization\u002Fdrift correction see metabolomics\u002Fnormalization-qc; for ML classifiers and selection-inside-CV leakage see machine-learning\u002Fbiomarker-discovery and machine-learning\u002Fmodel-validation; for pathway interpretation see metabolomics\u002Fpathway-mapping; for design\u002Fpower\u002Fmultiplicity regime see experimental-design\u002Fmultiple-testing.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-statistical-analysis\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M7CW2BCBF851WYE03Z8XPEDQ","bio-metabolomics-pathway-mapping","Maps metabolomics results to biological pathways via over-representation (ORA), metabolite-set enrichment (MSEA\u002FQEA), mummichog\u002FPSEA on raw m\u002Fz peaks, and network-diffusion enrichment (FELLA), with correct background-set construction and honest interpretive ceilings. Use when interpreting differential metabolites or an untargeted LC-MS feature table in pathway context, choosing ORA vs MSEA vs mummichog vs topology, or setting the reference\u002Fbackground set. For annotation confidence levels feeding ORA see metabolomics\u002Fmetabolite-annotation; for gene-set concepts see pathway-analysis\u002Fgo-enrichment and pathway-analysis\u002Fgsea; for joint gene+metabolite pathways see multi-omics-integration\u002Fmofa-integration.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-pathway-mapping\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M7CW21NSZMCPMF7D9CHJM718","bio-metabolomics-normalization-qc","Designs QC, corrects signal drift, removes batch effects, filters features, normalizes samples, and imputes missing values for untargeted LC-MS\u002FGC-MS metabolomics, framing each step as a measurement model that can create or erase biological signal. Use when processing a peak\u002Ffeature table before statistical analysis, choosing a drift-correction or sample-normalization method, deciding QC RSD vs D-ratio filtering, or handling left-censored missing values. The feature table is produced by metabolomics\u002Fxcms-preprocessing or metabolomics\u002Fmsdial-preprocessing; transformation\u002Fscaling for modeling defers to metabolomics\u002Fstatistical-analysis; cross-study design issues link to experimental-design\u002Fbatch-design.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-normalization-qc\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":19},"01M7CW1SWVM0NYHVE6Q7MA3G7R","bio-metabolomics-msdial-preprocessing","Runs the MS-DIAL preprocessing workflow (peak picking, MS2Dec spectral deconvolution, alignment, gap-filling) and imports the alignment-result table into R or Python with honest filtering. Use when preprocessing LC-MS DDA\u002FDIA (SWATH) or GC-MS raw data with MS-DIAL, deciding MS-DIAL vs XCMS, configuring the MSDIALCUI console run, or parsing an MS-DIAL export into a clean feature matrix. For programmatic R peak detection and the feature-table-as-artifact framing see metabolomics\u002Fxcms-preprocessing; for lipid annotation mode see metabolomics\u002Flipidomics; for MSI-level confidence honesty see metabolomics\u002Fmetabolite-annotation; for drift correction and QC see metabolomics\u002Fnormalization-qc.","https:\u002F\u002Fgithub.com\u002Fmrsonord2240\u002Fopenscience-specialists\u002Fblob\u002Fmain\u002Fspecialists\u002Funtargeted-metabolomics-analyst\u002Fversions\u002F1.0.0\u002Fpackage\u002Fskills\u002Fbio-metabolomics-msdial-preprocessing\u002FSKILL.md",[],[]]