diff --git a/code/SoS/association_scan/TensorQTL/TensorQTL.ipynb b/code/SoS/association_scan/TensorQTL/TensorQTL.ipynb index b7c88b61a..a62b12f67 100644 --- a/code/SoS/association_scan/TensorQTL/TensorQTL.ipynb +++ b/code/SoS/association_scan/TensorQTL/TensorQTL.ipynb @@ -8,7 +8,7 @@ "source": [ "# QTL Association Testing (TensorQTL)\n", "\n", - "This notebook performs cis- and trans-QTL association testing using [TensorQTL](https://doi.org/10.1186/s13059-019-1836-7). For each molecular phenotype it tests association against nearby (cis) or genome-wide (trans) genetic variants and reports nominal and region-level statistics." + "Tests each molecular phenotype for association with nearby (cis) or genome-wide (trans) genetic variants using [TensorQTL](https://doi.org/10.1186/s13059-019-1836-7), reporting both nominal pair statistics and region-level significance." ] }, { @@ -17,16 +17,17 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "Two workflows are available:\n", + "The model is the standard QTL regression: each molecular phenotype is regressed on each candidate variant, with the covariate matrix (known covariates plus hidden factors) entering every fit. TensorQTL evaluates those regressions as batched tensor operations, on GPU when one is available and on CPU otherwise, which is what makes a genome-wide scan tractable. Two workflows expose that model.\n", "\n", - "- `cis` : association between each molecular phenotype and variants within a window around it (default 1 Mb around the TSS). Produces nominal pair statistics plus region (gene) level significance.\n", - "- `trans`: association between phenotypes and variants on a chosen genotype chromosome, optionally restricted to a region list.\n", + "`cis` tests each phenotype against the variants near it. The search region is a symmetric radius around the phenotype set by `--window`, 1 Mb by default, or an explicit per-region interval supplied through `--customized-cis-windows`, in which case `--window` is forced to zero. It runs as two chained steps: the first computes nominal statistics for every variant-phenotype pair on a chromosome and, unless `--no-permutation` is given, a permutation pass that fits a beta distribution to each region null; the second gathers the per-chromosome results into a single region-level table carrying permutation and beta-approximation p-values with q-values and Benjamini-Hochberg FDR.\n", "\n", - "Inputs are the by-chromosome genotype/phenotype file lists and the covariate matrix produced by the genotype, phenotype, and covariate preprocessing steps.\n", + "`trans` tests phenotypes against variants far from them. A full scan is every phenotype against every variant, so memory rather than arithmetic is the binding constraint. The step therefore handles one phenotype chromosome at a time and loads a single genotype chromosome, named by `--trans-geno-chromosome`, so a genome-wide analysis is assembled from chromosome pairs rather than held in memory at once. Results are thinned as they are produced: `--pval` discards pairs above a nominal cutoff and records that cutoff in the output file name, while `--pvalue-cutoff` and `--qvalue-cutoff` set the significance filter applied to what remains. Permutation defaults to off here, because a null permuted within one chromosome is not the genome-wide null.\n", "\n", - "**Timing:** cis ~1 min; trans ~1.5 min on the toy dataset." + "How rare a variant may be is controlled in both workflows by `--MAC`, a minor-allele-count floor, or by `--maf-threshold`, which overrides it with a frequency floor.\n", + "\n", + "**When to run it.** After genotype, phenotype, and covariate preprocessing, which produce the by-chromosome file lists and the covariate matrix consumed here. The nominal summary statistics are the input to fine-mapping (`mnm_regression`) and to colocalization; the region-level table is what downstream enrichment and reporting read." ] }, { @@ -35,14 +36,50 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", - "\n", - "| Parameter | Toy file | Description |\n", - "|---|---|---|\n", - "| `--genotype-file` | `output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt` | Two-column list (chrom id, PLINK bed prefix) of by-chromosome genotypes |\n", - "| `--phenotype-file` | `output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt` | List of bgzipped+tabixed molecular phenotype `bed.gz` files by chromosome |\n", - "| `--covariate-file` | `output/covariate/...prune.pca.Marchenko_PC.gz` | Covariate matrix (known covariates + hidden factors) |\n", - "| `--region-list` | `data/combined_AD_genes.csv` | (trans, optional) subset of regions/genes to analyze; gene name in column 4 |" + "## Input\n", + "\n", + "Required:\n", + "\n", + "* `--phenotype-file` -- one bgzipped and tabixed molecular phenotype `bed.gz`, or a text file listing one such file per chromosome, e.g. `output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt`.\n", + "* `--genotype-file` -- a PLINK bed/bim/fam prefix, or a two-column list of chromosome ID and PLINK prefix, e.g. `output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt`. Only chromosomes present in both lists are analyzed, which is chr22 alone in the toy data.\n", + "* `--covariate-file` -- the covariate matrix, known covariates plus hidden factors, e.g. `output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz`.\n", + "* `--name` -- prefix for every output file, e.g. `protocol_example`.\n", + "\n", + "Scope of the test:\n", + "\n", + "* `--window` -- cis radius in bp around each phenotype, default `1000000`.\n", + "* `--customized-cis-windows` -- four-column bed (chr, start, end, region ID) giving an explicit window per region; supplying it forces `--window` to zero.\n", + "* `--region-list` and `--region-list-phenotype-column` -- restrict the analysis to the regions named in a file, reading names from the given column (default `4`).\n", + "* `--trans-geno-chromosome` -- for `trans`, the single genotype chromosome to load; without it the step uses the chromosome that came in with the phenotype.\n", + "* `--chromosome` -- restrict to particular phenotype chromosomes.\n", + "* `--phenotype-group` -- group file mapping molecular traits into trait objects, for cases such as sQTL where one region holds several events.\n", + "* `--keep-sample` -- list of samples to retain.\n", + "* `--covariate-pattern` -- keep only covariates whose names match these prefixes or exact names.\n", + "* `--interaction` -- a file holding an interaction term when it is not already a covariate column; the name of its first column becomes the interaction name and is written into the output file names.\n", + "\n", + "Thresholds:\n", + "\n", + "* `--MAC` -- minor-allele-count floor, default `0`. `--MAC 5` is used below because the toy cohort is small.\n", + "* `--maf-threshold` -- minor-allele-frequency floor; overrides `--MAC` when set.\n", + "* `--permutation` / `--no-permutation` -- region-level permutation testing, on by default for `cis` and off for `trans`.\n", + "* `--pval`, `--pval-threshold`, `--pvalue-cutoff`, `--qvalue-cutoff` -- nominal and significance filters for `trans`.\n", + "* `--skip-nominal-if-exist` -- reuse existing nominal `parquet` files instead of recomputing them.\n", + "\n", + "Runtime:\n", + "\n", + "* `--cwd` -- output directory, default `output`.\n", + "* `--numThreads`, `--batch-size`, `--job-size`, `--walltime`, `--mem` -- threads, variants per tensor batch, and cluster resources.\n", + "* `--container`, `--entrypoint` -- software environment.\n", + "* `--modular-script-dir` -- location of the Python driver, default `code/script`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Example phenotype file" ] }, { @@ -198,12 +235,12 @@ "\t<int><chr>\n", "\n", "\n", - "\t 2/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed \n", - "\t 6/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed \n", - "\t13/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed\n", - "\t 8/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed \n", - "\t 7/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed \n", - "\t11/restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed\n", + "\t 2/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed \n", + "\t 6/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed \n", + "\t13/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed\n", + "\t 8/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed \n", + "\t 7/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed \n", + "\t11/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed\n", "\n", "\n" ], @@ -213,12 +250,12 @@ " \\#id & \\#path\\\\\n", " & \\\\\n", "\\hline\n", - "\t 2 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.2.bed \\\\\n", - "\t 6 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.6.bed \\\\\n", - "\t 13 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.13.bed\\\\\n", - "\t 8 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.8.bed \\\\\n", - "\t 7 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.7.bed \\\\\n", - "\t 11 & /restricted/projectnb/xqtl/jaempawi/xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.11.bed\\\\\n", + "\t 2 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.2.bed \\\\\n", + "\t 6 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.6.bed \\\\\n", + "\t 13 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.13.bed\\\\\n", + "\t 8 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.8.bed \\\\\n", + "\t 7 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.7.bed \\\\\n", + "\t 11 & /xqtl\\_protocol/toy\\_example/output/genotype\\_by\\_chrom/protocol\\_example.genotype.merged.plink\\_qc.11.bed\\\\\n", "\\end{tabular}\n" ], "text/markdown": [ @@ -227,12 +264,12 @@ "\n", "| #id <int> | #path <chr> |\n", "|---|---|\n", - "| 2 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed |\n", - "| 6 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed |\n", - "| 13 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed |\n", - "| 8 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed |\n", - "| 7 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed |\n", - "| 11 | /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed |\n", + "| 2 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed |\n", + "| 6 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed |\n", + "| 13 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed |\n", + "| 8 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed |\n", + "| 7 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed |\n", + "| 11 | /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed |\n", "\n" ], "text/plain": [ @@ -244,12 +281,12 @@ "5 7 \n", "6 11 \n", " #path \n", - "1 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed \n", - "2 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed \n", - "3 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed\n", - "4 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed \n", - "5 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed \n", - "6 /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed" + "1 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.2.bed \n", + "2 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.6.bed \n", + "3 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.13.bed\n", + "4 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.8.bed \n", + "5 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.7.bed \n", + "6 /xqtl_protocol/toy_example/output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.11.bed" ] }, "metadata": {}, @@ -670,111 +707,60 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Output\n", "\n", - "**cis** (`output/tensorqtl_cis/`):\n", + "* `._.cis_qtl.pairs.tsv.gz` (with `.tbi`) -- nominal statistics for every variant-phenotype pair tested in cis:\n", "\n", - "| File | Description |\n", - "|---|---|\n", - "| `*.cis_qtl.pairs.tsv.gz` (+`.tbi`) | Nominal variant-phenotype association statistics |\n", - "| `*.cis_qtl_regional_significance.tsv.gz` | Region (gene) level significance |\n", - "| `*.cis_qtl_regional_significance.summary.txt` | Summary of regional results |\n", - "| `*.cis_qtl_pairs..parquet` | Per-chromosome nominal results (parquet) |\n", + " ```\n", + " chrom\tpos\tmolecular_trait_id\tvariant_id\ttss_distance\ttes_distance\taf\tma_samples\tma_count\tpvalue\t\n", + " 22\t10685239\tENSG00000283047\tchr22:10685239_C_T\t-254148\t-276098\t0.059322033\t7\t7\t0.572662489372593\n", + " 22\t10761227\tENSG00000283047\tchr22:10761227_G_A\t-178160\t-200110\t0.15254237\t18\t18\t0.75215622793613\n", + " ```\n", "\n", - "**trans** (`output/tensorqtl_trans/`):\n", + "* `..cis_qtl_pairs..parquet` -- the same nominal results in the columnar form TensorQTL writes natively, kept so that a rerun with `--skip-nominal-if-exist` need not recompute them.\n", + "* `._.cis_qtl_regional_significance.tsv.gz` (with `.tbi`) -- one row per region carrying the top variant, the fitted beta parameters, permutation and beta-approximation p-values, q-values, FDR, and the per-region genomic inflation factor:\n", "\n", - "| File | Description |\n", - "|---|---|\n", - "| `*_geno_.trans_qtl.pairs.tsv.gz` (+`.tbi`) | Trans variant-phenotype association statistics |" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Steps\n", + " ```\n", + " chrom\tpos\tn_variants\tbeta_shape1\tbeta_shape2\ttrue_df\tp_true_df\tvariant_id\ttss_distance\ttes_dista\n", + " 22\t11797697\t6\t0.9833031\t5.6122484\t30.858135\t0.0676042590649028\tchr22:11797697_C_T\t858310\t836360\t\n", + " ```\n", "\n", - "The commands below run on the included toy data and write results under `--cwd`. The genotype, phenotype, and covariate inputs are produced by the preprocessing notebooks." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### cis-QTL association\n", + "* `._.cis_qtl_regional_significance.summary.txt` -- how many traits were tested and how many pass each threshold, written by the collecting step:\n", "\n", - "Test each molecular phenotype against variants within the cis window. Matching chromosomes between the genotype and phenotype lists are analyzed (chr22 in the toy data). `--MAC 5` sets the minor-allele-count cutoff for the small toy sample." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "Bash" - }, - "outputs": [], - "source": [ - "sos run pipeline/TensorQTL.ipynb cis \\\n", - " --genotype-file output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt \\\n", - " --phenotype-file output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt \\\n", - " --covariate-file output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", - " --cwd output/tensorqtl_cis --name protocol_example --MAC 5 --numThreads 2" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### trans-QTL association\n", + " ```\n", + " TensorQTL cis-QTL regional significance summary\n", + " Input files: 1\n", + " Chromosomes: 1\n", + " Molecular traits tested: 200\n", + " Molecular trait objects: 200\n", + " \n", + " ```\n", "\n", - "For trans-analysis:\n", + "* `.<...>.cis_qtl.pairs.tsv.gz.cis_regional..fdr.gz` -- the region-level table repeated under each multiple-testing correction: `permutation_adjusted`, and Bonferroni with Benjamini-Hochberg over the original and the filtered variant sets.\n", + "* `.<...>.maf__window__cis_n_variants_stats.tsv.gz` -- variants tested per region at the MAF and window actually applied:\n", "\n", - " **Computational strategy designed for trans analysis:**\n", - " \n", - " Trans analysis faces significant memory challenges as we calculate all associations between all molecular traits × all genetic variants across the genome, creating a massive computational burden. To address this challenge, we implement a two-stage chromosome-based parallelization approach:\n", + " ```\n", + " chrom\tmolecular_trait_object_id\tn_variants\tn_variants_filtered\n", + " chr22\tENSG00000063515\t44\t44\n", + " chr22\tENSG00000075234\t111\t111\n", + " ```\n", "\n", - " **Stage 1 (trans_1): Chromosome-based parallelization**\n", - " - Phenotype data is processed per chromosome (e.g., 22 separate jobs for autosomes)\n", - " - For each phenotype chromosome, we test associations against variants from all 22 chromosomes\n", - " - This creates phenotype_chr × genotype_chr combinations (e.g., phenotype chr1 vs genotype chr1-22); Garbage was collected between each chromosome combination caculation to release memory\n", - " - Results are combined across all chromosome combinations and saved as compressed files\n", + "* `._geno_chr.trans_qtl.pairs.tsv.gz` (with `.tbi`) -- trans statistics for the loaded genotype chromosome, with the phenotype and genotype chromosome recorded on each row; the file name gains `_p_` when `--pval` is set:\n", "\n", - " **Stage 2 (trans_2): Significance filtering**\n", - " - Supports p-value cutoffs (`--pvalue-cutoff`) or q-value cutoffs (`--qvalue-cutoff`)\n", + " ```\n", + " chrom\tpos\tvariant_id\tmolecular_trait_id\tpvalue\tbhat\tsebhat\tr2\taf\tn\tpheno_chrom\tgeno_chrom\tqvalue\n", + " 22\t10685239\tchr22:10685239_C_T\tENSG00000063515\t0.202382946055137\t-3.4470642\t2.6448517\t0.05358654\n", + " ```\n", "\n", + "* `._geno_chr.trans_qtl.genomic_inflation.tsv.gz` -- the genomic inflation factor of the trans scan for each molecular trait:\n", "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Test phenotypes against variants on a chosen genotype chromosome (`--trans-geno-chromosome 22`), restricted to the genes in `--region-list`. Trans analysis is memory-heavy genome-wide; here it is scoped to the toy chromosome." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "Bash" - }, - "outputs": [], - "source": [ - "sos run pipeline/TensorQTL.ipynb trans \\\n", - " --genotype-file output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt \\\n", - " --phenotype-file output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt \\\n", - " --covariate-file output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", - " --cwd output/tensorqtl_trans --name protocol_example --MAC 5 --numThreads 2 \\\n", - " --trans-geno-chromosome 22 --region-list data/combined_AD_genes.csv --region-list-phenotype-column 4" + " ```\n", + " molecular_trait_id\tgenomic_inflation_lambda\n", + " ENSG00000063515\t0.9919021540170271\n", + " ENSG00000075234\t1.1570695153778894\n", + " ```\n", + "\n", + "Every step writes `.stdout` and `.stderr` beside its output. Example results for the toy data are under `output/tensorqtl_cis/` and `output/tensorqtl_trans/`." ] }, { @@ -783,7 +769,7 @@ "kernel": "SoS" }, "source": [ - "## Output \n", + "### Result tables \n", "\n", "For each chromosome, several summary statistics files are generated, including both nominal test statistics for each test and region (gene) level association evidence. \n", "\n", @@ -811,7 +797,7 @@ "\n", "### Interaction Association Results \n", "\n", - "The columns of interaction association results are as follows (FIXME): \n", + "Interaction results are produced when `--interaction` is set. The column names carry the name of the interaction variable, shown here for `msex`: \n", "\n", "**Model:** \n", "$$\n", @@ -828,17 +814,17 @@ "- **a1**: Variant alternate allele. \n", "- **molecular_trait_id**: Molecular trait identifier, varies from phenotypes to phenotypes. \n", "- **variant_id**: ID of the top variant (rsid or chr:position:ref:alt). \n", - "- **af**: Alternative allele frequency in the MiGA cohort. \n", + "- **af**: Alternative allele frequency in the cohort analyzed. \n", "- **ma_samples**: Number of samples carrying the minor allele. \n", "- **ma_count**: Total number of minor alleles across individuals. \n", - "- **pvalue**: P-value of the main effect from the nonlinear regression. \n", - "- **bhat**: Slope of the main effect from the nonlinear regression. \n", + "- **pvalue**: P-value of the main effect from the interaction model. \n", + "- **bhat**: Slope of the main effect from the interaction model. \n", "- **se**: Standard error of beta. \n", - "- **pvalue_msex**: P-value of the msex term from the nonlinear regression. \n", - "- **bhat_msex**: Slope of the msex term from the nonlinear regression. \n", + "- **pvalue_msex**: P-value of the msex term from the interaction model. \n", + "- **bhat_msex**: Slope of the msex term from the interaction model. \n", "- **se_msex**: Standard error of bhat_msex. \n", - "- **pvalue_msex_interaction**: P-value of the interaction term from the nonlinear regression. \n", - "- **bhat_msex_interaction**: Slope of the interaction term from the nonlinear regression. \n", + "- **pvalue_msex_interaction**: P-value of the interaction term from the interaction model. \n", + "- **bhat_msex_interaction**: Slope of the interaction term from the interaction model. \n", "- **se_msex_interaction**: Standard error of beta_msex_interaction. \n", "- **molecular_trait_object_id**: An intermediate ID (can be ignored). \n", "- **n**: Number of samples.\n", @@ -885,9 +871,89 @@ "kernel": "SoS" }, "source": [ - "### Command interface\n", + "## Minimal Working Example\n", "\n", - "List all workflows and options:" + "The commands below run on the included toy data and write results under `--cwd`. The genotype, phenotype, and covariate inputs are produced by the preprocessing notebooks." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### cis-QTL association\n", + "\n", + "Test each molecular phenotype against variants within the cis window. Matching chromosomes between the genotype and phenotype lists are analyzed (chr22 in the toy data). `--MAC 5` sets the minor-allele-count cutoff for the small toy sample." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/TensorQTL.ipynb cis \\\n", + " --genotype-file output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt \\\n", + " --phenotype-file output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt \\\n", + " --covariate-file output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", + " --cwd output/tensorqtl_cis --name protocol_example --MAC 5 --numThreads 2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### trans-QTL association\n", + "\n", + "Test phenotypes against variants on a chosen genotype chromosome (`--trans-geno-chromosome 22`), restricted to the genes in `--region-list`. Trans analysis is memory-heavy genome-wide; here it is scoped to the toy chromosome." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/TensorQTL.ipynb trans \\\n", + " --genotype-file output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt \\\n", + " --phenotype-file output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt \\\n", + " --covariate-file output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", + " --cwd output/tensorqtl_trans --name protocol_example --MAC 5 --numThreads 2 \\\n", + " --trans-geno-chromosome 22 --region-list data/combined_AD_genes.csv --region-list-phenotype-column 4" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command Interface" ] }, { @@ -907,7 +973,117 @@ "kernel": "SoS" }, "source": [ - "## Pipeline Code\n", + "```\n", + "usage: sos run pipeline/TensorQTL.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " cis\n", + " trans\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " Path to the work directory of the analysis.\n", + " --phenotype-file VAL (as path, required)\n", + " Phenotype file, or a list of phenotype per region.\n", + " --genotype-file VAL (as path, required)\n", + " A genotype file in PLINK binary format (bed/bam/fam)\n", + " format, or a list of genotype per chrom\n", + " --covariate-file VAL (as path, required)\n", + " Covariate file\n", + " --covariate-pattern (as list)\n", + " Optional pattern to filter covariates (list of covariate\n", + " prefixes or exact names)\n", + " --name VAL (as str, required)\n", + " Prefix for the analysis output\n", + " --region-list . (as path)\n", + " An optional subset of regions of molecular features to\n", + " analyze. The last column is the gene names\n", + " --region-list-phenotype-column 4 (as int)\n", + " --keep-sample . (as path)\n", + " Set list of sample to be keep\n", + " --interaction ''\n", + " FIXME: please document\n", + " --customized-cis-windows . (as path)\n", + " An optional list documenting the custom cis window for\n", + " each region to analyze, with four column, chr, start,\n", + " end, region ID (eg gene ID). If this list is not\n", + " provided, the default `window` parameter (see below)\n", + " will be used.\n", + " --phenotype-group . (as path)\n", + " The phenotype group file to group molecule_trait into\n", + " molecule_trait_object This applies to multiple molecular\n", + " events in the same region, such as sQTL analysis.\n", + " --chromosome (as list)\n", + " The name of phenotype corresponding to gene_id or\n", + " gene_name in the region\n", + " --MAC 0 (as int)\n", + " Minor allele count cutoff\n", + " --trans-geno-chromosome ''\n", + " Specify genotype chromosome for trans analysis (e.g.\n", + " --trans-geno-chromosome 5) When set, trans step loads\n", + " this genotype chrom instead of the one from input_files\n", + " --window 1000000 (as int)\n", + " Specify the cis window for the up and downstream radius\n", + " to analyze around the region of interest in units of bp\n", + " This parameter will be set to zero if\n", + " `customized_cis_windows` is provided.\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 12h\n", + " --mem 16G\n", + " --container ''\n", + " Container option for software to run the analysis:\n", + " docker or singularity\n", + " --entrypoint ''\n", + " --maf-threshold MAC/(2.0*N)\n", + "\n", + " Minor allele frequency cutoff. It will overwrite minor\n", + " allele cutoff. You may consider setting it to higher for\n", + " interaction analysis if you have statistical power\n", + " concerns\n", + " --pvalue-cutoff '5e-8'\n", + " Filtering significant trans associations (for trans_2\n", + " workflow)\n", + " --qvalue-cutoff ''\n", + "\n", + "Sections\n", + " cis_1:\n", + " Workflow Options:\n", + " --[no-]skip-nominal-if-exist (default to False)\n", + " parse input file lists skip nominal association results\n", + " if the files exists already This is false by default\n", + " which means to recompute everything This is only\n", + " relevant when the `parquet` files for nominal results\n", + " exist but not the other files and you want to avoid\n", + " computing the nominal results again\n", + " --[no-]permutation (default to True)\n", + " cis_2:\n", + " trans:\n", + " Workflow Options:\n", + " --batch-size 10000 (as int)\n", + " --pval-threshold 1.0 (as float)\n", + " --[no-]permutation (default to False)\n", + " Permutation testing is incorrect when the analysis is\n", + " done by chrom\n", + " --pval 0.0 (as float)\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation\n", "\n", "The SoS workflow definitions below are unchanged from the original protocol." ] @@ -1193,17 +1369,6 @@ " Rscript ${modular_script_dir}/association_scan/TensorQTL/TensorQTL.R \\\n", " trans_qvalues \"${_output['nominal']}\"\n" ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] } ], "metadata": { diff --git a/code/SoS/association_scan/qtl_association_postprocessing.ipynb b/code/SoS/association_scan/qtl_association_postprocessing.ipynb index 9766c05bc..9d7e402cf 100644 --- a/code/SoS/association_scan/qtl_association_postprocessing.ipynb +++ b/code/SoS/association_scan/qtl_association_postprocessing.ipynb @@ -8,7 +8,7 @@ "source": [ "# Hierarchical Multiple Testing\n", "\n", - "This is a runnable, toy-data example of the `qtl_association_testing` post-processing step. It performs hierarchical multiple-testing correction on the per-gene cis-QTL association results produced by TensorQTL, then archives the bulky intermediate files." + "Applies hierarchical multiple-testing correction to the per-gene cis-QTL results from TensorQTL and assembles the survivors into one consolidated object." ] }, { @@ -17,11 +17,25 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "Given the per-gene association output from a cis-QTL scan, this pipeline implements a three-step hierarchical procedure: (1) local adjustment of the p-values of all cis-variants within each gene, (2) global adjustment of the minimum adjusted p-value across genes, and (3) identification of significant xQTL whose locally adjusted p-value falls below the threshold. It also reorganises the intermediate TensorQTL files into an archive folder for book-keeping or deletion.\n", + "A cis scan reports a p-value for every variant against every molecular phenotype, which is\n", + "not yet a result: the variants within a gene's window are correlated and the genes are\n", + "many, so raw p-values overstate significance twice over.\n", "\n", - "The same `default` workflow handles three flavours of upstream results: the **genetic (cis) effect** (shown below), the **interaction effect** (run on `*.cis_qtl_top_assoc.txt.gz` with `--maf-cutoff 0 --cis-window 0` and interaction p/q-value patterns), and **quantile QTL**. This example demonstrates the genetic-effect flavour on toy data. (cf. Huang et al. 2018)" + "The correction is hierarchical, in three steps: local adjustment of the p-values of all cis\n", + "variants within each gene, global adjustment of the minimum adjusted p-value across genes,\n", + "then selection of the xQTLs whose locally adjusted p-value falls below the threshold\n", + "(the eigenMT-BH procedure of [Huang et al. 2018, *NAR* 46(22):e133](https://doi.org/10.1093/nar/gky780)). The survivors are packaged as a `QtlSumStats` object with a\n", + "regional FDR table, and the intermediate TensorQTL files are reorganised into an archive\n", + "folder for book-keeping or deletion.\n", + "\n", + "The same `default` workflow handles three flavours of upstream result: the genetic (cis)\n", + "effect shown below, the interaction effect - run on `*.cis_qtl_top_assoc.txt.gz` with\n", + "`--maf-cutoff 0 --cis-window 0` and the interaction p/q-value patterns - and quantile QTL.\n", + "\n", + "**When to run it.** Immediately after `TensorQTL`, before fine-mapping. Nothing downstream\n", + "reads the raw scan directory directly." ] }, { @@ -30,7 +44,44 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~1-2 min on typical compute infrastructure." + "## Input\n", + "\n", + "The workflow is pointed at a directory rather than at files: it globs `--cwd` for the three TensorQTL products below using `--regional-pattern`, `--qtl-pattern` and `--n-variants-suffix`. `output/tensorqtl_cis` is one directory in that shape.\n", + "\n", + "- `--cwd`: the TensorQTL working directory holding the scan output. Three kinds of file are picked up from it.\n", + "\n", + " The per-gene regional result, matched by `--regional-pattern` (default `cis_qtl[.]regional[.]tsv[.]gz$`). Example `output/tensorqtl_cis/protocol_example.chr22_chr22.cis_qtl.regional.tsv.gz`, 21 columns and 201 rows:\n", + "\n", + " ```\n", + " chrom pos n_variants beta_shape1 beta_shape2 true_df p_true_df variant_id\n", + " 22 11797697 6 0.9833031 5.6122484 30.858135 0.0676042590649028 chr22:11797697_C_T\n", + " 22 15838003 46 0.98497593 26.038029 30.771364 0.007232871450238482 chr22:15838003_CTTTC...\n", + " ```\n", + "\n", + " The full variant-level pairs file, matched by `--qtl-pattern` (default `cis_qtl[.]pairs[.]tsv[.]gz$`). Example `output/tensorqtl_cis/protocol_example.chr22_chr22.cis_qtl.pairs.tsv.gz`, 15 columns and 18319 rows:\n", + "\n", + " ```\n", + " chrom pos molecular_trait_id variant_id tss_distance tes_distance af pvalue\n", + " 22 10685239 ENSG00000283047 chr22:10685239_C_T -254148 -276098 0.059322033 0.572662489372593\n", + " 22 10761227 ENSG00000283047 chr22:10761227_G_A -178160 -200110 0.15254237 0.752156227936135\n", + " ```\n", + "\n", + " The recounted variant tallies, matched by `--n-variants-suffix` (default `cis_n_variants_stats[.]tsv[.]gz$`). Example `output/tensorqtl_cis/protocol_example.chr22_chr22.maf_0.01_window_1000000_cis_n_variants_stats.tsv.gz`, 4 columns and 201 rows:\n", + "\n", + " ```\n", + " chrom molecular_trait_object_id n_variants n_variants_filtered\n", + " chr22 ENSG00000063515 44 44\n", + " chr22 ENSG00000075234 111 111\n", + " ```\n", + "\n", + "- `--output-dir`: where the consolidated object and the regional FDR table are written. Required.\n", + "- `--modular-script-dir`: the `code/script` directory holding the pecotmr_integration wrappers. Required.\n", + "- `--maf-cutoff` and `--cis-window`: `0.01` and `1000000` by default. When either is non-zero the variant counts are recomputed from the full pairs file before Bonferroni correction, which matters because a correction taken over too wide a window, or over many low-frequency variants, overstates the number of independent tests. Set both to `0` to skip the recount and use the counts as given.\n", + "- `--pvalue-cutoff`: `0.05` by default. Pairs above it are dropped before assembly to keep the object small; the per-gene minimum variant is always retained so the Bonferroni minimum stays exact.\n", + "- `--fdr-threshold`: `0.05` by default, the threshold for the global significance call.\n", + "- `--study`, `--context`, `--genome`: labels stamped onto the assembled `QtlSumStats` object, `study` / `context` / `hg38` by default.\n", + "- `--af-col`, `--pvalue-col`, `--molecular-id-col`: the column names to read, `af` / `pvalue` / `molecular_trait_object_id` by default.\n", + "- `--[no-]enable-archive`: off by default. When on, the bulky TensorQTL intermediates are moved out of the working directory for book-keeping or deletion." ] }, { @@ -39,13 +90,14 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", + "\n", + "- `{output-dir}/{cwd basename}.qtl_association_postprocessing.rds` - the consolidated `QtlSumStats` object holding the surviving xQTLs together with the `--study`, `--context` and `--genome` labels. This is the only file named in the workflow's `output:` statement.\n", + "- `{output-dir}/{cwd basename}.qtl_association_postprocessing.cis_regional.fdr.tsv.gz` - the per-gene regional FDR table.\n", + "\n", + "Both are named from the basename of `--cwd`, so the example below writes `tensorqtl_cis.qtl_association_postprocessing.rds` and `tensorqtl_cis.qtl_association_postprocessing.cis_regional.fdr.tsv.gz` into `output/qtlpp`.\n", "\n", - "| Role | Toy file | Produced by |\n", - "|------|----------|-------------|\n", - "| Per-gene cis association | `output/tensorqtl_cis/*.cis_qtl.regional.tsv.gz` | TensorQTL cis scan |\n", - "| Full variant-level pairs | `output/tensorqtl_cis/*.cis_qtl.pairs.tsv.gz` | TensorQTL cis scan |\n", - "| Gene coordinates | `input/reference_data/look_up_gene_id.tsv` (`chr`, `start`, `end`, `gene_id`) | reference |" + "No example output ships for this step. The `*.cis_regional.*.fdr.gz` and `*_regional_significance.*` files sitting alongside the inputs in `output/tensorqtl_cis` were written by an earlier version of this interface and carry names the workflow no longer produces." ] }, { @@ -54,19 +106,9 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Minimal Working Example\n", "\n", - "Written under `--output-dir` (significance results) and `--archive-dir` (moved intermediates):\n", - "\n", - "| File | Meaning |\n", - "|------|---------|\n", - "| `*_multiple_testing_consolidated.rds` | Consolidated multiple-testing results object |\n", - "| `*.cis_regional.summary.txt` | Per-gene regional summary after correction |\n", - "| `*significant_qtl*.tsv.gz` | Significant variant-level QTL (Bonferroni / BH / permutation) |\n", - "| `*significant_events*.tsv.gz` | Significant gene-level events |\n", - "| `archive/.../*.parquet` | Bulky TensorQTL intermediates moved out of the working dir |\n", - "\n", - "On the 6-sample toy data the correction runs cleanly and produces the consolidated object and summary; no events pass the genome-wide significance threshold, which is expected at this tiny scale." + "The workflow globs `--cwd` for its inputs rather than taking file arguments, so it is pointed straight at the TensorQTL scan directory." ] }, { @@ -75,9 +117,7 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", - "\n", - "Run the hierarchical correction on the toy cis results. The MAF / cis-window options are non-zero, so the program recomputes the variant counts from the full pairs file before applying the Bonferroni correction. On this toy data the distance columns in the TensorQTL output are named `tss_distance` and `tes_distance`, so we point `--tss-dist-col` / `--tes-dist-col` at them." + "**Timing**: TBD (on toy dataset)" ] }, { @@ -90,15 +130,10 @@ "source": [ "sos run pipeline/qtl_association_postprocessing.ipynb default \\\n", " --cwd output/tensorqtl_cis \\\n", - " --gene-coordinates input/reference_data/look_up_gene_id.tsv \\\n", - " --sub-dir . \\\n", - " --tss-dist-col tss_distance --tes-dist-col tes_distance \\\n", - " --maf-cutoff 0.01 --cis-window 1000000 \\\n", - " --regional-pattern \"*.cis_qtl.regional.tsv.gz$\" \\\n", - " --output-dir output/hierarchical_multi_test/output \\\n", - " --archive-dir output/hierarchical_multi_test/archive --enable-archive True \\\n", - " --pecotmr-path ../pecotmr \\\n", - " -s force" + " --output-dir output/qtlpp \\\n", + " --modular-script-dir code/script \\\n", + " --maf-cutoff 0.01 --cis-window 1000000 --pvalue-cutoff 0.05 \\\n", + " --study protocol_example --context bulk_rnaseq --genome hg38" ] }, { @@ -107,16 +142,14 @@ "kernel": "SoS" }, "source": [ - "## Command interface\n", - "\n", - "Show all workflow options and their defaults:" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ @@ -129,9 +162,48 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation\n", + "```\n", + "usage: sos run pipeline/qtl_association_postprocessing.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", "\n", - "The cells below are the unmodified SoS workflow definition that the example above calls." + "Workflows:\n", + " default\n", + "\n", + "Global Workflow Options:\n", + " --cwd . (as path)\n", + " --modular-script-dir VAL (as path, required)\n", + " code/script dir that holds the pecotmr_integration\n", + " wrappers\n", + " --output-dir VAL (as path, required)\n", + " --sub-dir . (as path)\n", + " --study study\n", + " labels for the assembled QtlSumStats\n", + " --context context\n", + " --genome hg38\n", + " --maf-cutoff 0.01 (as float)\n", + " --cis-window 1000000 (as int)\n", + " --af-col af\n", + " --pvalue-col pvalue\n", + " --molecular-id-col 'molecular_trait_object_id'\n", + " --pvalue-cutoff 0.05 (as float)\n", + " drop pairs with p above this before assembling (keeps\n", + " the object small; the per-gene min variant is always\n", + " retained so the Bonferroni min is exact)\n", + " --fdr-threshold 0.05 (as float)\n", + " --regional-pattern 'cis_qtl[.]regional[.]tsv[.]gz$'\n", + " list.files() regex patterns to locate the inputs in the\n", + " work dir\n", + " --qtl-pattern 'cis_qtl[.]pairs[.]tsv[.]gz$'\n", + " --n-variants-suffix 'cis_n_variants_stats[.]tsv[.]gz$'\n", + " --[no-]enable-archive (default to False)\n", + "\n", + "Sections\n", + " default:\n", + "```" ] }, { @@ -140,9 +212,9 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", + "## Workflow implementation\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "The cells below are the unmodified SoS workflow definition that the example above calls." ] }, { diff --git a/code/SoS/association_scan/qtl_association_testing.ipynb b/code/SoS/association_scan/qtl_association_testing.ipynb index 6f5cbed56..79f26c004 100644 --- a/code/SoS/association_scan/qtl_association_testing.ipynb +++ b/code/SoS/association_scan/qtl_association_testing.ipynb @@ -2,122 +2,63 @@ "cells": [ { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "# QTL Association Testing \n", - "\n", - "This is an **introductory, run-through notebook** for the QTL association testing section of the xQTL protocol. If you are new to the protocol, start here: it explains what this section does, what inputs it needs, and walks you through each analysis on the included toy dataset so you can reproduce results end to end before applying the pipeline to your own data.\n", - "\n", - "The heavy lifting is done by the worker notebook [`TensorQTL.ipynb`](TensorQTL/TensorQTL.ipynb). This section notebook simply orchestrates it for the three common analyses." - ] - }, - { - "cell_type": "markdown", + "id": "4f5d029f", "metadata": {}, "source": [ - "## Prerequisites\n", + "# QTL association testing\n", "\n", - "Requires phenotype matrices from molecular phenotype steps and covariates from `covariate_preprocessing`." + "This mini-protocol selects and runs cis-, trans-, or interaction-QTL association testing with the TensorQTL module." ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description\n", - "\n", - "QTL association testing measures the statistical association between genetic variants and molecular phenotypes (e.g. gene expression). This section runs three flavours of that test, all through TensorQTL:\n", - "\n", - "1. **cis** \u2014 each phenotype against nearby variants (within a window around the gene). This is the most common QTL scan.\n", - "2. **trans** \u2014 phenotypes against variants elsewhere in the genome (here, a chosen chromosome), optionally limited to a set of genes of interest.\n", - "3. **interaction** \u2014 a cis scan that additionally tests whether the genotype effect is modified by a covariate (e.g. sex).\n", - "\n", - "Each analysis is an independent call to the same worker; you can run only the ones you need." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "6a1baa78", + "metadata": {}, "source": [ - "## How it fits in the pipeline\n", - "\n", - "This section sits **after** the data-preprocessing sections. Its inputs are produced by:\n", + "#### Miniprotocol Timing\n", "\n", - "- **genotype_preprocessing** \u2192 by-chromosome PLINK genotypes and the file list,\n", - "- **phenotype_preprocessing** \u2192 by-chromosome molecular phenotype `bed.gz` files and the file list,\n", - "- **covariate_preprocessing** \u2192 the covariate matrix (known covariates + hidden factors).\n", - "\n", - "The outputs of this section (cis/trans/interaction summary statistics) feed the downstream **association postprocessing** and fine-mapping / integration sections." + "Timing: TBD" ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "fc058d62", + "metadata": {}, "source": [ - "## Input\n", + "## Overview\n", "\n", - "Make sure the preprocessing sections have been run so the following toy inputs exist. The commands below assume you launch them from the toy-example root directory.\n", + "QTL association testing identifies genetic variants associated with molecular traits such as gene expression. This mini-protocol calls [`TensorQTL.ipynb`](TensorQTL/TensorQTL.ipynb) for three independent analyses: a cis scan of variants near each molecular trait, a trans scan of variants outside the local region, and an interaction scan testing whether a covariate modifies the genotype effect.\n", "\n", - "| Role | File | Produced by |\n", - "|---|---|---|\n", - "| Genotypes (by chrom) | `output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt` | genotype_preprocessing |\n", - "| Phenotypes (by chrom) | `output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt` | phenotype_preprocessing |\n", - "| Covariates | `output/covariate/...prune.pca.Marchenko_PC.gz` | covariate_preprocessing |\n", - "| Genes of interest (trans) | `data/combined_AD_genes.csv` | provided with the toy data |\n", - "| Cis-window definitions (optional) | `reference_data/TAD/TADB_enhanced_cis.bed` | provided reference data |\n", + "Run the genotype-, phenotype-, and covariate-preprocessing mini-protocols first. Their outputs provide chromosome-indexed PLINK genotypes, chromosome-indexed molecular phenotypes, and a sample-aligned covariate matrix. The association results can then be passed to association postprocessing, fine-mapping, or multi-omics integration.\n", "\n", - "You can confirm they are present by listing them:" + "Choose one route below; the three commands are alternatives rather than one mandatory chain." ] }, { "cell_type": "markdown", + "id": "8c638946", "metadata": {}, - "source": [ - "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "Bash" - }, - "outputs": [], - "source": [ - "ls -la output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt \\\n", - " output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt \\\n", - " output/covariate/*Marchenko_PC.gz \\\n", - " data/combined_AD_genes.csv reference_data/TAD/TADB_enhanced_cis.bed" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, "source": [ "## Steps\n", + "Choose one route; cis-, trans-, and interaction-QTL scans answer different questions and are not a mandatory chain.\n", "\n", - "Each analysis below is a single command. They are independent \u2014 read the short explanation, then run the cell. On the toy data each takes roughly 1\u20132 minutes." + "| Analysis goal | Command to run | Inputs |\n", + "|---|---:|---|\n", + "| Test local genetic effects within each phenotype's cis window | 1 | `output/genotype_by_chrom/protocol_example.genotype.merged.plink_qc.genotype_by_chrom_files.txt`; `output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.txt`; `output/covariate/protocol_example.rnaseq.bed.protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz` |\n", + "| Test distal effects across chromosomes | 2 | The same genotype, phenotype, and covariate files, plus `data/combined_AD_genes.csv` as the example phenotype-region list |\n", + "| Test whether a covariate modifies a cis-QTL effect | 3 | The same genotype, phenotype, and covariate files, plus the interaction variable `msex` in the covariate data |\n", + "\n", + "Run only the command matching the scientific question." ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "cd4853d9", + "metadata": {}, "source": [ - "### 1. cis-QTL scan\n", + "### 1. [cis-QTL scan](TensorQTL/TensorQTL.ipynb)\n", "\n", - "This is the standard scan: every molecular phenotype is tested against the variants within its cis window (1 Mb around the TSS by default). Genotype and phenotype lists are matched by chromosome (the toy data covers chr22). `--MAC 5` is a relaxed minor-allele-count cutoff appropriate for the small toy sample. Results land in `output/tensorqtl_cis/`." + "**What it does:** Tests each molecular trait against variants within its cis window, using `--MAC 5` for the small chromosome 22 example." ] }, { @@ -137,13 +78,12 @@ }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "21598aa2", + "metadata": {}, "source": [ - "### 2. trans-QTL scan\n", + "### 2. [trans-QTL scan](TensorQTL/TensorQTL.ipynb)\n", "\n", - "A trans scan tests phenotypes against variants on a chosen genotype chromosome (`--trans-geno-chromosome 22`). Because genome-wide trans testing is expensive, here we restrict the phenotypes to the genes listed in `--region-list` (gene name in column 4). Results land in `output/tensorqtl_trans/`." + "**What it does:** Tests the selected traits against variants on chromosome 22, restricting traits to the identifiers listed in `data/combined_AD_genes.csv`." ] }, { @@ -164,13 +104,12 @@ }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "b6f552ec", + "metadata": {}, "source": [ - "### 3. interaction (iQTL) scan\n", + "### 3. [interaction-QTL scan](TensorQTL/TensorQTL.ipynb)\n", "\n", - "An interaction scan is a cis scan that also tests whether the variant effect depends on a covariate. Here we use `--interaction msex` (the sex column in the toy covariate file; in the full protocol this column is named `sex`). `--no-permutation` skips the permutation step (permutation is not meaningful for a single interaction test on toy data), and `--maf-threshold 0.05` sets the MAF cutoff. Results land in `output/tensorqtl_int/`." + "**What it does:** Runs the cis model with a genotype-by-`msex` interaction term and reports evidence that the genotype effect changes with this covariate." ] }, { @@ -191,41 +130,42 @@ }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "a3d087be", + "metadata": {}, "source": [ - "## Output\n", - "\n", - "After running the cells above you will have three result folders:\n", + "## Output Files\n", "\n", - "| Folder | Key files | Meaning |\n", + "| Route | Relative path | Contents |\n", "|---|---|---|\n", - "| `output/tensorqtl_cis/` | `*.cis_qtl.pairs.tsv.gz`, `*.cis_qtl_regional_significance.tsv.gz` (+summary), `*.parquet` | cis nominal + region-level statistics |\n", - "| `output/tensorqtl_trans/` | `*_geno_.trans_qtl.pairs.tsv.gz` | trans nominal statistics |\n", - "| `output/tensorqtl_int/` | `*_.cis_qtl.pairs.tsv.gz`, `*.parquet` | interaction (iQTL) nominal statistics |\n", + "| cis-QTL | `output/tensorqtl_cis/protocol_example._.cis_qtl.pairs.tsv.gz` | Nominal statistics for tested cis variant-trait pairs |\n", + "| cis-QTL | `output/tensorqtl_cis/protocol_example._.cis_qtl_regional_significance.tsv.gz` | Region-level permutation and multiple-testing results |\n", + "| cis-QTL | `output/tensorqtl_cis/protocol_example..cis_qtl_pairs..parquet` | Native TensorQTL nominal results retained for reuse |\n", + "| trans-QTL | `output/tensorqtl_trans/protocol_example._geno_chr22.trans_qtl.pairs.tsv.gz` | Trans-association statistics for chromosome 22 |\n", + "| interaction-QTL | `output/tensorqtl_int/protocol_example.__msex.cis_qtl.pairs.tsv.gz` | Nominal genotype, interaction, and genotype-by-interaction effects |\n", "\n", - "The nominal `pairs` files contain one row per variant\u2013phenotype pair with effect size, standard error and p-value; the regional-significance files summarise the strongest signal per gene." + "Tabix index files (`.tbi`) accompany the bgzipped result tables. Exact chromosome tokens follow the input file lists." ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "id": "38c65345", + "metadata": {}, "source": [ - "## Next steps\n", + "## Anticipated Results\n", "\n", - "Proceed to **association postprocessing** to filter, calibrate and summarise these statistics, and then to the fine-mapping / multi-omics integration sections. For full parameter documentation of any analysis, open the worker notebook directly:" + "The selected route produces association statistics for the chromosome 22 example. Cis analysis returns nominal variant-trait results plus region-level significance summaries; trans analysis returns the restricted cross-region tests; interaction analysis adds main and genotype-by-covariate effect estimates.\n", + "\n", + "Proceed to association postprocessing when calibrated regional summaries are needed, or use the nominal and region-level tables as input to the appropriate fine-mapping or integration workflow." ] }, { "cell_type": "markdown", + "id": "2073dd44", "metadata": {}, "source": [ - "## Anticipated Results\n", + "## Command interface\n", "\n", - "Produces `.cis_qtl_pairs.chr*.parquet` files with nominal p-values and `.cis_qtl.txt.gz` with significant results. For the toy chr22 dataset expect hundreds of nominal associations." + "Inspect all TensorQTL workflows, options, and defaults:" ] }, { @@ -266,5 +206,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 } \ No newline at end of file diff --git a/code/SoS/association_scan/quantile_models/qr_and_twas.ipynb b/code/SoS/association_scan/quantile_models/qr_and_twas.ipynb index 089ff788f..c9cccd6d8 100644 --- a/code/SoS/association_scan/quantile_models/qr_and_twas.ipynb +++ b/code/SoS/association_scan/quantile_models/qr_and_twas.ipynb @@ -8,13 +8,7 @@ "source": [ "# Quantile regression for QTL association testing\n", "\n", - "## Description\n", - "\n", - "This module performs quantile QTL (QR) association testing and computes quantile TWAS weights. For each genomic region it fits quantile regression across quantile levels (0.05, 0.1, ..., 0.95) and integrates the quantile-level p-values into a single QR p-value using the Cauchy combination method, then derives TWAS weights for use in downstream gene-trait association.\n", - "\n", - "The analysis is region-based: regions can be selected by name (`--region-name`), by a region list (`--region-list`), or, if neither is given, the union of all regions present in the phenotype region lists is analyzed.\n", - "\n", - "**Timing:** ~2-5 min on typical compute infrastructure.\n" + "Fits quantile regression of a molecular phenotype on genotype across a grid of quantiles, and turns the fit into TWAS weights." ] }, { @@ -23,43 +17,121 @@ "kernel": "SoS" }, "source": [ - "## Step 1: Quantile QTL association and TWAS weight\n", - "\n", - "For each region the workflow fits quantile regression of the molecular phenotype on genotype across the quantile grid, combines the per-quantile p-values into a single QR p-value via the Cauchy combination method, and computes quantile TWAS weights. Covariates (genotype PCs, hidden factors, fixed covariates) are regressed out, and cis/trans windows are taken from a customized association-window file when provided, otherwise a fixed cis-window around each region is used.\n", + "## Overview\n", "\n", - "**Inputs**\n", + "Standard QTL mapping models the mean: it asks whether genotype shifts average expression. That misses variants whose effect is confined to part of the distribution - acting only in highly expressing samples, or changing spread rather than centre. Quantile regression tests across the distribution instead, so those effects become visible, and the same fit yields weights that can be carried into a TWAS.\n", "\n", - "| Option | Description |\n", - "|--------|-------------|\n", - "| `--genoFile` | Either a list of per-chromosome genotype files, or one PLINK `.bed` file for the whole genome. |\n", - "| `--phenoFile` | One or more lists of phenotype files per region (`bed.gz` with `.bed.gz.tbi` index), output of the `phenotype_per_region`/`annotate_coord` preprocessing steps. |\n", - "| `--covFile` | One or more covariate files matched to the phenotype lists (genotype PCs, hidden factors, fixed covariates). |\n", - "| `--customized-association-windows` | Optional 4-column file (chr, start, end, region ID) defining cis/trans windows. If omitted, a fixed cis-window around each region is used. |\n", - "| `--region-name` / `--region-list` | Optional ways to restrict the analysis to selected regions. Region IDs must match the 4th column of the phenotype list. |\n", - "| `--phenotype-names` | Names for the phenotypic conditions (`cond1 cond2 ...`). |\n", + "For each region the workflow fits quantile regression of the molecular phenotype on genotype across the quantile grid, combines the per-quantile p-values into a single QR p-value by the Cauchy combination method, and computes quantile TWAS weights. Covariates - genotype PCs, hidden factors and fixed covariates - are regressed out, and cis or trans windows are taken from a customized association-window file when one is given, otherwise a fixed cis-window around each region is used.\n", "\n", - "*Example genotype list* (`--genoFile`):\n", - "\n", - "```\n", - "#chr\tpath\n", - "chr21\tprotocol_example.genotype.chr21.bed\n", - "chr22\tprotocol_example.genotype.chr22.bed\n", - "```\n", - "\n", - "Alternatively use `protocol_example.genotype.chr21_22.bed` if all chromosomes are in one file.\n", - "\n", - "*Example association-window file* (strictly 4 columns, header commented out):\n", - "\n", - "```\n", - "#chr\tstart\tend\tgene_id\n", - "chr10\t0\t6480000\tENSG00000008128\n", - "chr1\t0\t6480000\tENSG00000008130\n", - "chr1\t0\t6480000\tENSG00000067606\n", - "```\n", + "**When to run it.** As an alternative to mean-based association and TWAS weight estimation, when you have reason to expect distribution-dependent effects." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "## Input\n", + "\n", + "- `--genoFile`: either one PLINK `.bed` for the whole genome, or a two-column list of per-chromosome genotype files:\n", + "\n", + " ```\n", + " #chr path\n", + " chr21 protocol_example.genotype.chr21.bed\n", + " chr22 protocol_example.genotype.chr22.bed\n", + " ```\n", + "\n", + "- `--phenoFile`: one or more per-region phenotype lists, as written by the `phenotype_per_region` and `annotate_coord` preprocessing steps. Each row names a region and points at its `bed.gz`, which must carry a `bed.gz.tbi` index. Example `output/phenotype_protein/protocol_example_protein.phenotype_by_chrom_files.region_list.txt`:\n", + "\n", + " ```\n", + " #chr start end ID path\n", + " chr22 17592135 17628748 ENSG00000131100_P36543 output/phenotype_protein/protocol_example_protein.chr22.bed.gz\n", + " chr22 17787648 18024560 ENSG00000243156_Q7RTP6 output/phenotype_protein/protocol_example_protein.chr22.bed.gz\n", + " ```\n", + "\n", + "- `--covFile`: one or more covariate files matched to the phenotype lists, carrying genotype PCs, hidden factors and fixed covariates, samples in columns. Example `output/covariate_protein/protocol_example_protein.chr22.<...>.Marchenko_PC.gz`:\n", + "\n", + " ```\n", + " #id SAMPLE_001 SAMPLE_002 SAMPLE_003 SAMPLE_004\n", + " msex 1 1 1 1\n", + " age_death 90.97 80.24 83.9 74.1\n", + " pmi 10.57 7.87 9.93 2.91\n", + " ```\n", + "\n", + "- `--customized-association-windows`: an optional 4-column file giving the cis or trans window for each region. Its 4th column must match the region ID in the 4th column of the phenotype list, otherwise the window for that region is not found. Without it a fixed cis-window is used around each region. Example `input/reference_data/TAD/protocol_example_protein.enhanced_cis_chr22.bed`:\n", + "\n", + " ```\n", + " #chr start end gene_id\n", + " chr22 0 18960000 ENSG00000131100_P36543\n", + " chr22 0 19024561 ENSG00000243156_Q7RTP6\n", + " ```\n", + "\n", + "- `--region-name` and `--region-list`: optional ways to restrict the run to selected regions, by naming them or by supplying a window file. Region IDs must match the 4th column of the phenotype list. With neither, every region in the phenotype lists is analysed.\n", + "- `--phenotype-names`: names for the phenotypic conditions, defaulting to the phenotype file basenames.\n", + "- `--name`: the stem of the output files.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--maf`, `--mac` and `--imiss`: variant filters, `0.0025`, `5` and `1.0` by default. `--min-twas-maf` (`0.01`) applies to the TWAS weight step instead.\n", + "- `--indel`: `True` by default. Set `--no-indel` to drop indels from the analysis.\n", + "- `--screen-threshold` and `--screen-method`: `0.01` and `qvalue`, controlling which variants survive the QR screen before weights are computed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "jp-MarkdownHeadingCollapsed": true, + "kernel": "SoS", + "tags": [] + }, + "source": [ + "## Output\n", + "\n", + "- `{cwd}/quantile_qtl_twas_weight/{name}.{region}.univariate_qr_twas_weights.rds` - one file per analysed region, holding the quantile-QTL association results and the quantile TWAS weights. Example `output/quantile_twas/quantile_qtl_twas_weight/protocol_example_protein.chr22_ENSG00000241973_P42356.univariate_qr_twas_weights.rds`:\n", + "\n", + " ```\n", + " List of 1\n", + " $ ENSG00000241973_P42356:List of 1\n", + " ..$ protein_ENSG00000241973_P42356:List of 5\n", + " .. ..$ vqtl_results :'data.frame': 275 obs. of 12 variables:\n", + " .. ..$ qr_screen_pvalue_df:'data.frame': 275 obs. of 65 variables:\n", + " .. ..$ message : chr \"No significant SNPs detected in region ENSG00000241973_P42356_protein\"\n", + " .. ..$ region_info :List of 3\n", + " .. ..$ maf : Named num [1:275] 0.2583 0.3583 0.2417 0.0536 0.0536 ...\n", + " ```\n", + "\n", + "The object is nested by region, then by phenotype condition. `qr_screen_pvalue_df` carries the per-quantile QR p-values and q-values alongside the integrated Cauchy p-value, and `vqtl_results` carries the variance-QTL fit. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", "\n", - "**Output**\n", + "The analysis is region-based. Regions can be picked one at a time by name, or taken from a region list; if neither is given, every region present in the phenotype region lists is analysed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### One region by name\n", "\n", - "The pipeline writes results to the `--cwd` directory, named after the workflow step. Each region yields a quantile-QTL association result table (per-quantile and integrated Cauchy QR p-values) and the corresponding quantile TWAS weight object used downstream.\n" + "`--region-name` restricts the run to a single region, which is the quickest way to check the setup end to end." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -82,6 +154,26 @@ " " ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Every region in a list\n", + "\n", + "`--region-list` runs the same workflow over each region in a 4-column window file. Dropping both options analyses every region in the phenotype lists." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -101,11 +193,20 @@ " --phenotype-names protein \n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command Interface" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ @@ -118,9 +219,112 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation\n", - "\n", - "The cells below define the SoS workflow steps used by the commands above. They are not meant to be edited for routine analysis.\n" + "```\n", + "usage: sos run pipeline/qr_and_twas.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " get_analysis_regions\n", + " quantile_qtl_twas_weight\n", + "\n", + "Global Workflow Options:\n", + " --name VAL (as str, required)\n", + " It is required to input the name of the analysis\n", + " --cwd output (as path)\n", + " --genoFile VAL (as path, required)\n", + " A list of file paths for genotype data, or the genotype\n", + " data itself.\n", + " --phenoFile paths\n", + "\n", + " One or multiple lists of file paths for phenotype data.\n", + " --phenoIDFile paths()\n", + "\n", + " One or multiple lists of file paths for phenotype ID\n", + " mapping file. The first column should be the original\n", + " ID, the 2nd column should be the ID to be mapped to.\n", + " --covFile paths\n", + "\n", + " Covariate file path\n", + " --region-list . (as path)\n", + " Optional: if a region list is provide the analysis will\n", + " be focused on provided region. The LAST column of this\n", + " list will contain the ID of regions to focus on\n", + " Otherwise, all regions with both genotype and phenotype\n", + " files will be analyzed\n", + " --region-name (as list)\n", + " Optional: if a region name is provided the analysis\n", + " would be focused on the union of provides region list\n", + " and region names\n", + " --keep-samples . (as path)\n", + " Only focus on a subset of samples\n", + " --customized-association-windows . (as path)\n", + " An optional list documenting the custom association\n", + " window for each region to analyze, with four column,\n", + " chr, start, end, region ID (eg gene ID). If this list is\n", + " not provided, the default `window` parameter (see below)\n", + " will be used.\n", + " --cis-window -1 (as int)\n", + " Specify the cis window for the up and downstream radius\n", + " to analyze around the region of interest in units of bp\n", + " When this is set to negative, we will rely on using\n", + " customized_association_windows\n", + " --[no-]save-data (default to False)\n", + " save data object or not\n", + " --phenotype-names [f'{x:bn}' for x in phenoFile]\n", + "\n", + " Name of phenotypes\n", + " --seed 999 (as int)\n", + " --imiss 1.0 (as float)\n", + " remove a variant if it has more than imiss missing\n", + " individual level data\n", + " --maf 0.0025 (as float)\n", + " MAF cutoff\n", + " --mac 5 (as int)\n", + " MAC cutoff, on top of MAF cutoff\n", + " --[no-]indel (default to True)\n", + " Remove indels if indel = False\n", + " --min-twas-maf 0.01 (as float)\n", + " --screen-threshold 0.01 (as float)\n", + " --screen-method qvalue\n", + " --[no-]screen-significant (default to True)\n", + " --[no-]pre-filter-by-pqr (default to False)\n", + " --initial-corr-filter-cutoff 0.8 (as float)\n", + " --full-rank-corr-filter-cutoff 'seq(0.75, 0.5, by = -0.05)'\n", + " --ld-reference-meta-file . (as path)\n", + " --keep-variants . (as path)\n", + " Only focus on a subset of variants\n", + " --[no-]marginal-beta-calculate (default to True)\n", + " --[no-]twas-weight-calculate (default to True)\n", + " --[no-]qrank-screen-calculate (default to True)\n", + " --[no-]vqtl-calculate (default to True)\n", + " --container ''\n", + " Analysis environment settings\n", + " --job-size 200 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 1h\n", + " Wall clock time expected\n", + " --mem 20G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " get_analysis_regions:\n", + " quantile_qtl_twas_weight:\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation" ] }, { @@ -264,7 +468,192 @@ "kernel": "SoS" }, "outputs": [], - "source": "[get_analysis_regions: shared = \"regional_data\"]\n# input is genoFile, phenoFile, covFile and optionally region_list. If region_list presents then we only analyze what's contained in the list.\n# regional_data should be a dictionary like:\n#{'data': [(\"genotype_1.bed\", \"phenotype_1.bed.gz\", \"covariate_1.gz\"), (\"genotype_2.bed\", \"phenotype_1.bed.gz\", \"phenotype_2.bed.gz\", \"covariate_1.gz\", \"covariate_2.gz\") ... ],\n# 'meta_info': [(\"chr12:752578-752579\",\"chr12:752577-752580\", \"gene_1\", \"trait_1\"), (\"chr13:852580-852581\",\"chr13:852579-852580\", \"gene_2\", \"trait_1\", \"trait_2\") ... ]}\nimport numpy as np\n\ndef preload_id_map(id_map_files):\n id_maps = {}\n for id_map_file in id_map_files:\n if id_map_file is not None and os.path.isfile(id_map_file):\n df = pd.read_csv(id_map_file, sep=r'\\s+', header=None, comment='#', names=['old_ID', 'new_ID'])\n id_maps[id_map_file] = df.set_index('old_ID')['new_ID'].to_dict()\n return id_maps\n\ndef load_and_apply_id_map(pheno_path, id_map_path, preloaded_id_maps):\n pheno_df = pd.read_csv(pheno_path, sep=r\"\\s+\", header=0)\n pheno_df['Original_ID'] = pheno_df['ID']\n if id_map_path in preloaded_id_maps:\n id_map = preloaded_id_maps[id_map_path]\n pheno_df['ID'] = pheno_df['ID'].map(id_map).fillna(pheno_df['ID'])\n return pheno_df\n\ndef filter_by_region_ids(data, region_ids):\n if region_ids is not None and len(region_ids) > 0:\n # Check both ID (mapped) and Original_ID (unmapped) to handle phenoIDFile cases\n # where region_name uses the original ID but ID column has been mapped\n if 'Original_ID' in data.columns:\n data = data[data['ID'].isin(region_ids) | data['Original_ID'].isin(region_ids)]\n else:\n data = data[data['ID'].isin(region_ids)]\n return data\n\ndef custom_join(series):\n # Initialize an empty list to hold the processed items\n result = []\n for item in series:\n if ',' in item:\n # If the item contains commas, split by comma and convert to tuple\n result.append(tuple(item.split(',')))\n else:\n # If the item does not contain commas, add it directly\n result.append(item)\n # Convert the list of items to a tuple and return\n return tuple(result)\n\ndef aggregate_phenotype_data(accumulated_pheno_df):\n if not accumulated_pheno_df.empty:\n accumulated_pheno_df = accumulated_pheno_df.groupby(['#chr','ID','cond','path','cov_path'], as_index=False).agg({\n '#chr': lambda x: np.unique(x).astype(str)[0],\n 'ID': lambda x: np.unique(x).astype(str)[0],\n 'Original_ID': ','.join,\n 'start': 'min',\n 'end': 'max'\n }).groupby(['#chr','ID'], as_index=False).agg({\n 'cond': ','.join,\n 'path': ','.join,\n 'Original_ID': custom_join,\n 'cov_path': ','.join,\n 'start': 'min',\n 'end': 'max'\n })\n return accumulated_pheno_df\n\ndef process_cis_files(pheno_files, cov_files, phenotype_names, pheno_id_files, region_ids, preloaded_id_maps):\n '''\n Example output:\n #chr start end ID Original_ID path cov_path cond\n chr12 752578 752579 ENSG00000060237 Q9H4A3,P62873 protocol_example.protein_1.bed.gz,protocol_example.protein_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B\n '''\n accumulated_pheno_df = pd.DataFrame()\n pheno_id_files = [None] * len(pheno_files) if len(pheno_id_files) == 0 else pheno_id_files\n for pheno_path, cov_path, phenotype_name, id_map_path in zip(pheno_files, cov_files, phenotype_names, pheno_id_files):\n if not os.path.isfile(cov_path):\n raise FileNotFoundError(f\"No valid path found for file: {cov_path}\")\n pheno_df = load_and_apply_id_map(pheno_path, id_map_path, preloaded_id_maps)\n pheno_df = filter_by_region_ids(pheno_df, region_ids)\n if not pheno_df.empty:\n # Use 'path' column by name to handle both 5-col (#chr,start,end,ID,path)\n # and 6-col (#chr,start,end,ID,strand,path) region_list formats\n pheno_df['path'] = adapt_file_path_all(pheno_df, 'path', f\"{pheno_path:a}\")\n pheno_df = pheno_df.assign(cov_path=str(cov_path), cond=phenotype_name) \n accumulated_pheno_df = pd.concat([accumulated_pheno_df, pheno_df], ignore_index=True)\n\n accumulated_pheno_df = aggregate_phenotype_data(accumulated_pheno_df)\n return accumulated_pheno_df\n\ndef process_trans_files(pheno_files, cov_files, phenotype_names, pheno_id_files, region_ids, customized_association_windows):\n '''\n Example output:\n #chr start end ID Original_ID path cov_path cond\n chr21 0 0 chr21_18133254_19330300 carnitine,benzoate,hippurate metabolon_1.bed.gz,metabolon_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B\n '''\n \n if not os.path.isfile(customized_association_windows):\n raise ValueError(\"Customized association analysis window must be specified for trans analysis.\")\n accumulated_pheno_df = pd.DataFrame()\n pheno_id_files = [None] * len(pheno_files) if len(pheno_id_files) == 0 else pheno_id_files\n genotype_windows = pd.read_csv(customized_association_windows, comment=\"#\", header=None, names=[\"#chr\",\"start\",\"end\",\"ID\"], sep=\"\\t\")\n genotype_windows = filter_by_region_ids(genotype_windows, region_ids)\n if genotype_windows.empty:\n return accumulated_pheno_df\n \n for pheno_path, cov_path, phenotype_name, id_map_path in zip(pheno_files, cov_files, phenotype_names, pheno_id_files):\n if not os.path.isfile(cov_path):\n raise FileNotFoundError(f\"No valid path found for file: {cov_path}\")\n pheno_df = pd.read_csv(pheno_path, sep=r\"\\s+\", header=0, names=['Original_ID', 'path'])\n if not pheno_df.empty:\n pheno_df.iloc[:, -1] = adapt_file_path_all(pheno_df, pheno_df.columns[-1], f\"{pheno_path:a}\")\n pheno_df = pheno_df.assign(cov_path=str(cov_path), cond=phenotype_name)\n # Here we combine genotype_windows which contains \"#chr\" and \"ID\" to pheno_df by creating a cartesian product\n pheno_df = pd.merge(genotype_windows.assign(key=1), pheno_df.assign(key=1), on='key').drop('key', axis=1)\n # then set start and end columns to zero\n pheno_df['start'] = 0\n pheno_df['end'] = 0\n if id_map_path is not None:\n # Filter pheno_df by specific association-window and phenotype pairs\n association_analysis_pair = pd.read_csv(id_map_path, sep=r'\\s+', header=None, comment='#', names=['ID', 'Original_ID'])\n pheno_df = pd.merge(pheno_df, association_analysis_pair, on=['ID', 'Original_ID'])\n accumulated_pheno_df = pd.concat([accumulated_pheno_df, pheno_df], ignore_index=True)\n\n accumulated_pheno_df = aggregate_phenotype_data(accumulated_pheno_df)\n return accumulated_pheno_df\n\n# Load genotype meta data\nif f\"{genoFile:x}\" == \".bed\":\n geno_meta_data = pd.DataFrame([(\"chr\"+str(x), f\"{genoFile:a}\") for x in range(1,23)] + [(\"chrX\", f\"{genoFile:a}\")], columns=['#chr', 'geno_path'])\nelse:\n geno_meta_data = pd.read_csv(f\"{genoFile:a}\", sep = r\"\\s+\", header=0)\n geno_meta_data.iloc[:, 1] = adapt_file_path_all(geno_meta_data, geno_meta_data.columns[1], f\"{genoFile:a}\")\n geno_meta_data.columns = ['#chr', 'geno_path']\n geno_meta_data['#chr'] = geno_meta_data['#chr'].apply(lambda x: str(x) if str(x).startswith('chr') else f'chr{x}')\n\n# Checking the DataFrame\nvalid_chr_values = [f'chr{x}' for x in range(1, 23)] + ['chrX']\nif not all(value in valid_chr_values for value in geno_meta_data['#chr']):\n raise ValueError(\"Invalid chromosome values found. Allowed values are chr1 to chr22 and chrX.\")\n\nregion_ids = []\n# If region_list is provided, read the file and extract IDs\nif region_list.is_file():\n region_list_df = pd.read_csv(region_list, sep=r'\\s+', header=None, comment = \"#\")\n region_ids = region_list_df.iloc[:, -1].unique() # Extracting the last column for IDs\n# If region_name is provided, include those IDs as well\n# --region-name A B C will result in a list of [\"A\", \"B\", \"C\"] here\nif len(region_name) > 0:\n region_ids = list(set(region_ids).union(set(region_name)))\n\ntrans_analysis = False\nif trans_analysis:\n meta_data = process_trans_files(phenoFile, covFile, phenotype_names, phenoIDFile, region_ids, customized_association_windows)\nelse:\n meta_data = process_cis_files(phenoFile, covFile, phenotype_names, phenoIDFile, region_ids, preload_id_map(phenoIDFile))\n\nif not meta_data.empty:\n meta_data = meta_data.merge(geno_meta_data, on='#chr', how='inner')\n # Adjust association-window\n if os.path.isfile(customized_association_windows):\n print(f\"Loading customized association analysis window from {customized_association_windows}\")\n association_windows_list = pd.read_csv(customized_association_windows, comment=\"#\", header=None, names=[\"#chr\",\"start\",\"end\",\"ID\"], sep=\"\\t\")\n meta_data = pd.merge(meta_data, association_windows_list, on=['#chr', 'ID'], how='left', suffixes=('', '_association'))\n mismatches = meta_data[meta_data['start_association'].isna()]\n if not mismatches.empty:\n raise ValueError(f\"{len(mismatches)} regions to analyze cannot be found in ``{customized_association_windows}``. Please check your ``{customized_association_windows}`` database to make sure it contains all association-window definitions. \")\n else:\n if cis_window < 0 :\n raise ValueError(\"Please either input valid path to association-window file via ``--customized-association-windows``, or set ``--cis-window`` to a non-negative integer.\")\n if cis_window == 0:\n print(\"Warning: only variants within the range of start and end of molecular phenotype will be considered since cis_window is set to zero and no customized association window file was found. Please make sure this is by design.\")\n meta_data['start_association'] = meta_data['start'].apply(lambda x: max(x - cis_window, 0))\n meta_data['end_association'] = meta_data['end'] + cis_window\n\n # Example meta_data:\n # #chr start end start_association end_association ID Original_ID path cov_path cond coordinate geno_path\n # 0 chr12 752578 752579 652578 852579 ENSG00000060237 Q9H4A3,P62873 protocol_example.protein_1.bed.gz,protocol_example.protein_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B chr12:752578-752579 protocol_example.genotype.chr21_22.bed \n # Create the final dictionary\n regional_data = {\n 'data': [(row['geno_path'], *row['path'].split(','), *row['cov_path'].split(',')) for _, row in meta_data.iterrows()],\n 'meta_info': [(f\"{row['#chr']}:{row['start']}-{row['end']}\", # this is the phenotypic region to extract data from\n f\"{row['#chr']}:{row['start_association']}-{row['end_association']}\", # this is the association window region\n row['ID'], row['Original_ID'], *row['cond'].split(',')) for _, row in meta_data.iterrows()]\n }\nelse:\n regional_data = {'data':[], 'meta_info':[]}" + "source": [ + "[get_analysis_regions: shared = \"regional_data\"]\n", + "# input is genoFile, phenoFile, covFile and optionally region_list. If region_list presents then we only analyze what's contained in the list.\n", + "# regional_data should be a dictionary like:\n", + "#{'data': [(\"genotype_1.bed\", \"phenotype_1.bed.gz\", \"covariate_1.gz\"), (\"genotype_2.bed\", \"phenotype_1.bed.gz\", \"phenotype_2.bed.gz\", \"covariate_1.gz\", \"covariate_2.gz\") ... ],\n", + "# 'meta_info': [(\"chr12:752578-752579\",\"chr12:752577-752580\", \"gene_1\", \"trait_1\"), (\"chr13:852580-852581\",\"chr13:852579-852580\", \"gene_2\", \"trait_1\", \"trait_2\") ... ]}\n", + "import numpy as np\n", + "\n", + "def preload_id_map(id_map_files):\n", + " id_maps = {}\n", + " for id_map_file in id_map_files:\n", + " if id_map_file is not None and os.path.isfile(id_map_file):\n", + " df = pd.read_csv(id_map_file, sep=r'\\s+', header=None, comment='#', names=['old_ID', 'new_ID'])\n", + " id_maps[id_map_file] = df.set_index('old_ID')['new_ID'].to_dict()\n", + " return id_maps\n", + "\n", + "def load_and_apply_id_map(pheno_path, id_map_path, preloaded_id_maps):\n", + " pheno_df = pd.read_csv(pheno_path, sep=r\"\\s+\", header=0)\n", + " pheno_df['Original_ID'] = pheno_df['ID']\n", + " if id_map_path in preloaded_id_maps:\n", + " id_map = preloaded_id_maps[id_map_path]\n", + " pheno_df['ID'] = pheno_df['ID'].map(id_map).fillna(pheno_df['ID'])\n", + " return pheno_df\n", + "\n", + "def filter_by_region_ids(data, region_ids):\n", + " if region_ids is not None and len(region_ids) > 0:\n", + " # Check both ID (mapped) and Original_ID (unmapped) to handle phenoIDFile cases\n", + " # where region_name uses the original ID but ID column has been mapped\n", + " if 'Original_ID' in data.columns:\n", + " data = data[data['ID'].isin(region_ids) | data['Original_ID'].isin(region_ids)]\n", + " else:\n", + " data = data[data['ID'].isin(region_ids)]\n", + " return data\n", + "\n", + "def custom_join(series):\n", + " # Initialize an empty list to hold the processed items\n", + " result = []\n", + " for item in series:\n", + " if ',' in item:\n", + " # If the item contains commas, split by comma and convert to tuple\n", + " result.append(tuple(item.split(',')))\n", + " else:\n", + " # If the item does not contain commas, add it directly\n", + " result.append(item)\n", + " # Convert the list of items to a tuple and return\n", + " return tuple(result)\n", + "\n", + "def aggregate_phenotype_data(accumulated_pheno_df):\n", + " if not accumulated_pheno_df.empty:\n", + " accumulated_pheno_df = accumulated_pheno_df.groupby(['#chr','ID','cond','path','cov_path'], as_index=False).agg({\n", + " '#chr': lambda x: np.unique(x).astype(str)[0],\n", + " 'ID': lambda x: np.unique(x).astype(str)[0],\n", + " 'Original_ID': ','.join,\n", + " 'start': 'min',\n", + " 'end': 'max'\n", + " }).groupby(['#chr','ID'], as_index=False).agg({\n", + " 'cond': ','.join,\n", + " 'path': ','.join,\n", + " 'Original_ID': custom_join,\n", + " 'cov_path': ','.join,\n", + " 'start': 'min',\n", + " 'end': 'max'\n", + " })\n", + " return accumulated_pheno_df\n", + "\n", + "def process_cis_files(pheno_files, cov_files, phenotype_names, pheno_id_files, region_ids, preloaded_id_maps):\n", + " '''\n", + " Example output:\n", + " #chr start end ID Original_ID path cov_path cond\n", + " chr12 752578 752579 ENSG00000060237 Q9H4A3,P62873 protocol_example.protein_1.bed.gz,protocol_example.protein_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B\n", + " '''\n", + " accumulated_pheno_df = pd.DataFrame()\n", + " pheno_id_files = [None] * len(pheno_files) if len(pheno_id_files) == 0 else pheno_id_files\n", + " for pheno_path, cov_path, phenotype_name, id_map_path in zip(pheno_files, cov_files, phenotype_names, pheno_id_files):\n", + " if not os.path.isfile(cov_path):\n", + " raise FileNotFoundError(f\"No valid path found for file: {cov_path}\")\n", + " pheno_df = load_and_apply_id_map(pheno_path, id_map_path, preloaded_id_maps)\n", + " pheno_df = filter_by_region_ids(pheno_df, region_ids)\n", + " if not pheno_df.empty:\n", + " # Use 'path' column by name to handle both 5-col (#chr,start,end,ID,path)\n", + " # and 6-col (#chr,start,end,ID,strand,path) region_list formats\n", + " pheno_df['path'] = adapt_file_path_all(pheno_df, 'path', f\"{pheno_path:a}\")\n", + " pheno_df = pheno_df.assign(cov_path=str(cov_path), cond=phenotype_name) \n", + " accumulated_pheno_df = pd.concat([accumulated_pheno_df, pheno_df], ignore_index=True)\n", + "\n", + " accumulated_pheno_df = aggregate_phenotype_data(accumulated_pheno_df)\n", + " return accumulated_pheno_df\n", + "\n", + "def process_trans_files(pheno_files, cov_files, phenotype_names, pheno_id_files, region_ids, customized_association_windows):\n", + " '''\n", + " Example output:\n", + " #chr start end ID Original_ID path cov_path cond\n", + " chr21 0 0 chr21_18133254_19330300 carnitine,benzoate,hippurate metabolon_1.bed.gz,metabolon_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B\n", + " '''\n", + " \n", + " if not os.path.isfile(customized_association_windows):\n", + " raise ValueError(\"Customized association analysis window must be specified for trans analysis.\")\n", + " accumulated_pheno_df = pd.DataFrame()\n", + " pheno_id_files = [None] * len(pheno_files) if len(pheno_id_files) == 0 else pheno_id_files\n", + " genotype_windows = pd.read_csv(customized_association_windows, comment=\"#\", header=None, names=[\"#chr\",\"start\",\"end\",\"ID\"], sep=\"\\t\")\n", + " genotype_windows = filter_by_region_ids(genotype_windows, region_ids)\n", + " if genotype_windows.empty:\n", + " return accumulated_pheno_df\n", + " \n", + " for pheno_path, cov_path, phenotype_name, id_map_path in zip(pheno_files, cov_files, phenotype_names, pheno_id_files):\n", + " if not os.path.isfile(cov_path):\n", + " raise FileNotFoundError(f\"No valid path found for file: {cov_path}\")\n", + " pheno_df = pd.read_csv(pheno_path, sep=r\"\\s+\", header=0, names=['Original_ID', 'path'])\n", + " if not pheno_df.empty:\n", + " pheno_df.iloc[:, -1] = adapt_file_path_all(pheno_df, pheno_df.columns[-1], f\"{pheno_path:a}\")\n", + " pheno_df = pheno_df.assign(cov_path=str(cov_path), cond=phenotype_name)\n", + " # Here we combine genotype_windows which contains \"#chr\" and \"ID\" to pheno_df by creating a cartesian product\n", + " pheno_df = pd.merge(genotype_windows.assign(key=1), pheno_df.assign(key=1), on='key').drop('key', axis=1)\n", + " # then set start and end columns to zero\n", + " pheno_df['start'] = 0\n", + " pheno_df['end'] = 0\n", + " if id_map_path is not None:\n", + " # Filter pheno_df by specific association-window and phenotype pairs\n", + " association_analysis_pair = pd.read_csv(id_map_path, sep=r'\\s+', header=None, comment='#', names=['ID', 'Original_ID'])\n", + " pheno_df = pd.merge(pheno_df, association_analysis_pair, on=['ID', 'Original_ID'])\n", + " accumulated_pheno_df = pd.concat([accumulated_pheno_df, pheno_df], ignore_index=True)\n", + "\n", + " accumulated_pheno_df = aggregate_phenotype_data(accumulated_pheno_df)\n", + " return accumulated_pheno_df\n", + "\n", + "# Load genotype meta data\n", + "if f\"{genoFile:x}\" == \".bed\":\n", + " geno_meta_data = pd.DataFrame([(\"chr\"+str(x), f\"{genoFile:a}\") for x in range(1,23)] + [(\"chrX\", f\"{genoFile:a}\")], columns=['#chr', 'geno_path'])\n", + "else:\n", + " geno_meta_data = pd.read_csv(f\"{genoFile:a}\", sep = r\"\\s+\", header=0)\n", + " geno_meta_data.iloc[:, 1] = adapt_file_path_all(geno_meta_data, geno_meta_data.columns[1], f\"{genoFile:a}\")\n", + " geno_meta_data.columns = ['#chr', 'geno_path']\n", + " geno_meta_data['#chr'] = geno_meta_data['#chr'].apply(lambda x: str(x) if str(x).startswith('chr') else f'chr{x}')\n", + "\n", + "# Checking the DataFrame\n", + "valid_chr_values = [f'chr{x}' for x in range(1, 23)] + ['chrX']\n", + "if not all(value in valid_chr_values for value in geno_meta_data['#chr']):\n", + " raise ValueError(\"Invalid chromosome values found. Allowed values are chr1 to chr22 and chrX.\")\n", + "\n", + "region_ids = []\n", + "# If region_list is provided, read the file and extract IDs\n", + "if region_list.is_file():\n", + " region_list_df = pd.read_csv(region_list, sep=r'\\s+', header=None, comment = \"#\")\n", + " region_ids = region_list_df.iloc[:, -1].unique() # Extracting the last column for IDs\n", + "# If region_name is provided, include those IDs as well\n", + "# --region-name A B C will result in a list of [\"A\", \"B\", \"C\"] here\n", + "if len(region_name) > 0:\n", + " region_ids = list(set(region_ids).union(set(region_name)))\n", + "\n", + "trans_analysis = False\n", + "if trans_analysis:\n", + " meta_data = process_trans_files(phenoFile, covFile, phenotype_names, phenoIDFile, region_ids, customized_association_windows)\n", + "else:\n", + " meta_data = process_cis_files(phenoFile, covFile, phenotype_names, phenoIDFile, region_ids, preload_id_map(phenoIDFile))\n", + "\n", + "if not meta_data.empty:\n", + " meta_data = meta_data.merge(geno_meta_data, on='#chr', how='inner')\n", + " # Adjust association-window\n", + " if os.path.isfile(customized_association_windows):\n", + " print(f\"Loading customized association analysis window from {customized_association_windows}\")\n", + " association_windows_list = pd.read_csv(customized_association_windows, comment=\"#\", header=None, names=[\"#chr\",\"start\",\"end\",\"ID\"], sep=\"\\t\")\n", + " meta_data = pd.merge(meta_data, association_windows_list, on=['#chr', 'ID'], how='left', suffixes=('', '_association'))\n", + " mismatches = meta_data[meta_data['start_association'].isna()]\n", + " if not mismatches.empty:\n", + " raise ValueError(f\"{len(mismatches)} regions to analyze cannot be found in ``{customized_association_windows}``. Please check your ``{customized_association_windows}`` database to make sure it contains all association-window definitions. \")\n", + " else:\n", + " if cis_window < 0 :\n", + " raise ValueError(\"Please either input valid path to association-window file via ``--customized-association-windows``, or set ``--cis-window`` to a non-negative integer.\")\n", + " if cis_window == 0:\n", + " print(\"Warning: only variants within the range of start and end of molecular phenotype will be considered since cis_window is set to zero and no customized association window file was found. Please make sure this is by design.\")\n", + " meta_data['start_association'] = meta_data['start'].apply(lambda x: max(x - cis_window, 0))\n", + " meta_data['end_association'] = meta_data['end'] + cis_window\n", + "\n", + " # Example meta_data:\n", + " # #chr start end start_association end_association ID Original_ID path cov_path cond coordinate geno_path\n", + " # 0 chr12 752578 752579 652578 852579 ENSG00000060237 Q9H4A3,P62873 protocol_example.protein_1.bed.gz,protocol_example.protein_2.bed.gz covar_1.gz,covar_2.gz trait_A,trait_B chr12:752578-752579 protocol_example.genotype.chr21_22.bed \n", + " # Create the final dictionary\n", + " regional_data = {\n", + " 'data': [(row['geno_path'], *row['path'].split(','), *row['cov_path'].split(',')) for _, row in meta_data.iterrows()],\n", + " 'meta_info': [(f\"{row['#chr']}:{row['start']}-{row['end']}\", # this is the phenotypic region to extract data from\n", + " f\"{row['#chr']}:{row['start_association']}-{row['end_association']}\", # this is the association window region\n", + " row['ID'], row['Original_ID'], *row['cond'].split(',')) for _, row in meta_data.iterrows()]\n", + " }\n", + "else:\n", + " regional_data = {'data':[], 'meta_info':[]}" + ] }, { "cell_type": "code", @@ -546,4 +935,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/data_preprocessing/covariate/covariate_formatting.ipynb b/code/SoS/data_preprocessing/covariate/covariate_formatting.ipynb index 6dcb64cb7..50d575e8b 100644 --- a/code/SoS/data_preprocessing/covariate/covariate_formatting.ipynb +++ b/code/SoS/data_preprocessing/covariate/covariate_formatting.ipynb @@ -8,25 +8,8 @@ }, "source": [ "# Covariate Data Formatting\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Our covariate preprocessing steps merge genotypic principal components and fixed covariate files into one file for downstream QTL analysis. " + "\n", + "Merges known covariates, genotype principal components and hidden factors into the single file the association scan expects." ] }, { @@ -35,12 +18,16 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Overview\n", + "\n", + "The association scan takes a single covariate file, but covariates arrive from several\n", + "places: batch and demographic variables you supply, genotype principal components from\n", + "`PCA`, and hidden factors estimated by `covariate_hidden_factor`. This step merges them,\n", + "reconciles sample identifiers across the sources, and writes the combined matrix in the\n", + "orientation the scan expects.\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds` | Genotype PCA result (RDS) produced by the genotype PCA module; contains the `pc_scores` matrix of per-sample principal components. |\n", - "| `protocol_example.covariates.tsv` | Fixed/known covariates (e.g. sex, age, PMI, study), samples in rows and covariates in columns with an `#id` header. |" + "**When to run it.** After PCA and hidden-factor estimation, immediately before QTL\n", + "association testing." ] }, { @@ -49,11 +36,40 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Input\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz` | Combined covariate matrix: the fixed covariates stacked with the selected genotype PCs, samples as columns and an `#id` header, ready for downstream QTL analysis. |" + "- `--covFile`: the known covariate table, samples in columns and covariates in rows, with an `#id` header line. Example `input/covariate/protocol_example.covariates.base.tsv`, showing the first 4 of 59 samples:\n", + "\n", + " ```\n", + " #id SAMPLE_001 SAMPLE_002 SAMPLE_003 SAMPLE_004\n", + " sex 1 1 1 1\n", + " age 90.97 80.24 83.9 74.1\n", + " ```\n", + "\n", + "- `--pcaFile`: the genotype PCA result written by the `PCA` module, an RDS holding the per-sample scores in `pc_scores`. Example `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds`:\n", + "\n", + " ```\n", + " List of 6\n", + " $ pca_model :List of 7\n", + " ..- attr(*, \"class\")= chr \"flashpca\"\n", + " $ pc_scores :'data.frame': 60 obs. of 28 variables:\n", + " $ meta : chr \"protocol_example.genotype.merged.plink_qc.plink_qc.prune \"\n", + " $ pc_cov : num [1:5, 1:5] 1.91e-02 -4.83e-18 6.02e-18 -1.35e-18 2.33e-18 ...\n", + " $ pc_mean : num [1:5] 5.17e-17 -1.22e-17 -4.58e-17 7.87e-17 -3.73e-17\n", + " $ pc_median : num [1:5] 0.00271 0.00131 0.00781 -0.00328 0.00532\n", + " ```\n", + "\n", + "- `--k`: how many genotype PCs to keep, 20 by default. The example instead reads the count off the PCA scree file, taking the last PC whose cumulative variance explained stays under 80%. Scree file `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.scree.txt`:\n", + "\n", + " ```\n", + " PCs PVE PVE_cum\n", + " 1 0.05 0.05\n", + " 2 0.05 0.1\n", + " ```\n", + "\n", + "- `--tol-cov`: the largest fraction of missing values a covariate row may carry and still be kept, its missing entries mean-imputed rather than the row dropped. The default `-1.0` drops any row that has a missing value; `0.4` admits rows up to 40% missing.\n", + "- `--name`: the stem of the output file.\n", + "- `--cwd`: the directory the output is written to." ] }, { @@ -62,9 +78,18 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example Steps\n", + "## Output\n", + "\n", + "- `{cwd}/{name}.gz`: the combined covariate matrix, samples in columns and covariates in rows under an `#id` header, in the orientation the association scan expects. Example `output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz` has 60 columns and 18 rows, the header plus the 2 supplied covariates plus the 15 PCs `--k` selected. First 4 columns and first 6 rows:\n", "\n", - "The data and singularity used in this minimal working example can be found on [Synapse](https://www.synapse.org/#!Synapse:syn69670658)." + " ```\n", + " #id SAMPLE_001 SAMPLE_002 SAMPLE_003\n", + " sex 1 1 1\n", + " age 90.97 80.24 83.9\n", + " PC1 -0.45257953377688636 -0.04501122972985456 0.07044283190889761\n", + " PC2 0.049068179683990002 -0.1674973221595418 -0.004163580814102901\n", + " PC3 -0.021287959073347167 0.011427192975949114 0.2219354934004062\n", + " ```" ] }, { @@ -73,9 +98,7 @@ "kernel": "SoS" }, "source": [ - "### Merge Covariates and Genotype PCs\n", - "\n", - "The data and singularity used in this minimal working example can be found on [Synapse](https://www.synapse.org/#!Synapse:syn69670658)." + "## Minimal Working Example" ] }, { @@ -84,16 +107,19 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min" + "### Merge covariates and genotype PCs\n", + "\n", + "This step keeps the samples present in both the PCA result and the covariate table, then stacks the chosen genotype PCs on top of the known covariates to give the association scan a single matrix." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "This step reads the genotype PCA result (`--pcaFile`) and the fixed covariate table (`--covFile`), keeps the samples present in both, and stacks the chosen genotype PCs on top of the covariates to produce a single matrix for QTL analysis. The number of PCs to keep is set with `--k`; here we pick the count whose cumulative variance explained stays under 80% by reading the PCA scree file. `--tol-cov 0.4` allows samples with up to 40% missing covariate values to be mean-imputed rather than dropped." + "**Timing**: TBD (on toy dataset)" ] }, { @@ -129,11 +155,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run covariate_formatting.ipynb -h" + "sos run pipeline/covariate_formatting.ipynb -h" ] }, { @@ -142,7 +168,65 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "```\n", + "usage: sos run pipeline/covariate_formatting.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " merge_genotype_pc\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --covFile VAL (as path, required)\n", + " The covariate file\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 2G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", + " --entrypoint ''\n", + "\n", + "Sections\n", + " merge_genotype_pc:\n", + " Workflow Options:\n", + " --pcaFile VAL (as path, required)\n", + " An RDS file as the output of the genotype PCA module\n", + " --k 20 (as int)\n", + " The number of PCs to retain, by default is 20, in\n", + " practice can be the number of PC that captured more than\n", + " 70% PVE\n", + " --name f'{covFile:bn}.{pcaFile:bn}'\n", + "\n", + " --outliersFile . (as path)\n", + " Outliers\n", + " --[no-]remove-outliers (default to False)\n", + " --tol-cov -1.0 (as float)\n", + " Tolerance of missingness in covariates, -1 means do\n", + " nothing, otherwise for samples with covariates missing\n", + " rate larger than tol_cov will be removed, with missing\n", + " rate smaller than tol_cov will be kept.\n", + " --[no-]mean-impute (default to True)\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation" ] }, { @@ -173,29 +257,9 @@ "cwd = path(f\"{cwd:a}\")" ] }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### **Step 0.** Merge Covariates and Genotype PCs" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] - }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "kernel": "SoS" }, @@ -232,6 +296,15 @@ " ${\"--mean-impute\" if mean_impute else \"\"} \\\n", " --numThreads ${numThreads}\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/code/SoS/data_preprocessing/covariate/covariate_hidden_factor.ipynb b/code/SoS/data_preprocessing/covariate/covariate_hidden_factor.ipynb index d22dedd5a..f65e78dcd 100644 --- a/code/SoS/data_preprocessing/covariate/covariate_hidden_factor.ipynb +++ b/code/SoS/data_preprocessing/covariate/covariate_hidden_factor.ipynb @@ -7,7 +7,9 @@ "tags": [] }, "source": [ - "# Hidden Factor Analysis" + "# Hidden Factor Analysis\n", + "\n", + "Infers hidden factors - latent technical and biological covariates - from a molecular phenotype matrix." ] }, { @@ -16,18 +18,13 @@ "kernel": "SoS" }, "source": [ - "## Description\n", - "\n", - "This step infers **hidden factors** (latent technical/biological covariates) from a molecular phenotype matrix. Including these factors as covariates in xQTL mapping improves power and controls for unwanted variation.\n", + "## Overview\n", "\n", - "The pipeline provides several procedures:\n", + "Molecular phenotype matrices carry structure nobody recorded: batch, cell-type composition, unmeasured technical variation. Left in, that structure inflates false positives in the association scan, because a variant that happens to track a batch looks like a QTL. This step estimates those hidden factors from the data and adds them to the known covariates, so the scan can regress them out.\n", "\n", - "- **PEER** – Probabilistic Estimation of Expression Residuals (Stegle et al. 2010), the approach used by GTEx.\n", - "- **PCA (Marchenko-Pastur)** – the approach used for our main analyses: residualize the phenotype on known covariates, run PCA, and keep the number of PCs above the Marchenko-Pastur noise threshold.\n", - "- **PCA (Buja & Eyuboglu permutation)** – an alternative that chooses the number of PCs by permutation (`jackstraw`).\n", - "- **BiCV factor analysis with APEX** – Bi-cross-validation using the APEX tool.\n", + "Every method here follows the same shape: residualise the phenotype on the covariates you already have, estimate factors from what is left, then stack the chosen factors back on top of the known covariates. They differ only in how factors are estimated and how many are kept.\n", "\n", - "The minimal working example below runs the **PCA (Marchenko-Pastur)** method, since it runs fully on the toy data with no external container or network access." + "**When to run it.** After known covariates are merged and before the association scan, on the phenotype matrix the scan will use." ] }, { @@ -36,14 +33,24 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Input\n", + "\n", + "- `--phenoFile`: the molecular phenotype matrix in UCSC `bed.gz` form, one row per feature and one column per sample. Example `output/rnaseq/protocol_example.rnaseq.bed.bed.gz`.\n", + "- `--covFile`: the merged known-covariate matrix, an `#id` header plus one column per sample, as written by `covariate_formatting`. Example `output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz`:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `--phenoFile` | Molecular phenotype matrix in indexed `bed.gz` format (`#chr start end ID` + one column per sample). Toy file: `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` (200 genes × 60 samples). |\n", - "| `--covFile` | Merged known-covariate matrix (`#id` + one column per sample), e.g. the output of `covariate_formatting`. Toy file: `output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz`. |\n", + " ```\n", + " #id SAMPLE_001 SAMPLE_002 SAMPLE_003\n", + " sex 1 1 1\n", + " age 90.97 80.24 83.9\n", + " PC1 -0.4525795 -0.0450112 0.0704428\n", + " ```\n", "\n", - "Notes: the covariate file is optional for PEER but recommended so a proper xQTL model is built. The `BiCV`/`APEX` method additionally requires an indexed VCF." + " The covariate file is optional for `PEER` but recommended, so that a proper xQTL model is built. `BiCV` additionally requires an indexed VCF, which the workflow generates for itself.\n", + "\n", + "- `--N`: how many hidden factors to keep. `0`, the default, lets the method choose: `Marchenko_PC` keeps components above the Marchenko-Pastur bound and `PCA` uses the Buja and Eyuboglu permutation. Give a positive number to fix the count instead, which `PEER` needs.\n", + "- `--choose_k_method`: `Marchenko` or the permutation alternative, selecting which rule the shared PCA step applies. It also names the output file.\n", + "- `--mean-impute-missing`: off by default. When set, missing phenotype values are mean-imputed rather than the feature being dropped.\n", + "- `--cwd`: the directory outputs are written to. Must be a full path." ] }, { @@ -52,14 +59,25 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Output\n", + "\n", + "- `{cwd}/{name}.{choose_k_method}_PC.gz` - the deliverable: the known covariates with the inferred `Hidden_Factor_PC*` rows stacked underneath, ready for the association scan. `{name}` is the phenotype file stem joined to the covariate file stem. Example `...prune.pca.Marchenko_PC.gz` has 60 columns and 26 rows, being the header plus 2 known covariates plus the 15 genotype PCs plus the 8 hidden factors this method kept:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `{phenoFile:bn}.{covFile:bn}.Marchenko_PC.gz` | Combined covariate matrix: known covariates + inferred `Hidden_Factor_PC*` rows, ready for xQTL mapping. |\n", - "| `{phenoFile:bn}.{covFile:bn}.residual.bed.gz` | Intermediate residualized phenotype matrix used as input to PCA. |\n", + " ```\n", + " #id SAMPLE_001 SAMPLE_002 SAMPLE_003\n", + " sex 1 1 1\n", + " age 90.97 80.24 83.9\n", + " PC1 -0.4525795337766864 -0.04501122972985456 0.07044283190889761\n", + " PC2 0.04906817968399002 -0.1674973221595418 -0.0041635808141029\n", + " ...\n", + " Hidden_Factor_PC8 ... ... ...\n", + " ```\n", "\n", - "For PEER, additional diagnostic outputs (precision, residuals, weights, convergence plots) are produced." + "- `{cwd}/{name}.residual.bed.gz` - the residualised phenotype matrix produced by the shared first step and consumed by whichever method follows, written with a `.tbi` index.\n", + "- `{cwd}/{name}.residual.PEER_MODEL.hd5` - the fitted PEER model, from `PEER` only.\n", + "- `{cwd}/{name}.residual.PEER.gz` and `{cwd}/{name}.residual.PEER.diag.pdf` - the PEER factors and the convergence diagnostic plot.\n", + "- `{cwd}/{name}.residual.bed.fake.vcf.gz` - the indexed VCF `BiCV` builds for APEX, an intermediate rather than a result.\n", + "- `{cwd}/{name}.residual.BiCV.gz` - the BiCV factors." ] }, { @@ -68,11 +86,9 @@ "kernel": "SoS" }, "source": [ - "### PCA with Marchenko-Pastur (recommended)\n", + "## Minimal Working Example\n", "\n", - "This is the method used for our main analyses. The `Marchenko_PC` workflow first regresses the molecular phenotype on the known covariates to get residuals, then runs PCA on the residual matrix and keeps the number of principal components whose eigenvalues exceed the Marchenko-Pastur random-matrix noise threshold. The retained components are written out as `Hidden_Factor_PC*` rows, stacked together with the known covariates so the result is ready to use directly in xQTL mapping. Use `--mean-impute-missing` to mean-impute any missing phenotype values.\n", - "\n", - "Timing: <1 min." + "Four alternative methods, each a chain that starts from the same residualisation step and then estimates hidden factors its own way. Pick one; they are not run in sequence." ] }, { @@ -81,7 +97,19 @@ "kernel": "SoS" }, "source": [ - "## Steps\n" + "### PCA with Marchenko-Pastur (recommended)\n", + "\n", + "The default choice. `Marchenko_PC` first residualises the phenotype on the known covariates, runs PCA on the residual matrix, and keeps the components whose eigenvalues exceed the Marchenko-Pastur upper bound, which is the threshold random noise alone would produce. The kept components are stacked back onto the known covariates." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -107,9 +135,17 @@ "source": [ "### PEER (GTEx-style)\n", "\n", - "PEER infers hidden factors using a MOFA-based probabilistic model (Stegle et al.). The number of factors follows GTEx recommendations based on sample size, or can be fixed with `--N`. This method runs natively here (it uses the `mofapy2` Python package), so the example below is fully runnable on the toy data and produces the factor matrix plus a convergence-diagnostic PDF.\n", - "\n", - "Timing: ~1 min." + "PEER infers hidden factors using a MOFA-based probabilistic model (Stegle et al.). The number of factors follows GTEx recommendations based on sample size, or can be fixed with `--N`. This method runs natively here (it uses the `mofapy2` Python package), so the example below is fully runnable on the toy data and produces the factor matrix plus a convergence-diagnostic PDF.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -135,9 +171,17 @@ "source": [ "### PCA with Buja & Eyuboglu permutation\n", "\n", - "This is the same PCA workflow as above (`PCA`), but the number of components to keep is chosen by the Buja & Eyuboglu permutation procedure instead of the Marchenko-Pastur threshold. Set `--choose_k_method Buja_Eyuboglu`. This route uses `jackstraw::permutationPA` (B=100 permutations), so it runs a little longer than the Marchenko variant but is fully runnable on the toy data.\n", - "\n", - "Timing: ~1 min." + "This is the same PCA workflow as above (`PCA`), but the number of components to keep is chosen by the Buja & Eyuboglu permutation procedure instead of the Marchenko-Pastur threshold. Set `--choose_k_method Buja_Eyuboglu`. This route uses `jackstraw::permutationPA` (B=100 permutations), so it runs a little longer than the Marchenko variant but is fully runnable on the toy data.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -164,10 +208,17 @@ "source": [ "### BiCV factor analysis with APEX\n", "\n", - "BiCV chooses the number of hidden factors by bi-cross-validation using the APEX software (Owen et al. 2016). The pipeline computes residuals on the merged covariates, builds the inputs APEX expects (an indexed VCF placeholder and a phenotype matrix), then calls `apex factor`. The number of factors follows GTEx recommendations or can be fixed with `--N`.\n", - "\n", - "\n", - "Timing: ~30 s." + "BiCV chooses the number of hidden factors by bi-cross-validation using the APEX software (Owen et al. 2016). The pipeline computes residuals on the merged covariates, builds the inputs APEX expects (an indexed VCF placeholder and a phenotype matrix), then calls `apex factor`. The number of factors follows GTEx recommendations or can be fixed with `--N`.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -177,7 +228,13 @@ "kernel": "Bash" }, "outputs": [], - "source": "sos run pipeline/covariate_hidden_factor.ipynb BiCV \\\n --cwd output/covariate \\\n --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n --N 3" + "source": [ + "sos run pipeline/covariate_hidden_factor.ipynb BiCV \\\n", + " --cwd output/covariate \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n", + " --N 3" + ] }, { "cell_type": "markdown", @@ -195,88 +252,97 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/covariate_hidden_factor.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: sos run covariate_hidden_factor.ipynb\n", - " [workflow_name | -t targets] [options] [workflow_options]\n", - " workflow_name: Single or combined workflows defined in this script\n", - " targets: One or more targets to generate\n", - " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", - " workflow_options: Double-hyphen workflow-specific parameters\n", - "\n", - "Workflows:\n", - " Marchenko_PC\n", - " PEER\n", - " BiCV\n", - "\n", - "Global Workflow Options:\n", - " --cwd output (as path)\n", - " The output directory for generated files. MUST BE FULL\n", - " PATH\n", - " --covFile VAL (as path, required)\n", - " Merged Covariates File\n", - " --phenoFile VAL (as path, required)\n", - " Path to the input molecular phenotype data.\n", - " --name f'{phenoFile:bnn}.{covFile:bn}'\n", - "\n", - " --job-size 1 (as int)\n", - " For cluster jobs, number commands to run per job\n", - " --walltime 5h\n", - " Wall clock time expected\n", - " --mem 16G\n", - " Memory expected\n", - " --numThreads 8 (as int)\n", - " Number of threads\n", - " --container ''\n", - " Software container option\n", - "\n", - "\n", - "Sections\n", - " *_1:\n", - " Workflow Options:\n", - " --[no-]mean-impute-missing (default to False)\n", - " Marchenko_PC_2:\n", - " PEER_2:\n", - " Workflow Options:\n", - " --N 0 (as int)\n", - " N PEER factors, If do not specify or specified as 0,\n", - " default values suggested by GTEx (based on different\n", - " sample size) will be used\n", - " --iteration 1000 (as int)\n", - " Default values from PEER software: The number of max\n", - " iteration\n", - " --tol 0.001 (as float)\n", - " Prior parameters parameter: Alpha_a = 0.001 parameter:\n", - " Alpha_b = 0.1 parameter: Eps_a = 0.1 parameter: Eps_b =\n", - " 10.0 Tolarance parameters\n", - " --[no-]r2-tol (default to False)\n", - " parameter: var_tol = 0.00001 minimum variance explained\n", - " criteria to drop factors while training\n", - " --convergence-mode fast\n", - " Convergence mode: Convergence mode for MOFAr \"slow\",\n", - " \"medium\" or \"fast\", corresponding to 1e-5%, 1e-4% or\n", - " 1e-3% deltaELBO change.\n", - " PEER_3:\n", - " BiCV_2:\n", - " BiCV_3:\n", - " Workflow Options:\n", - " --N 0 (as int)\n", - " N factors, if not specify, calculated based on sample\n", - " size according to GTeX\n", - " --iteration 10 (as int)\n", - " The number of iteration\n" - ] - } - ], "source": [ - "sos run covariate_hidden_factor.ipynb -h" + "```\n", + "usage: sos run pipeline/covariate_hidden_factor.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " Marchenko_PC\n", + " PCA\n", + " PEER\n", + " BiCV\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files. MUST BE FULL\n", + " PATH\n", + " --covFile VAL (as path, required)\n", + " Merged Covariates File\n", + " --phenoFile VAL (as path, required)\n", + " Path to the input molecular phenotype data.\n", + " --name f'{phenoFile:bnn}.{covFile:bn}'\n", + "\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", + " --entrypoint ''\n", + "\n", + "Sections\n", + " *_1:\n", + " Workflow Options:\n", + " --[no-]mean-impute-missing (default to False)\n", + " Marchenko_PC_2, PCA_2:\n", + " Workflow Options:\n", + " --choose-k-method Marchenko\n", + " Marchenko or Marchenko\n", + " --N 0 (as int)\n", + " PEER_2:\n", + " Workflow Options:\n", + " --N 0 (as int)\n", + " N PEER factors, If do not specify or specified as 0,\n", + " default values suggested by GTEx (based on different\n", + " sample size) will be used\n", + " --iteration 1000 (as int)\n", + " Default values from PEER software: The number of max\n", + " iteration\n", + " --tol 0.001 (as float)\n", + " Prior parameters parameter: Alpha_a = 0.001 parameter:\n", + " Alpha_b = 0.1 parameter: Eps_a = 0.1 parameter: Eps_b =\n", + " 10.0 Tolarance parameters\n", + " --[no-]r2-tol (default to False)\n", + " parameter: var_tol = 0.00001 minimum variance explained\n", + " criteria to drop factors while training\n", + " --convergence-mode fast\n", + " Convergence mode: Convergence mode for MOFAr \"slow\",\n", + " \"medium\" or \"fast\", corresponding to 1e-5%, 1e-4% or\n", + " 1e-3% deltaELBO change.\n", + " PEER_3:\n", + " BiCV_2:\n", + " BiCV_3:\n", + " Workflow Options:\n", + " --N 0 (as int)\n", + " N factors, if not specify, calculated based on sample\n", + " size according to GTeX\n", + " --iteration 10 (as int)\n", + " The number of iteration\n", + "```" ] }, { @@ -285,7 +351,7 @@ "kernel": "R" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation" ] }, { @@ -394,7 +460,43 @@ "kernel": "SoS" }, "outputs": [], - "source": "[PEER_2]\n# N PEER factors, If do not specify or specified as 0, default values suggested by \n# GTEx (based on different sample size) will be used\nparameter: N = 0\n# Default values from PEER software:\n## The number of max iteration\nparameter: iteration = 1000\n### Prior parameters\n#parameter: Alpha_a = 0.001\n#parameter: Alpha_b = 0.1\n#parameter: Eps_a = 0.1\n#parameter: Eps_b = 10.0\n# Tolarance parameters\nparameter: tol = 0.001\n#parameter: var_tol = 0.00001\n# minimum variance explained criteria to drop factors while training\nparameter: r2_tol = False\n# Convergence mode: Convergence mode for MOFAr \"slow\", \"medium\" or \"fast\", corresponding to 1e-5%, 1e-4% or 1e-3% deltaELBO change.\nparameter: convergence_mode = \"fast\"\n# input is the residual file from the first step\noutput: f'{cwd:a}/{_input:bnn}.PEER_MODEL.hd5'\ntask: trunk_workers = 1, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout', container = container, entrypoint = entrypoint\n python ${modular_script_dir}/data_preprocessing/covariate/covariate_hidden_factor_peer.py \\\n --resid-file \"${_input}\" \\\n --model-file \"${_output}\" \\\n --factors-out \"${cwd:a}/${_input:bnn}.PEER.factors.tsv\" \\\n --weights-out \"${cwd:a}/${_input:bnn}.PEER.weights.tsv\" \\\n --variance-out \"${cwd:a}/${_input:bnn}.PEER.variance.tsv\" \\\n --num-factor ${N} \\\n --iteration ${iteration} \\\n --convergence-mode \"${convergence_mode}\" \\\n --num-threads ${numThreads} \\\n --tol ${tol} \\\n --r2-tol ${r2_tol}\n" + "source": [ + "[PEER_2]\n", + "# N PEER factors, If do not specify or specified as 0, default values suggested by \n", + "# GTEx (based on different sample size) will be used\n", + "parameter: N = 0\n", + "# Default values from PEER software:\n", + "## The number of max iteration\n", + "parameter: iteration = 1000\n", + "### Prior parameters\n", + "#parameter: Alpha_a = 0.001\n", + "#parameter: Alpha_b = 0.1\n", + "#parameter: Eps_a = 0.1\n", + "#parameter: Eps_b = 10.0\n", + "# Tolarance parameters\n", + "parameter: tol = 0.001\n", + "#parameter: var_tol = 0.00001\n", + "# minimum variance explained criteria to drop factors while training\n", + "parameter: r2_tol = False\n", + "# Convergence mode: Convergence mode for MOFAr \"slow\", \"medium\" or \"fast\", corresponding to 1e-5%, 1e-4% or 1e-3% deltaELBO change.\n", + "parameter: convergence_mode = \"fast\"\n", + "# input is the residual file from the first step\n", + "output: f'{cwd:a}/{_input:bnn}.PEER_MODEL.hd5'\n", + "task: trunk_workers = 1, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout', container = container, entrypoint = entrypoint\n", + " python ${modular_script_dir}/data_preprocessing/covariate/covariate_hidden_factor_peer.py \\\n", + " --resid-file \"${_input}\" \\\n", + " --model-file \"${_output}\" \\\n", + " --factors-out \"${cwd:a}/${_input:bnn}.PEER.factors.tsv\" \\\n", + " --weights-out \"${cwd:a}/${_input:bnn}.PEER.weights.tsv\" \\\n", + " --variance-out \"${cwd:a}/${_input:bnn}.PEER.variance.tsv\" \\\n", + " --num-factor ${N} \\\n", + " --iteration ${iteration} \\\n", + " --convergence-mode \"${convergence_mode}\" \\\n", + " --num-threads ${numThreads} \\\n", + " --tol ${tol} \\\n", + " --r2-tol ${r2_tol}\n" + ] }, { "cell_type": "code", @@ -436,9 +538,7 @@ "source": [ "### BiCV Factor Analysis with APEX\n", "\n", - "Factor anallysis using Bi-Cross validation with the APEX software package [[cf. Owen et al., Statistical Science, 2016](https://doi.org/10.1214/15-STS539)] [[cf. Quick et al., bioRxiv, 2020](https://doi.org/10.1101/2020.12.18.423490)]\n", - "\n", - "Notice that the command options are different from those on the APEX website documentation. The commands on the documentation page does not work (last updated September 2021). The commands below were constructed and tested by our team based on our understanding of the program, without input from APEX authors.\n" + "The commands below were constructed and tested against the maintainers' own reading of the program, without input from the APEX authors, so treat the parameter choices as a starting point rather than as endorsed defaults." ] }, { @@ -473,17 +573,33 @@ } }, "outputs": [], - "source": "[BiCV_3]\n# N factors, if not specify, calculated based on sample size according to GTeX\nparameter: N = 0\n# The number of iteration\nparameter: iteration = 10\ninput: output_from(1), output_from(2)\noutput: f'{cwd:a}/{_input[0]:bnn}.BiCV.gz'\ntask: trunk_workers = 1, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout', container = container, entrypoint = entrypoint\n n_factors_file=\"${_output[0]:nn}.n_factors.txt\"\n Rscript ${modular_script_dir}/data_preprocessing/covariate/covariate_hidden_factor.R \\\n --step BiCV_nfactors \\\n --residFile \"${_input[0]}\" \\\n --N ${N} \\\n --output \"$n_factors_file\"\n n_factors=$(cat \"$n_factors_file\")\n out_prefix=\"${_output[0]:nn}\"\n apex factor \\\n --out \"$out_prefix\" \\\n --iter ${iteration} \\\n --factors \"$n_factors\" \\\n --bed \"${_input[0]}\" \\\n --vcf \"${_input[1]}\" \\\n --threads ${numThreads} \\\n --cov \"${covFile}\"\n mv -f \"$out_prefix.cov.gz\" \"${_output[0]}\"" - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "[BiCV_3]\n", + "# N factors, if not specify, calculated based on sample size according to GTeX\n", + "parameter: N = 0\n", + "# The number of iteration\n", + "parameter: iteration = 10\n", + "input: output_from(1), output_from(2)\n", + "output: f'{cwd:a}/{_input[0]:bnn}.BiCV.gz'\n", + "task: trunk_workers = 1, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout', container = container, entrypoint = entrypoint\n", + " n_factors_file=\"${_output[0]:nn}.n_factors.txt\"\n", + " Rscript ${modular_script_dir}/data_preprocessing/covariate/covariate_hidden_factor.R \\\n", + " --step BiCV_nfactors \\\n", + " --residFile \"${_input[0]}\" \\\n", + " --N ${N} \\\n", + " --output \"$n_factors_file\"\n", + " n_factors=$(cat \"$n_factors_file\")\n", + " out_prefix=\"${_output[0]:nn}\"\n", + " apex factor \\\n", + " --out \"$out_prefix\" \\\n", + " --iter ${iteration} \\\n", + " --factors \"$n_factors\" \\\n", + " --bed \"${_input[0]}\" \\\n", + " --vcf \"${_input[1]}\" \\\n", + " --threads ${numThreads} \\\n", + " --cov \"${covFile}\"\n", + " mv -f \"$out_prefix.cov.gz\" \"${_output[0]}\"" ] } ], diff --git a/code/SoS/data_preprocessing/covariate_preprocessing.ipynb b/code/SoS/data_preprocessing/covariate_preprocessing.ipynb index ec1f72902..49835e9c9 100644 --- a/code/SoS/data_preprocessing/covariate_preprocessing.ipynb +++ b/code/SoS/data_preprocessing/covariate_preprocessing.ipynb @@ -6,8 +6,11 @@ "kernel": "SoS" }, "source": [ - "# Covariate Data Preprocessing" - ] + "# Covariate data preprocessing\n", + "\n", + "Combine known covariates with genotype principal components and optionally infer hidden factors for xQTL association testing.\n" + ], + "id": "25e9e86a" }, { "cell_type": "markdown", @@ -15,12 +18,13 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "#### Miniprotocol Timing\n", "\n", - "This notebook runs the full covariate preprocessing pipeline end-to-end on the toy dataset. It chains the two covariate worker notebooks: it first merges the user-supplied covariates with the genotype principal components, then computes residuals on the merged covariates and infers hidden factors. The result is a single covariate matrix (known covariates + genotype PCs + hidden factors) ready for QTL association testing.\n", + "This is the total duration for one complete toy-data route; module-specific timings appear on their respective pages.\n", "\n", - "Timing: < 3 minutes on the toy data." - ] + "Timing: <3 min (on the toy dataset)\n" + ], + "id": "c9f10ef3" }, { "cell_type": "markdown", @@ -28,15 +32,13 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Overview\n", + "\n", + "This mini-protocol walks through construction of an association-ready covariate matrix. [`covariate_formatting.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_formatting.html) first merges sample covariates with genotype principal components. [`covariate_hidden_factor.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_hidden_factor.html) then residualizes the molecular phenotype against those observed covariates and optionally estimates latent factors using Marchenko\u2013Pastur selection, a user-specified PCA dimension, PEER, or bi-cross-validation (BiCV).\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/covariate/protocol_example.covariates.base.tsv` | Known sample covariates (e.g. sex, age, study) |\n", - "| `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds` | Genotype PCA result (from genotype preprocessing) |\n", - "| `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.scree.txt` | Scree values used to choose the number of PCs to keep |\n", - "| `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` | Molecular phenotype matrix (from phenotype preprocessing) |" - ] + "Run step 1 once, then choose one hidden-factor method from steps 2\u20135. These alternatives are not a four-step chain. Use the resulting matrix as the covariate input to association testing.\n" + ], + "id": "5d626526" }, { "cell_type": "markdown", @@ -44,13 +46,21 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Steps\n", + "\n", + "Choose a route before running commands; steps 2\u20135 are alternative hidden-factor methods.\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Observed covariates and genotype PCs only | 1 | `input/covariate/protocol_example.covariates.base.tsv`; `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds`; `output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.scree.txt` |\n", + "| Automatically select PCA hidden factors | 1 \u2192 2 | Step 1 inputs; `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` |\n", + "| Use a fixed number of PEER factors | 1 \u2192 3 | Step 1 inputs; `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` |\n", + "| Use PCA factors with configurable dimension selection | 1 \u2192 4 | Step 1 inputs; `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` |\n", + "| Select hidden factors by bi-cross-validation | 1 \u2192 5 | Step 1 inputs; `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` |\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz` | Merged covariates + genotype PCs (output of step i) |\n", - "| `output/covariate/...prune.pca.Marchenko_PC.gz` | Final covariate matrix with known covariates, genotype PCs, and inferred hidden factors, ready for TensorQTL |" - ] + "Run only the row matching the intended analysis goal." + ], + "id": "e88d7b48" }, { "cell_type": "markdown", @@ -58,8 +68,29 @@ "kernel": "SoS" }, "source": [ - "## Steps" - ] + "### 1. [Merge observed covariates and genotype PCs](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_formatting.html)\n", + "\n", + "**What it does:** Combine the base covariate table with the selected genotype principal components.\n" + ], + "id": "0c4ac9c6" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/covariate_formatting.ipynb merge_genotype_pc \\\n", + " --cwd output/covariate \\\n", + " --pcaFile output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds \\\n", + " --covFile input/covariate/protocol_example.covariates.base.tsv \\\n", + " --name protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca \\\n", + " --tol-cov 0.4 \\\n", + " --k `awk '$3 < 0.8' output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.scree.txt | tail -1 | cut -f 1`\n" + ], + "id": "f5e2ad67" }, { "cell_type": "markdown", @@ -67,10 +98,11 @@ "kernel": "SoS" }, "source": [ - "### Merge covariates and genotype PCs\n", + "### 2. [Infer PCA factors with Marchenko\u2013Pastur selection](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_hidden_factor.html)\n", "\n", - "Merge the known covariates with the genotype PCs, keeping only PCs that explain a meaningful fraction of variance. The number of PCs to keep is read from the scree file (here, components with the scree statistic below 0.8). This writes the merged covariate file used as input to the hidden-factor step." - ] + "**What it does:** Residualize the phenotype and automatically retain PCA factors above the Marchenko\u2013Pastur noise threshold.\n" + ], + "id": "b0523bf6" }, { "cell_type": "code", @@ -80,14 +112,13 @@ }, "outputs": [], "source": [ - "sos run pipeline/covariate_formatting.ipynb merge_genotype_pc \\\n", - " --cwd output/covariate/ \\\n", - " --pcaFile output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.rds \\\n", - " --covFile input/covariate/protocol_example.covariates.base.tsv \\\n", - " --name protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca \\\n", - " --tol-cov 0.4 \\\n", - " --k `awk '$3 < 0.8' output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.scree.txt | tail -1 | cut -f 1`" - ] + "sos run pipeline/covariate_hidden_factor.ipynb Marchenko_PC \\\n", + " --cwd output/covariate \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n", + " --mean-impute-missing\n" + ], + "id": "a10fb6ad" }, { "cell_type": "markdown", @@ -95,10 +126,27 @@ "kernel": "SoS" }, "source": [ - "### Compute residuals and infer hidden factors\n", + "### 3. [Infer PEER factors](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_hidden_factor.html)\n", "\n", - "Using the merged covariate file and the molecular phenotype matrix, compute residuals on the known covariates and infer hidden factors with the Marchenko-Pastur PCA method. `--mean-impute-missing` fills any missing covariate values with the column mean. The output is the final covariate matrix (known covariates + genotype PCs + hidden factors)." - ] + "**What it does:** Residualize the phenotype and estimate the requested number of probabilistic PEER factors.\n" + ], + "id": "89e6dabb" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/covariate_hidden_factor.ipynb PEER \\\n", + " --cwd output/covariate \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n", + " --N 3\n" + ], + "id": "afa6aaa5" }, { "cell_type": "markdown", @@ -106,10 +154,11 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", + "### 4. [Infer configurable PCA factors](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_hidden_factor.html)\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] + "**What it does:** Residualize the phenotype and estimate PCA factors using the selected dimension rule.\n" + ], + "id": "0fa9e389" }, { "cell_type": "code", @@ -119,12 +168,99 @@ }, "outputs": [], "source": [ - "sos run pipeline/covariate_hidden_factor.ipynb Marchenko_PC \\\n", + "sos run pipeline/covariate_hidden_factor.ipynb PCA \\\n", + " --cwd output/covariate \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n", + " --choose_k_method Marchenko \\\n", + " --mean-impute-missing\n" + ], + "id": "60317089" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 5. [Infer factors with bi-cross-validation](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/covariate/covariate_hidden_factor.html)\n", + "\n", + "**What it does:** Residualize the phenotype and select latent structure using the BiCV workflow.\n" + ], + "id": "c5d0f178" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/covariate_hidden_factor.ipynb BiCV \\\n", " --cwd output/covariate \\\n", " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", " --covFile output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz \\\n", - " --mean-impute-missing" - ] + " --N 3\n" + ], + "id": "a104f40d" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Route or step | Products and relative paths |\n", + "| --- | --- |\n", + "| Step 1 | `output/covariate/protocol_example.covariates.protocol_example.genotype.merged.plink_qc.plink_qc.prune.pca.gz` |\n", + "| Step 2 | `output/covariate/protocol_example.rnaseq.Marchenko_PC.gz` |\n", + "| Step 3 | `output/covariate/protocol_example.rnaseq.bed.PEER.gz`; `output/covariate/protocol_example.rnaseq.bed.PEER.diag.pdf`; `output/covariate/protocol_example.rnaseq.bed.PEER_MODEL.hd5` |\n", + "| Step 4 | `output/covariate/protocol_example.rnaseq.Marchenko_PC.gz` when `--choose_k_method Marchenko` is used |\n", + "| Step 5 | `output/covariate/protocol_example.rnaseq.bed.BiCV.gz` |" + ], + "id": "5bd240a3" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", + "\n", + "Step 1 produces a sample-by-covariate matrix containing the observed covariates and selected genotype principal components. A selected hidden-factor route adds latent factors estimated after residualizing the molecular phenotype against those observed covariates.\n", + "\n", + "Use exactly one final matrix in association testing; do not concatenate results from alternative hidden-factor methods.\n" + ], + "id": "eefe4f67" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface\n", + "\n", + "List the workflows and parameters available in each module used by this mini-protocol.\n" + ], + "id": "af8ffbf0" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/covariate_formatting.ipynb -h\n", + "sos run pipeline/covariate_hidden_factor.ipynb -h\n" + ], + "id": "cc7345e3" } ], "metadata": { @@ -162,5 +298,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/data_preprocessing/genotype/GRM.ipynb b/code/SoS/data_preprocessing/genotype/GRM.ipynb index d55068b62..25eb5f56e 100644 --- a/code/SoS/data_preprocessing/genotype/GRM.ipynb +++ b/code/SoS/data_preprocessing/genotype/GRM.ipynb @@ -20,30 +20,38 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "A genomic relationship matrix summarises how genetically similar every pair of samples is, and association models use it to absorb that relatedness rather than mistake it for signal. Computing it from all chromosomes at once creates a problem: the variant being tested contributes to the matrix that is supposed to control for background relatedness, which deflates the very association being measured.\n", + "\n", + "The leave-one-chromosome-out construction avoids that. For each chromosome the GRM is built from every *other* chromosome, so the variants under test never appear in the matrix correcting them. `GCTA` does the computation, and a final step reformats the result for APEX.\n", + "\n", + "Calling the `grm` workflow runs four numbered steps in sequence: write the leave-one-out file list per chromosome, compute the GRM with GCTA, format it for APEX, then collect the per-chromosome results into one list.\n", + "\n", + "**When to run it.** Once per genotype set, before any association scan that takes a GRM." ] }, { + "attachments": {}, "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "For each chromosome, we compute a GRM using data excluding this chromosome. Computation is implemented using `GCTA` software package.\n", + "## Input\n", "\n", - "Running the `grm` pipeline executes **four steps** in sequence:\n", + "- `--genoFile`: a two-column, tab-separated list with one row per chromosome, giving the chromosome number and the path to that chromosome's PLINK 1.0 `.bed`. Its `.bim` and `.fam` must sit beside each `.bed`. Common variants, MAF above 1%, are recommended. Example `input/genotype/protocol_example.genotype.list`, 3 rows:\n", "\n", - "1. **Generate LOCO file list** \u2014 for each chromosome, write a list of the per-chromosome genotype files of all *other* chromosomes (leave-one-chromosome-out).\n", - "2. **Compute LOCO-GRM** \u2014 run `GCTA` on that leave-one-out set to produce the GRM for the held-out chromosome.\n", - "3. **Format output for APEX** \u2014 reshape each GRM into the APEX-compatible kinship table.\n", - "4. **Generate APEX input list** \u2014 write a master list mapping each chromosome to its APEX-formatted LOCO GRM." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Timing:** ~5-10 min on typical compute infrastructure." + " ```\n", + " 20 output/plink/protocol_example.genotype.chr20.bed\n", + " 21 output/plink/protocol_example.genotype.chr21.bed\n", + " 22 output/plink/protocol_example.genotype.chr22.bed\n", + " ```\n", + "\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--numThreads`: threads handed to GCTA, `20` by default.\n", + "- `--job-size`, `--walltime` and `--mem`: cluster job resources." ] }, { @@ -54,40 +62,45 @@ "tags": [] }, "source": [ - "## Input Files\n", + "## Output\n", + "\n", + "- `{cwd}/{name}.chr.loco.txt` - for chromosome N, the list of every *other* chromosome's genotype file. This is what makes it leave-one-out. Example `output/grm_uf/protocol_example.genotype.chr20.loco.txt`, 2 lines:\n", + "\n", + " ```\n", + " output/plink/protocol_example.genotype.chr21\n", + " output/plink/protocol_example.genotype.chr22\n", + " ```\n", + "\n", + "- `{cwd}/{name}.chr.loco.grm.gz` - the GRM for chromosome N computed by GCTA from all other chromosomes, with `.grm.id` naming the samples and `.log` recording the run.\n", + "- `{cwd}/{name}.chr.loco.apex.grm` - the same matrix reformatted for APEX.\n", + "- `{cwd}/{name}.loco_grm_list.txt` - the per-chromosome results collected into one table, `#chr` and the GRM directory. Example:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/genotype/protocol_example.genotype.list` | Two-column, tab-separated list: chromosome number and the path to that chromosome's PLINK 1.0 `.bed` file. One row per chromosome. |\n", - "| `output/plink/protocol_example.genotype.chr.{bed,bim,fam}` | Per-chromosome PLINK 1.0 genotype files referenced by the list above. Common variants (MAF > 1%) are recommended for GRM. |" + " ```\n", + " #chr\tdir\n", + " chr20chr21chr22\toutput/grm_uf/protocol_example.genotype.chr20.apex.grm\n", + " chr20chr21chr22\toutput/grm_uf/protocol_example.genotype.chr21.apex.grm\n", + " ```" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ - "## Output Files\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/grm_uf/protocol_example.genotype.chr.loco.txt` | Per-chromosome leave-one-chromosome-out file list (all chromosomes except chr N). |\n", - "| `output/grm_uf/protocol_example.genotype.chr.loco.grm.gz` | LOCO GRM for chr N, computed by GCTA from all other chromosomes. |\n", - "| `output/grm_uf/protocol_example.genotype.chr.loco.apex.grm` | LOCO GRM reformatted for APEX (LMM) input. |\n", - "| `output/grm_uf/protocol_example.genotype.loco_grm_list.txt` | Master list mapping each chromosome to its APEX-formatted LOCO GRM. |" + "## Minimal Working Example" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Minimal Working Example" + "**Timing**: TBD (on toy dataset)" ] }, { @@ -98,7 +111,9 @@ }, "outputs": [], "source": [ - "sos run pipeline/GRM.ipynb grm \\\n --cwd output/grm_uf \\\n --genoFile input/genotype/protocol_example.genotype.list" + "sos run pipeline/GRM.ipynb grm \\\n", + " --cwd output/grm_uf \\\n", + " --genoFile input/genotype/protocol_example.genotype.list" ] }, { @@ -108,7 +123,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -123,24 +138,54 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], "source": [ - "[global]\n# Work directory & output directory\nparameter: cwd = path(\"output\")\n# The filename name for output data\nparameter: modular_script_dir = path('code/script')\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n# Number of threads\nparameter: numThreads = 20\nparameter: genoFile = paths\ncwd = f\"{cwd:a}\"\n\n## Code below are copied from genotype_formatting.ipynb. Change should be made to codes in that document and sync with this chunk.\nfrom sos.utils import expand_size\nimport os\n\ndef get_genotype_file(geno_file_paths):\n #\n def valid_geno_file(x):\n suffixes = path(x).suffixes\n if suffixes[-1] == '.bed':\n return True\n if len(suffixes)>1 and ''.join(suffixes[-2:]) == \".vcf.gz\":\n return True\n return False\n #\n def complete_geno_path(x, geno_file):\n if not valid_geno_file(x):\n raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n if not os.path.isfile(x):\n # relative path\n if not os.path.isfile(f'{geno_file:ad}/' + x):\n raise ValueError(f\"Cannot find genotype file {x}\")\n else:\n x = f'{geno_file:ad}/' + x\n return x\n # \n def format_chrom(chrom):\n if chrom.startswith('chr'):\n chrom = chrom[3:]\n return chrom\n # Inputs are either VCF or bed, or a vector of them \n if len(geno_file_paths) > 1:\n if all([valid_geno_file(x) for x in geno_file_paths]):\n return paths(geno_file_paths)\n else: \n raise ValueError(f\"Invalid input {geno_file_paths}\")\n # Input is one genotype file or text list of genotype files\n geno_file = geno_file_paths[0]\n if valid_geno_file(geno_file):\n return path(geno_file)\n else: \n units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n if all([len(x) == 1 for x in units]):\n return paths([complete_geno_path(x[0], geno_file) for x in units])\n elif all([len(x) == 2 for x in units]):\n genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n else:\n raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n return genos\n \ngenotypes = get_genotype_file(genoFile)" + "```\n", + "\u001b[91mERROR\u001b[0m: \u001b[91mNotebook JSON is invalid: %s\u001b[0m\n", + "usage: sos run code/SoS/data_preprocessing/genotype/GRM.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " grm\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Work directory & output directory\n", + " --modular-script-dir code/script (as path)\n", + " The filename name for output data\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 20 (as int)\n", + " Number of threads\n", + " --genoFile paths\n", + "\n", + "\n", + "Sections\n", + " grm_1: Generate LOCO file list\n", + " grm_2: Compute LOCO-GRM\n", + " grm_3: Format output for APEX\n", + " grm_4: Generate APEX input list\n", + "```" ] }, { - "attachments": {}, "cell_type": "markdown", "metadata": { "kernel": "SoS" }, "source": [ - "### **Step 1.** Generate LOCO file list" + "## Workflow implementation" ] }, { @@ -151,7 +196,72 @@ }, "outputs": [], "source": [ - "# Generate LOCO file list\n[grm_1]\nchrom = list(genotypes.keys())\ninput: for_each = 'chrom'\noutput: f'{cwd}/{genotypes[_chrom]:bn}.loco.txt'\nwith open(_output, 'w') as f:\n f.write('\\n'.join([str(genotypes[x].with_suffix('')) for x in genotypes if x != _chrom]))" + "[global]\n", + "# Work directory & output directory\n", + "parameter: cwd = path(\"output\")\n", + "# The filename name for output data\n", + "parameter: modular_script_dir = path('code/script')\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "# Number of threads\n", + "parameter: numThreads = 20\n", + "parameter: genoFile = paths\n", + "cwd = f\"{cwd:a}\"\n", + "\n", + "## Code below are copied from genotype_formatting.ipynb. Change should be made to codes in that document and sync with this chunk.\n", + "from sos.utils import expand_size\n", + "import os\n", + "\n", + "def get_genotype_file(geno_file_paths):\n", + " #\n", + " def valid_geno_file(x):\n", + " suffixes = path(x).suffixes\n", + " if suffixes[-1] == '.bed':\n", + " return True\n", + " if len(suffixes)>1 and ''.join(suffixes[-2:]) == \".vcf.gz\":\n", + " return True\n", + " return False\n", + " #\n", + " def complete_geno_path(x, geno_file):\n", + " if not valid_geno_file(x):\n", + " raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n", + " if not os.path.isfile(x):\n", + " # relative path\n", + " if not os.path.isfile(f'{geno_file:ad}/' + x):\n", + " raise ValueError(f\"Cannot find genotype file {x}\")\n", + " else:\n", + " x = f'{geno_file:ad}/' + x\n", + " return x\n", + " # \n", + " def format_chrom(chrom):\n", + " if chrom.startswith('chr'):\n", + " chrom = chrom[3:]\n", + " return chrom\n", + " # Inputs are either VCF or bed, or a vector of them \n", + " if len(geno_file_paths) > 1:\n", + " if all([valid_geno_file(x) for x in geno_file_paths]):\n", + " return paths(geno_file_paths)\n", + " else: \n", + " raise ValueError(f\"Invalid input {geno_file_paths}\")\n", + " # Input is one genotype file or text list of genotype files\n", + " geno_file = geno_file_paths[0]\n", + " if valid_geno_file(geno_file):\n", + " return path(geno_file)\n", + " else: \n", + " units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n", + " if all([len(x) == 1 for x in units]):\n", + " return paths([complete_geno_path(x[0], geno_file) for x in units])\n", + " elif all([len(x) == 2 for x in units]):\n", + " genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n", + " else:\n", + " raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n", + " return genos\n", + " \n", + "genotypes = get_genotype_file(genoFile)" ] }, { @@ -161,7 +271,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 2.** Compute LOCO-GRM" + "#### Generate LOCO file list" ] }, { @@ -172,7 +282,13 @@ }, "outputs": [], "source": [ - "# Compute LOCO-GRM\n[grm_2]\noutput: f'{_input:nn}.grm.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n gcta \\\n --mbfile $[_input] \\\n --make-grm-gz \\\n --out $[_output:nn]\n" + "# Generate LOCO file list\n", + "[grm_1]\n", + "chrom = list(genotypes.keys())\n", + "input: for_each = 'chrom'\n", + "output: f'{cwd}/{genotypes[_chrom]:bn}.loco.txt'\n", + "with open(_output, 'w') as f:\n", + " f.write('\\n'.join([str(genotypes[x].with_suffix('')) for x in genotypes if x != _chrom]))" ] }, { @@ -182,7 +298,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 3.** Format output for APEX" + "#### Compute LOCO-GRM" ] }, { @@ -193,7 +309,15 @@ }, "outputs": [], "source": [ - "# Format output for APEX\n[grm_3]\noutput: f'{_input:nn}.apex.grm'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n Rscript $[modular_script_dir:a]/data_preprocessing/genotype/GRM.R --step format_apex \\\n --grm $[_input] \\\n --id $[_input:n].id \\\n --output $[_output]\n" + "# Compute LOCO-GRM\n", + "[grm_2]\n", + "output: f'{_input:nn}.grm.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " gcta \\\n", + " --mbfile $[_input] \\\n", + " --make-grm-gz \\\n", + " --out $[_output:nn]\n" ] }, { @@ -203,14 +327,36 @@ "kernel": "SoS" }, "source": [ - "### **Step 4.** Generate APEX input list" + "#### Format output for APEX" ] }, { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "# Format output for APEX\n", + "[grm_3]\n", + "output: f'{_input:nn}.apex.grm'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " Rscript $[modular_script_dir:a]/data_preprocessing/genotype/GRM.R --step format_apex \\\n", + " --grm $[_input] \\\n", + " --id $[_input:n].id \\\n", + " --output $[_output]\n" + ] + }, + { + "attachments": {}, "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "#### Generate APEX input list" ] }, { @@ -221,7 +367,15 @@ }, "outputs": [], "source": [ - "# Generate APEX input list\n[grm_4]\ninput: group_by = \"all\"\noutput: f'{cwd}/{path(list(genotypes.values())[1]):bnn}.loco_grm_list.txt'\nbash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n Rscript $[modular_script_dir:a]/data_preprocessing/genotype/GRM.R --step apex_list \\\n --input $[_input:r,] \\\n --chroms $[\" \".join(genotypes.keys())] \\\n --output $[_output]\n" + "# Generate APEX input list\n", + "[grm_4]\n", + "input: group_by = \"all\"\n", + "output: f'{cwd}/{path(list(genotypes.values())[1]):bnn}.loco_grm_list.txt'\n", + "bash: expand= \"$[ ]\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " Rscript $[modular_script_dir:a]/data_preprocessing/genotype/GRM.R --step apex_list \\\n", + " --input $[_input:r,] \\\n", + " --chroms $[\" \".join(genotypes.keys())] \\\n", + " --output $[_output]\n" ] } ], diff --git a/code/SoS/data_preprocessing/genotype/GWAS_QC.ipynb b/code/SoS/data_preprocessing/genotype/GWAS_QC.ipynb index b7af43e26..50c01cfaa 100644 --- a/code/SoS/data_preprocessing/genotype/GWAS_QC.ipynb +++ b/code/SoS/data_preprocessing/genotype/GWAS_QC.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Genotype PLINK File Quality Control\n\nThis workflow implements some preliminary data QC steps for PLINK input files. It supports both PLINK1 binary format (BED/BIM/FAM) and PLINK2 format (PGEN/PVAR/PSAM). VCF format of inputs will be converted to PLINK before performing QC." + "# Genotype PLINK File Quality Control\n", + "\n", + "Runs kinship estimation, variant- and sample-level filtering, and LD pruning over a merged PLINK genotype set, producing the QC-ed genotypes and the pruned variant list used for PCA." ] }, { @@ -15,7 +17,32 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "This module is the standard quality-control pass over a merged PLINK genotype set. It estimates kinship to identify related individuals, filters variants and samples on allele frequency, missingness and Hardy-Weinberg equilibrium, and LD-prunes what survives into the variant set used for PCA. Input may be PLINK1 (`bed/bim/fam`) or PLINK2 (`pgen/pvar/psam`); VCF has to be converted first by `genotype_formatting`.\n", + "\n", + "Four workflows are available, and how they are combined depends on whether the cohort contains relatives.\n", + "\n", + "- `king` estimates kinship with KING, flags pairs above `--kinship`, and splits the cohort into an `*.unrelated` and a `*.related` PLINK set. When no pair passes the threshold it writes an empty related-ID list and stops without splitting.\n", + "- `qc` applies the variant- and sample-level filters and then LD-prunes, writing both the filtered set and the `.prune.in` variant list.\n", + "- `qc_no_prune` is that same filtering step without the pruning stage, which is what to run when the pruned variant list already exists and only has to be extracted.\n", + "- `genotype_phenotype_sample_overlap` intersects the genotype sample list with the samples in a molecular phenotype file. A two-column `--sample-participant-lookup` (`genotype_id`, `sample_id`) translates between naming schemes; without one, the names are assumed to match already.\n", + "\n", + "The usual sequence is `qc_no_prune` for basic filtering, `genotype_phenotype_sample_overlap` to restrict to samples that have phenotype data, `king` to detect relatives, and finally `qc` on the unrelated set to produce the pruned variants for PCA. If KING finds no relatives there is nothing to split, and `qc` runs on the full filtered set with `--keep-samples` instead.\n", + "\n", + "The defaults follow Table 1 of [this GWAS quality-control tutorial](https://dx.doi.org/10.1002%2Fmpr.1608) and are deliberately permissive, because the appropriate thresholds depend on the analysis that follows:\n", + "\n", + "- kinship coefficient 0.0625, which is third-degree relatives and closer\n", + "- MAF and MAC both 0, so common and rare variants are kept\n", + "- variant-level and sample-level missingness both 0.1\n", + "- HWE 1e-15, which is very lenient\n", + "- LD pruning over a 50-variant window, shifting 10 variants at a time, at r2 0.1\n", + "\n", + "For PCA a MAF cutoff of 0.01 is the usual choice, since [common variants are the appropriate basis](https://bmcgenomdata.biomedcentral.com/articles/10.1186/s12863-020-0833-x); for single-variant association a MAC floor of 5 is typical.\n", + "\n", + "One constraint is structural: because both sample- and variant-level QC are applied together, all samples and chromosomes have to be merged into a single file first. That has been run at the scale of 200K exomes and 15 million variants on one merged PLINK set.\n", + "\n", + "**When to run it.** After `genotype_formatting` has merged the per-chromosome genotypes, and before PCA and any association scan. The sample-overlap workflow additionally needs the molecular phenotype file to exist." ] }, { @@ -24,7 +51,53 @@ "kernel": "SoS" }, "source": [ - "This notebook includes workflow for\n\n- Compute kinship matrix in sample and estimate related individuals\n- Genotype and sample QC: by MAF, missing data and HWE\n- LD pruning for follow up PCA analysis on genotype, as needed\n\nA potential limitation is that the workflow requires all samples and chromosomes to be merged as one single file, in order to perform both sample and variant level QC. However, in our experience using this pipeline with 200K exomes with 15 million variants, this pipeline works on the single merged PLINK file." + "## Input\n", + "\n", + "* `--genoFile` -- the merged genotype set, PLINK1 `bed/bim/fam` or PLINK2 `pgen/pvar/psam`, e.g. `output/genotype_formatting/plink/protocol_example.genotype.merged.bed`. `king` takes the QC-ed `.bed`, while `genotype_phenotype_sample_overlap` takes the `.fam` instead. Samples are identified by the FID and IID columns:\n", + "\n", + " ```\n", + " 0\tSAMPLE_001\t0\t0\t0\t-9\n", + " 0\tSAMPLE_002\t0\t0\t0\t-9\n", + " 0\tSAMPLE_003\t0\t0\t0\t-9\n", + " ```\n", + "\n", + "* `--phenoFile` -- the molecular phenotype whose samples are matched against the genotype, `bed.gz` or tsv, e.g. `input/rnaseq/protocol_example.rnaseq.bed.gz`. Sample IDs are the column names after the four positional columns:\n", + "\n", + " ```\n", + " #chr\tstart\tend\tID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMP\n", + " ```\n", + "\n", + "* `--name` -- string identifying the run; it is inserted into every output file name.\n", + "* `--cwd` -- output directory, default `output`.\n", + "\n", + "Restricting samples and variants:\n", + "\n", + "* `--keep-samples` / `--remove-samples` -- FID/IID lists limiting or excluding samples; `--keep-samples` is how the QC step is confined to, say, one ancestry group, or to the samples that have phenotype data.\n", + "* `--keep-variants` / `--exclude-variants` -- variant ID lists. Supplying `--keep-variants` also inserts `.extracted` into the output file name.\n", + "* `--sample-participant-lookup` -- two-column table (`genotype_id`, `sample_id`) used when genotype and phenotype name their samples differently.\n", + "\n", + "Filter thresholds:\n", + "\n", + "* `--kinship` -- kinship coefficient above which a pair counts as related, default `0.0625`.\n", + "* `--kin-maf` -- MAF floor applied before the KING estimate, default `0.01`.\n", + "* `--maf-filter` / `--maf-max-filter` and `--mac-filter` / `--mac-max-filter` -- allele frequency and count bounds; `0` disables a bound.\n", + "* `--geno-filter` -- maximum missingness per variant, default `0.1`.\n", + "* `--mind-filter` -- maximum missingness per sample, default `0.1`.\n", + "* `--hwe-filter` -- Hardy-Weinberg p-value cutoff, default `1e-15`.\n", + "* `--rm-dups` -- drop duplicate variants.\n", + "* `--treat-dosage-missing` -- handle dosage data.\n", + "* `--meta-only` -- write only the SNP and sample lists rather than a PLINK binary set.\n", + "* `--other-args` -- extra PLINK arguments passed through, such as `snps_only` or `write-samples`.\n", + "\n", + "LD pruning:\n", + "\n", + "* `--window`, `--shift`, `--r2` -- pruning window in variants (default `50`), how far it moves each time (`10`), and the r2 ceiling (`0.1`). Setting `--r2 0` skips pruning altogether.\n", + "* `--bad-ld` -- pass PLINK `--bad-ld`, which suppresses the pruning diagnostics that otherwise abort on regions of extreme LD.\n", + "\n", + "Runtime:\n", + "\n", + "* `--numThreads`, `--job-size`, `--walltime`, `--mem` -- threads (default `20`) and cluster resources.\n", + "* `--modular-script-dir` -- location of the shell and R drivers, default `code/script`." ] }, { @@ -33,16 +106,58 @@ "kernel": "SoS" }, "source": [ - "## Methods\n\nDepending on the context of your problem, the workflow can be executed in two ways:\n\n1. Run `qc` command to perform genotype data QC and LD pruning to generate a subset of variants in preparation for analysis such as PCA.\n2. Run `king` first on either the original or a subset of common variants to identify unrelated individuals. The `king` pipeline will split samples to related and unrelated individuals. Then you perform `qc` on these individuals only and finally extract the same set of QC-ed variants for related individuals." + "## Output\n", + "\n", + "* `..plink_qc.{bed,bim,fam}` -- the filtered genotype set, written by `qc_no_prune` and by the filtering step of `qc`. `.extracted` is inserted when `--keep-variants` was supplied, and `--meta-only` produces a `.snplist` instead of a binary set.\n", + "* `..plink_qc.prune.{bed,bim,fam}` and `..plink_qc.prune.in` -- the LD-pruned genotype set and the variant list that defines it. The `.prune.in` list is what PCA consumes:\n", + "\n", + " ```\n", + " chr1:820919_CACTACCTGCTTGTCCAGCAGGTCCACCCTGTCTACACTACCTGCCTGCAAAGCAGATCCACCCTGTCTACACTACCTGGCTGG\n", + " chr1:820929_TTGTCCAGCAGGTCCACCCTGTCTACACTACCTGCCTGCAAAGCAGATCCACCCTGTCTACACTACCTGGCTGGCCAGTAGATC\n", + " chr1:820929_TTGTCCAGCAGGTCCACCCTGTCTACACTACCTGCCTGCAAAGCAGATCCACCCTGTCTACACTACCTGGCTGGCCAGTAGATC\n", + " ```\n", + "\n", + "* `..kin0` -- the KING kinship table, one row per pair above the threshold, with the kinship coefficient in the last column:\n", + "\n", + " ```\n", + " #FID1\tIID1\tFID2\tIID2\tNSNP\tHETHET\tIBS0\tKINSHIP\n", + " 0\tSAMPLE_060\t0\tSAMPLE_059\t59818\t0.108178\t0\t0.248649\n", + " ```\n", + "\n", + "* `..related_id` -- the individuals dropped to leave a maximal unrelated set; the file is created empty when no pair passes `--kinship`:\n", + "\n", + " ```\n", + " 0 SAMPLE_060\n", + " ```\n", + "\n", + "* `..unrelated.{bed,bim,fam}` and `..related.{bed,bim,fam}` -- the split cohort, written only when relatives were found.\n", + "* `.sample_genotypes.txt` -- FID/IID of the samples present in both genotype and phenotype, in the form PLINK `--keep` expects:\n", + "\n", + " ```\n", + " 0\tSAMPLE_001\n", + " 0\tSAMPLE_002\n", + " 0\tSAMPLE_003\n", + " ```\n", + "\n", + "* `.sample_overlap.txt` -- the same overlap as a `genotype_id` / `sample_id` table:\n", + "\n", + " ```\n", + " genotype_id\tsample_id\n", + " SAMPLE_001\tSAMPLE_001\n", + " SAMPLE_002\tSAMPLE_002\n", + " ```\n", + "\n", + "Each step also writes PLINK `.log` files and `.stdout` / `.stderr` beside its output. Example results for the toy data are under `output/gwas_qc/`." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Default Parameters: QC\n\n- Kinship coefficient for related individuals: 0.0625\n- MAF and MAC default: 0\n - Above default includes both common and are variant\n - Recommand MAF for PCA: 0.01, [we should stick to common variants](https://bmcgenomdata.biomedcentral.com/articles/10.1186/s12863-020-0833-x)\n - Recommand MAC for single variant analysis: 5.\n- Variant level missingness threshold: 0.1\n- Sample level missingness threshold: 0.1\n- LD pruning via PLINK for PCA analysis:\n - window 50 \n - shift 10 \n - r2 0.1\n- HWE default: 1E-15 which is very lenient" + "## Minimal Working Example" ] }, { @@ -51,7 +166,9 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n\n| File | Description |\n|------|-------------|\n| `output/genotype_formatting/plink/protocol_example.genotype.merged.{bed,bim,fam}` | Merged genome-wide PLINK bundle from genotype_formatting (Step 1 input) |\n| `input/rnaseq/protocol_example.rnaseq.bed.gz` | Toy RNA-seq expression phenotype (60 samples SAMPLE_001..060) for sample matching |\n\nGenotype input may be PLINK1 (bed/bim/fam) or PLINK2 (pgen/pvar/psam). For VCF input, first convert with the `genotype_formatting` pipeline.\n" + "### Genotype QC of the protocol example data\n", + "\n", + "The `chr1_chr6` set was merged from the `chr1` and `chr6` data with the `merge_plink` command in [genotype formatting](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html). The steps below run in order, each consuming what the earlier ones produced." ] }, { @@ -60,17 +177,9 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n\n| File | Description |\n|------|-------------|\n| `output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.{bed,bim,fam}` | Basic-QC genotype (Step 1) |\n| `output/gwas_qc/genotype/protocol_example.rnaseq.bed.sample_genotypes.txt` | Genotype-sample list overlapping the phenotype (Step 2) |\n| `output/gwas_qc/kinship/*.king.unrelated.{bed,bim,fam}` and `*.king.related.{bed,bim,fam}` | KING-split unrelated/related sets (Step 3) |\n| `output/gwas_qc/genotype/*.king.unrelated.plink_qc.prune.in` | LD-pruned variant list for PCA (Step 4) |\n| `output/gwas_qc/cache/*.for_pca.{bed,bim,fam}` | Pruned genotype set prepared for PCA (Step 5) |\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS", - "tags": [] - }, - "source": [ - "## Minimal Working Example\n\nMinimal working example data-set can be downloaded from [Synapse](https://www.synapse.org/#!Synapse:syn69670658/files/).\n\nThe `chr1_chr6` data-set was merged from `chr1` and `chr6` data, using `merge_plink` command from [genotype formatting](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html) pipeline." + "#### Step 1. Basic QC (rare and common variants)\n", + "\n", + "Apply the variant- and sample-level filters: missingness, HWE and MAC." ] }, { @@ -79,16 +188,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** Basic QC (rare and common variants)\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Apply variant- and sample-level filters (missingness, HWE, MAC). Timing: <1 min on toy data.\n" + "**Timing**: <1 min (on toy dataset)" ] }, { @@ -101,7 +201,14 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n --cwd output/gwas_qc/plink \\\n --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n --name protocol_example \\\n --geno-filter 0.1 \\\n --mind-filter 0.1 \\\n --hwe-filter 1e-08 \\\n --mac-filter 0" + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/gwas_qc/plink \\\n", + " --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n", + " --name protocol_example \\\n", + " --geno-filter 0.1 \\\n", + " --mind-filter 0.1 \\\n", + " --hwe-filter 1e-08 \\\n", + " --mac-filter 0" ] }, { @@ -110,7 +217,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 2.** Sample Match with Phenotype\n" + "#### Step 2. Sample match with phenotype\n", + "\n", + "Find the samples shared between genotype and phenotype and write the overlapping sample lists." ] }, { @@ -119,7 +228,7 @@ "kernel": "SoS" }, "source": [ - "Find samples shared between genotype and phenotype, writing the overlapping sample lists. Timing: <1 min.\n" + "**Timing**: <1 min (on toy dataset)" ] }, { @@ -133,7 +242,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb genotype_phenotype_sample_overlap \\\n --cwd output/gwas_qc/genotype \\\n --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.fam \\\n --phenoFile input/rnaseq/protocol_example.rnaseq.bed.gz \\\n --name protocol_example" + "sos run pipeline/GWAS_QC.ipynb genotype_phenotype_sample_overlap \\\n", + " --cwd output/gwas_qc/genotype \\\n", + " --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.fam \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.bed.gz \\\n", + " --name protocol_example" ] }, { @@ -143,7 +256,9 @@ "tags": [] }, "source": [ - "### **Step 3.** Kinship QC\n\nEstimate kinship with KING and split samples into related and unrelated sets. In this toy dataset SAMPLE_059 and SAMPLE_060 are a parent-offspring pair, so KING **does** detect related individuals and produces both `*.related.bed` and `*.unrelated.bed`.\n" + "#### Step 3. Kinship QC\n", + "\n", + "Estimate kinship with KING and split the samples into related and unrelated sets. In the toy data SAMPLE_059 and SAMPLE_060 are a parent-offspring pair, so KING does find relatives and writes both `*.related.bed` and `*.unrelated.bed`." ] }, { @@ -152,7 +267,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <2 min on toy data.\n" + "**Timing**: <2 min (on toy dataset)" ] }, { @@ -165,7 +280,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb king \\\n --cwd output/gwas_qc/kinship \\\n --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n --name protocol_example.king \\\n --keep-samples output/gwas_qc/genotype/protocol_example.rnaseq.bed.sample_genotypes.txt" + "sos run pipeline/GWAS_QC.ipynb king \\\n", + " --cwd output/gwas_qc/kinship \\\n", + " --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n", + " --name protocol_example.king \\\n", + " --keep-samples output/gwas_qc/genotype/protocol_example.rnaseq.bed.sample_genotypes.txt" ] }, { @@ -174,7 +293,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 4.** Prepare Unrelated Individuals for PCA\n\nBecause related individuals were detected (Step 3), run `qc` on the KING `*.unrelated.bed` to produce the LD-pruned, unrelated genotype set used downstream for PCA.\n" + "#### Step 4. Prepare unrelated individuals for PCA\n", + "\n", + "Because Step 3 found related individuals, run `qc` on the KING `*.unrelated.bed` to produce the LD-pruned, unrelated genotype set used downstream for PCA." ] }, { @@ -183,7 +304,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min on toy data.\n" + "**Timing**: <1 min (on toy dataset)" ] }, { @@ -197,18 +318,23 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc \\\n --cwd output/gwas_qc/genotype \\\n --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.bed \\\n --name protocol_example \\\n --mac-filter 5" + "sos run pipeline/GWAS_QC.ipynb qc \\\n", + " --cwd output/gwas_qc/genotype \\\n", + " --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.bed \\\n", + " --name protocol_example \\\n", + " --mac-filter 5" ] }, { "cell_type": "markdown", "metadata": { - "jp-MarkdownHeadingCollapsed": true, "kernel": "SoS", "tags": [] }, "source": [ - "**Alternative (no related individuals):** if KING reports `No related individuals detected` and produces no `*.unrelated.bed`, run `qc` on the original QC genotype with `--keep-samples` instead. For this toy dataset related individuals ARE present, so the Step 4 path above applies; the command below is shown for reference.\n" + "#### Alternative to Step 4: no related individuals\n", + "\n", + "If KING reports no related individuals and writes no `*.unrelated.bed`, run `qc` on the QC-ed genotype with `--keep-samples` instead. Relatives are present in this toy data, so Step 4 is the path that applies here and the command below is shown only for reference." ] }, { @@ -217,7 +343,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min" + "**Timing**: <1 min (on toy dataset)" ] }, { @@ -228,7 +354,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc \\\n --cwd output/gwas_qc/genotype \\\n --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n --name protocol_example \\\n --mac-filter 5" + "sos run pipeline/GWAS_QC.ipynb qc \\\n", + " --cwd output/gwas_qc/genotype \\\n", + " --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n", + " --name protocol_example \\\n", + " --mac-filter 5" ] }, { @@ -237,7 +367,18 @@ "kernel": "Bash" }, "source": [ - "### **Step 5.** Extract Pruned Variants for PCA\n\nExtract the LD-pruned variants (from Step 4) out of the full genotype set, applying only sample-level missingness, in preparation for PCA.\n" + "#### Step 5. Extract pruned variants for PCA\n", + "\n", + "Extract the LD-pruned variants from Step 4 out of the full genotype set, applying only sample-level missingness, in preparation for PCA." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -248,7 +389,14 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n --cwd output/gwas_qc/cache \\\n --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n --geno-filter 0 \\\n --mind-filter 0.1 \\\n --maf-filter 0 \\\n --keep-variants output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.in \\\n --name for_pca" + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/gwas_qc/cache \\\n", + " --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n", + " --geno-filter 0 \\\n", + " --mind-filter 0.1 \\\n", + " --maf-filter 0 \\\n", + " --keep-variants output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.in \\\n", + " --name for_pca" ] }, { @@ -269,18 +417,130 @@ }, "outputs": [], "source": [ - "sos run GWAS_QC.ipynb -h" + "sos run pipeline/GWAS_QC.ipynb -h" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], "source": [ - "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# the output directory for generated files\nparameter: cwd = path(\"output\")\n# A string to identify your analysis run\nparameter: name = str\n# PLINK binary files (either BED/BIM/FAM or PGEN/PVAR/PSAM format)\nparameter: genoFile = paths\n# The path to the file that contains the list of samples to remove (format FID, IID)\nparameter: remove_samples = path('.')\n# The path to the file that contains the list of samples to keep (format FID, IID)\nparameter: keep_samples = path('.')\n# The path to the file that contains the list of variants to keep\nparameter: keep_variants = path('.')\n# The path to the file that contains the list of variants to exclude\nparameter: exclude_variants = path('.')\n# Kinship coefficient threshold for related individuals\n# (e.g first degree above 0.25, second degree above 0.125, third degree above 0.0625)\nparameter: kinship = 0.0625\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n# Number of threads\nparameter: numThreads = 20\n# use this function to edit memory string for PLINK input\nfrom sos.utils import expand_size\ncwd = path(f\"{cwd:a}\")\n\n# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\ndef determine_plink_format(file_path):\n \"\"\"\n Determine the PLINK file format based on file extensions and companion files.\n \n Args:\n file_path (str or Path): Path to the input file\n \n Returns:\n str: 'plink1' or 'plink2'\n \"\"\"\n # Convert to string if it's a Path object\n file_path = str(file_path)\n \n # Check direct file extensions\n if file_path.endswith('.bed'):\n return 'plink1'\n elif file_path.endswith('.pgen'):\n return 'plink2'\n \n # If the file doesn't have a standard extension, try to infer format\n try:\n # Remove the file extension if present\n base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n \n # Check for PLINK1 companion files\n plink1_companion_files = [\n f\"{base_path}.bim\",\n f\"{base_path}.fam\"\n ]\n \n # Check for PLINK2 companion files\n plink2_companion_files = [\n f\"{base_path}.pvar\",\n f\"{base_path}.psam\"\n ]\n \n # Check PLINK1 format\n if all(os.path.exists(f) for f in plink1_companion_files):\n return 'plink1'\n \n # Check PLINK2 format\n if all(os.path.exists(f) for f in plink2_companion_files):\n return 'plink2'\n \n except Exception as e:\n print(f\"Error determining PLINK format: {e}\")\n \n # Default to PLINK1 if can't determine\n return 'plink1'\n\n\n# Get the appropriate PLINK command based on the input file format\ndef get_plink_command_prefix(file_path):\n format_type = determine_plink_format(file_path)\n if format_type == 'plink1':\n return \"--bfile\"\n else: # plink2\n return \"--pfile\"\n \n# Generate the appropriate file extension based on the requested format\ndef get_output_extension(output_format, is_prune=False):\n if output_format == 'plink1':\n return '.bed' if not is_prune else '.prune.bed'\n else: # plink2\n return '.pgen' if not is_prune else '.prune.pgen'\n \n# Choose the make-bed or make-pgen command based on desired output format\ndef get_make_command(output_format):\n if output_format == 'plink1':\n return '--make-bed'\n else: # plink2\n return '--make-pgen'\n\ndef get_other_args_flags(other_args):\n import re\n if not other_args:\n return \"\"\n args = [other_args] if isinstance(other_args, str) else list(other_args)\n flags = []\n for arg in args:\n arg = str(arg)\n if not re.fullmatch(r\"[A-Za-z0-9][A-Za-z0-9_.:-]*\", arg):\n raise ValueError(f\"Cannot safely pass PLINK other_args value: {arg}\")\n flags.append(f\"--other-arg {arg}\")\n return \" \".join(flags)" + "```\n", + "usage: sos run pipeline/GWAS_QC.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " king\n", + " qc_no_prune\n", + " qc\n", + " genotype_phenotype_sample_overlap\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " the output directory for generated files\n", + " --name VAL (as str, required)\n", + " A string to identify your analysis run\n", + " --genoFile paths\n", + "\n", + " PLINK binary files (either BED/BIM/FAM or PGEN/PVAR/PSAM\n", + " format)\n", + " --remove-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to remove (format FID, IID)\n", + " --keep-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to keep (format FID, IID)\n", + " --keep-variants . (as path)\n", + " The path to the file that contains the list of variants\n", + " to keep\n", + " --exclude-variants . (as path)\n", + " The path to the file that contains the list of variants\n", + " to exclude\n", + " --kinship 0.0625 (as float)\n", + " Kinship coefficient threshold for related individuals\n", + " (e.g first degree above 0.25, second degree above 0.125,\n", + " third degree above 0.0625)\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 20 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " king_1: Inference of relationships in the sample to identify\n", + " closely related individuals\n", + " Workflow Options:\n", + " --kin-maf 0.01 (as float)\n", + " PLINK binary file\n", + " king_2: Select a list of unrelated individual with an attempt to\n", + " maximize the unrelated individuals selected from the\n", + " data\n", + " king_3: Split genotype data into related and unrelated samples,\n", + " if related individuals are detected\n", + " qc_no_prune, qc_1: Filter SNPs and select individuals\n", + " Workflow Options:\n", + " --maf-filter 0.0 (as float)\n", + " minimum MAF filter to use. 0 means do not apply this\n", + " filter.\n", + " --maf-max-filter 0.0 (as float)\n", + " maximum MAF filter to use. 0 means do not apply this\n", + " filter.\n", + " --mac-filter 0.0 (as float)\n", + " minimum MAC filter to use. 0 means do not apply this\n", + " filter.\n", + " --mac-max-filter 0.0 (as float)\n", + " maximum MAC filter to use. 0 means do not apply this\n", + " filter.\n", + " --geno-filter 0.1 (as float)\n", + " Maximum missingess per-variant\n", + " --mind-filter 0.1 (as float)\n", + " Maximum missingness per-sample\n", + " --hwe-filter 1e-15 (as float)\n", + " HWE filter -- a very lenient one\n", + " --other-args (as list)\n", + " Other PLINK arguments e.g snps_only, write-samples, etc\n", + " --[no-]meta-only (default to False)\n", + " Only output SNP and sample list, rather than the PLINK\n", + " binary format of subset data\n", + " --[no-]rm-dups (default to False)\n", + " Remove duplicate variants\n", + " --[no-]treat-dosage-missing (default to False)\n", + " Add option to process dosage\n", + " qc_2: LD prunning and remove related individuals (both ind of\n", + " a pair) Plink2 has multi-threaded calculation for LD\n", + " prunning\n", + " Workflow Options:\n", + " --window 50 (as int)\n", + " Window size\n", + " --shift 10 (as int)\n", + " Shift window every 10 snps\n", + " --r2 0.1 (as float)\n", + " --mac-filter 0.0 (as float)\n", + " --other-args (as list)\n", + " --[no-]bad-ld (default to False)\n", + " Use PLINK --bad-ld flag (skip LD pruning diagnostics for\n", + " regions with extreme LD)\n", + " genotype_phenotype_sample_overlap: This workflow extracts overlapping samples\n", + " for genotype data with phenotype data, and output the\n", + " filtered sample genotype list as well as sample\n", + " phenotype list\n", + " Workflow Options:\n", + " --phenoFile VAL (as path, required)\n", + " A phenotype file, can be bed.gz or tsv\n", + " --sample-participant-lookup . (as path)\n", + " If this file is provided, a genotype/phenotype sample\n", + " name match will be performed It must contain two column\n", + " names: genotype_id, sample_id\n", + "```" ] }, { @@ -289,7 +549,9 @@ "kernel": "SoS" }, "source": [ - "## Estimate kinship in the sample\n\nThe output is a list of related individuals, as well as the kinship matrix" + "## Workflow implementation\n", + "\n", + "The SoS workflow definitions below are unchanged from the original protocol." ] }, { @@ -300,18 +562,134 @@ }, "outputs": [], "source": [ - "# Inference of relationships in the sample to identify closely related individuals\n[king_1]\n# PLINK binary file\nparameter: kin_maf = 0.01\ninput: genoFile\noutput: f'{cwd}/{_input:bn}{(\".\"+name) if name else \"\"}.kin0'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nplink_command = get_plink_command_prefix(genoFile)\nbash: expand= \"${ }\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh king \\\n --cwd \"${cwd}\" \\\n --genoFile \"${genoFile}\" \\\n --plink-command \"${plink_command}\" \\\n --out-prefix \"${_output:n}\" \\\n --keep-samples \"${keep_samples}\" \\\n --remove-samples \"${remove_samples}\" \\\n --name \"${name}\" \\\n --kinship ${kinship} \\\n --kin-maf ${kin_maf} \\\n --numThreads ${numThreads}" + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# the output directory for generated files\n", + "parameter: cwd = path(\"output\")\n", + "# A string to identify your analysis run\n", + "parameter: name = str\n", + "# PLINK binary files (either BED/BIM/FAM or PGEN/PVAR/PSAM format)\n", + "parameter: genoFile = paths\n", + "# The path to the file that contains the list of samples to remove (format FID, IID)\n", + "parameter: remove_samples = path('.')\n", + "# The path to the file that contains the list of samples to keep (format FID, IID)\n", + "parameter: keep_samples = path('.')\n", + "# The path to the file that contains the list of variants to keep\n", + "parameter: keep_variants = path('.')\n", + "# The path to the file that contains the list of variants to exclude\n", + "parameter: exclude_variants = path('.')\n", + "# Kinship coefficient threshold for related individuals\n", + "# (e.g first degree above 0.25, second degree above 0.125, third degree above 0.0625)\n", + "parameter: kinship = 0.0625\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "# Number of threads\n", + "parameter: numThreads = 20\n", + "# use this function to edit memory string for PLINK input\n", + "from sos.utils import expand_size\n", + "cwd = path(f\"{cwd:a}\")\n", + "\n", + "# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\n", + "def determine_plink_format(file_path):\n", + " \"\"\"\n", + " Determine the PLINK file format based on file extensions and companion files.\n", + " \n", + " Args:\n", + " file_path (str or Path): Path to the input file\n", + " \n", + " Returns:\n", + " str: 'plink1' or 'plink2'\n", + " \"\"\"\n", + " # Convert to string if it's a Path object\n", + " file_path = str(file_path)\n", + " \n", + " # Check direct file extensions\n", + " if file_path.endswith('.bed'):\n", + " return 'plink1'\n", + " elif file_path.endswith('.pgen'):\n", + " return 'plink2'\n", + " \n", + " # If the file doesn't have a standard extension, try to infer format\n", + " try:\n", + " # Remove the file extension if present\n", + " base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n", + " \n", + " # Check for PLINK1 companion files\n", + " plink1_companion_files = [\n", + " f\"{base_path}.bim\",\n", + " f\"{base_path}.fam\"\n", + " ]\n", + " \n", + " # Check for PLINK2 companion files\n", + " plink2_companion_files = [\n", + " f\"{base_path}.pvar\",\n", + " f\"{base_path}.psam\"\n", + " ]\n", + " \n", + " # Check PLINK1 format\n", + " if all(os.path.exists(f) for f in plink1_companion_files):\n", + " return 'plink1'\n", + " \n", + " # Check PLINK2 format\n", + " if all(os.path.exists(f) for f in plink2_companion_files):\n", + " return 'plink2'\n", + " \n", + " except Exception as e:\n", + " print(f\"Error determining PLINK format: {e}\")\n", + " \n", + " # Default to PLINK1 if can't determine\n", + " return 'plink1'\n", + "\n", + "\n", + "# Get the appropriate PLINK command based on the input file format\n", + "def get_plink_command_prefix(file_path):\n", + " format_type = determine_plink_format(file_path)\n", + " if format_type == 'plink1':\n", + " return \"--bfile\"\n", + " else: # plink2\n", + " return \"--pfile\"\n", + " \n", + "# Generate the appropriate file extension based on the requested format\n", + "def get_output_extension(output_format, is_prune=False):\n", + " if output_format == 'plink1':\n", + " return '.bed' if not is_prune else '.prune.bed'\n", + " else: # plink2\n", + " return '.pgen' if not is_prune else '.prune.pgen'\n", + " \n", + "# Choose the make-bed or make-pgen command based on desired output format\n", + "def get_make_command(output_format):\n", + " if output_format == 'plink1':\n", + " return '--make-bed'\n", + " else: # plink2\n", + " return '--make-pgen'\n", + "\n", + "def get_other_args_flags(other_args):\n", + " import re\n", + " if not other_args:\n", + " return \"\"\n", + " args = [other_args] if isinstance(other_args, str) else list(other_args)\n", + " flags = []\n", + " for arg in args:\n", + " arg = str(arg)\n", + " if not re.fullmatch(r\"[A-Za-z0-9][A-Za-z0-9_.:-]*\", arg):\n", + " raise ValueError(f\"Cannot safely pass PLINK other_args value: {arg}\")\n", + " flags.append(f\"--other-arg {arg}\")\n", + " return \" \".join(flags)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], "source": [ - "# Select a list of unrelated individual with an attempt to maximize the unrelated individuals selected from the data \n[king_2: shared = \"related_id\" ]\nrelated_id = [x.strip() for x in open(_input).readlines() if not x.startswith(\"#\")]\noutput: f'{_input:n}.related_id'\nwith open(_output, 'a'):\n pass\ndone_if(len(related_id) == 0, msg = f\"No related individuals detected from {_input}.\")\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.R \\\n --step king_2 \\\n --input \"${_input}\" \\\n --output \"${_output}\" \\\n --kinship ${kinship}" + "### Kinship estimation and cohort split\n", + "\n", + "`king_1` runs KING to produce the kinship table, `king_2` chooses which individuals to drop, and `king_3` writes the related and unrelated PLINK sets." ] }, { @@ -322,16 +700,50 @@ }, "outputs": [], "source": [ - "# Split genotype data into related and unrelated samples, if related individuals are detected\n[king_3]\ndepends: sos_variable(\"related_id\")\ninput: output_from(2), genoFile\noutput_format = determine_plink_format(_input[1])\noutput_ext = get_output_extension(output_format)\noutput: unrelated_bed = f'{cwd}/{_input[0]:bn}.unrelated{output_ext}',\n related_bed = f'{cwd}/{_input[0]:bn}.related{output_ext}'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh king_split \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input[1]}\" \\\n --remove-samples \"${_input[0]}\" \\\n ${('--keep-samples \"%s\"' % keep_samples) if keep_samples.is_file() else \"\"} \\\n --out-unrelated \"${_output[0]:n}\" \\\n --out-related \"${_output[1]:n}\" \\\n --related-output \"${_output[1]}\" \\\n --numThreads ${numThreads}\n" + "# Inference of relationships in the sample to identify closely related individuals\n", + "[king_1]\n", + "# PLINK binary file\n", + "parameter: kin_maf = 0.01\n", + "input: genoFile\n", + "output: f'{cwd}/{_input:bn}{(\".\"+name) if name else \"\"}.kin0'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "plink_command = get_plink_command_prefix(genoFile)\n", + "bash: expand= \"${ }\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh king \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${genoFile}\" \\\n", + " --plink-command \"${plink_command}\" \\\n", + " --out-prefix \"${_output:n}\" \\\n", + " --keep-samples \"${keep_samples}\" \\\n", + " --remove-samples \"${remove_samples}\" \\\n", + " --name \"${name}\" \\\n", + " --kinship ${kinship} \\\n", + " --kin-maf ${kin_maf} \\\n", + " --numThreads ${numThreads}" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Genotype and sample QC\n\nQC the genetic data based on MAF, sample and variant missigness and Hardy-Weinberg Equilibrium (HWE).\n\nIn this step you may also provide a list of samples to keep, for example in the case when you would like to subset a sample based on their ancestries to perform independent analyses on each of these groups.\n\nThe default parameters are set to reflect some suggestions in Table 1 of [this paper](https://dx.doi.org/10.1002%2Fmpr.1608)." + "# Select a list of unrelated individual with an attempt to maximize the unrelated individuals selected from the data \n", + "[king_2: shared = \"related_id\" ]\n", + "related_id = [x.strip() for x in open(_input).readlines() if not x.startswith(\"#\")]\n", + "output: f'{_input:n}.related_id'\n", + "with open(_output, 'a'):\n", + " pass\n", + "done_if(len(related_id) == 0, msg = f\"No related individuals detected from {_input}.\")\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.R \\\n", + " --step king_2 \\\n", + " --input \"${_input}\" \\\n", + " --output \"${_output}\" \\\n", + " --kinship ${kinship}" ] }, { @@ -342,7 +754,36 @@ }, "outputs": [], "source": [ - "# Filter SNPs and select individuals \n[qc_no_prune, qc_1 (basic QC filters)]\n# minimum MAF filter to use. 0 means do not apply this filter.\nparameter: maf_filter = 0.0\n# maximum MAF filter to use. 0 means do not apply this filter.\nparameter: maf_max_filter = 0.0\n# minimum MAC filter to use. 0 means do not apply this filter.\nparameter: mac_filter = 0.0\n# maximum MAC filter to use. 0 means do not apply this filter.\nparameter: mac_max_filter = 0.0 \n# Maximum missingess per-variant\nparameter: geno_filter = 0.1\n# Maximum missingness per-sample\nparameter: mind_filter = 0.1\n# HWE filter -- a very lenient one\nparameter: hwe_filter = 1e-15\n# Other PLINK arguments e.g snps_only, write-samples, etc\nparameter: other_args = []\n# Only output SNP and sample list, rather than the PLINK binary format of subset data\nparameter: meta_only = False\n# Remove duplicate variants\nparameter: rm_dups = False\n# Add option to process dosage\nparameter: treat_dosage_missing = False\n\nfail_if(not (keep_samples.is_file() or keep_samples == path('.')), msg = f'Cannot find ``{keep_samples}``')\nfail_if(not (keep_variants.is_file() or keep_variants == path('.')), msg = f'Cannot find ``{keep_variants}``')\nfail_if(not (remove_samples.is_file() or remove_samples == path('.')), msg = f'Cannot find ``{remove_samples}``')\n\ninput: genoFile, group_by=1\nplink_command = get_plink_command_prefix(_input)\noutput_format = determine_plink_format(_input)\nmake_command = get_make_command(output_format) if not meta_only else \"--write-snplist --write-samples\"\noutput_ext = get_output_extension(output_format) if not meta_only else \".snplist\"\nother_args_flags = get_other_args_flags(other_args)\noutput: f'{cwd}/{_input:bn}{(\".\" + name) if name else \"\"}.plink_qc{\".extracted\" if keep_variants.is_file() else \"\"}{output_ext}'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh qc_no_prune \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --plink-command \"${plink_command}\" \\\n --output-format \"${output_format}\" \\\n --make-command \"${make_command}\" \\\n --out-prefix \"${_output:n}\" \\\n --name \"${name}\" \\\n --mac-filter ${mac_filter} \\\n --maf-filter ${maf_filter} \\\n --maf-max-filter ${maf_max_filter} \\\n --mac-max-filter ${mac_max_filter} \\\n --geno-filter ${geno_filter} \\\n --mind-filter ${mind_filter} \\\n --hwe-filter ${hwe_filter} \\\n ${\"--keep-samples \" + str(keep_samples) if keep_samples.is_file() else \"\"} \\\n ${\"--remove-samples \" + str(remove_samples) if remove_samples.is_file() else \"\"} \\\n ${\"--exclude-variants \" + str(exclude_variants) if exclude_variants.is_file() else \"\"} \\\n ${\"--keep-variants \" + str(keep_variants) if keep_variants.is_file() else \"\"} \\\n ${\"--meta-only\" if meta_only else \"\"} \\\n ${\"--rm-dups\" if rm_dups else \"\"} \\\n ${\"--treat-dosage-missing\" if treat_dosage_missing else \"\"} \\\n ${other_args_flags} \\\n --numThreads ${numThreads}" + "# Split genotype data into related and unrelated samples, if related individuals are detected\n", + "[king_3]\n", + "depends: sos_variable(\"related_id\")\n", + "input: output_from(2), genoFile\n", + "output_format = determine_plink_format(_input[1])\n", + "output_ext = get_output_extension(output_format)\n", + "output: unrelated_bed = f'{cwd}/{_input[0]:bn}.unrelated{output_ext}',\n", + " related_bed = f'{cwd}/{_input[0]:bn}.related{output_ext}'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh king_split \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input[1]}\" \\\n", + " --remove-samples \"${_input[0]}\" \\\n", + " ${('--keep-samples \"%s\"' % keep_samples) if keep_samples.is_file() else \"\"} \\\n", + " --out-unrelated \"${_output[0]:n}\" \\\n", + " --out-related \"${_output[1]:n}\" \\\n", + " --related-output \"${_output[1]}\" \\\n", + " --numThreads ${numThreads}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Variant and sample filtering\n", + "\n", + "`qc_no_prune`, which doubles as the first step of `qc`, applies the frequency, missingness and HWE filters; `qc_2` performs the LD pruning." ] }, { @@ -353,16 +794,114 @@ }, "outputs": [], "source": [ - "# LD prunning and remove related individuals (both ind of a pair)\n# Plink2 has multi-threaded calculation for LD prunning\n[qc_2 (LD pruning)]\n# Window size\nparameter: window = 50\n# Shift window every 10 snps\nparameter: shift = 10\nparameter: r2 = 0.1\nparameter: mac_filter = 0.0\nparameter: other_args = []\n# Use PLINK --bad-ld flag (skip LD pruning diagnostics for regions with extreme LD)\nparameter: bad_ld = False\nstop_if(r2==0)\nplink_command = get_plink_command_prefix(_input)\noutput_format = determine_plink_format(_input)\nmake_command = get_make_command(output_format)\noutput_ext = get_output_extension(output_format, is_prune=True)\nother_args_flags = get_other_args_flags(other_args)\noutput: bed=f'{cwd}/{_input:bn}{output_ext}', prune=f'{cwd}/{_input:bn}.prune.in'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh qc \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --plink-command \"${plink_command}\" \\\n --output-format \"${output_format}\" \\\n --make-command \"${make_command}\" \\\n --prune-prefix \"${_output['prune']:nn}\" \\\n --out-prefix \"${_output['bed']:n}\" \\\n --mac-filter ${mac_filter} \\\n --window ${window} \\\n --shift ${shift} \\\n --r2 ${r2} \\\n ${\"--bad-ld\" if bad_ld else \"\"} \\\n ${other_args_flags} \\\n --numThreads ${numThreads}" + "# Filter SNPs and select individuals \n", + "[qc_no_prune, qc_1 (basic QC filters)]\n", + "# minimum MAF filter to use. 0 means do not apply this filter.\n", + "parameter: maf_filter = 0.0\n", + "# maximum MAF filter to use. 0 means do not apply this filter.\n", + "parameter: maf_max_filter = 0.0\n", + "# minimum MAC filter to use. 0 means do not apply this filter.\n", + "parameter: mac_filter = 0.0\n", + "# maximum MAC filter to use. 0 means do not apply this filter.\n", + "parameter: mac_max_filter = 0.0 \n", + "# Maximum missingess per-variant\n", + "parameter: geno_filter = 0.1\n", + "# Maximum missingness per-sample\n", + "parameter: mind_filter = 0.1\n", + "# HWE filter -- a very lenient one\n", + "parameter: hwe_filter = 1e-15\n", + "# Other PLINK arguments e.g snps_only, write-samples, etc\n", + "parameter: other_args = []\n", + "# Only output SNP and sample list, rather than the PLINK binary format of subset data\n", + "parameter: meta_only = False\n", + "# Remove duplicate variants\n", + "parameter: rm_dups = False\n", + "# Add option to process dosage\n", + "parameter: treat_dosage_missing = False\n", + "\n", + "fail_if(not (keep_samples.is_file() or keep_samples == path('.')), msg = f'Cannot find ``{keep_samples}``')\n", + "fail_if(not (keep_variants.is_file() or keep_variants == path('.')), msg = f'Cannot find ``{keep_variants}``')\n", + "fail_if(not (remove_samples.is_file() or remove_samples == path('.')), msg = f'Cannot find ``{remove_samples}``')\n", + "\n", + "input: genoFile, group_by=1\n", + "plink_command = get_plink_command_prefix(_input)\n", + "output_format = determine_plink_format(_input)\n", + "make_command = get_make_command(output_format) if not meta_only else \"--write-snplist --write-samples\"\n", + "output_ext = get_output_extension(output_format) if not meta_only else \".snplist\"\n", + "other_args_flags = get_other_args_flags(other_args)\n", + "output: f'{cwd}/{_input:bn}{(\".\" + name) if name else \"\"}.plink_qc{\".extracted\" if keep_variants.is_file() else \"\"}{output_ext}'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh qc_no_prune \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --plink-command \"${plink_command}\" \\\n", + " --output-format \"${output_format}\" \\\n", + " --make-command \"${make_command}\" \\\n", + " --out-prefix \"${_output:n}\" \\\n", + " --name \"${name}\" \\\n", + " --mac-filter ${mac_filter} \\\n", + " --maf-filter ${maf_filter} \\\n", + " --maf-max-filter ${maf_max_filter} \\\n", + " --mac-max-filter ${mac_max_filter} \\\n", + " --geno-filter ${geno_filter} \\\n", + " --mind-filter ${mind_filter} \\\n", + " --hwe-filter ${hwe_filter} \\\n", + " ${\"--keep-samples \" + str(keep_samples) if keep_samples.is_file() else \"\"} \\\n", + " ${\"--remove-samples \" + str(remove_samples) if remove_samples.is_file() else \"\"} \\\n", + " ${\"--exclude-variants \" + str(exclude_variants) if exclude_variants.is_file() else \"\"} \\\n", + " ${\"--keep-variants \" + str(keep_variants) if keep_variants.is_file() else \"\"} \\\n", + " ${\"--meta-only\" if meta_only else \"\"} \\\n", + " ${\"--rm-dups\" if rm_dups else \"\"} \\\n", + " ${\"--treat-dosage-missing\" if treat_dosage_missing else \"\"} \\\n", + " ${other_args_flags} \\\n", + " --numThreads ${numThreads}" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Extract genotype based on overlap with phenotype\n\nThis is an auxiliary step to match genotype and phenotype based on the data and look-up table. The look up table should contain two columns: `sample_id`, `genotype_id`. If the look up table is not provided or look-up table file not found, then we will assume the names have already been matched." + "# LD prunning and remove related individuals (both ind of a pair)\n", + "# Plink2 has multi-threaded calculation for LD prunning\n", + "[qc_2 (LD pruning)]\n", + "# Window size\n", + "parameter: window = 50\n", + "# Shift window every 10 snps\n", + "parameter: shift = 10\n", + "parameter: r2 = 0.1\n", + "parameter: mac_filter = 0.0\n", + "parameter: other_args = []\n", + "# Use PLINK --bad-ld flag (skip LD pruning diagnostics for regions with extreme LD)\n", + "parameter: bad_ld = False\n", + "stop_if(r2==0)\n", + "plink_command = get_plink_command_prefix(_input)\n", + "output_format = determine_plink_format(_input)\n", + "make_command = get_make_command(output_format)\n", + "output_ext = get_output_extension(output_format, is_prune=True)\n", + "other_args_flags = get_other_args_flags(other_args)\n", + "output: bed=f'{cwd}/{_input:bn}{output_ext}', prune=f'{cwd}/{_input:bn}.prune.in'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh qc \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --plink-command \"${plink_command}\" \\\n", + " --output-format \"${output_format}\" \\\n", + " --make-command \"${make_command}\" \\\n", + " --prune-prefix \"${_output['prune']:nn}\" \\\n", + " --out-prefix \"${_output['bed']:n}\" \\\n", + " --mac-filter ${mac_filter} \\\n", + " --window ${window} \\\n", + " --shift ${shift} \\\n", + " --r2 ${r2} \\\n", + " ${\"--bad-ld\" if bad_ld else \"\"} \\\n", + " ${other_args_flags} \\\n", + " --numThreads ${numThreads}" ] }, { @@ -371,7 +910,9 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### Genotype-phenotype sample matching\n", + "\n", + "An auxiliary step matching genotype to phenotype samples through the optional look-up table; if no table is given, or the file is not found, the names are assumed to match already." ] }, { @@ -382,7 +923,26 @@ }, "outputs": [], "source": [ - "# This workflow extracts overlapping samples for genotype data with phenotype data, and output the filtered sample genotype list as well as sample phenotype list\n[genotype_phenotype_sample_overlap]\n# A genotype fam file\nparameter: genoFile = path\n# A phenotype file, can be bed.gz or tsv\nparameter: phenoFile = path\n# If this file is provided, a genotype/phenotype sample name match will be performed\n# It must contain two column names: genotype_id, sample_id\nparameter: sample_participant_lookup = path(\".\")\ndepends: executable('tabix'), executable('bgzip')\ninput: genoFile, phenoFile\noutput: f'{cwd:a}/{path(_input[1]):bn}.sample_overlap.txt', f'{cwd:a}/{path(_input[1]):bn}.sample_genotypes.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh genotype_phenotype_sample_overlap \\\n --cwd \"${cwd}\" \\\n --genoFile \"${genoFile}\" \\\n --phenoFile \"${phenoFile}\" \\\n --name \"${name}\" \\\n --numThreads ${numThreads}" + "# This workflow extracts overlapping samples for genotype data with phenotype data, and output the filtered sample genotype list as well as sample phenotype list\n", + "[genotype_phenotype_sample_overlap]\n", + "# A genotype fam file\n", + "parameter: genoFile = path\n", + "# A phenotype file, can be bed.gz or tsv\n", + "parameter: phenoFile = path\n", + "# If this file is provided, a genotype/phenotype sample name match will be performed\n", + "# It must contain two column names: genotype_id, sample_id\n", + "parameter: sample_participant_lookup = path(\".\")\n", + "depends: executable('tabix'), executable('bgzip')\n", + "input: genoFile, phenoFile\n", + "output: f'{cwd:a}/{path(_input[1]):bn}.sample_overlap.txt', f'{cwd:a}/{path(_input[1]):bn}.sample_genotypes.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/GWAS_QC.sh genotype_phenotype_sample_overlap \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${genoFile}\" \\\n", + " --phenoFile \"${phenoFile}\" \\\n", + " --name \"${name}\" \\\n", + " --numThreads ${numThreads}" ] } ], diff --git a/code/SoS/data_preprocessing/genotype/PCA.ipynb b/code/SoS/data_preprocessing/genotype/PCA.ipynb index 82fba5af7..16ac94c3a 100644 --- a/code/SoS/data_preprocessing/genotype/PCA.ipynb +++ b/code/SoS/data_preprocessing/genotype/PCA.ipynb @@ -13,15 +13,41 @@ }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, + "metadata": {}, "source": [ - "## Description\n", + "## Overview\n", + "\n", + "Population structure is the classic confounder in genetic association: if ancestry\n", + "correlates with both genotype and phenotype, unadjusted tests return associations that are\n", + "real but not causal. The remedy is to compute principal components of the genotype matrix\n", + "and carry the leading ones as covariates.\n", + "\n", + "Components are computed on **unrelated** individuals and the remaining related samples are\n", + "projected back into that space, so relatives cannot distort the axes but every sample still\n", + "gets coordinates. The sequence is: remove related individuals, LD-prune the variants, run\n", + "PCA on the unrelated set, then exclude PCA-space outliers. Relatedness estimation and\n", + "sample QC happen upstream in `GWAS_QC.ipynb`.\n", + "\n", + "The workflows cover the whole job rather than just the decomposition: `pca_plink` and\n", + "`flashpca` compute components, `project_samples` places new samples onto axes computed\n", + "elsewhere, `plot_pca` produces the scree and scatter plots you inspect, and\n", + "`detect_outliers` flags samples that sit far from any cluster.\n", + "\n", + "Steps to generate a PCA include:\n", "\n", - "This notebook performs PCA on genotype data of **unrelated** individuals and projects the remaining (related) samples back into that PCA space. The main steps are: remove related individuals, LD-prune the variants, run PCA on the unrelated set, and exclude PCA-space outliers.\n", + "- removing related individuals\n", + "- pruning variants in linkage disequilibrium (LD)\n", + "- performing PCA analysis on the genotypes of the unrelated individuals\n", + "- excluding outlier samples in the PCA space for individuals of homogeneous self-reported ancestry. These outliers may suggest poor genotyping quality or distant relatedness.\n", "\n", - "Relatedness estimation and sample QC are done upstream in `GWAS_QC.ipynb`." + "Limitations:\n", + "\n", + "1. Some of the PCs may capture LD structure rather than population structure, which decreases power to detect associations in these regions of high LD.\n", + "2. When projecting a new study dataset onto the PCA space computed from a reference dataset, the projected PCs are shrunk toward 0 in the new dataset.\n", + "3. PC scores may capture outliers arising from family structure, population structure or other reasons. Detecting and removing these individuals can be worthwhile, either to maximise the population structure captured by the PCA when only a few outliers are involved, or to restrict analyses to genetically homogeneous samples.\n", + "\n", + "**When to run it.** After genotype QC and LD pruning, before covariate preprocessing; the\n", + "components become part of the covariate file used by the association scan." ] }, { @@ -30,15 +56,27 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Input\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed` | LD-pruned PLINK bundle for **unrelated** individuals (from GWAS_QC). PCA is computed on these samples. |\n", - "| `output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.bed` | PLINK bundle for **related** individuals (from GWAS_QC), projected back onto the PCA model. |\n", - "| `input/covariate/protocol_example.pca_pheno.txt` | Phenotype/label table with an `IID` column (plus optional `FID`) used to label/colour the projected samples. A PLINK `.fam` file may be used instead. |\n", + "- `--genoFile` `output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed` (the LD-pruned PLINK bundle for the **unrelated** individuals, as produced by GWAS QC. PCA is computed on these samples)\n", + "- `--phenoFile`: a phenotype or label table carrying an `IID` column, optionally `FID`, used to label and colour the projected samples. A PLINK `.fam` may be used instead. Its extra columns are what `--pop-col` and `--label-col` select from. Example `input/covariate/protocol_example.pca_pheno.txt`, 60 samples and 7 columns:\n", "\n", - "Genotypes must be in PLINK format (common variants, LD pruned) and split into related and unrelated sets. The phenotype file may also carry population/disease columns for labelling the PCA plots." + " ```\n", + " FID IID msex age_death pmi study race\n", + " SAMPLE_001 SAMPLE_001 1 90.97 10.57 1 1\n", + " SAMPLE_002 SAMPLE_002 1 80.24 7.87 0 1\n", + " SAMPLE_003 SAMPLE_003 1 83.9 9.93 0 1\n", + " ```\n", + "- `--pca-model`: the fitted PCA model to project onto, used by the projection step rather than the fitting step.\n", + "- `--name`: the stem of the output files. Required.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--k`: how many principal components to compute, `20` by default.\n", + "- `--maha-k`: how many components the Mahalanobis outlier distance is computed over, `5` by default.\n", + "- `--pop-col` and `--pops`: the phenotype column naming each sample's population and the subset of populations to analyse, for admixed or multi-ancestry data.\n", + "- `--label-col`: the phenotype column used to colour points in the PCA plots.\n", + "- `--keep-samples` and `--remove-samples`: sample lists to restrict or exclude before fitting.\n", + "- `--keep-variants`: a variant list to restrict to.\n", + "- `--maf-filter`, `--mac-filter`, `--geno-filter` and `--mind-filter`: the PLINK frequency, count, variant-missingness and sample-missingness thresholds applied before PCA." ] }, { @@ -47,16 +85,31 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Output\n", + "\n", + "- `{cwd}/{name}.pca.rds` and `{cwd}/{name}.pca.txt` - the fitted PCA model and the PC scores for the unrelated samples. Every path below sits under `--cwd` and shares the stem set by `--name`.\n", + "- `{name}.pca.scree.txt` and `{name}.pca.scree.png` - variance explained per component, as a table and a plot. The table is what `covariate_formatting` reads to choose how many PCs to keep:\n", + "\n", + " ```\n", + " PCs PVE PVE_cum\n", + " 1 0.05 0.05\n", + " 2 0.05 0.1\n", + " ```\n", + "\n", + "- `{name}.pca.mahalanobis.rds`, `.mahalanobis_hist.png` and `.mahalanobis_qq.png` - the per-population Mahalanobis distances and their diagnostic plots.\n", + "- `{name}.pca.outliers` - the samples flagged as PC outliers, an index and a sample ID per line:\n", + "\n", + " ```\n", + " 0 SAMPLE_001\n", + " 0 SAMPLE_026\n", + " 0 SAMPLE_050\n", + " ```\n", + "\n", + "- `{name}.pca.pc.png` - the PCA plot.\n", + "- `{name}.projected.rds`, `.projected.txt` and `.projected.pc.png` - the related individuals projected back onto the model, and the plot including them.\n", + "- `{name}.pca.analysis_summary.md` - a written summary of the run.\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/pca_uf/*.pca.rds` | PCA model + PC scores for the unrelated samples (RDS). |\n", - "| `output/pca_uf/*.pca.txt` | PC scores table for the unrelated samples. |\n", - "| `output/pca_uf/*.pca.scree.png` | Scree plot of variance explained. |\n", - "| `output/pca_uf/*.pca.mahalanobis.*`, `*.pca.outliers` | Mahalanobis distances per population and the list of PC outliers. |\n", - "| `output/pca_uf/*.projected.rds` / `*.projected.txt` | Projected PC scores for the related individuals. |\n", - "| `output/pca_uf/*.projected.pc.png` | PCA plot including the projected related samples. |" + "The `pca_plink` sanity-check workflow declares `{genoFile}.pca.eigenvec`, but no `.eigenvec` file ships in `output/pca_uf`; only the flashpca products are present." ] }, { @@ -67,9 +120,7 @@ "source": [ "## Minimal Working Example\n", "\n", - "The data can be found on [Synapse](https://www.synapse.org/#!Synapse:syn69670658/files/).\n", - "\n", - "**Note: parameters set for the MWE are meant to let the MWE work to show the workflow procedures. They may be unrealistic and should not be used in practice. The pipeline has reasonable default values for what we suggest to use in practice for most of the parameters.**" + "**Note: parameters set for the MWE are meant to let the MWE work to show the workflow procedures. They may be unrealistic and should not be used in practice. The pipeline has reasonable default values for what is suggested in practice for most of the parameters.**" ] }, { @@ -80,7 +131,16 @@ "source": [ "### **Step 1.** Estimate kinship in the sample (prerequisite)\n", "\n", - "Before PCA we need to know which individuals are related, because PCA must be computed on an **unrelated** subset and the related individuals are projected back afterwards. This step runs the `king` workflow from GWAS_QC to estimate pairwise kinship and split the samples into *unrelated* and *related* sets. It is an upstream prerequisite \u2014 its outputs (the `king.unrelated` and `king.related` PLINK bundles) feed the PCA steps below." + "Before PCA it is necessary to know which individuals are related, because PCA must be computed on an **unrelated** subset and the related individuals are projected back afterwards. This step runs the `king` workflow from GWAS_QC to estimate pairwise kinship and split the samples into *unrelated* and *related* sets. It is an upstream prerequisite — its outputs (the `king.unrelated` and `king.related` PLINK bundles) feed the PCA steps below." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -94,7 +154,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb king \\\n --cwd output/gwas_qc/kinship \\\n --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n --name protocol_example.king \\\n --keep-samples output/gwas_qc/genotype/protocol_example.rnaseq.bed.sample_genotypes.txt" + "sos run pipeline/GWAS_QC.ipynb king \\\n", + " --cwd output/gwas_qc/kinship \\\n", + " --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n", + " --name protocol_example.king \\\n", + " --keep-samples output/gwas_qc/genotype/protocol_example.rnaseq.bed.sample_genotypes.txt" ] }, { @@ -105,7 +169,7 @@ "source": [ "### **Step 2.** Sample selection and QC of the genotype data (prerequisite)\n", "\n", - "QC the genotypes that will go into PCA: filter on MAF, sample/variant missingness and Hardy-Weinberg equilibrium, and LD-prune the variants. You can restrict to one population or to the related / unrelated split. Here we QC and LD-prune the **unrelated** individuals to build the PCA reference, and separately extract the same variants for the related individuals so they can be projected later. These `qc` / `qc_no_prune` calls come from GWAS_QC and are upstream prerequisites for the PCA steps." + "QC the genotypes that will go into PCA: filter on MAF, sample/variant missingness and Hardy-Weinberg equilibrium, and LD-prune the variants. You can restrict to one population or to the related / unrelated split. Here the QC and LD-pruning are applied to the **unrelated** individuals to build the PCA reference, and separately extract the same variants for the related individuals so they can be projected later. These `qc` / `qc_no_prune` calls come from GWAS_QC and are upstream prerequisites for the PCA steps." ] }, { @@ -118,6 +182,15 @@ "#### Variant level and sample level QC on unrelated individuals, in preparation for PCA analysis" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -129,7 +202,10 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc \\\n --cwd output/gwas_qc/genotype \\\n --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.bed \\\n --mac-filter 5" + "sos run pipeline/GWAS_QC.ipynb qc \\\n", + " --cwd output/gwas_qc/genotype \\\n", + " --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.bed \\\n", + " --mac-filter 5" ] }, { @@ -141,6 +217,15 @@ "Extract the previously selected (LD-pruned) variants from the **related** individuals, applying only a sample-level missingness filter so the related samples carry exactly the same variant set as the unrelated reference." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -152,7 +237,12 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n --cwd output/pca_related \\\n --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.bed \\\n --geno-filter 0 --mind-filter 0.1 --maf-filter 0 \\\n --keep-variants output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.in \\\n --name for_pca" + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/pca_related \\\n", + " --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.bed \\\n", + " --geno-filter 0 --mind-filter 0.1 --maf-filter 0 \\\n", + " --keep-variants output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.in \\\n", + " --name for_pca" ] }, { @@ -175,6 +265,15 @@ "The `--name` argument tags all output files; point `--genoFile` at the LD-pruned unrelated bed produced upstream." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -186,7 +285,10 @@ }, "outputs": [], "source": [ - "sos run pipeline/PCA.ipynb flashpca \\\n --cwd output/pca_uf \\\n --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n --name protocol_example" + "sos run pipeline/PCA.ipynb flashpca \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n", + " --name protocol_example" ] }, { @@ -195,7 +297,7 @@ "kernel": "SoS" }, "source": [ - "**What you should see:** the workflow runs `flashpca_1` (PCA), then `detect_outliers` (Mahalanobis distance per population) and `plot_pca`, finishing with \"executed successfully with 5 completed steps\". The PCA model and PC scores are written to the `--cwd` directory. The scree plot below shows the proportion of variance explained by each PC \u2014 use it to decide how many PCs to keep." + "**What you should see:** the workflow runs `flashpca_1` (PCA), then `detect_outliers` (Mahalanobis distance per population) and `plot_pca`, finishing with \"executed successfully with 5 completed steps\". The PCA model and PC scores are written to the `--cwd` directory. The scree plot below shows the proportion of variance explained by each PC — use it to decide how many PCs to keep." ] }, { @@ -217,7 +319,16 @@ "source": [ "### **Step 4.** Project the related individuals onto the PCA model\n", "\n", - "The related individuals were held out of the PCA, so we now project them onto the model fitted from the unrelated samples. First reduce the related genotypes to **exactly** the same pruned variant set used to build the model (the `plink2 --extract` cell below) \u2014 otherwise the projection errors with \"Input number of variants should be the same as used in the previous PCA model\". Then run `project_samples`, passing a phenotype table (must contain an `IID` column) and, if available, a population/ethnicity column via `--label-col` / `--pop-col` (here the `race` column) so the projected samples can be coloured and the outlier detection can run." + "The related individuals were held out of the PCA, so they are now projected onto the model fitted from the unrelated samples. First reduce the related genotypes to **exactly** the same pruned variant set used to build the model (the `plink2 --extract` cell below) — otherwise the projection errors with \"Input number of variants should be the same as used in the previous PCA model\". Then run `project_samples`, passing a phenotype table (must contain an `IID` column) and, if available, a population/ethnicity column via `--label-col` / `--pop-col` (here the `race` column) so the projected samples can be coloured and the outlier detection can run." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -231,7 +342,15 @@ }, "outputs": [], "source": [ - "sos run pipeline/PCA.ipynb project_samples \\\n --cwd output/pca_uf \\\n --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n --pca-model output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.protocol_example.pca.rds \\\n --label-col race \\\n --pop-col race \\\n --name protocol_example \\\n --maha-k 2" + "sos run pipeline/PCA.ipynb project_samples \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n", + " --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n", + " --pca-model output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.protocol_example.pca.rds \\\n", + " --label-col race \\\n", + " --pop-col race \\\n", + " --name protocol_example \\\n", + " --maha-k 2" ] }, { @@ -245,6 +364,15 @@ "%preview output/pca_uf/protocol_example.pca_pheno.pca.projected.pc.png" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -256,7 +384,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n --cwd output/pca_related \\\n --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n --remove-samples output/pca_uf/protocol_example.pca_pheno.pca.projected.outliers \\\n --name no_outlier" + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/pca_related \\\n", + " --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n", + " --remove-samples output/pca_uf/protocol_example.pca_pheno.pca.projected.outliers \\\n", + " --name no_outlier" ] }, { @@ -279,6 +411,15 @@ "Finally, merge back related and unrelated individuals as finalized genotype in PLINK format," ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -290,7 +431,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.no_outlier.plink_qc.bed \\\n --cwd output/genotype_final \\\n --name protocol_example.qced" + "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n", + " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n", + " output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.no_outlier.plink_qc.bed \\\n", + " --cwd output/genotype_final \\\n", + " --name protocol_example.qced" ] }, { @@ -308,20 +453,9 @@ "kernel": "SoS" }, "source": [ - "## Optional \u2014 Analysis by population (admixed / multi-ancestry data)\n", - "\n", - "The Steps 1\u20134 above produce a single PCA for the whole cohort, which is appropriate for a **homogeneous** population. If your cohort contains **multiple ancestry groups**, run the per-population workflow below instead: split the samples by population, then repeat the same QC \u2192 PCA \u2192 projection steps **separately within each population**.\n", + "### Analysis by population (admixed / multi-ancestry data)\n", "\n", - "The sub-steps below mirror Steps 1\u20134 exactly, just looped over each population (`for i in race1 race3`). Follow them in order:\n", - "\n", - "| Sub-step | What it does |\n", - "| --- | --- |\n", - "| **P0. Split by population** | Write a per-population sample-ID list |\n", - "| **P1. QC unrelated** | Variant/sample QC within each population (unrelated samples) |\n", - "| **P2. Extract variants in related** | Keep the P1 pruned variants in the related samples |\n", - "| **P3. PCA on unrelated** | Run `flashpca` per population |\n", - "| **P4. Project related** | Project related samples onto each population\u2019s PCA |\n", - "| **P5. Finalize** | Per-population QC to finalize genotypes |" + "The Steps 1–4 above produce a single PCA for the whole cohort, which is appropriate for a **homogeneous** population. If your cohort contains **multiple ancestry groups**, run the per-population workflow below instead: split the samples by population, then repeat the same QC → PCA → projection steps **separately within each population**.\n" ] }, { @@ -333,7 +467,17 @@ }, "outputs": [], "source": [ - "# Build per-population sample keep-lists from the phenotype table.\n# One file per ancestry group, named output/pca_uf/protocol_example.ID..txt\n# Each file holds two columns (FID, IID) with no header, matching plink's --keep format.\nsetwd(\"/mnt/lustre/lab/gwang/home/rl3328/evo2/xqtl-protocol\")\npheno <- read.table(\"input/covariate/protocol_example.pca_pheno.txt\", header = TRUE, stringsAsFactors = FALSE)\n\nif (all(pheno$FID == pheno$IID)) pheno$FID <- \"0\"\n\nfor (i in 1:3) {\n race <- subset(pheno, race == i)\n race_id <- cbind(race$FID, race$IID)\n write.table(race_id,\n paste0(\"output/pca_uf/protocol_example.ID.\", i, \".txt\"),\n quote = FALSE, sep = \"\\t\", col.names = FALSE, row.names = FALSE)\n}" + "pheno <- read.table(\"input/covariate/protocol_example.pca_pheno.txt\", header = TRUE, stringsAsFactors = FALSE)\n", + "\n", + "if (all(pheno$FID == pheno$IID)) pheno$FID <- \"0\"\n", + "\n", + "for (i in 1:3) {\n", + " race <- subset(pheno, race == i)\n", + " race_id <- cbind(race$FID, race$IID)\n", + " write.table(race_id,\n", + " paste0(\"output/pca_uf/protocol_example.ID.\", i, \".txt\"),\n", + " quote = FALSE, sep = \"\\t\", col.names = FALSE, row.names = FALSE)\n", + "}" ] }, { @@ -342,9 +486,9 @@ "kernel": "SoS" }, "source": [ - "### P1 \u2014 QC on unrelated samples, per population\n", + "### Step 1. QC on unrelated samples, per population\n", "\n", - "Same as Step 2 (QC), but looped over each population. Below we only show Populations 1 and 3 as an example. **Next:** once each population has a QC\u2019d unrelated set, extract those variants from the related samples (P2)." + "Same as Step 2 previously (QC), but looped over each population. Below only Populations 1 and 3 are shown as an example. " ] }, { @@ -358,7 +502,15 @@ }, "outputs": [], "source": [ - "for i in 3; do\n sos run pipeline/GWAS_QC.ipynb qc \\\n --cwd output/pca_uf \\\n --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.bed \\\n --keep-samples output/pca_uf/protocol_example.ID.$i.txt \\\n --mac-filter 5 \\\n --bad-ld True \\\n --name pop_$i\ndone" + "for i in 3; do\n", + " sos run pipeline/GWAS_QC.ipynb qc \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.bed \\\n", + " --keep-samples output/pca_uf/protocol_example.ID.$i.txt \\\n", + " --mac-filter 5 \\\n", + " --bad-ld True \\\n", + " --name pop_$i\n", + "done" ] }, { @@ -367,11 +519,11 @@ "kernel": "SoS" }, "source": [ - "### P2 \u2014 Extract the selected variants from related samples, per population\n", + "### Step 2. Extract the selected variants from related samples, per population\n", "\n", - "Same as the extract part of Step 4, looped per population (sample-level missingness filter only).\n", + "Same as the extract part of Step 4 above, looped per population (sample-level missingness filter only).\n", "\n", - "> Note: Population 1 may have **no related samples**, in which case its `*.related.for_pca_race1.filtered.extracted.stderr` log will say `Error: No people remaining after --keep.` That is expected \u2014 just continue with the populations that do have related samples. **Next:** run PCA on each population\u2019s unrelated set (P3)." + "> Note: Population 1 may have **no related samples**, in which case its `*.related.for_pca_race1.filtered.extracted.stderr` log will say `Error: No people remaining after --keep.` That is expected — just continue with the populations that do have related samples. " ] }, { @@ -385,7 +537,15 @@ }, "outputs": [], "source": [ - "for i in 3; do\n sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n --cwd output/pca_uf \\\n --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n --keep-variants output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.pop_$i.plink_qc.prune.in \\\n --keep-samples output/pca_uf/protocol_example.ID.$i.txt \\\n --maf-filter 0 --geno-filter 0 --mind-filter 0.1 --hwe-filter 0 \\\n --name pop_$i\ndone" + "for i in 3; do\n", + " sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n", + " --keep-variants output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.pop_$i.plink_qc.prune.in \\\n", + " --keep-samples output/pca_uf/protocol_example.ID.$i.txt \\\n", + " --maf-filter 0 --geno-filter 0 --mind-filter 0.1 --hwe-filter 0 \\\n", + " --name pop_$i\n", + "done" ] }, { @@ -394,9 +554,9 @@ "kernel": "SoS" }, "source": [ - "### P3 \u2014 Run PCA (flashpca) on unrelated samples, per population\n", + "### Step 3. Run PCA (flashpca) on unrelated samples, per population\n", "\n", - "Same as Step 3, looped per population. Here the number of PCs is set to 5 (`--k 5`) because each population\u2019s sample size is small. **Next:** project the related samples onto each population\u2019s PCA model (P4)." + "Same as Step 3 above, looped per population. Here the number of PCs is set to 5 (`--k 5`) because each population’s sample size is small. " ] }, { @@ -410,7 +570,17 @@ }, "outputs": [], "source": [ - "for i in 3; do\n sos run pipeline/PCA.ipynb flashpca \\\n --name pop_$i \\\n --cwd output/pca_uf \\\n --genoFile output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.pop_$i.plink_qc.prune.bed \\\n --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n --label-col race \\\n --pop-col race \\\n --maha-k 2 \\\n --k 5\ndone" + "for i in 3; do\n", + " sos run pipeline/PCA.ipynb flashpca \\\n", + " --name pop_$i \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.pop_$i.plink_qc.prune.bed \\\n", + " --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n", + " --label-col race \\\n", + " --pop-col race \\\n", + " --maha-k 2 \\\n", + " --k 5\n", + "done" ] }, { @@ -419,9 +589,9 @@ "kernel": "SoS" }, "source": [ - "### P4 \u2014 Project related samples onto each population\u2019s PCA, per population\n", + "### Step 4. Project related samples onto each population’s PCA, per population\n", "\n", - "Same as Step 4 (projection), looped per population. Only populations that actually have related samples are projected (here, Population 3 only). **Next:** finalize genotypes per population (P5)." + "Same as Step 4 in homogenous dataset PCA (projection), looped per population. Only populations that actually have related samples are projected (here, Population 3 only). " ] }, { @@ -435,7 +605,18 @@ }, "outputs": [], "source": [ - "for i in 3; do\n sos run pipeline/PCA.ipynb project_samples \\\n --name pop_$i \\\n --cwd output/pca_uf \\\n --genoFile output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.pop_$i.plink_qc.extracted.bed \\\n --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n --pca-model output/pca_uf/protocol_example.pca_pheno.pop_$i.pca.rds \\\n --label-col race \\\n --pop-col race \\\n --maha-k 2 \\\n --k 5\ndone" + "for i in 3; do\n", + " sos run pipeline/PCA.ipynb project_samples \\\n", + " --name pop_$i \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.pop_$i.plink_qc.extracted.bed \\\n", + " --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n", + " --pca-model output/pca_uf/protocol_example.pca_pheno.pop_$i.pca.rds \\\n", + " --label-col race \\\n", + " --pop-col race \\\n", + " --maha-k 2 \\\n", + " --k 5\n", + "done" ] }, { @@ -465,9 +646,7 @@ "kernel": "SoS" }, "source": [ - "### P5 \u2014 Finalize genotypes per population\n", - "\n", - "Same as the **Finalize genotype QC by PCA** step for a homogeneous population, applied per population and taking the detected outliers into account. See the `GWAS_QC.ipynb` documentation for the available QC options and recommendations. This is the end of the per-population workflow." + "Finalizing genotypes per population is the same as the **Finalize genotype QC by PCA** step for a homogeneous population, applied per population and taking the detected outliers into account. It is not run from this notebook; see the `GWAS_QC.ipynb` documentation for the available QC options and recommendations." ] }, { @@ -482,12 +661,127 @@ { "cell_type": "code", "execution_count": null, - "metadata": { - "kernel": "Bash" - }, + "metadata": {}, "outputs": [], "source": [ - "sos run PCA.ipynb -h" + "sos run pipeline/PCA.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```\n", + "usage: sos run pipeline/PCA.ipynb [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " pca_plink\n", + " flashpca\n", + " project_samples\n", + " plot_pca\n", + " detect_outliers\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " the output directory for generated files\n", + " --name VAL (as str, required)\n", + " A string to identify your analysis run\n", + " --pop-col ''\n", + " Name of the population column in the phenoFile\n", + " --pops (as list)\n", + " Name of the populations (from the population column) you\n", + " would like to plot and show on the PCA plot\n", + " --label-col ''\n", + " Name of the color label column in the phenoFile; can be\n", + " the same as population column. Can also be a separate\n", + " column eg a \"super population\" column as a way to enable\n", + " you to combine selected populations based on another\n", + " column.\n", + " --k 20 (as int)\n", + " Number of Principal Components to output,must be\n", + " consistant between flashpca run and project samples run\n", + " (flashpca partial PCA method).\n", + " --maha-k 5 (as int)\n", + " Number of Principal Components based on which outliers\n", + " should be evaluated. Default is 5 but this should be\n", + " based on examine the scree plot\n", + " --[no-]homogeneous (default to False)\n", + " Homogeneity of populations. Set to --homogeneous when\n", + " true and --no-homogeneous when false\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 10 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " pca_plink: PCA command with PLINK, as a sanity check\n", + " Workflow Options:\n", + " --genoFile VAL (as path, required)\n", + " PLINK binary file\n", + " flashpca_1: Run PCA analysis using flashpca\n", + " Workflow Options:\n", + " --genoFile VAL (as path, required)\n", + " Plink binary file\n", + " --phenoFile path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n", + "\n", + " The phenotypic file\n", + " --min-pop-size 2 (as int)\n", + " minimum population size to consider in the analysis\n", + " --stand binom2\n", + " How to standardize X before PCA\n", + " project_samples_1: Project back to PCA model additional samples\n", + " Workflow Options:\n", + " --genoFile VAL (as path, required)\n", + " Plink binary file\n", + " --phenoFile path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n", + "\n", + " The phenotypic file\n", + " --stand binom2\n", + " How to standardize X before PCA\n", + " --pca-model f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.{(suffix+\".\") if suffix != \"\" else \"\"}pca.rds'\n", + "\n", + " plot_pca: Plot PCA results. Can be used independently as\n", + " \"plot_pca\" or combined with other workflow as eg\n", + " \"flashpca+plot_pca\"\n", + " Workflow Options:\n", + " --outlier-file . (as path)\n", + " --plot-data VAL (as path, required)\n", + " --min-axis ''\n", + " --max-axis ''\n", + " detect_outliers: Calculate Mahalanobis distance per population and report\n", + " outliers\n", + " Workflow Options:\n", + " --prob 0.997 (as float)\n", + " Set the probability to remove outliers eg 0.95 or 0.997\n", + " --pval 0.05 (as float)\n", + " Mahalanobis distance p-value cutoff\n", + " --[no-]robust (default to True)\n", + " Robust Mahalanobis to outliers\n", + " --pca-result VAL (as path, required)\n", + " flashpca_2, project_samples_2:\n", + " Workflow Options:\n", + " --prob 0.997 (as float)\n", + " Set the probability to remove outliers eg 0.95 or 0.997\n", + " --[no-]robust (default to True)\n", + " Robust Mahalanobis to outliers\n", + " flashpca_3, project_samples_3:\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Workflow implementation" ] }, { @@ -498,7 +792,121 @@ }, "outputs": [], "source": [ - "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# the output directory for generated files\nparameter: cwd = path(\"output\")\n# A string to identify your analysis run\nparameter: name = str\n# Name of the population column in the phenoFile\nparameter: pop_col = \"\"\n# Name of the populations (from the population column) you would like to plot and show on the PCA plot\nparameter: pops = []\n# Name of the color label column in the phenoFile; can be the same as population column. Can also be a separate column eg a \"super population\" column as a way to enable you to combine selected populations based on another column.\nparameter: label_col = \"\"\n# Number of Principal Components to output,must be consistant between flashpca run and project samples run (flashpca partial PCA method).\nparameter: k = 20\n# Number of Principal Components based on which outliers should be evaluated. Default is 5 but this should be based on examine the scree plot\nparameter: maha_k = 5\n# Homogeneity of populations. Set to --homogeneous when true and --no-homogeneous when false\nparameter: homogeneous = False\nimport re\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n# Number of threads\nparameter: numThreads = 10\nsuffix = '_'.join(pops)\ncwd = path(f\"{cwd:a}\")\nif not pop_col:\n homogeneous = True\n\n# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\ndef determine_plink_format(file_path):\n \"\"\"\n Determine the PLINK file format based on file extensions and companion files.\n \n Args:\n file_path (str or Path): Path to the input file\n \n Returns:\n str: 'plink1' or 'plink2'\n \"\"\"\n # Convert to string if it's a Path object\n file_path = str(file_path)\n \n # Check direct file extensions\n if file_path.endswith('.bed'):\n return 'plink1'\n elif file_path.endswith('.pgen'):\n return 'plink2'\n \n # If the file doesn't have a standard extension, try to infer format\n try:\n # Remove the file extension if present\n base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n \n # Check for PLINK1 companion files\n plink1_companion_files = [\n f\"{base_path}.bim\",\n f\"{base_path}.fam\"\n ]\n \n # Check for PLINK2 companion files\n plink2_companion_files = [\n f\"{base_path}.pvar\",\n f\"{base_path}.psam\"\n ]\n \n # Check PLINK1 format\n if all(os.path.exists(f) for f in plink1_companion_files):\n return 'plink1'\n \n # Check PLINK2 format\n if all(os.path.exists(f) for f in plink2_companion_files):\n return 'plink2'\n \n except Exception as e:\n print(f\"Error determining PLINK format: {e}\")\n \n # Default to PLINK1 if can't determine\n return 'plink1'\n\n# Get the appropriate PLINK command prefix\ndef get_plink_command_prefix(file_path):\n format_type = determine_plink_format(file_path)\n if format_type == 'plink1':\n return \"--bfile\"\n else: # plink2\n return \"--pfile\"\n\ndef normalize_phenoFile(pheno_path, out_dir):\n \"\"\"Return a phenoFile path where FID=0 if the file has FID==IID in every data row.\n Writes a normalized copy to out_dir when needed; otherwise returns the original path.\"\"\"\n import os, csv\n pheno_path = str(pheno_path)\n with open(pheno_path) as fh:\n rows = [r for r in csv.reader(fh, delimiter='\\t')]\n if not rows:\n return path(pheno_path)\n # Detect header: first row is a header when its first cell is not a sample value\n has_header = rows[0][0].upper() in ('FID', '#FID', 'IID', 'SAMPLE', 'SAMPLE_ID')\n data_rows = rows[1:] if has_header else rows\n if not data_rows or not all(len(r) >= 2 and r[0] == r[1] for r in data_rows):\n return path(pheno_path)\n # FID==IID everywhere \u2014 write a normalized copy to out_dir with FID=0\n out_path = os.path.join(str(out_dir), os.path.basename(pheno_path))\n with open(out_path, 'w', newline='') as fh:\n w = csv.writer(fh, delimiter='\\t')\n if has_header:\n w.writerow(rows[0])\n for r in data_rows:\n r[0] = '0'\n w.writerow(r)\n return path(out_path)" + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# the output directory for generated files\n", + "parameter: cwd = path(\"output\")\n", + "# A string to identify your analysis run\n", + "parameter: name = str\n", + "# Name of the population column in the phenoFile\n", + "parameter: pop_col = \"\"\n", + "# Name of the populations (from the population column) you would like to plot and show on the PCA plot\n", + "parameter: pops = []\n", + "# Name of the color label column in the phenoFile; can be the same as population column. Can also be a separate column eg a \"super population\" column as a way to enable you to combine selected populations based on another column.\n", + "parameter: label_col = \"\"\n", + "# Number of Principal Components to output,must be consistant between flashpca run and project samples run (flashpca partial PCA method).\n", + "parameter: k = 20\n", + "# Number of Principal Components based on which outliers should be evaluated. Default is 5 but this should be based on examine the scree plot\n", + "parameter: maha_k = 5\n", + "# Homogeneity of populations. Set to --homogeneous when true and --no-homogeneous when false\n", + "parameter: homogeneous = False\n", + "import re\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "# Number of threads\n", + "parameter: numThreads = 10\n", + "suffix = '_'.join(pops)\n", + "cwd = path(f\"{cwd:a}\")\n", + "if not pop_col:\n", + " homogeneous = True\n", + "\n", + "# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\n", + "def determine_plink_format(file_path):\n", + " \"\"\"\n", + " Determine the PLINK file format based on file extensions and companion files.\n", + " \n", + " Args:\n", + " file_path (str or Path): Path to the input file\n", + " \n", + " Returns:\n", + " str: 'plink1' or 'plink2'\n", + " \"\"\"\n", + " # Convert to string if it's a Path object\n", + " file_path = str(file_path)\n", + " \n", + " # Check direct file extensions\n", + " if file_path.endswith('.bed'):\n", + " return 'plink1'\n", + " elif file_path.endswith('.pgen'):\n", + " return 'plink2'\n", + " \n", + " # If the file doesn't have a standard extension, try to infer format\n", + " try:\n", + " # Remove the file extension if present\n", + " base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n", + " \n", + " # Check for PLINK1 companion files\n", + " plink1_companion_files = [\n", + " f\"{base_path}.bim\",\n", + " f\"{base_path}.fam\"\n", + " ]\n", + " \n", + " # Check for PLINK2 companion files\n", + " plink2_companion_files = [\n", + " f\"{base_path}.pvar\",\n", + " f\"{base_path}.psam\"\n", + " ]\n", + " \n", + " # Check PLINK1 format\n", + " if all(os.path.exists(f) for f in plink1_companion_files):\n", + " return 'plink1'\n", + " \n", + " # Check PLINK2 format\n", + " if all(os.path.exists(f) for f in plink2_companion_files):\n", + " return 'plink2'\n", + " \n", + " except Exception as e:\n", + " print(f\"Error determining PLINK format: {e}\")\n", + " \n", + " # Default to PLINK1 if can't determine\n", + " return 'plink1'\n", + "\n", + "# Get the appropriate PLINK command prefix\n", + "def get_plink_command_prefix(file_path):\n", + " format_type = determine_plink_format(file_path)\n", + " if format_type == 'plink1':\n", + " return \"--bfile\"\n", + " else: # plink2\n", + " return \"--pfile\"\n", + "\n", + "def normalize_phenoFile(pheno_path, out_dir):\n", + " \"\"\"Return a phenoFile path where FID=0 if the file has FID==IID in every data row.\n", + " Writes a normalized copy to out_dir when needed; otherwise returns the original path.\"\"\"\n", + " import os, csv\n", + " pheno_path = str(pheno_path)\n", + " with open(pheno_path) as fh:\n", + " rows = [r for r in csv.reader(fh, delimiter='\\t')]\n", + " if not rows:\n", + " return path(pheno_path)\n", + " # Detect header: first row is a header when its first cell is not a sample value\n", + " has_header = rows[0][0].upper() in ('FID', '#FID', 'IID', 'SAMPLE', 'SAMPLE_ID')\n", + " data_rows = rows[1:] if has_header else rows\n", + " if not data_rows or not all(len(r) >= 2 and r[0] == r[1] for r in data_rows):\n", + " return path(pheno_path)\n", + " # FID==IID everywhere — write a normalized copy to out_dir with FID=0\n", + " out_path = os.path.join(str(out_dir), os.path.basename(pheno_path))\n", + " with open(out_path, 'w', newline='') as fh:\n", + " w = csv.writer(fh, delimiter='\\t')\n", + " if has_header:\n", + " w.writerow(rows[0])\n", + " for r in data_rows:\n", + " r[0] = '0'\n", + " w.writerow(r)\n", + " return path(out_path)" ] }, { @@ -509,7 +917,16 @@ }, "outputs": [], "source": [ - "# PCA command with PLINK, as a sanity check\n[pca_plink]\n# PLINK binary file\nparameter: genoFile = path\ninput: genoFile\nplink_command = get_plink_command_prefix(_input)\noutput: f'{cwd}/{genoFile:bn}.pca.eigenvec'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand = \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n plink2 ${plink_command} ${_input:n} --out ${_output:n} --pca ${k}" + "# PCA command with PLINK, as a sanity check\n", + "[pca_plink]\n", + "# PLINK binary file\n", + "parameter: genoFile = path\n", + "input: genoFile\n", + "plink_command = get_plink_command_prefix(_input)\n", + "output: f'{cwd}/{genoFile:bn}.pca.eigenvec'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand = \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " plink2 ${plink_command} ${_input:n} --out ${_output:n} --pca ${k}" ] }, { @@ -518,7 +935,7 @@ "kernel": "SoS" }, "source": [ - "## PCA analysis" + "### PCA analysis" ] }, { @@ -529,7 +946,37 @@ }, "outputs": [], "source": [ - "# Run PCA analysis using flashpca \n[flashpca_1]\n# Plink binary file\nparameter: genoFile = path\n# The phenotypic file\nparameter: phenoFile = path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n# minimum population size to consider in the analysis\nparameter: min_pop_size = 2\n# How to standardize X before PCA\nparameter: stand = \"binom2\"\n## Input genoFile here is for unrelated samples\nphenoFile = normalize_phenoFile(phenoFile, cwd)\ninput: genoFile, phenoFile\noutput: f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.{(suffix+\".\") if suffix != \"\" else \"\"}pca.rds'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n --step flashpca \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input[0]}\" \\\n --phenoFile \"${_input[1]}\" \\\n --output \"${_output}\" \\\n --stand \"${stand}\" \\\n --min-pop-size ${min_pop_size} \\\n --homogeneous \"${homogeneous}\" \\\n --pop-col \"${pop_col}\" \\\n --label-col \"${label_col}\" \\\n --pops \"${\",\".join([str(x) for x in pops])}\" \\\n --k ${k} \\\n --maha-k ${maha_k} \\\n --numThreads ${numThreads}" + "# Run PCA analysis using flashpca \n", + "[flashpca_1]\n", + "# Plink binary file\n", + "parameter: genoFile = path\n", + "# The phenotypic file\n", + "parameter: phenoFile = path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n", + "# minimum population size to consider in the analysis\n", + "parameter: min_pop_size = 2\n", + "# How to standardize X before PCA\n", + "parameter: stand = \"binom2\"\n", + "## Input genoFile here is for unrelated samples\n", + "phenoFile = normalize_phenoFile(phenoFile, cwd)\n", + "input: genoFile, phenoFile\n", + "output: f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.{(suffix+\".\") if suffix != \"\" else \"\"}pca.rds'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n", + " --step flashpca \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input[0]}\" \\\n", + " --phenoFile \"${_input[1]}\" \\\n", + " --output \"${_output}\" \\\n", + " --stand \"${stand}\" \\\n", + " --min-pop-size ${min_pop_size} \\\n", + " --homogeneous \"${homogeneous}\" \\\n", + " --pop-col \"${pop_col}\" \\\n", + " --label-col \"${label_col}\" \\\n", + " --pops \"${\",\".join([str(x) for x in pops])}\" \\\n", + " --k ${k} \\\n", + " --maha-k ${maha_k} \\\n", + " --numThreads ${numThreads}" ] }, { @@ -538,7 +985,7 @@ "kernel": "SoS" }, "source": [ - "## Project related individuals back" + "### Project related individuals back" ] }, { @@ -549,7 +996,34 @@ }, "outputs": [], "source": [ - "# Project back to PCA model additional samples\n[project_samples_1]\n# Plink binary file\nparameter: genoFile = path\n# The phenotypic file\nparameter: phenoFile = path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n# How to standardize X before PCA\nparameter: stand = \"binom2\"\nparameter: pca_model = f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.{(suffix+\".\") if suffix != \"\" else \"\"}pca.rds'\n## Input genoFile here is for related samples\nphenoFile = normalize_phenoFile(phenoFile, cwd)\ninput: genoFile, phenoFile, pca_model\noutput: f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.pca.projected.rds'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n --step project_samples \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input[0]}\" \\\n --phenoFile \"${_input[1]}\" \\\n --output \"${_output}\" \\\n --stand \"${stand}\" \\\n --pop-col \"${pop_col}\" \\\n --label-col \"${label_col}\" \\\n --pops \"${\",\".join([str(x) for x in pops])}\" \\\n --pca-model \"${_input[2]}\" \\\n --maha-k ${maha_k} \\\n --numThreads ${numThreads}" + "# Project back to PCA model additional samples\n", + "[project_samples_1]\n", + "# Plink binary file\n", + "parameter: genoFile = path\n", + "# The phenotypic file\n", + "parameter: phenoFile = path(f'{genoFile}'.replace(\".bed\", \".fam\").replace(\".pgen\", \".psam\"))\n", + "# How to standardize X before PCA\n", + "parameter: stand = \"binom2\"\n", + "parameter: pca_model = f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.{(suffix+\".\") if suffix != \"\" else \"\"}pca.rds'\n", + "## Input genoFile here is for related samples\n", + "phenoFile = normalize_phenoFile(phenoFile, cwd)\n", + "input: genoFile, phenoFile, pca_model\n", + "output: f'{cwd}/{phenoFile:bn}{(\".\"+name) if name else \"\"}.pca.projected.rds'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n", + " --step project_samples \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input[0]}\" \\\n", + " --phenoFile \"${_input[1]}\" \\\n", + " --output \"${_output}\" \\\n", + " --stand \"${stand}\" \\\n", + " --pop-col \"${pop_col}\" \\\n", + " --label-col \"${label_col}\" \\\n", + " --pops \"${\",\".join([str(x) for x in pops])}\" \\\n", + " --pca-model \"${_input[2]}\" \\\n", + " --maha-k ${maha_k} \\\n", + " --numThreads ${numThreads}" ] }, { @@ -558,7 +1032,7 @@ "kernel": "SoS" }, "source": [ - "## Plot PCA results\n" + "### Plot PCA results\n" ] }, { @@ -569,7 +1043,34 @@ }, "outputs": [], "source": [ - "# Plot PCA results. \n# Can be used independently as \"plot_pca\" or combined with other workflow as eg \"flashpca+plot_pca\"\n[plot_pca]\nparameter: outlier_file = path()\nparameter: plot_data = path\nparameter: min_axis = \"\"\nparameter: max_axis = \"\"\ninput: plot_data\noutput: f'{cwd}/{_input:bn}.pc.png',\n f'{cwd}/{_input:bn}.scree.png',\n f'{cwd}/{_input:bn}.scree.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = 1, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n --step plot_pca \\\n --cwd \"${cwd}\" \\\n --plot-data \"${_input}\" \\\n --outlier-file \"${outlier_file}\" \\\n --min-axis \"${min_axis}\" \\\n --max-axis \"${max_axis}\" \\\n --pop-col \"${pop_col}\" \\\n --label-col \"${label_col}\" \\\n --pops \"${\",\".join([str(x) for x in pops])}\" \\\n --k ${k} \\\n --output-pc-plot \"${_output[0]}\" \\\n --output-scree-plot \"${_output[1]}\" \\\n --output-scree-text \"${_output[2]}\" \\\n --numThreads ${numThreads}" + "# Plot PCA results. \n", + "# Can be used independently as \"plot_pca\" or combined with other workflow as eg \"flashpca+plot_pca\"\n", + "[plot_pca]\n", + "parameter: outlier_file = path()\n", + "parameter: plot_data = path\n", + "parameter: min_axis = \"\"\n", + "parameter: max_axis = \"\"\n", + "input: plot_data\n", + "output: f'{cwd}/{_input:bn}.pc.png',\n", + " f'{cwd}/{_input:bn}.scree.png',\n", + " f'{cwd}/{_input:bn}.scree.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = 1, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n", + " --step plot_pca \\\n", + " --cwd \"${cwd}\" \\\n", + " --plot-data \"${_input}\" \\\n", + " --outlier-file \"${outlier_file}\" \\\n", + " --min-axis \"${min_axis}\" \\\n", + " --max-axis \"${max_axis}\" \\\n", + " --pop-col \"${pop_col}\" \\\n", + " --label-col \"${label_col}\" \\\n", + " --pops \"${\",\".join([str(x) for x in pops])}\" \\\n", + " --k ${k} \\\n", + " --output-pc-plot \"${_output[0]}\" \\\n", + " --output-scree-plot \"${_output[1]}\" \\\n", + " --output-scree-text \"${_output[2]}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -578,7 +1079,7 @@ "kernel": "SoS" }, "source": [ - "## Detect outliers" + "### Detect outliers" ] }, { @@ -589,7 +1090,38 @@ }, "outputs": [], "source": [ - "# Calculate Mahalanobis distance per population and report outliers\n[detect_outliers]\n# Set the probability to remove outliers eg 0.95 or 0.997\nparameter: prob = 0.997\n# Mahalanobis distance p-value cutoff\nparameter: pval = 0.05\n# Robust Mahalanobis to outliers\nparameter: robust = True\nparameter: pca_result = path\ninput: pca_result\noutput: distance=f'{_input:n}.mahalanobis.rds',\n identified_outliers=f'{_input:n}.outliers',\n analysis_summary=f'{_input:n}.analysis_summary.md',\n qqplot_mahalanobis=f'{_input:n}.mahalanobis_qq.png',\n hist_mahalanobis=f'{_input:n}.mahalanobis_hist.png'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = 1, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n --step detect_outliers \\\n --cwd \"${cwd}\" \\\n --pca-result \"${_input}\" \\\n --prob ${prob} \\\n --pval ${pval} \\\n --robust ${\"TRUE\" if robust else \"FALSE\"} \\\n --pop-col \"${pop_col}\" \\\n --k ${k} \\\n --distance-output \"${_output['distance']}\" \\\n --identified-outliers-output \"${_output['identified_outliers']}\" \\\n --analysis-summary-output \"${_output['analysis_summary']}\" \\\n --qqplot-output \"${_output['qqplot_mahalanobis']}\" \\\n --hist-output \"${_output['hist_mahalanobis']}\" \\\n --numThreads ${numThreads}" + "# Calculate Mahalanobis distance per population and report outliers\n", + "[detect_outliers]\n", + "# Set the probability to remove outliers eg 0.95 or 0.997\n", + "parameter: prob = 0.997\n", + "# Mahalanobis distance p-value cutoff\n", + "parameter: pval = 0.05\n", + "# Robust Mahalanobis to outliers\n", + "parameter: robust = True\n", + "parameter: pca_result = path\n", + "input: pca_result\n", + "output: distance=f'{_input:n}.mahalanobis.rds',\n", + " identified_outliers=f'{_input:n}.outliers',\n", + " analysis_summary=f'{_input:n}.analysis_summary.md',\n", + " qqplot_mahalanobis=f'{_input:n}.mahalanobis_qq.png',\n", + " hist_mahalanobis=f'{_input:n}.mahalanobis_hist.png'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = 1, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/PCA.R \\\n", + " --step detect_outliers \\\n", + " --cwd \"${cwd}\" \\\n", + " --pca-result \"${_input}\" \\\n", + " --prob ${prob} \\\n", + " --pval ${pval} \\\n", + " --robust ${\"TRUE\" if robust else \"FALSE\"} \\\n", + " --pop-col \"${pop_col}\" \\\n", + " --k ${k} \\\n", + " --distance-output \"${_output['distance']}\" \\\n", + " --identified-outliers-output \"${_output['identified_outliers']}\" \\\n", + " --analysis-summary-output \"${_output['analysis_summary']}\" \\\n", + " --qqplot-output \"${_output['qqplot_mahalanobis']}\" \\\n", + " --hist-output \"${_output['hist_mahalanobis']}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -598,18 +1130,7 @@ "kernel": "SoS" }, "source": [ - "## Add plot and outlier detection to PCA steps" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### Add plot and outlier detection to PCA steps" ] }, { @@ -620,7 +1141,24 @@ }, "outputs": [], "source": [ - "[flashpca_2, project_samples_2]\n# Set the probability to remove outliers eg 0.95 or 0.997\nparameter: prob = 0.997\n# Robust Mahalanobis to outliers\nparameter: robust = True\noutput: distance=f'{_input:n}.mahalanobis.rds',\n identified_outliers=f'{_input:n}.outliers',\n analysis_summary=f'{_input:n}.analysis_summary.md',\n qqplot_mahalanobis=f'{_input:n}.mahalanobis_qq.png',\n hist_mahalanobis=f'{_input:n}.mahalanobis_hist.png'\nsos_run(\"detect_outliers\", pca_result=_input, prob=prob, robust=robust)\n\n[flashpca_3, project_samples_3]\ninput: output_from(1), output_from(2)['identified_outliers']\noutliers = [x.strip() for x in open(_input[1]).readlines() if x.strip()]\noutput: f\"{cwd}/{_input[0]:bn}.pc.png\",\n f\"{cwd}/{_input[0]:bn}.scree.png\"\nsos_run(\"plot_pca\", plot_data = _input[0], outlier_file = _input[1] if len(outliers) else path())" + "[flashpca_2, project_samples_2]\n", + "# Set the probability to remove outliers eg 0.95 or 0.997\n", + "parameter: prob = 0.997\n", + "# Robust Mahalanobis to outliers\n", + "parameter: robust = True\n", + "output: distance=f'{_input:n}.mahalanobis.rds',\n", + " identified_outliers=f'{_input:n}.outliers',\n", + " analysis_summary=f'{_input:n}.analysis_summary.md',\n", + " qqplot_mahalanobis=f'{_input:n}.mahalanobis_qq.png',\n", + " hist_mahalanobis=f'{_input:n}.mahalanobis_hist.png'\n", + "sos_run(\"detect_outliers\", pca_result=_input, prob=prob, robust=robust)\n", + "\n", + "[flashpca_3, project_samples_3]\n", + "input: output_from(1), output_from(2)['identified_outliers']\n", + "outliers = [x.strip() for x in open(_input[1]).readlines() if x.strip()]\n", + "output: f\"{cwd}/{_input[0]:bn}.pc.png\",\n", + " f\"{cwd}/{_input[0]:bn}.scree.png\"\n", + "sos_run(\"plot_pca\", plot_data = _input[0], outlier_file = _input[1] if len(outliers) else path())" ] } ], @@ -636,7 +1174,7 @@ "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", - "version": "4.4.3" + "version": "4.5.3" }, "nbdime-conflicts": { "local_diff": [ diff --git a/code/SoS/data_preprocessing/genotype/VCF_QC.ipynb b/code/SoS/data_preprocessing/genotype/VCF_QC.ipynb index ae1471e13..cf79e3e2b 100644 --- a/code/SoS/data_preprocessing/genotype/VCF_QC.ipynb +++ b/code/SoS/data_preprocessing/genotype/VCF_QC.ipynb @@ -18,38 +18,67 @@ "kernel": "SoS" }, "source": [ - "## Description\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "A major challenge in biomedical research is the quality control (QC) of sequencing data. False positive variant calls can hinder the ability to detect disease associated variants or introduce spurious associations, therefore the need for a rigorous QC. Our pipeline focuses on QC after the variant calling stage and requires project Variant Calling Format (pVCF) as input files. We have defined default thresholds for genotype and variant-level hard filtering based on recommendations from the UK Biobank team and a thorough review of the literature [[cf. Carson et al. BMC Bioinformatics (2014)](https://doi.org/10.1186/1471-2105-15-125),[cf. Lek et al. Nature (2016)](https://doi.org/10.1038/nature19057),[cf. Szustakowski et al. Nature Genetics (2021)](https://doi.org/10.1038/s41588-021-00885-0)]. Bcftools is used in our QC steps. We first handle multi-allelic sites by splitting them into bi-allelic records. We include an optional workflow to keep only bi-allelic sites in the data. Variants are then annotated based on dbSNP data. Genotypes are kept if they have a Genotype Depth (DP) >= 10 and a Genotype Quality (GQ) >= 20. Variants are included if at least one sample has an allelic balance (AB) >= 0.15 for Single Nucleotide Variants (SNVs) and AB>=0.2 for indels, variant missigness is below 20% and Hardy-Weinberg Equilibrium p-value is > 1e-08. Allele balance is calculated for heterozygotes as the number of bases supporting the least-represented allele over the total number of base observations. Output summary statistics, such as transistion/transversion ratios (TS/TV ratio) are calculated to determine the effectiveness of QC. " + "## Overview\n", + "\n", + "Genotype problems are cheap to fix here and expensive to find later. Chromosome naming\n", + "differs between references (`1` versus `chr1`), the same variant can be represented several\n", + "ways, and low-depth or low-quality calls look like real genotypes to every tool downstream.\n", + "This step normalises naming, annotates variants against dbSNP so identifiers are consistent\n", + "across cohorts, and applies the depth and quality filters, so everything after it works from\n", + "one convention.\n", + "\n", + "A major challenge in biomedical research is the quality control (QC) of sequencing data. False positive variant calls can hinder the ability to detect disease associated variants or introduce spurious associations, therefore the need for a rigorous QC. This module focuses on QC after the variant calling stage and requires project Variant Calling Format (pVCF) as input files. Default thresholds are defined for genotype and variant-level hard filtering based on recommendations from the UK Biobank team and a thorough review of the literature [[cf. Carson et al. BMC Bioinformatics (2014)](https://doi.org/10.1186/1471-2105-15-125),[cf. Lek et al. Nature (2016)](https://doi.org/10.1038/nature19057),[cf. Szustakowski et al. Nature Genetics (2021)](https://doi.org/10.1038/s41588-021-00885-0)]. Bcftools performs the QC steps. Multi-allelic sites are first split into bi-allelic records. An optional workflow keeps only bi-allelic sites in the data. Variants are then annotated based on dbSNP data. Genotypes are kept if they have a Genotype Depth (DP) >= 10 and a Genotype Quality (GQ) >= 20. Variants are included if at least one sample has an allelic balance (AB) >= 0.15 for Single Nucleotide Variants (SNVs) and AB>=0.2 for indels, variant missigness is below 20% and, when an HWE cutoff is supplied, the Hardy-Weinberg Equilibrium p-value exceeds it. Allele balance is calculated for heterozygotes as the number of bases supporting the least-represented allele over the total number of base observations. Output summary statistics, such as transistion/transversion ratios (TS/TV ratio) are calculated to determine the effectiveness of QC. \n", + "\n", + "**When to run it.** First, on the raw VCF, before formatting, PCA or association testing.\n", + "A meta-analysis across cohorts is where naming and identifier mismatches surface, and by\n", + "then it is far harder to trace." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Default Parameters: VCF QC Filters\n", + "## Input\n", + "\n", + "- `--genoFile input/genotype/protocol_example.genotype.chr*.vcf.gz` (+ `.tbi`): the per-chromosome\n", + " pVCFs to QC, from upstream genotype calling. A manifest may be given instead --\n", + " `input/genotype/protocol_example.genotype.vcf_list.txt`, two columns, chromosome number and VCF\n", + " path -- which lets the chromosomes run in parallel. This is the only required data input;\n", + " everything else is reference material or a threshold.\n", + "- `--dbsnp-variants input/reference_data/00-All.add_chr.variants.gz` (+ `.tbi`) (required for `qc`):\n", + " chr-renamed dbSNP table, `CHROM/POS/ID/REF/ALT`, used to split variants into known and novel.\n", + "- `--reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta`\n", + " (+ `.fai`) (required for `qc`): FASTA for left-normalization and the REF check.\n", + "- `--cwd` (default `output`): work directory for the analysis.\n", + "- `--modular-script-dir` (default `code/script`): directory holding the modular wrapper scripts.\n", + "- `--remove-samples` / `--keep-samples` (both default `.`): optional sample lists applied before QC.\n", + "- `--skip-vcf-header-filtering` (default off): skip the header-based contig filtering.\n", + "- `--gt-only-vcf-qc` (default off): treat the input as genotype-only, so the depth and quality\n", + " filters below are not applied. Required for the toy `protocol_example.genotype.*` VCFs, whose\n", + " FORMAT carries only `GT` -- with no `DP`, `GQ` or `AD` those filters have nothing to read.\n", "\n", + "Variant preprocessing (`qc_1`):\n", "\n", - "1. Genotype depth filters: For WES data, UK Biobank recommends **SNPs DP>10 and Indels DP>10 for indels.** However we think for WGS we can be less stringent, or simply rely on GQ. Users can set it to 1 eg, `--DP 1 --DP-indel 1 `\n", - "2. Genotype quality GQ>20.\n", - "3. At least one sample per site passed the allele balance threshold >= 0.15 for SNPs and >=0.20 for indels (heterozygous variants). \n", - " - Allele balance is calculated for heterozygotes as the number of bases supporting the least-represented allele over the total number of base observations.\n", - "4. This module also allows for filtering by HWE and missingness although by default we don't filter on them.\n", + "- `--bi-allelic` (default off): keep only bi-allelic sites.\n", + "- `--snp-only` (default off): drop indels.\n", "\n", - "Filtering are done with `bcftools`. Here is a [useful cheatsheet from github user @elowy01](https://gist.github.com/elowy01/93922762e131d7abd3c7e8e166a74a0b).\n", + "Variant- and genotype-level filters (`qc_2`):\n", "\n", - "### A note on TS/TV summary from VCF genotype data\n", + "- `--geno-filter` (default `0.2`): maximum per-variant missingness.\n", + "- `--DP-snp` (default `10`) and `--DP-indel` (default `10`): minimum read depth per genotype.\n", + "- `--GQ` (default `20`): minimum genotype quality.\n", + "- `--AB-snp` (default `0.15`) and `--AB-indel` (default `0.2`): allele-balance thresholds for\n", + " heterozygous calls.\n", + "- `--hwe-filter` (default `0.0`): HWE p-value cutoff. The parameter help calls `0.0` \"no HWE\n", + " filter\", but the script applies `HWE > ` literally, so `0.0` still drops any site whose HWE\n", + " p-value is exactly 0 or whose `HWE` tag is missing.\n", "\n", - "`bcftools stats` command provides useful summary statistics including TS/TV ratio, which is routinely used as a quality measure of variant calls. With dbSNP based annotation of novel and known variants, `bcftools` can compute TS/TV for novel and known variants at variant level, and at sample level. It should be noted that variant level TS/TV does not take sample genotype into consideration -- it simply counts the TS and TV event for observed SNPs in the data. Other tools, such as `snpsift`, implements variant level TS/TV by counting TS and TV events in sample genotypes and compute the ratio after summing up TS and TV across all samples. See [here](https://github.com/samtools/bcftools/issues/1526) some discussions on this issue. We provide these TS/TV calculations before and after QC but users should be aware of the difference when interpreting the results." + "Cluster resources: `--numThreads` (default `1`), `--job-size` (default `1`), `--walltime` (default\n", + "`24h`), `--mem` (default `60G`). A whole-genome VCF needs the full 60G; `qc_1` and `qc_2` process\n", + "roughly 14G of data per hour, so scale `--walltime` with input size." ] }, { @@ -58,29 +87,54 @@ "kernel": "SoS" }, "source": [ - "## Default Parameters: Resource Usage\n", + "### On choosing the filter thresholds\n", + "\n", + "For WES data the UK Biobank recommendation is DP>10 for both SNPs and indels. For WGS the depth\n", + "thresholds can be relaxed, or GQ relied on alone -- `--DP-snp 1 --DP-indel 1` effectively disables\n", + "the depth filter.\n", + "\n", + "The allele-balance filters keep a site if at least one sample passes the threshold. Allele balance is\n", + "computed for heterozygotes as the number of bases supporting the least-represented allele over the\n", + "total number of base observations.\n", "\n", - "- Memory: Usually a whole genome VCF.gz file has the size of 200+GB, after testing, a minimum of 60GB of mem is requried.\n", - "- Walltimes: For every hour qc_1 or qc_2 can process ~14G of data. The default is set to be 24h, corresponding to ~300GB of input. Please set the --walltime parameter according to the size of your input files." + "Filtering is done with `bcftools`; this\n", + "[cheatsheet](https://gist.github.com/elowy01/93922762e131d7abd3c7e8e166a74a0b) is a useful\n", + "reference." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", "\n", - "| File | Produced by | Used as |\n", - "|------|-------------|---------|\n", - "| `input/genotype/protocol_example.genotype.chr*.vcf.gz` (+ `.tbi`) | upstream genotype calling | per-chromosome target VCFs to QC |\n", - "| `input/genotype/protocol_example.genotype.vcf_list.txt` | manifest (2 columns: chrom number, VCF path) | list of VCFs for parallel QC |\n", - "| `input/reference_data/00-All.add_chr.variants.gz` (+ `.tbi`) | dbSNP, `chr`-renamed | dbSNP variants for known/novel annotation |\n", - "| `input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta` (+ `.fai`) | reference genome | reference for left-normalization / REF check |\n", + "- `.leftnorm.vcf.gz` (+ `.tbi`) -- from `qc_1`: left-normalized, variant-ID-assigned,\n", + " dbSNP-annotated VCF.\n", + "- `.leftnorm.bcftools_qc.vcf.gz` (+ `.tbi`) -- from `qc_2`: the same VCF after the missingness,\n", + " depth, quality and allele-balance filters. This is the file downstream modules read.\n", + "- `.leftnorm.bcftools_qc.known_variant.snipsift_tstv` and\n", + " `.leftnorm.bcftools_qc.novel_variant.snipsift_tstv` -- from `qc_3`: TS/TV and Hom/Het\n", + " summaries, split by whether the variant carries a dbSNP rsID.\n", + "- `.leftnorm.bcftools_qc.known_variant_sumstats` and\n", + " `.leftnorm.bcftools_qc.novel_variant_sumstats` -- from `qc_3`: the full `bcftools stats`\n", + " report per split, with the `SN` record counts and the per-sample `PSC` block.\n", + "- a `.stdout` / `.stderr` log and the generated shell script beside each target.\n", "\n", - "**Note:** the toy `protocol_example.genotype.*` VCFs carry only the `GT` FORMAT field (no `DP`/`GQ`/`AB`), so QC is run with `--skip_vcf_header_filtering True` (see Step 3)." + "All paths are relative to `--cwd`, and `` is the `--genoFile` stem, e.g.\n", + "`protocol_example.genotype.chr22`.\n", + "\n", + "With `--gt-only-vcf-qc` the intermediate and final names carry an extra `.gt_only` segment, e.g.\n", + "`.leftnorm.gt_only.bcftools_qc.vcf.gz`.\n", + "\n", + "**No example output is committed for the QC stages.** On the toy chr22 data every\n", + "`bcftools_qc.*_sumstats` file reports `number of records: 0`, with or without `--gt-only-vcf-qc`,\n", + "while the input to that step holds 18,455 variants of which `bcftools view -c1` retains 4,259. The\n", + "`qc_2` filters are discarding everything and the step still exits successfully, so the committed\n", + "example output is empty and no dump can be shown here yet.\n", + "\n", + "`bcftools stats` command provides useful summary statistics including TS/TV ratio, which is routinely used as a quality measure of variant calls. With dbSNP based annotation of novel and known variants, `bcftools` can compute TS/TV for novel and known variants at variant level, and at sample level. It should be noted that variant level TS/TV does not take sample genotype into consideration -- it simply counts the TS and TV event for observed SNPs in the data. Other tools, such as `snpsift`, implements variant level TS/TV by counting TS and TV events in sample genotypes and compute the ratio after summing up TS and TV across all samples. See [here](https://github.com/samtools/bcftools/issues/1526) some discussions on this issue. TS/TV is reported before and after QC, but users should be aware of the difference when interpreting the results." ] }, { @@ -89,15 +143,9 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", - "\n", - "| File | Produced by | Description |\n", - "|------|-------------|-------------|\n", - "| `output/vcf_qc/protocol_example.genotype.chr*.leftnorm.vcf.gz` | `qc` | left-normalized, variant-ID-assigned, dbSNP-annotated VCF |\n", - "| `output/vcf_qc/protocol_example.genotype.chr*.leftnorm.{known,novel}_variant.snipsift_tstv` | `qc` | Ts/Tv summary statistics (known vs novel variants) |\n", - "| `output/vcf_qc/protocol_example.genotype.chr*.leftnorm.{known,novel}_variant_sumstats` | `qc` | per-file variant summary statistics |\n", + "## Minimal Working Example\n", "\n", - "The QC-ed genotype VCFs can be converted to PLINK format with `vcf_to_plink` in `genotype_formatting.ipynb`." + "The steps below run on the toy `protocol_example` genotype data. Steps 1 and 2 are optional helpers; Step 3 is the main QC workflow." ] }, { @@ -106,11 +154,9 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example\n", + "#### Step 1. Rename Chromosomes (optional)\n", "\n", - "The steps below run on the toy `protocol_example` genotype data. Steps 1 and 2 are optional helpers; Step 3 is the main QC workflow.\n", - "\n", - "## Steps" + "Add a `chr` prefix to chromosome names so they match the reference `fasta`. Timing: ~40 min on full data." ] }, { @@ -119,18 +165,17 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** Rename Chromosomes (optional)\n", - "\n", - "Add a `chr` prefix to chromosome names so they match the reference `fasta`. Timing: ~40 min on full data." + "The toy genotypes are already `chr`-prefixed, so to demonstrate `rename_chrs` the protocol ships a small derived input `protocol_example.genotype.rawchr.chr22.vcf.gz` whose chromosome is named `22` (no `chr`). Running `rename_chrs` adds the prefix back, writing `protocol_example.genotype.rawchr.add_chr.vcf.gz` next to the input." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "The toy genotypes are already `chr`-prefixed, so to demonstrate `rename_chrs` we ship a small derived input `protocol_example.genotype.rawchr.chr22.vcf.gz` whose chromosome is named `22` (no `chr`). Running `rename_chrs` adds the prefix back, writing `protocol_example.genotype.rawchr.add_chr.vcf.gz` next to the input." + "**Timing**: TBD (on toy dataset)" ] }, { @@ -144,7 +189,9 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb rename_chrs \\\n --genoFile input/genotype/protocol_example.genotype.rawchr.chr22.vcf.gz \\\n --cwd output/vcf_qc" + "sos run pipeline/VCF_QC.ipynb rename_chrs \\\n", + " --genoFile input/genotype/protocol_example.genotype.rawchr.chr22.vcf.gz \\\n", + " --cwd output/vcf_qc" ] }, { @@ -153,7 +200,7 @@ "kernel": "SoS" }, "source": [ - "Extracts `CHROM/POS/ID/REF/ALT` from a VCF into the compact `.variants.gz` dbSNP table used by the QC step. Here we run it on a toy genotype VCF to produce `protocol_example.genotype.chr22.variants.gz`." + "Extracts `CHROM/POS/ID/REF/ALT` from a VCF into the compact `.variants.gz` dbSNP table used by the QC step. It is run here on a toy genotype VCF to produce `protocol_example.genotype.chr22.variants.gz`." ] }, { @@ -165,6 +212,16 @@ "Annotates against the dbSNP database in VCF format." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -176,7 +233,9 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb dbsnp_annotate \\\n --genoFile input/genotype/protocol_example.genotype.chr22.vcf.gz \\\n --cwd output/vcf_qc" + "sos run pipeline/VCF_QC.ipynb dbsnp_annotate \\\n", + " --genoFile input/genotype/protocol_example.genotype.chr22.vcf.gz \\\n", + " --cwd output/vcf_qc" ] }, { @@ -185,19 +244,22 @@ "kernel": "Bash" }, "source": [ - "### **Step 2.** Merge separated bed files into one\n", - "Converting VCF to PLINK keeping only the ROSMAP samples." + "#### Step 2. Merge per-chromosome files (handled elsewhere)\n", + "\n", + "Converting the QC-d VCFs to PLINK format and merging them is done by `genotype_formatting.ipynb`\n", + "(`vcf_to_plink`, then `merge_plink`), not by this module. See that notebook for the commands and its\n", + "own `--name` option." ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/genotype_formatting.ipynb vcf_to_plink \\\n --genoFile `ls input/genotype/protocol_example.genotype.chr*.vcf.gz` \\\n --cwd output/plink/\n\nsos run pipeline/genotype_formatting.ipynb merge_plink \\\n --genoFile `ls output/plink/protocol_example.genotype.chr*.bed` \\\n --name protocol_example.genotype.merged \\\n --cwd output/plink/" + "#### Step 3. Quality Control\n", + "\n", + "The main QC workflow: split multi-allelic sites, left-normalize indels, assign variant IDs, and annotate known/novel variants against dbSNP." ] }, { @@ -206,18 +268,17 @@ "kernel": "SoS" }, "source": [ - "### **Step 3.** Quality Control\n", - "\n", - "The main QC workflow: split multi-allelic sites, left-normalize indels, assign variant IDs, and annotate known/novel variants against dbSNP." + "Run on a single chromosome (chr22) below, or in parallel over all chromosomes." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "Run on a single chromosome (chr22) below, or in parallel over all chromosomes." + "**Timing**: TBD (on toy dataset)" ] }, { @@ -231,7 +292,12 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb qc \\\n --genoFile input/genotype/protocol_example.genotype.chr22.vcf.gz \\\n --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n --cwd output/vcf_qc \\\n --skip_vcf_header_filtering True" + "sos run pipeline/VCF_QC.ipynb qc \\\n", + " --genoFile input/genotype/protocol_example.genotype.chr22.vcf.gz \\\n", + " --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n", + " --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --cwd output/vcf_qc \\\n", + " --skip_vcf_header_filtering True" ] }, { @@ -242,7 +308,17 @@ "source": [ "To run in parallel for all genotype data listed in `protocol_example.genotype.vcf_list.txt`:\n", "\n", - "**Note on `--skip_vcf_header_filtering True`:** the toy `protocol_example.genotype.*` VCFs contain only the `GT` (genotype) FORMAT field. The default depth/quality filtering relies on the `DP` FORMAT tag, which is absent here, so `--skip_vcf_header_filtering True` runs left-normalization, variant-ID assignment and dbSNP annotation while skipping the `DP`-based filtering \u2014 the appropriate path for genotype-only VCFs. To see the **default** path (which does apply the `DP`/`GQ`/`AD` filters), use the `protocol_example.genotype.withfmt.chr22.vcf.gz` file in **Step 3b** below, which carries those tags." + "**Note on `--skip_vcf_header_filtering True`:** the toy `protocol_example.genotype.*` VCFs contain only the `GT` (genotype) FORMAT field. The default depth/quality filtering relies on the `DP` FORMAT tag, which is absent here, so `--skip_vcf_header_filtering True` runs left-normalization, variant-ID assignment and dbSNP annotation while skipping the `DP`-based filtering — the appropriate path for genotype-only VCFs. To see the **default** path (which does apply the `DP`/`GQ`/`AD` filters), use the `protocol_example.genotype.withfmt.chr22.vcf.gz` file in **Step 3b** below, which carries those tags." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -256,7 +332,13 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb qc \\\n --genoFile input/genotype/protocol_example.genotype.vcf_list.txt \\\n --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n --cwd output/vcf_qc \\\n --skip_vcf_header_filtering True \\\n -j 2" + "sos run pipeline/VCF_QC.ipynb qc \\\n", + " --genoFile input/genotype/protocol_example.genotype.vcf_list.txt \\\n", + " --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n", + " --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --cwd output/vcf_qc \\\n", + " --skip_vcf_header_filtering True \\\n", + " -j 2" ] }, { @@ -265,9 +347,19 @@ "kernel": "SoS" }, "source": [ - "### Step 3b \u2014 Quality Control on data with DP/GQ/AD tags (default path)\n", + "#### Step 3b — Quality Control on data with DP/GQ/AD tags (default path)\n", "\n", - "The genotype VCFs above are genotype-only (`GT`), so QC is run with `--skip_vcf_header_filtering True` to bypass the depth/quality filters. To demonstrate the **default** QC path (which filters on read depth `DP`, genotype quality `GQ`, and allele balance from `AD`), we ship `protocol_example.genotype.withfmt.chr22.vcf.gz`. Its `DP/GQ/AD/AB` values are **synthetic placeholders** (seed=22), not real measurements, and exist only to exercise the default filters." + "The genotype VCFs above are genotype-only (`GT`), so QC is run with `--skip_vcf_header_filtering True` to bypass the depth/quality filters. To demonstrate the **default** QC path (which filters on read depth `DP`, genotype quality `GQ`, and allele balance from `AD`), the protocol ships `protocol_example.genotype.withfmt.chr22.vcf.gz`. Its `DP/GQ/AD/AB` values are **synthetic placeholders** (seed=22), not real measurements, and exist only to exercise the default filters." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -278,7 +370,12 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb qc \\\n --genoFile input/genotype/protocol_example.genotype.withfmt.chr22.vcf.gz \\\n --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n --cwd output/vcf_qc_withfmt \\\n -j 2" + "sos run pipeline/VCF_QC.ipynb qc \\\n", + " --genoFile input/genotype/protocol_example.genotype.withfmt.chr22.vcf.gz \\\n", + " --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n", + " --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --cwd output/vcf_qc_withfmt \\\n", + " -j 2" ] }, { @@ -359,12 +456,102 @@ "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash", - "tags": [] + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run VCF_QC.ipynb -h" + "sos run pipeline/VCF_QC.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/VCF_QC.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " rename_chrs\n", + " dbsnp_annotate\n", + " qc\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --genoFile paths\n", + "\n", + " input can either be 1 vcf genoFile, or a list of vcf\n", + " genoFile.\n", + " --remove-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to remove (format FID, IID)\n", + " --keep-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to keep (format FID, IID)\n", + " --cwd output (as path)\n", + " Workdir\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 24h\n", + " Walltime\n", + " --mem 60G\n", + " Usually a whole genome VCF.gz file has the size of\n", + " 200+GB, after testing, a minimum of 60GB of mem is\n", + " requried.\n", + " --[no-]gt-only-vcf-qc (default to False)\n", + " Whether to run GT-only VCF QC for inputs that do not\n", + " carry per-sample DP/GQ/AD FORMAT fields.\n", + " --[no-]skip-vcf-header-filtering (default to False)\n", + " Deprecated alias for GT-only VCF QC.\n", + "\n", + "Sections\n", + " rename_chrs:\n", + " dbsnp_annotate:\n", + " qc_1: Handel multi-allelic sites, left normalization of indels\n", + " and add variant ID\n", + " Workflow Options:\n", + " --dbsnp-variants VAL (as path, required)\n", + " Path to dbSNP variants generated previously\n", + " --reference-genome VAL (as path, required)\n", + " Path to fasta file for HG reference genome, eg\n", + " GRCh38_full_analysis_set_plus_decoy_hla.fa\n", + " --[no-]bi-allelic (default to False)\n", + " --[no-]snp-only (default to False)\n", + " qc_2: genotype QC\n", + " Workflow Options:\n", + " --geno-filter 0.2 (as float)\n", + " Maximum missingess per-variant, default to 0.2\n", + " --DP-snp 10 (as int)\n", + " Sample level QC - read depth (DP) to filter out SNPs\n", + " below this value Default to 10, with WES data in mind\n", + " But for WGS, setting it to 2 may be fine considering the\n", + " WGS may have low DP but the GQ filter should be good\n", + " enough\n", + " --GQ 20 (as int)\n", + " Sample level QC - genotype quality (GQ) of specific\n", + " sample. This measure tells you how confident we are that\n", + " the genotype we assigned to a particular sample is\n", + " correct\n", + " --DP-indel 10 (as int)\n", + " Sample level QC - read depth (DP) to filter out indels\n", + " below this value\n", + " --AB-snp 0.15 (as float)\n", + " Allele balance for snps\n", + " --AB-indel 0.2 (as float)\n", + " Allele balance for indels\n", + " --hwe-filter 0.0 (as float)\n", + " HWE filter, default to 0.0 which means no HWE filter is\n", + " applied\n", + " qc_3:\n", + "```" ] }, { @@ -373,7 +560,7 @@ "kernel": "Bash" }, "source": [ - "## Global parameters" + "## Workflow implementation" ] }, { @@ -384,7 +571,84 @@ }, "outputs": [], "source": [ - "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# input can either be 1 vcf genoFile, or a list of vcf genoFile.\nparameter: genoFile = paths\n# The path to the file that contains the list of samples to remove (format FID, IID)\nparameter: remove_samples = path('.')\n# The path to the file that contains the list of samples to keep (format FID, IID)\nparameter: keep_samples = path('.')\n# Workdir\nparameter: cwd = path(\"output\")\n# Number of threads\nparameter: numThreads = 1\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Walltime \nparameter: walltime = '24h'\n# Usually a whole genome VCF.gz file has the size of 200+GB, after testing, a minimum of 60GB of mem is requried.\nparameter: mem = '60G'\nimport re\n# Whether to run GT-only VCF QC for inputs that do not carry per-sample DP/GQ/AD FORMAT fields.\nparameter: gt_only_vcf_qc = False\n# Deprecated alias for GT-only VCF QC.\nparameter: skip_vcf_header_filtering = False\ngt_only_vcf_qc = bool(gt_only_vcf_qc or skip_vcf_header_filtering)\nvcf_qc_mode_suffix = '.gt_only' if gt_only_vcf_qc else ''\n# use this function to edit memory string for PLINK input\nfrom sos.utils import expand_size\ncwd = path(f\"{cwd:a}\")\n\nimport os\ndef get_genotype_file(geno_file_paths):\n #\n def valid_geno_file(x):\n suffixes = path(x).suffixes\n if suffixes[-1] == '.bed':\n return True\n elif suffixes[-1] == '.vcf':\n return True\n elif len(suffixes)>1 and ''.join(suffixes[-2:]) == \".vcf.gz\" :\n return True\n return False\n #\n def complete_geno_path(x, geno_file):\n if not valid_geno_file(x):\n raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n if not os.path.isfile(x):\n # relative path\n if not os.path.isfile(f'{geno_file:ad}/' + x):\n raise ValueError(f\"Cannot find genotype file {x}\")\n else:\n x = f'{geno_file:ad}/' + x\n return x\n # \n def format_chrom(chrom):\n if chrom.startswith('chr'):\n chrom = chrom[3:]\n return chrom\n # Inputs are either VCF or bed, or a vector of them \n if len(geno_file_paths) > 1:\n if all([valid_geno_file(x) for x in geno_file_paths]):\n return paths(geno_file_paths)\n else: \n raise ValueError(f\"Invalid input {geno_file_paths}\")\n # Input is one genotype file or text list of genotype files\n geno_file = geno_file_paths[0]\n if valid_geno_file(geno_file):\n return paths(geno_file)\n else: \n units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n if all([len(x) == 1 for x in units]):\n return paths([complete_geno_path(x[0], geno_file) for x in units])\n elif all([len(x) == 2 for x in units]):\n genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n else:\n raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n return genos\n \ngenoFile = get_genotype_file(genoFile)" + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# input can either be 1 vcf genoFile, or a list of vcf genoFile.\n", + "parameter: genoFile = paths\n", + "# The path to the file that contains the list of samples to remove (format FID, IID)\n", + "parameter: remove_samples = path('.')\n", + "# The path to the file that contains the list of samples to keep (format FID, IID)\n", + "parameter: keep_samples = path('.')\n", + "# Workdir\n", + "parameter: cwd = path(\"output\")\n", + "# Number of threads\n", + "parameter: numThreads = 1\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Walltime \n", + "parameter: walltime = '24h'\n", + "# Usually a whole genome VCF.gz file has the size of 200+GB, after testing, a minimum of 60GB of mem is requried.\n", + "parameter: mem = '60G'\n", + "import re\n", + "# Whether to run GT-only VCF QC for inputs that do not carry per-sample DP/GQ/AD FORMAT fields.\n", + "parameter: gt_only_vcf_qc = False\n", + "# Deprecated alias for GT-only VCF QC.\n", + "parameter: skip_vcf_header_filtering = False\n", + "gt_only_vcf_qc = bool(gt_only_vcf_qc or skip_vcf_header_filtering)\n", + "vcf_qc_mode_suffix = '.gt_only' if gt_only_vcf_qc else ''\n", + "# use this function to edit memory string for PLINK input\n", + "from sos.utils import expand_size\n", + "cwd = path(f\"{cwd:a}\")\n", + "\n", + "import os\n", + "def get_genotype_file(geno_file_paths):\n", + " #\n", + " def valid_geno_file(x):\n", + " suffixes = path(x).suffixes\n", + " if suffixes[-1] == '.bed':\n", + " return True\n", + " elif suffixes[-1] == '.vcf':\n", + " return True\n", + " elif len(suffixes)>1 and ''.join(suffixes[-2:]) == \".vcf.gz\" :\n", + " return True\n", + " return False\n", + " #\n", + " def complete_geno_path(x, geno_file):\n", + " if not valid_geno_file(x):\n", + " raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n", + " if not os.path.isfile(x):\n", + " # relative path\n", + " if not os.path.isfile(f'{geno_file:ad}/' + x):\n", + " raise ValueError(f\"Cannot find genotype file {x}\")\n", + " else:\n", + " x = f'{geno_file:ad}/' + x\n", + " return x\n", + " # \n", + " def format_chrom(chrom):\n", + " if chrom.startswith('chr'):\n", + " chrom = chrom[3:]\n", + " return chrom\n", + " # Inputs are either VCF or bed, or a vector of them \n", + " if len(geno_file_paths) > 1:\n", + " if all([valid_geno_file(x) for x in geno_file_paths]):\n", + " return paths(geno_file_paths)\n", + " else: \n", + " raise ValueError(f\"Invalid input {geno_file_paths}\")\n", + " # Input is one genotype file or text list of genotype files\n", + " geno_file = geno_file_paths[0]\n", + " if valid_geno_file(geno_file):\n", + " return paths(geno_file)\n", + " else: \n", + " units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n", + " if all([len(x) == 1 for x in units]):\n", + " return paths([complete_geno_path(x[0], geno_file) for x in units])\n", + " elif all([len(x) == 2 for x in units]):\n", + " genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n", + " else:\n", + " raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n", + " return genos\n", + " \n", + "genoFile = get_genotype_file(genoFile)" ] }, { @@ -394,7 +658,7 @@ "tags": [] }, "source": [ - "## Annotate known and novel variants\n", + "### Annotate known and novel variants\n", "\n", "You can download the known variant reference from [this link](https://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606_b150_GRCh38p7/VCF/00-All.vcf.gz).\n", "\n", @@ -409,7 +673,15 @@ }, "outputs": [], "source": [ - "[rename_chrs: provides = '{genoFile:nn}.add_chr.vcf.gz']\n# This file can be downloaded from https://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606_b150_GRCh38p7/VCF/00-All.vcf.gz.\ninput: genoFile\noutput: f'{_input:nn}.add_chr.vcf.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh rename_chrs \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\"\n" + "[rename_chrs: provides = '{genoFile:nn}.add_chr.vcf.gz']\n", + "# This file can be downloaded from https://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606_b150_GRCh38p7/VCF/00-All.vcf.gz.\n", + "input: genoFile\n", + "output: f'{_input:nn}.add_chr.vcf.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh rename_chrs \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\"\n" ] }, { @@ -420,7 +692,14 @@ }, "outputs": [], "source": [ - "[dbsnp_annotate]\ninput: genoFile\noutput: f\"{cwd}/{_input:bnn}.variants.gz\"\ntask: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh dbsnp_annotate \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\"\n" + "[dbsnp_annotate]\n", + "input: genoFile\n", + "output: f\"{cwd}/{_input:bnn}.variants.gz\"\n", + "task: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh dbsnp_annotate \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\"\n" ] }, { @@ -429,9 +708,9 @@ "kernel": "SoS" }, "source": [ - "## Genotype QC\n", + "### Genotype QC\n", "\n", - "This step handles multi-allelic sites and annotate variants to known and novel. We add an RS ID to variants in dbSNP. Variants without rsID are considered novel variants. For every hour it can produce ~14Gb of data, please set the --walltime parameter according to the size of your input files." + "This step handles multi-allelic sites and annotate variants to known and novel. An RS ID is added to variants in dbSNP. Variants without rsID are considered novel variants. For every hour it can produce ~14Gb of data, please set the --walltime parameter according to the size of your input files." ] }, { @@ -442,7 +721,28 @@ }, "outputs": [], "source": [ - "# Handel multi-allelic sites, left normalization of indels and add variant ID\n[qc_1 (variant preprocessing)]\n# Path to dbSNP variants generated previously\nparameter: dbsnp_variants = path\n# Path to fasta file for HG reference genome, eg GRCh38_full_analysis_set_plus_decoy_hla.fa\nparameter: reference_genome = path\nparameter: bi_allelic = False\nparameter: snp_only = False\ninput: genoFile, group_by = 1\noutput: f'{cwd}/{_input:bnn}.{\"leftnorm\" if not bi_allelic else \"biallelic\"}{\".snp\" if snp_only else \"\"}{vcf_qc_mode_suffix}.vcf.gz'\ntask: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\" \\\n --dbsnp-variants \"${dbsnp_variants}\" \\\n --reference-genome \"${reference_genome}\" \\\n --bi-allelic \"${bi_allelic}\" \\\n --snp-only \"${snp_only}\" \\\n --gt-only-vcf-qc \"${gt_only_vcf_qc}\" \\\n --numThreads ${numThreads}" + "# Handel multi-allelic sites, left normalization of indels and add variant ID\n", + "[qc_1 (variant preprocessing)]\n", + "# Path to dbSNP variants generated previously\n", + "parameter: dbsnp_variants = path\n", + "# Path to fasta file for HG reference genome, eg GRCh38_full_analysis_set_plus_decoy_hla.fa\n", + "parameter: reference_genome = path\n", + "parameter: bi_allelic = False\n", + "parameter: snp_only = False\n", + "input: genoFile, group_by = 1\n", + "output: f'{cwd}/{_input:bnn}.{\"leftnorm\" if not bi_allelic else \"biallelic\"}{\".snp\" if snp_only else \"\"}{vcf_qc_mode_suffix}.vcf.gz'\n", + "task: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\" \\\n", + " --dbsnp-variants \"${dbsnp_variants}\" \\\n", + " --reference-genome \"${reference_genome}\" \\\n", + " --bi-allelic \"${bi_allelic}\" \\\n", + " --snp-only \"${snp_only}\" \\\n", + " --gt-only-vcf-qc \"${gt_only_vcf_qc}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -462,7 +762,40 @@ }, "outputs": [], "source": [ - "# genotype QC\n[qc_2 (variant level QC)]\n# Maximum missingess per-variant, default to 0.2\nparameter: geno_filter = 0.2\n# Sample level QC - read depth (DP) to filter out SNPs below this value\n# Default to 10, with WES data in mind \n# But for WGS, setting it to 2 may be fine considering the WGS may have low DP but the GQ filter should be good enough\nparameter: DP_snp = 10\n# Sample level QC - genotype quality (GQ) of specific sample. This measure tells you how confident we are that the genotype we assigned to a particular sample is correct\nparameter: GQ = 20\n# Sample level QC - read depth (DP) to filter out indels below this value\nparameter: DP_indel = 10\n# Allele balance for snps\nparameter: AB_snp = 0.15\n# Allele balance for indels\nparameter: AB_indel = 0.2\n# HWE filter, default to 0.0 which means no HWE filter is applied\nparameter: hwe_filter = 0.0\noutput: f\"{_input:nn}.bcftools_qc.vcf.gz\"\ntask: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc_2 \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\" \\\n --gt-only-vcf-qc \"${gt_only_vcf_qc}\" \\\n --geno-filter ${geno_filter} \\\n --DP-snp ${DP_snp} \\\n --GQ ${GQ} \\\n --DP-indel ${DP_indel} \\\n --AB-snp ${AB_snp} \\\n --AB-indel ${AB_indel} \\\n --hwe-filter ${hwe_filter} \\\n --numThreads ${numThreads}" + "# genotype QC\n", + "[qc_2 (variant level QC)]\n", + "# Maximum missingess per-variant, default to 0.2\n", + "parameter: geno_filter = 0.2\n", + "# Sample level QC - read depth (DP) to filter out SNPs below this value\n", + "# Default to 10, with WES data in mind \n", + "# But for WGS, setting it to 2 may be fine considering the WGS may have low DP but the GQ filter should be good enough\n", + "parameter: DP_snp = 10\n", + "# Sample level QC - genotype quality (GQ) of specific sample. This measure tells you how confident we are that the genotype we assigned to a particular sample is correct\n", + "parameter: GQ = 20\n", + "# Sample level QC - read depth (DP) to filter out indels below this value\n", + "parameter: DP_indel = 10\n", + "# Allele balance for snps\n", + "parameter: AB_snp = 0.15\n", + "# Allele balance for indels\n", + "parameter: AB_indel = 0.2\n", + "# HWE filter, default to 0.0 which means no HWE filter is applied\n", + "parameter: hwe_filter = 0.0\n", + "output: f\"{_input:nn}.bcftools_qc.vcf.gz\"\n", + "task: trunk_workers = 1, trunk_size=job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc_2 \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\" \\\n", + " --gt-only-vcf-qc \"${gt_only_vcf_qc}\" \\\n", + " --geno-filter ${geno_filter} \\\n", + " --DP-snp ${DP_snp} \\\n", + " --GQ ${GQ} \\\n", + " --DP-indel ${DP_indel} \\\n", + " --AB-snp ${AB_snp} \\\n", + " --AB-indel ${AB_indel} \\\n", + " --hwe-filter ${hwe_filter} \\\n", + " --numThreads ${numThreads}" ] }, { @@ -473,18 +806,22 @@ }, "outputs": [], "source": [ - "[qc_3 (genotype data summary statistics)]\ninput: output_from('qc_1'), output_from('qc_2'), group_by = 1\noutput: f\"{cwd}/{_input:bnn}.novel_variant_sumstats\", \n f\"{cwd}/{_input:bnn}.known_variant_sumstats\", \n f\"{cwd}/{_input:bnn}.novel_variant.snipsift_tstv\",\n f\"{cwd}/{_input:bnn}.known_variant.snipsift_tstv\"\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc_3 \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --novel-sumstats \"${_output[0]}\" \\\n --known-sumstats \"${_output[1]}\" \\\n --novel-tstv \"${_output[2]}\" \\\n --known-tstv \"${_output[3]}\" \\\n --numThreads ${numThreads}" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "[qc_3 (genotype data summary statistics)]\n", + "input: output_from('qc_1'), output_from('qc_2'), group_by = 1\n", + "output: f\"{cwd}/{_input:bnn}.novel_variant_sumstats\", \n", + " f\"{cwd}/{_input:bnn}.known_variant_sumstats\", \n", + " f\"{cwd}/{_input:bnn}.novel_variant.snipsift_tstv\",\n", + " f\"{cwd}/{_input:bnn}.known_variant.snipsift_tstv\"\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/VCF_QC.sh qc_3 \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --novel-sumstats \"${_output[0]}\" \\\n", + " --known-sumstats \"${_output[1]}\" \\\n", + " --novel-tstv \"${_output[2]}\" \\\n", + " --known-tstv \"${_output[3]}\" \\\n", + " --numThreads ${numThreads}" ] } ], diff --git a/code/SoS/data_preprocessing/genotype/genotype_formatting.ipynb b/code/SoS/data_preprocessing/genotype/genotype_formatting.ipynb index 3945a8608..bdf17e268 100644 --- a/code/SoS/data_preprocessing/genotype/genotype_formatting.ipynb +++ b/code/SoS/data_preprocessing/genotype/genotype_formatting.ipynb @@ -19,7 +19,15 @@ "tags": [] }, "source": [ - "## Description" + "## Overview\n", + "\n", + "Nothing here changes the genotypes; it changes how they are packaged. Tools in the protocol\n", + "disagree about format - some want PLINK, some want VCF - and the association and fine-mapping\n", + "steps run per region or per chromosome, so the genotype data has to be split the same way to\n", + "be processed in parallel. These workflows do those conversions and splits, plus the LD\n", + "matrix computation per region that summary-statistic fine-mapping needs.\n", + "\n", + "**When to run it.** Run the relevant workflow after genotype quality control and before association scanning, LD calculation, or fine-mapping that requires the corresponding genotype layout.\n" ] }, { @@ -28,7 +36,16 @@ "kernel": "SoS" }, "source": [ - "We include steps for the formatting of genotype files. This includes the conversion between VCF and PLINK formats, the splitting of data (by specified input, chromosomes or genes) and the merging of data (by specified input, or by chromosomes)." + "This module provides workflows for the formatting of genotype files. This includes the conversion between VCF and PLINK formats, the splitting of data (by specified input, chromosomes or genes) and the merging of data (by specified input, or by chromosomes)." + ] + }, + { + "cell_type": "markdown", + "id": "faa2bdaa", + "metadata": {}, + "source": [ + "**When to run it.** After `VCF_QC`, before PCA and association testing. Which workflows you\n", + "need depends on the tools you plan to run, not on your data." ] }, { @@ -38,15 +55,47 @@ "tags": [] }, "source": [ - "## Input Files\n", + "## Input\n", + "\n", + "- `--genoFile`: the genotype data to convert. Its meaning follows the workflow -- one or more PLINK\n", + " prefixes for `plink_to_vcf` and the `merge_*` workflows, one or more VCFs for `vcf_to_plink`.\n", + "- `--name` (required): output prefix for this run, e.g. `protocol_example.genotype.merged`.\n", + "- `--cwd` (default `output`): work directory for the analysis.\n", + "- `--modular-script-dir` (default `code/script`): directory holding the modular wrapper scripts.\n", + "\n", + "`vcf_to_plink` -- VCF to PLINK:\n", + "\n", + "- `--add-chr` / `--no-add-chr` (default on): prefix contig names with `chr`.\n", + "- `--remove-duplicates` / `--no-remove-duplicates` (default off): drop duplicated variant IDs.\n", + "- `--keep-dosage` / `--no-keep-dosage` (default off): retain dosages rather than hard calls.\n", + "- `--remove-samples` / `--keep-samples` (both default `.`): optional sample lists.\n", + "\n", + "`genotype_by_region` -- split PLINK genotypes into regions:\n", + "\n", + "- `--region-list` (required): regions to cut the genotypes into.\n", + "- `--window` (default `0`): flanking bp added either side of each region.\n", + "\n", + "`ld_by_region_plink` -- LD matrices per region:\n", + "\n", + "- `--region-list` (required): regions to compute LD for.\n", + "- `--float-type` (default `16`): float width of the stored matrix.\n", + "\n", + "`genotype_by_chrom` -- split by chromosome:\n", + "\n", + "- `--chrom` (required): the chromosomes to emit, e.g. `--chrom 21 22`.\n", + "\n", + "`write_data_list` -- write a manifest of produced files:\n", + "\n", + "- `--out` (required) and `--ext` (required): manifest path and the file extension to collect.\n", + "- `--data-files`: the files to list, when they are not discovered from the previous step.\n", "\n", - "This minimal working example starts from the per-chromosome toy genotype VCFs under `input/genotype/`:\n", + "`merge_plink` -- merge PLINK filesets:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/genotype/protocol_example.genotype.chr{1..22}.vcf.gz` | 22 per-chromosome toy genotype VCFs (60 samples) |\n", + "- `--keep-samples` (default `.`): optional sample list.\n", + "- `--extra-plink-opts`: extra options passed straight to PLINK.\n", "\n", - "The pipeline also accepts a single whole-genome VCF or PLINK bed/bim/fam bundle, a list of VCF/PLINK files, or a two-column (chrom, file) list.\n" + "Cluster resources: `--numThreads` (default `20`), `--job-size` (default `1`), `--walltime` (default\n", + "`5h`), `--mem` (default `16G`)." ] }, { @@ -55,15 +104,52 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Output\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/genotype_formatting/plink/protocol_example.genotype.chr{1..22}.{bed,bim,fam}` | Per-chromosome PLINK bundles (Step 1) |\n", - "| `output/genotype_formatting/plink/protocol_example.genotype.merged.{bed,bim,fam}` | Single merged genome-wide PLINK bundle (Step 2) |\n", - "| `output/genotype_formatting/genotype_by_chrom/protocol_example.genotype.merged.{1..22}.{bed,bim,fam}` | Merged bundle partitioned back by chromosome (Step 3) |\n", + "- `.vcf.gz` (+ `.tbi`) -- from `plink_to_vcf`: the genotypes as a bgzipped, tabix-indexed VCF.\n", + "- `.bed` / `.bim` / `.fam`, or `.pgen` / `.pvar` / `.psam` -- from `vcf_to_plink`, and from\n", + " `merge_plink` for the merged fileset: a PLINK1 or PLINK2 fileset.\n", + "- `..bed` / `.bim` / `.fam` -- from `genotype_by_region`: one fileset per region in\n", + " `--region-list`, widened by `--window`.\n", + "- `..ld.rds` -- from `ld_by_region_plink`: the LD matrix for a region, stored at the\n", + " width `--float-type` sets.\n", + "- `..bed` / `.bim` / `.fam` -- from `genotype_by_chrom`: one fileset per `--chrom`.\n", + "- the manifest named by `--out`, a plain `.txt` or `.list` file of the produced paths -- from\n", + " `write_data_list`. Downstream modules read this rather than globbing.\n", + "- a `.stdout` / `.stderr` log and the generated script beside each target.\n", "\n", - "The merged PLINK bundle is the input expected by downstream genotype workers (GWAS_QC, GRM, PCA).\n" + "All paths are relative to `--cwd`, and `` is whatever `--name` was set to.\n", + "\n", + "A `.pvar` file carries meta_file headers ahead of the variant table, so it must be read with a parser\n", + "that skips them rather than as a plain TSV.\n", + "\n", + "The merged fileset from Route A, `output/genotype_formatting/plink/protocol_example.genotype.merged`,\n", + "holds 371,802 variants across 60 samples. First rows of the `.bim`:\n", + "\n", + "```\n", + "1\tchr1:113886_CTCTT_C\t0\t113886\tC\tCTCTT\n", + "1\tchr1:191223_C_*\t0\t191223\t*\tC\n", + "```\n", + "\n", + "and of the `.fam`, which carries no phenotype (`-9`):\n", + "\n", + "```\n", + "0 SAMPLE_001 0 0 0 -9\n", + "0 SAMPLE_002 0 0 0 -9\n", + "```\n", + "\n", + "Route A step 3 writes one fileset per chromosome plus its manifest:\n", + "\n", + "```\n", + "protocol_example.genotype.merged.10.bed\n", + "protocol_example.genotype.merged.10.bim\n", + "protocol_example.genotype.merged.10.fam\n", + "protocol_example.genotype_by_chrom_files.txt\n", + "```\n", + "\n", + "**Routes B and C have no committed example output.** Route B (`plink_to_vcf`, `merge_vcf`) and the\n", + "manifest step are runnable but have not been executed here; Route C additionally needs a region list,\n", + "which the protocol does not yet ship." ] }, { @@ -72,7 +158,7 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example\n\nThe data can be downloaded from [Synapse](https://www.synapse.org/#!Synapse:syn69670658/files/)." + "## Minimal Working Example\n" ] }, { @@ -81,7 +167,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** VCF to PLINK\n" + "### VCF to PLINK, merged, then split by chromosome" ] }, { @@ -90,7 +176,7 @@ "kernel": "SoS" }, "source": [ - "Convert the 22 per-chromosome toy VCFs into per-chromosome PLINK bed/bim/fam bundles. Timing: <1 min on the toy data.\n" + "#### Step 1. VCF to PLINK\n" ] }, { @@ -99,7 +185,17 @@ "kernel": "SoS" }, "source": [ - "Each input VCF becomes one PLINK bundle named after the input stem.\n" + "Convert the 22 per-chromosome toy VCFs into per-chromosome PLINK bed/bim/fam bundles. Each input VCF becomes one PLINK bundle named after the input stem.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -113,7 +209,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/genotype_formatting.ipynb vcf_to_plink \\\n --genoFile `ls input/genotype/protocol_example.genotype.chr*.vcf.gz | grep -vE \"rawchr|withfmt|add_chr\"` \\\n --cwd output/genotype_formatting/plink \\\n --name protocol_example \\\n -j 4" + "sos run pipeline/genotype_formatting.ipynb vcf_to_plink \\\n", + " --genoFile `ls input/genotype/protocol_example.genotype.chr*.vcf.gz | grep -vE \"rawchr|withfmt|add_chr\"` \\\n", + " --cwd output/genotype_formatting/plink \\\n", + " --name protocol_example \\\n", + " -j 4" ] }, { @@ -122,7 +222,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 2.** Merge PLINK Files\n" + "#### Step 2. Merge PLINK Files\n" ] }, { @@ -131,16 +231,17 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min on the toy data.\n" + "This step merges all per-chromosome PLINK files into one genome-wide bundle. Note: only `plink` (v1.9) can perform the merge — `plink2` does not support it.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "This step merges all per-chromosome PLINK files into one genome-wide bundle. Note: only `plink` (v1.9) can perform the merge — `plink2` does not support it.\n" + "**Timing**: TBD (on toy dataset)" ] }, { @@ -154,7 +255,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n --genoFile `ls output/genotype_formatting/plink/protocol_example.genotype.chr*.bed` \\\n --name protocol_example.genotype.merged \\\n --cwd output/genotype_formatting/plink \\\n -j 2" + "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n", + " --genoFile `ls output/genotype_formatting/plink/protocol_example.genotype.chr*.bed` \\\n", + " --name protocol_example.genotype.merged \\\n", + " --cwd output/genotype_formatting/plink \\\n", + " -j 2" ] }, { @@ -163,7 +268,7 @@ "kernel": "SoS" }, "source": [ - "### **Step 3.** Partition Genotype Data by Chromosome\n" + "#### Step 3. Partition Genotype Data by Chromosome\n" ] }, { @@ -172,7 +277,17 @@ "kernel": "SoS" }, "source": [ - "Split the merged genome-wide bundle back into per-chromosome PLINK files. Timing: <1 min on the toy data.\n" + "Split the merged genome-wide bundle back into per-chromosome PLINK files.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -186,7 +301,11 @@ }, "outputs": [], "source": [ - "sos run pipeline/genotype_formatting.ipynb genotype_by_chrom \\\n --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n --cwd output/genotype_formatting/genotype_by_chrom \\\n --chrom `cut -f 1 output/genotype_formatting/plink/protocol_example.genotype.merged.bim | uniq | sed \"s/chr//g\"` \\\n -j 4" + "sos run pipeline/genotype_formatting.ipynb genotype_by_chrom \\\n", + " --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged.bed \\\n", + " --cwd output/genotype_formatting/genotype_by_chrom \\\n", + " --chrom `cut -f 1 output/genotype_formatting/plink/protocol_example.genotype.merged.bim | uniq | sed \"s/chr//g\"` \\\n", + " -j 4" ] }, { @@ -195,50 +314,81 @@ "kernel": "SoS" }, "source": [ - "## Command Interface" + "### PLINK to VCF, then merged" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Step 1. PLINK to VCF\n", + "\n", + "The inverse of Step 1: `plink_to_vcf` writes one bgzipped VCF per input fileset." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } }, "outputs": [], "source": [ - "sos run genotype_formatting.ipynb -h" + "sos run pipeline/genotype_formatting.ipynb plink_to_vcf \\\n", + " --genoFile `ls output/genotype_formatting/plink/protocol_example.genotype.chr*.bed | sed \"s/.bed//g\"` \\\n", + " --cwd output/genotype_formatting/vcf \\\n", + " --name protocol_example.genotype" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], "source": [ - "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# Work directory & output directory\nparameter: cwd = path(\"output\")\nimport re\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n# Number of threads\nparameter: numThreads = 20\n# the path to a bed file or VCF file, a vector of bed files or VCF files, or a text file listing the bed files or VCF files to process\nparameter: genoFile = paths\nparameter: name = str\n# use this function to edit memory string for PLINK input\nfrom sos.utils import expand_size\ncwd = f\"{cwd:a}\"\n\nimport os\ndef get_genotype_file(geno_file_paths):\n def valid_geno_file(x):\n suffixes = path(x).suffixes\n if suffixes[-1] in ['.bed', '.pgen']:\n return True\n if len(suffixes) > 1 and ''.join(suffixes[-2:]) == \".vcf.gz\":\n return True\n return False\n #\n def complete_geno_path(x, geno_file):\n if not valid_geno_file(x):\n raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n if not os.path.isfile(x):\n # relative path\n if not os.path.isfile(f'{geno_file:ad}/' + x):\n raise ValueError(f\"Cannot find genotype file {x}\")\n else:\n x = f'{geno_file:ad}/' + x\n return x\n # \n def format_chrom(chrom):\n if chrom.startswith('chr'):\n chrom = chrom[3:]\n return chrom\n # Inputs are either VCF or bed, or a vector of them \n if len(geno_file_paths) > 1:\n if all([valid_geno_file(x) for x in geno_file_paths]):\n return paths(geno_file_paths)\n else: \n raise ValueError(f\"Invalid input {geno_file_paths}\")\n # Input is one genotype file or text list of genotype files\n geno_file = geno_file_paths[0]\n if valid_geno_file(geno_file):\n return paths(geno_file)\n else: \n units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n if all([len(x) == 1 for x in units]):\n return paths([complete_geno_path(x[0], geno_file) for x in units])\n elif all([len(x) == 2 for x in units]):\n genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n else:\n raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n return genos\n\n# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\ndef determine_plink_format(file_path):\n \"\"\"\n Determine the PLINK file format based on file extensions and companion files.\n \n Args:\n file_path (str or Path): Path to the input file\n \n Returns:\n str: 'plink1' or 'plink2'\n \"\"\"\n # Convert to string if it's a Path object\n file_path = str(file_path)\n \n # Check direct file extensions\n if file_path.endswith('.bed'):\n return 'plink1'\n elif file_path.endswith('.pgen'):\n return 'plink2'\n \n # If the file doesn't have a standard extension, try to infer format\n try:\n # Remove the file extension if present\n base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n \n # Check for PLINK1 companion files\n plink1_companion_files = [\n f\"{base_path}.bim\",\n f\"{base_path}.fam\"\n ]\n \n # Check for PLINK2 companion files\n plink2_companion_files = [\n f\"{base_path}.pvar\",\n f\"{base_path}.psam\"\n ]\n \n # Check PLINK1 format\n if all(os.path.exists(f) for f in plink1_companion_files):\n return 'plink1'\n \n # Check PLINK2 format\n if all(os.path.exists(f) for f in plink2_companion_files):\n return 'plink2'\n \n except Exception as e:\n print(f\"Error determining PLINK format: {e}\")\n \n # Default to PLINK1 if can't determine\n return 'plink1'\n\n# Get the appropriate PLINK command prefix\ndef get_plink_command_prefix(file_path):\n format_type = determine_plink_format(file_path)\n if format_type == 'plink1':\n return \"--bfile\"\n else: # plink2\n return \"--pfile\"\n\n# Get output file extension based on format\ndef get_output_extension(format_type):\n if format_type == 'plink1':\n return \"bed\"\n else: # plink2\n return \"pgen\" \n \n# Choose the make-bed or make-pgen command based on desired output format\ndef get_make_command(output_format):\n if output_format == 'plink1':\n return '--make-bed'\n else: # plink2\n return '--make-pgen'\ngenoFile = get_genotype_file(genoFile)" + "#### Step 2. Merge VCF files\n", + "\n", + "`merge_vcf` concatenates the per-chromosome VCFs into one, the VCF counterpart of Step 2." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ - "## PLINK to VCF" + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } }, "outputs": [], "source": [ - "[plink_to_vcf_1]\nif isinstance(genoFile, dict):\n genoFile = genoFile.values()\n\ninput: genoFile, group_by = 1\noutput: f'{cwd}/{_input:bn}.vcf.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh plink_to_vcf_1 \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\" \\\n --mem \"${mem}\" \\\n --numThreads ${numThreads}\n\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n --step vcf_gz_summary \\\n --data-files \"${_output}\"" + "sos run pipeline/genotype_formatting.ipynb merge_vcf \\\n", + " --genoFile output/genotype_formatting/vcf/protocol_example.genotype.chr*.vcf.gz \\\n", + " --cwd output/genotype_formatting/vcf \\\n", + " --name protocol_example.genotype.merged" ] }, { @@ -247,43 +397,136 @@ "kernel": "SoS" }, "source": [ - "## VCF to PLINK\n", + "### Split by region and compute LD\n", "\n", - "Export VCF files to PLINK 1.0 format, **without keeping allele orders by default**. The resulting PLINK will lose ref/alt allele information but will go by major/minor allele, as conventionally used in standard PLINK format. Notice that PLINK 1.0 format does not allow for dosages. PLINK 2.0 format support it, but it is generally not supported by downstreams data analysis. \n", + "Both steps read the merged fileset from Route A step 2, so run that first." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Step 1. Split PLINK genotypes into regions\n", "\n", - "In the following code block the option `--vcf-half-call m` treat half-call as missing." + "`genotype_by_region` cuts one fileset per region in `--region-list`, widened by `--window`. The protocol does not yet ship an example region list, so this command cannot be run against\n", + "the toy data as it stands; `input/genotype/protocol_example.genotype.region_list.txt` is the path it expects." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } }, "outputs": [], "source": [ - "[vcf_to_plink]\nparameter: remove_duplicates = False\nparameter: add_chr = True\nparameter: keep_dosage = False\n# The path to the file that contains the list of samples to remove (format FID, IID)\nparameter: remove_samples = path('.')\n# The path to the file that contains the list of samples to keep (format FID, IID)\nparameter: keep_samples = path('.')\nfail_if(not (keep_samples.is_file() or keep_samples == path('.')), msg = f'Cannot find ``{keep_samples}``')\nfail_if(not (remove_samples.is_file() or remove_samples == path('.')), msg = f'Cannot find ``{remove_samples}``')\n\nif isinstance(genoFile, dict):\n genoFile = genoFile.values()\n\ninput: genoFile, group_by = 1\noutput: f'{cwd}/{_input:bnn}.{\"pgen\" if keep_dosage else \"bed\"}'\n\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh vcf_to_plink \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --numThreads ${numThreads}" + "sos run pipeline/genotype_formatting.ipynb genotype_by_region \\\n", + " --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged \\\n", + " --region-list input/genotype/protocol_example.genotype.region_list.txt \\\n", + " --window 0 \\\n", + " --cwd output/genotype_formatting/by_region \\\n", + " --name protocol_example.genotype" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ - "## Split PLINK genotypes into specified regions" + "#### Step 2. LD matrices per region\n", + "\n", + "`ld_by_region_plink` computes an LD matrix per region and writes a `.ld.list` index alongside. The protocol does not yet ship an example region list, so this command cannot be run against the toy data as it stands; `input/genotype/protocol_example.genotype.region_list.txt` is the path it expects." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, + "metadata": { + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "sos run pipeline/genotype_formatting.ipynb ld_by_region_plink \\\n", + " --genoFile output/genotype_formatting/plink/protocol_example.genotype.merged \\\n", + " --region-list input/genotype/protocol_example.genotype.region_list.txt \\\n", + " --float-type 16 \\\n", + " --cwd output/genotype_formatting/ld \\\n", + " --name protocol_example.genotype" + ] + }, + { + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, + "source": [ + "### Building a file manifest by hand" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "`write_data_list` collects paths into a manifest that downstream modules read instead of globbing.\n", + "The `_1` conversion steps emit their own `*_files.txt` automatically; this workflow is for building\n", + "one by hand." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } + }, "outputs": [], "source": [ - "[genotype_by_region_1]\n# cis window size\nparameter: window = 0\n# Region definition\nparameter: region_list = path\nregions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\ninput: genoFile, for_each = 'regions'\noutput: f'{cwd}/{region_list:bn}_genotype_by_region/{_input:bn}.{_regions[3]}.bed'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh genotype_by_region_1 \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\" \\\n --region-chrom \"${_regions[0]}\" \\\n --region-start \"${_regions[1]}\" \\\n --region-end \"${_regions[2]}\" \\\n --window ${window} \\\n --numThreads ${numThreads}\n\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n --step file_size_summary \\\n --data-files \"${_output}\"" + "sos run pipeline/genotype_formatting.ipynb write_data_list \\\n", + " --data-files `ls output/genotype_formatting/plink/protocol_example.genotype.chr*.bed` \\\n", + " --out output/genotype_formatting/plink/protocol_example.genotype.plink_files.txt \\\n", + " --ext bed \\\n", + " --cwd output/genotype_formatting/plink \\\n", + " --name protocol_example.genotype" ] }, { @@ -292,11 +535,7 @@ "kernel": "SoS" }, "source": [ - "## Compute LD matrices for given input region\n", - "\n", - "### PLINK based implementation\n", - "\n", - "**FIXME: Hao, I suggest including all contents for LD matrix storage type benchmarking into this repo, so we justify why we would like to save the data as square 0, float 16 and using the RDS format**. Perhaps we should start a folder called \"code/auxillary\" to keep notebooks such as these? You can then remove what you have in the `brain-xqtl-analysis` repository after you migrate all the relevant contents here." + "## Command Interface" ] }, { @@ -306,7 +545,9 @@ "kernel": "SoS" }, "outputs": [], - "source": "[ld_by_region_plink_1]\n# Region definition\nparameter: region_list = path\nparameter: float_type = 16\nregions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\ninput: genoFile, for_each = 'regions'\noutput: f'{cwd}/{region_list:bn}_LD/{_input:bn}.{_regions[0]}_{_regions[1]}_{_regions[2]}.float{float_type}.rds'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n plink --bfile \"${_input:n}\" --out \"${_output:nn}\" \\\n --chr \"${_regions[0]}\" --from-bp \"${_regions[1]}\" --to-bp \"${_regions[2]}\" \\\n --r square0 --make-just-bim --threads ${numThreads}\n Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n --step ld_by_region_plink_1 \\\n --output \"${_output}\"" + "source": [ + "sos run pipeline/genotype_formatting.ipynb -h" + ] }, { "cell_type": "markdown", @@ -314,17 +555,90 @@ "kernel": "SoS" }, "source": [ - "### ldstore2 based implementation\n", + "```\n", + "usage: sos run pipeline/genotype_formatting.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", "\n", - "This is good for larger sample sizes such as data from UK Biobank although we are not facing this challenge in the FunGen-xQTL project.\n", + "Workflows:\n", + " plink_to_vcf\n", + " vcf_to_plink\n", + " genotype_by_region\n", + " ld_by_region_plink\n", + " genotype_by_chrom\n", + " write_data_list\n", + " merge_plink\n", + " merge_vcf\n", "\n", - "**FIXME: we need to build ldstore2 into a container image**. According to Diana it should be \n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " Work directory & output directory\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 20 (as int)\n", + " Number of threads\n", + " --genoFile paths\n", "\n", - "```\n", - "pip3 install https://files.pythonhosted.org/packages/a8/fd/f98ab7dea176f42cb61b80450b795ef19b329e8eb715b87b0d13c2a0854d/ldstore-0.1.9.tar.gz \n", - "```\n", + " the path to a bed file or VCF file, a vector of bed\n", + " files or VCF files, or a text file listing the bed files\n", + " or VCF files to process\n", + " --name VAL (as str, required)\n", "\n", - "**FIXME: Diana, what's the input for this workflow?**" + "Sections\n", + " plink_to_vcf_1:\n", + " vcf_to_plink:\n", + " Workflow Options:\n", + " --[no-]remove-duplicates (default to False)\n", + " --[no-]add-chr (default to True)\n", + " --[no-]keep-dosage (default to False)\n", + " --remove-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to remove (format FID, IID)\n", + " --keep-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to keep (format FID, IID)\n", + " genotype_by_region_1:\n", + " Workflow Options:\n", + " --window 0 (as int)\n", + " cis window size\n", + " --region-list VAL (as path, required)\n", + " Region definition\n", + " ld_by_region_plink_1:\n", + " Workflow Options:\n", + " --region-list VAL (as path, required)\n", + " Region definition\n", + " --float-type 16 (as int)\n", + " genotype_by_chrom_1:\n", + " Workflow Options:\n", + " --chrom VAL VAL ... (as type, required)\n", + " genotype_by_chrom_2:\n", + " plink_to_vcf_2:\n", + " genotype_by_region_2:\n", + " ld_by_region_*_2:\n", + " Workflow Options:\n", + " --region-list VAL (as path, required)\n", + " write_data_list:\n", + " Workflow Options:\n", + " --out VAL (as path, required)\n", + " --ext VAL (as str, required)\n", + " --data-files paths\n", + "\n", + " merge_plink:\n", + " Workflow Options:\n", + " --keep-samples . (as path)\n", + " The path to the file that contains the list of samples\n", + " to keep (format FID, IID)\n", + " --extra-plink-opts (as list)\n", + " merge_vcf:\n", + "```" ] }, { @@ -333,41 +647,206 @@ "kernel": "SoS" }, "source": [ - "#### Create `master` file for `ldstore2`\n", + "## Workflow implementation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# Work directory & output directory\n", + "parameter: cwd = path(\"output\")\n", + "import re\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "# Number of threads\n", + "parameter: numThreads = 20\n", + "# the path to a bed file or VCF file, a vector of bed files or VCF files, or a text file listing the bed files or VCF files to process\n", + "parameter: genoFile = paths\n", + "parameter: name = str\n", + "# use this function to edit memory string for PLINK input\n", + "from sos.utils import expand_size\n", + "cwd = f\"{cwd:a}\"\n", "\n", - "The master file is a semicolon-separated text file and contains no space. It contains the following mandatory column names and one dataset per line:\n", + "import os\n", + "def get_genotype_file(geno_file_paths):\n", + " def valid_geno_file(x):\n", + " suffixes = path(x).suffixes\n", + " if suffixes[-1] in ['.bed', '.pgen']:\n", + " return True\n", + " if len(suffixes) > 1 and ''.join(suffixes[-2:]) == \".vcf.gz\":\n", + " return True\n", + " return False\n", + " #\n", + " def complete_geno_path(x, geno_file):\n", + " if not valid_geno_file(x):\n", + " raise ValueError(f\"Genotype file {x} should be VCF (end with .vcf.gz) or PLINK bed file (end with .bed)\")\n", + " if not os.path.isfile(x):\n", + " # relative path\n", + " if not os.path.isfile(f'{geno_file:ad}/' + x):\n", + " raise ValueError(f\"Cannot find genotype file {x}\")\n", + " else:\n", + " x = f'{geno_file:ad}/' + x\n", + " return x\n", + " # \n", + " def format_chrom(chrom):\n", + " if chrom.startswith('chr'):\n", + " chrom = chrom[3:]\n", + " return chrom\n", + " # Inputs are either VCF or bed, or a vector of them \n", + " if len(geno_file_paths) > 1:\n", + " if all([valid_geno_file(x) for x in geno_file_paths]):\n", + " return paths(geno_file_paths)\n", + " else: \n", + " raise ValueError(f\"Invalid input {geno_file_paths}\")\n", + " # Input is one genotype file or text list of genotype files\n", + " geno_file = geno_file_paths[0]\n", + " if valid_geno_file(geno_file):\n", + " return paths(geno_file)\n", + " else: \n", + " units = [x.strip().split() for x in open(geno_file).readlines() if x.strip() and not x.strip().startswith('#')]\n", + " if all([len(x) == 1 for x in units]):\n", + " return paths([complete_geno_path(x[0], geno_file) for x in units])\n", + " elif all([len(x) == 2 for x in units]):\n", + " genos = dict([(format_chrom(x[0]), path(complete_geno_path(x[1], geno_file))) for x in units])\n", + " else:\n", + " raise ValueError(f\"{geno_file} should contain one column of file names, or two columns of chrom number and corresponding file name\")\n", + " return genos\n", "\n", - "**FIXME: Diana, this documentation is not clearly written. I cannot understand it. What are the mandatory column names? What does it mean by one data-set per line?**\n", + "# Determine if the file is in PLINK1 (BED/BIM/FAM) or PLINK2 (PGEN/PVAR/PSAM) format\n", + "def determine_plink_format(file_path):\n", + " \"\"\"\n", + " Determine the PLINK file format based on file extensions and companion files.\n", + " \n", + " Args:\n", + " file_path (str or Path): Path to the input file\n", + " \n", + " Returns:\n", + " str: 'plink1' or 'plink2'\n", + " \"\"\"\n", + " # Convert to string if it's a Path object\n", + " file_path = str(file_path)\n", + " \n", + " # Check direct file extensions\n", + " if file_path.endswith('.bed'):\n", + " return 'plink1'\n", + " elif file_path.endswith('.pgen'):\n", + " return 'plink2'\n", + " \n", + " # If the file doesn't have a standard extension, try to infer format\n", + " try:\n", + " # Remove the file extension if present\n", + " base_path = file_path.rsplit('.', 1)[0] if '.' in file_path else file_path\n", + " \n", + " # Check for PLINK1 companion files\n", + " plink1_companion_files = [\n", + " f\"{base_path}.bim\",\n", + " f\"{base_path}.fam\"\n", + " ]\n", + " \n", + " # Check for PLINK2 companion files\n", + " plink2_companion_files = [\n", + " f\"{base_path}.pvar\",\n", + " f\"{base_path}.psam\"\n", + " ]\n", + " \n", + " # Check PLINK1 format\n", + " if all(os.path.exists(f) for f in plink1_companion_files):\n", + " return 'plink1'\n", + " \n", + " # Check PLINK2 format\n", + " if all(os.path.exists(f) for f in plink2_companion_files):\n", + " return 'plink2'\n", + " \n", + " except Exception as e:\n", + " print(f\"Error determining PLINK format: {e}\")\n", + " \n", + " # Default to PLINK1 if can't determine\n", + " return 'plink1'\n", "\n", - "- For the Z file, the format should be `rsid:chrom:pos:a1:a2`. Formatting for chromosome should be `01,02,03` etc\n", - "- List of samples\n", + "# Get the appropriate PLINK command prefix\n", + "def get_plink_command_prefix(file_path):\n", + " format_type = determine_plink_format(file_path)\n", + " if format_type == 'plink1':\n", + " return \"--bfile\"\n", + " else: # plink2\n", + " return \"--pfile\"\n", "\n", - "**The LDstore draft is currently availale [here](https://github.com/statgenetics/UKBB_GWAS_dev/blob/master/workflow/111722_LDstore.ipynb) with the code to prepare for the genotypic input [here](https://github.com/statgenetics/UKBB_GWAS_dev/blob/master/workflow/113022_bgenix_ldblocks.ipynb). A minimal working example can be found [here]**" + "# Get output file extension based on format\n", + "def get_output_extension(format_type):\n", + " if format_type == 'plink1':\n", + " return \"bed\"\n", + " else: # plink2\n", + " return \"pgen\" \n", + " \n", + "# Choose the make-bed or make-pgen command based on desired output format\n", + "def get_make_command(output_format):\n", + " if output_format == 'plink1':\n", + " return '--make-bed'\n", + " else: # plink2\n", + " return '--make-pgen'\n", + "genoFile = get_genotype_file(genoFile)" ] }, { "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "### PLINK to VCF" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Split PLINK by Chromosome" + "[plink_to_vcf_1]\n", + "if isinstance(genoFile, dict):\n", + " genoFile = genoFile.values()\n", + "\n", + "input: genoFile, group_by = 1\n", + "output: f'{cwd}/{_input:bn}.vcf.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh plink_to_vcf_1 \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\" \\\n", + " --mem \"${mem}\" \\\n", + " --numThreads ${numThreads}\n", + "\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n", + " --step vcf_gz_summary \\\n", + " --data-files \"${_output}\"" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "vscode": { - "languageId": "plaintext" - } + "kernel": "SoS" }, "source": [ - "## Pls note that .pvar file have meta_file headers before the variant info dataframe\n", - "sos run /home/rl3328/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.ipynb genotype_by_chrom \\\n", - " --genoFile /home/rl3328/motor_data/geno_data/final/LD_pruning/chrAll_GRCh38_biallelic.motor_eQTL.plink_qc.pgen \\\n", - " --cwd /home/rl3328/motor_data/geno_data/final/genotype_by_chrom \\\n", - " --chrom `grep -v '^#' /home/rl3328/motor_data/geno_data/final/LD_pruning/chrAll_GRCh38_biallelic.motor_eQTL.plink_qc.pvar | cut -f 1 | uniq | sed \"s/chr//g\"`" + "### VCF to PLINK\n", + "\n", + "Export VCF files to PLINK 1.0 format, **without keeping allele orders by default**. The resulting PLINK will lose ref/alt allele information but will go by major/minor allele, as conventionally used in standard PLINK format. Notice that PLINK 1.0 format does not allow for dosages. PLINK 2.0 format support it, but it is generally not supported by downstreams data analysis. \n", + "\n", + "In the following code block the option `--vcf-half-call m` treat half-call as missing." ] }, { @@ -378,7 +857,39 @@ }, "outputs": [], "source": [ - "[genotype_by_chrom_1]\nstop_if(len(paths(genoFile))>1, msg = \"This workflow expects one input genotype file.\")\nparameter: chrom = list\nchrom = list(set(chrom))\ninput: genoFile, for_each = \"chrom\"\nplink_command = get_plink_command_prefix(_input)\noutput_format = determine_plink_format(_input)\noutput_ext = get_output_extension(output_format)\nmake_command = get_make_command(output_format)\noutput: f'{cwd}/{_input:bn}.{_chrom}.{output_ext}'\n# look up for genotype file\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh genotype_by_chrom \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --name \"${name}\" \\\n --output \"${_output}\" \\\n --plink-command \"${plink_command}\" \\\n --make-command \"${make_command}\" \\\n --output-format \"${output_format}\" \\\n --chrom ${_chrom} \\\n --mem \"${mem}\" \\\n --numThreads ${numThreads}" + "[vcf_to_plink]\n", + "parameter: remove_duplicates = False\n", + "parameter: add_chr = True\n", + "parameter: keep_dosage = False\n", + "# The path to the file that contains the list of samples to remove (format FID, IID)\n", + "parameter: remove_samples = path('.')\n", + "# The path to the file that contains the list of samples to keep (format FID, IID)\n", + "parameter: keep_samples = path('.')\n", + "fail_if(not (keep_samples.is_file() or keep_samples == path('.')), msg = f'Cannot find ``{keep_samples}``')\n", + "fail_if(not (remove_samples.is_file() or remove_samples == path('.')), msg = f'Cannot find ``{remove_samples}``')\n", + "\n", + "if isinstance(genoFile, dict):\n", + " genoFile = genoFile.values()\n", + "\n", + "input: genoFile, group_by = 1\n", + "output: f'{cwd}/{_input:bnn}.{\"pgen\" if keep_dosage else \"bed\"}'\n", + "\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh vcf_to_plink \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --numThreads ${numThreads}" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "### Split PLINK genotypes into specified regions" ] }, { @@ -389,7 +900,40 @@ }, "outputs": [], "source": [ - "[genotype_by_chrom_2]\ninput: group_by = \"all\"\noutput_format = determine_plink_format(_input)\noutput_ext = get_output_extension(output_format)\noutput: f'{_input[0]:nn}.{step_name[:-2]}_files.txt'\nsos_run(\"write_data_list\", data_files = _input, out = _output, ext = f\"{output_ext}\")" + "[genotype_by_region_1]\n", + "# cis window size\n", + "parameter: window = 0\n", + "# Region definition\n", + "parameter: region_list = path\n", + "regions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\n", + "input: genoFile, for_each = 'regions'\n", + "output: f'{cwd}/{region_list:bn}_genotype_by_region/{_input:bn}.{_regions[3]}.bed'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh genotype_by_region_1 \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\" \\\n", + " --region-chrom \"${_regions[0]}\" \\\n", + " --region-start \"${_regions[1]}\" \\\n", + " --region-end \"${_regions[2]}\" \\\n", + " --window ${window} \\\n", + " --numThreads ${numThreads}\n", + "\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n", + " --step file_size_summary \\\n", + " --data-files \"${_output}\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Compute LD matrices for given input region\n", + "\n", + "#### PLINK based implementation" ] }, { @@ -400,7 +944,64 @@ }, "outputs": [], "source": [ - "[plink_to_vcf_2]\ninput: group_by = \"all\"\noutput: f'{_input[0]:nnn}.{step_name[:-2]}_files.txt'\nsos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"vcf.gz\")" + "[ld_by_region_plink_1]\n", + "# Region definition\n", + "parameter: region_list = path\n", + "parameter: float_type = 16\n", + "regions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\n", + "input: genoFile, for_each = 'regions'\n", + "output: f'{cwd}/{region_list:bn}_LD/{_input:bn}.{_regions[0]}_{_regions[1]}_{_regions[2]}.float{float_type}.rds'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " plink --bfile \"${_input:n}\" --out \"${_output:nn}\" \\\n", + " --chr \"${_regions[0]}\" --from-bp \"${_regions[1]}\" --to-bp \"${_regions[2]}\" \\\n", + " --r square0 --make-just-bim --threads ${numThreads}\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n", + " --step ld_by_region_plink_1 \\\n", + " --output \"${_output}\"" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### ldstore2 based implementation\n", + "\n", + "**Not implemented.** No `ldstore2` section exists in this notebook and the tool is not in the\n", + "container, so nothing here is runnable; `ld_by_region_plink` above is the only LD workflow. ldstore2\n", + "would suit larger cohorts such as UK Biobank, which is not a constraint in the FunGen-xQTL project.\n", + "\n", + "For whoever picks this up, the draft lives outside this repository:\n", + "[LDstore workflow](https://github.com/statgenetics/UKBB_GWAS_dev/blob/master/workflow/111722_LDstore.ipynb)\n", + "and [genotype preparation](https://github.com/statgenetics/UKBB_GWAS_dev/blob/master/workflow/113022_bgenix_ldblocks.ipynb).\n", + "It needs a semicolon-separated master file with one dataset per line, Z-file IDs formatted as\n", + "`rsid:chrom:pos:a1:a2` with zero-padded chromosomes, plus a sample list." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Split PLINK by Chromosome\n", + "\n", + "One workflow covers both formats: `genotype_by_chrom` writes `{_chrom}.{output_ext}`, so\n", + "`--output-ext` chooses a PLINK fileset or a VCF per chromosome." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "vscode": { + "languageId": "plaintext" + } + }, + "source": [ + "Note that .pvar file have meta_file headers before the variant info dataframe" ] }, { @@ -411,7 +1012,30 @@ }, "outputs": [], "source": [ - "[genotype_by_region_2]\ninput: group_by = \"all\"\noutput: f'{_input[0]:nn}.{step_name[:-2]}_files.txt'\nsos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"bed\")" + "[genotype_by_chrom_1]\n", + "stop_if(len(paths(genoFile))>1, msg = \"This workflow expects one input genotype file.\")\n", + "parameter: chrom = list\n", + "chrom = list(set(chrom))\n", + "input: genoFile, for_each = \"chrom\"\n", + "plink_command = get_plink_command_prefix(_input)\n", + "output_format = determine_plink_format(_input)\n", + "output_ext = get_output_extension(output_format)\n", + "make_command = get_make_command(output_format)\n", + "output: f'{cwd}/{_input:bn}.{_chrom}.{output_ext}'\n", + "# look up for genotype file\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh genotype_by_chrom \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --name \"${name}\" \\\n", + " --output \"${_output}\" \\\n", + " --plink-command \"${plink_command}\" \\\n", + " --make-command \"${make_command}\" \\\n", + " --output-format \"${output_format}\" \\\n", + " --chrom ${_chrom} \\\n", + " --mem \"${mem}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -422,7 +1046,12 @@ }, "outputs": [], "source": [ - "[ld_by_region_*_2]\nparameter: region_list = path\ninput: group_by = \"all\"\noutput: f'{cwd}/{region_list:bn}_LD/{genoFile:bn}.ld.list'\nsos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"npy.gz\")" + "[genotype_by_chrom_2]\n", + "input: group_by = \"all\"\n", + "output_format = determine_plink_format(_input)\n", + "output_ext = get_output_extension(output_format)\n", + "output: f'{_input[0]:nn}.{step_name[:-2]}_files.txt'\n", + "sos_run(\"write_data_list\", data_files = _input, out = _output, ext = f\"{output_ext}\")" ] }, { @@ -433,27 +1062,39 @@ }, "outputs": [], "source": [ - "[write_data_list]\nparameter: out = path\nparameter: ext = str\nparameter: data_files = paths\ninput: data_files\noutput: out\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n --step write_data_list \\\n --data-files \"${\"::\".join([str(x) for x in _input])}\" \\\n --ext \"${ext}\" \\\n --output \"${_output}\" \\\n --numThreads ${numThreads}" + "[plink_to_vcf_2]\n", + "input: group_by = \"all\"\n", + "output: f'{_input[0]:nnn}.{step_name[:-2]}_files.txt'\n", + "sos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"vcf.gz\")" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Split VCF by Chromosome\n", - "\n", - "**FIXME: add this as needed**" + "[genotype_by_region_2]\n", + "input: group_by = \"all\"\n", + "output: f'{_input[0]:nn}.{step_name[:-2]}_files.txt'\n", + "sos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"bed\")" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Merge PLINK files" + "[ld_by_region_*_2]\n", + "parameter: region_list = path\n", + "input: group_by = \"all\"\n", + "output: f'{cwd}/{region_list:bn}_LD/{genoFile:bn}.ld.list'\n", + "sos_run(\"write_data_list\", data_files = _input, out = _output, ext = \"npy.gz\")" ] }, { @@ -464,7 +1105,20 @@ }, "outputs": [], "source": [ - "[merge_plink]\nskip_if(len(genoFile) == 1)\n# File prefix for the analysis output\nparameter: name = str\n# The path to the file that contains the list of samples to keep (format FID, IID)\nparameter: keep_samples = path('.')\nparameter: extra_plink_opts = []\nparameter: mem = '300G'\ninput: genoFile, group_by = 'all'\noutput: f\"{cwd}/{name}{_input[0]:x}\"\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh merge_plink \\\n --cwd \"${cwd}\" \\\n --genoFile \"${_input}\" \\\n --name \"${name}\" \\\n --mem \"${mem}\" \\\n --numThreads ${numThreads}" + "[write_data_list]\n", + "parameter: out = path\n", + "parameter: ext = str\n", + "parameter: data_files = paths\n", + "input: data_files\n", + "output: out\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n", + " --step write_data_list \\\n", + " --data-files \"${\"::\".join([str(x) for x in _input])}\" \\\n", + " --ext \"${ext}\" \\\n", + " --output \"${_output}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -473,7 +1127,35 @@ "kernel": "SoS" }, "source": [ - "## Merge VCF files" + "### Merge PLINK files" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "[merge_plink]\n", + "skip_if(len(genoFile) == 1)\n", + "# File prefix for the analysis output\n", + "parameter: name = str\n", + "# The path to the file that contains the list of samples to keep (format FID, IID)\n", + "parameter: keep_samples = path('.')\n", + "parameter: extra_plink_opts = []\n", + "parameter: mem = '300G'\n", + "input: genoFile, group_by = 'all'\n", + "output: f\"{cwd}/{name}{_input[0]:x}\"\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh merge_plink \\\n", + " --cwd \"${cwd}\" \\\n", + " --genoFile \"${_input}\" \\\n", + " --name \"${name}\" \\\n", + " --mem \"${mem}\" \\\n", + " --numThreads ${numThreads}" ] }, { @@ -482,9 +1164,7 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### Merge VCF files" ] }, { @@ -495,7 +1175,22 @@ }, "outputs": [], "source": [ - "[merge_vcf]\nskip_if(len(genoFile) == 1)\n# File prefix for the analysis output\nparameter: name = str\ninput: genoFile, group_by = 'all'\noutput: f\"{cwd}/{name}.vcf.gz\"\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh merge_vcf \\\n --genoFile \"${_input}\" \\\n --output \"${_output}\"\n\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n --step vcf_gz_summary \\\n --data-files \"${_output}\"" + "[merge_vcf]\n", + "skip_if(len(genoFile) == 1)\n", + "# File prefix for the analysis output\n", + "parameter: name = str\n", + "input: genoFile, group_by = 'all'\n", + "output: f\"{cwd}/{name}.vcf.gz\"\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " bash ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.sh merge_vcf \\\n", + " --genoFile \"${_input}\" \\\n", + " --output \"${_output}\"\n", + "\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", + " Rscript ${modular_script_dir}/data_preprocessing/genotype/genotype_formatting.R \\\n", + " --step vcf_gz_summary \\\n", + " --data-files \"${_output}\"" ] } ], diff --git a/code/SoS/data_preprocessing/genotype_preprocessing.ipynb b/code/SoS/data_preprocessing/genotype_preprocessing.ipynb index 741c519da..b7172a5cd 100644 --- a/code/SoS/data_preprocessing/genotype_preprocessing.ipynb +++ b/code/SoS/data_preprocessing/genotype_preprocessing.ipynb @@ -6,9 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Genotype Preprocessing\n", + "# Genotype preprocessing\n", "\n", - "This notebook is a minimal working example (MWE) of the genotype preprocessing section of the xQTL protocol. It chains the genotype worker pipelines on the bundled toy dataset (60 samples, `protocol_example.*`) so the whole section runs end-to-end without editing." + "Convert raw genotype VCFs into quality-controlled, sample-matched PLINK datasets and genetic principal components for downstream xQTL analysis." ] }, { @@ -17,16 +17,11 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "#### Miniprotocol Timing\n", "\n", - "The genotype preprocessing section takes raw genotype data (VCF) through quality control, format conversion, and produces clean PLINK files plus genetic principal components for use as covariates downstream. It chains four worker pipelines:\n", + "This is the total duration for all phases; module-specific timings appear on their respective pages.\n", "\n", - "- `VCF_QC.ipynb` — quality control on VCF files\n", - "- `genotype_formatting.ipynb` — VCF→PLINK conversion, merging, and partition by chromosome\n", - "- `GWAS_QC.ipynb` — QC on PLINK files, sample matching, kinship, and preparing unrelated individuals\n", - "- `PCA.ipynb` — principal component analysis on the unrelated samples\n", - "\n", - "**Timing:** ~3–5 min for the toy dataset on a single node." + "Timing: ~3-5 min (on the toy dataset)" ] }, { @@ -35,32 +30,11 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Overview\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `input/genotype/protocol_example.genotype.chr*.vcf.gz` | Per-chromosome toy genotype VCFs (60 samples) |\n", - "| `input/reference_data/00-All.add_chr.variants.gz` | dbSNP variant reference (for annotation) |\n", - "| `input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta` | GRCh38 reference genome |\n", - "| `input/rnaseq/protocol_example.rnaseq.bed.gz` | Molecular phenotype, used for sample matching |" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Output Files\n", + "This mini-protocol walks through how raw genotype VCFs are normalized, converted to PLINK, quality-controlled, matched to molecular-phenotype samples, and prepared for population-structure adjustment. Each step calls a workflow from [`VCF_QC.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/VCF_QC.html), [`genotype_formatting.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html), [`GWAS_QC.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html), or [`PCA.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/PCA.html).\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/vcf_qc/*.leftnorm.*.vcf.gz` | QC-passed, left-normalized VCF |\n", - "| `output/genotype_formatting/plink/protocol_example.genotype.merged.bed` | Merged genome-wide PLINK dataset |\n", - "| `output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed` | QC-passed PLINK dataset |\n", - "| `output/genotype_formatting/genotype_by_chrom/*.bed` | Per-chromosome PLINK files |\n", - "| `output/gwas_qc/kinship/*.unrelated.bed` | Unrelated-individuals subset |\n", - "| `output/pca_uf/*.pca.rds` / `*.pca.scree.png` | Genetic principal components and scree plot |" + "The commands are organized as selectable routes rather than one mandatory 12-step chain. The standard route estimates principal components in unrelated individuals. Use the conditional extension only when related individuals will remain in the analysis and must be projected into the same PCA space before the datasets are recombined.\n" ] }, { @@ -71,7 +45,15 @@ "source": [ "## Steps\n", "\n", - "Run the commands below in order from the toy example root. Each one invokes the corresponding worker pipeline through the `pipeline/` symlinks. Outputs from earlier commands feed the later ones." + "Choose a route before running commands; the 12 commands are not one mandatory chain.\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Produce a QC-passed, chromosome-partitioned PLINK dataset | 1 \u2192 2 \u2192 3 \u2192 4 | `input/genotype/protocol_example.genotype.chr22.vcf.gz`
`input/reference_data/00-All.add_chr.variants.gz`
`input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta` |\n", + "| Match samples and estimate PCA in unrelated individuals | 1 \u2192 2 \u2192 3 \u2192 4 \u2192 5 \u2192 6 \u2192 7 \u2192 8 | Basic-route inputs plus `input/rnaseq/protocol_example.rnaseq.bed.gz` |\n", + "| Retain related individuals by PCA projection | 1 \u2192 2 \u2192 3 \u2192 4 \u2192 5 \u2192 6 \u2192 7 \u2192 8 \u2192 9 \u2192 10 \u2192 11 \u2192 12 | Standard-PCA inputs plus `input/covariate/protocol_example.pca_pheno.txt` |\n", + "\n", + "Run only the row matching the intended analysis goal, following its commands in numerical order.\n" ] }, { @@ -80,9 +62,9 @@ "kernel": "SoS" }, "source": [ - "### Quality control on VCF files\n", + "### 1. [Quality-control the input VCF](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/VCF_QC.html)\n", "\n", - "Apply variant-level QC to a genotype VCF (here chromosome 22), annotating against dbSNP and the GRCh38 reference. `--skip_vcf_header_filtering True` is used for the toy VCFs." + "**What it does:** Normalize and filter the toy VCF against dbSNP and GRCh38.\n" ] }, { @@ -98,7 +80,7 @@ " --dbsnp-variants input/reference_data/00-All.add_chr.variants.gz \\\n", " --reference-genome input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", " --cwd output/vcf_qc \\\n", - " --skip_vcf_header_filtering True" + " --skip-vcf-header-filtering True" ] }, { @@ -107,9 +89,9 @@ "kernel": "SoS" }, "source": [ - "### Convert VCF to PLINK and merge\n", + "### 2. [Convert the QC-passed VCF to PLINK and merge chromosomes](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html)\n", "\n", - "Convert each per-chromosome VCF to PLINK format, then merge the per-chromosome PLINK files into a single genome-wide dataset." + "**What it does:** Convert the output of step 1 to PLINK. The merge command generalizes to multiple chromosome-level files.\n" ] }, { @@ -121,8 +103,9 @@ "outputs": [], "source": [ "sos run pipeline/genotype_formatting.ipynb vcf_to_plink \\\n", - " --genoFile `ls input/genotype/protocol_example.genotype.chr*.vcf.gz | grep -vE \"rawchr|withfmt|add_chr\"` \\\n", + " --genoFile output/vcf_qc/protocol_example.genotype.chr22.leftnorm.vcf.gz \\\n", " --cwd output/genotype_formatting/plink \\\n", + " --name protocol_example \\\n", " -j 4\n", "\n", "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n", @@ -138,9 +121,9 @@ "kernel": "SoS" }, "source": [ - "### Quality control on PLINK files\n", + "### 3. [Apply PLINK-level quality control](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", "\n", - "Apply genotype-, sample-, and HWE-level filters to the merged PLINK dataset." + "**What it does:** Apply genotype-, sample- and Hardy-Weinberg-equilibrium filters to the merged PLINK dataset.\n" ] }, { @@ -166,9 +149,9 @@ "kernel": "SoS" }, "source": [ - "### Partition genotype data by chromosome\n", + "### 4. [Partition the QC-passed genotype data by chromosome](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html)\n", "\n", - "Split the QC-passed PLINK dataset back into per-chromosome files, which several downstream xQTL steps expect." + "**What it does:** Create chromosome-specific PLINK files required by chromosome-oriented downstream workflows.\n" ] }, { @@ -192,9 +175,9 @@ "kernel": "SoS" }, "source": [ - "### Match samples with the molecular phenotype\n", + "### 5. [Match genotype and molecular-phenotype samples](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", "\n", - "Identify the samples that have both genotype and molecular phenotype data, producing the overlap sample list." + "**What it does:** Retain the sample intersection between the QC-passed genotype data and molecular phenotype.\n" ] }, { @@ -217,9 +200,9 @@ "kernel": "SoS" }, "source": [ - "### Estimate kinship\n", + "### 6. [Estimate kinship and separate related individuals](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", "\n", - "Run KING to estimate relatedness among the matched samples and flag related pairs." + "**What it does:** Use KING to identify related pairs and produce related and unrelated subsets.\n" ] }, { @@ -243,9 +226,9 @@ "kernel": "SoS" }, "source": [ - "### Prepare unrelated individuals for PCA\n", + "### 7. [Prepare the unrelated, LD-pruned PCA subset](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", "\n", - "Apply a minor-allele-count filter to the unrelated subset produced by the kinship step, yielding the pruned dataset used for PCA." + "**What it does:** Apply the minor-allele-count filter and LD pruning used to estimate ancestry axes.\n" ] }, { @@ -268,9 +251,23 @@ "kernel": "SoS" }, "source": [ - "### Principal component analysis on genotype\n", + "### 8. [Estimate principal components in unrelated individuals](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/PCA.html)\n", "\n", - "Run flashPCA on the unrelated, pruned dataset to compute genetic principal components for use as covariates." + "**What it does:** Estimate the PCA model and scores in unrelated individuals.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/PCA.ipynb flashpca \\\n", + " --cwd output/pca_uf \\\n", + " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n", + " --name protocol_example" ] }, { @@ -279,65 +276,172 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", + "### 9. [Extract the related samples at the PCA variants](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "**What it does:** Restrict the related subset to the variants used by the unrelated-sample PCA model.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "Bash", + "tags": [] }, "outputs": [], "source": [ - "sos run pipeline/PCA.ipynb flashpca \\\n", + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/pca_related \\\n", + " --genoFile output/gwas_qc/kinship/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.bed \\\n", + " --geno-filter 0 --mind-filter 0.1 --maf-filter 0 \\\n", + " --keep-variants output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.in \\\n", + " --name for_pca" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 10. [Project related samples and detect PCA outliers](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/PCA.html)\n", + "\n", + "**What it does:** Project related individuals into the PCA space and identify ancestry-space outliers.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash", + "tags": [] + }, + "outputs": [], + "source": [ + "sos run pipeline/PCA.ipynb project_samples \\\n", " --cwd output/pca_uf \\\n", - " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n", - " --name protocol_example" + " --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n", + " --phenoFile input/covariate/protocol_example.pca_pheno.txt \\\n", + " --pca-model output/pca_uf/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.protocol_example.pca.rds \\\n", + " --label-col race --pop-col race --name protocol_example --maha-k 2" ] }, { "cell_type": "markdown", - "id": "genotype-pca-for-covariates", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "Compute a genotype PCA directly on the basic QC-passed merged dataset ", - "(MAC-filtered and LD-pruned) and write results to `output/genotype/genotype_pca/`. ", - "This `.rds` model is used by the covariate formatting step." + "### 11. [Remove projected PCA outliers](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/GWAS_QC.html)\n", + "\n", + "**What it does:** Remove projected outliers before recombining samples.\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "genotype-pca-qc", "metadata": { "kernel": "Bash", "tags": [] }, "outputs": [], "source": [ - "sos run pipeline/GWAS_QC.ipynb qc \\\n", - " --cwd output/genotype/genotype_pca \\\n", - " --genoFile output/gwas_qc/plink/protocol_example.genotype.merged.plink_qc.bed \\\n", - " --mac-filter 5" + "sos run pipeline/GWAS_QC.ipynb qc_no_prune \\\n", + " --cwd output/pca_related \\\n", + " --genoFile output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.bed \\\n", + " --remove-samples output/pca_uf/protocol_example.pca_pheno.pca.projected.outliers \\\n", + " --name no_outlier" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 12. [Recombine unrelated and projected related samples](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/genotype_formatting.html)\n", + "\n", + "**What it does:** Merge the unrelated PCA subset with the retained projected related samples for downstream analysis.\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "genotype-pca-flashpca", "metadata": { "kernel": "Bash", "tags": [] }, "outputs": [], "source": [ - "sos run pipeline/PCA.ipynb flashpca \\\n", - " --cwd output/genotype/genotype_pca \\\n", - " --genoFile output/genotype/genotype_pca/protocol_example.genotype.merged.plink_qc.plink_qc.prune.bed" + "sos run pipeline/genotype_formatting.ipynb merge_plink \\\n", + " --genoFile output/gwas_qc/genotype/protocol_example.genotype.merged.plink_qc.protocol_example.king.unrelated.plink_qc.prune.bed \\\n", + " output/pca_related/protocol_example.genotype.merged.plink_qc.protocol_example.king.related.for_pca.plink_qc.extracted.no_outlier.plink_qc.bed \\\n", + " --cwd output/genotype_final \\\n", + " --name protocol_example.qced" ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Route or step | Products |\n", + "| --- | --- |\n", + "| Step 1: VCF quality control | `output/vcf_qc/*.leftnorm.vcf.gz` and its index |\n", + "| Step 2: PLINK conversion and merge | `output/genotype_formatting/plink/protocol_example.genotype.merged.{bed,bim,fam}` |\n", + "| Step 3: PLINK quality control | `output/gwas_qc/plink/*.plink_qc.{bed,bim,fam}` |\n", + "| Step 4: Chromosome partitioning | `output/genotype_by_chrom/*.{bed,bim,fam}` |\n", + "| Step 5: Sample matching | `output/gwas_qc/genotype/*.sample_genotypes.txt` |\n", + "| Step 6: Kinship | KING results and related/unrelated PLINK subsets under `output/gwas_qc/kinship/` |\n", + "| Steps 7\u20138: Unrelated-sample PCA | LD-pruned PLINK data under `output/gwas_qc/genotype/`, plus the PCA model, scores and plots under `output/pca_uf/` |\n", + "| Steps 9\u201311: Related-sample projection | Variant-matched related PLINK data under `output/pca_related/`, projected PCA scores and the outlier list under `output/pca_uf/`, and an outlier-filtered related subset |\n", + "| Step 12: Recombined analysis dataset | `output/genotype_final/protocol_example.qced.{bed,bim,fam}` |\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", + "\n", + "The QC route produces normalized genotype data in PLINK format, including chromosome-partitioned files for downstream xQTL workflows. The standard PCA route additionally produces sample-matched related and unrelated subsets, an LD-pruned unrelated dataset, and principal-component scores estimated without close relatives.\n", + "\n", + "When related individuals are retained, steps 9\u201312 project them using the unrelated-sample PCA loadings, remove designated projection outliers, and recombine the retained samples into the final analysis dataset.\n", + "\n", + "Proceed to phenotype and covariate preprocessing before association testing.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface\n", + "\n", + "List the workflows and parameters available in each module used by this mini-protocol.\n" + ], + "id": "d48efec1" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/VCF_QC.ipynb -h\n", + "sos run pipeline/genotype_formatting.ipynb -h\n", + "sos run pipeline/GWAS_QC.ipynb -h\n", + "sos run pipeline/PCA.ipynb -h\n" + ], + "id": "56a944bc" } ], "metadata": { @@ -375,5 +479,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/data_preprocessing/phenotype/gene_annotation.ipynb b/code/SoS/data_preprocessing/phenotype/gene_annotation.ipynb index e6f1c375f..9631ed322 100644 --- a/code/SoS/data_preprocessing/phenotype/gene_annotation.ipynb +++ b/code/SoS/data_preprocessing/phenotype/gene_annotation.ipynb @@ -7,25 +7,9 @@ "tags": [] }, "source": [ - "# Gene Coordinate Annotation\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "We use a gene coordinate annotation pipeline based on [`pyqtl`, as demonstrated here](https://github.com/broadinstitute/gtex-pipeline/blob/master/qtl/src/eqtl_prepare_expression.py). This adds genomic coordinate annotations to gene-level molecular phenotype files generated in `gct` format and converts them to `bed` format for downstreams analysis.\n" + "# Gene Coordinate Annotation\n", + "\n", + "Attaches genomic coordinates to a molecular phenotype matrix, and emits the region and gene lists that downstream steps split work by." ] }, { @@ -34,16 +18,17 @@ "kernel": "SoS" }, "source": [ - "### Alternative implementation\n", + "## Overview\n", "\n", - "Previously we use `biomaRt` package in R instead of code from `pyqtl`. The core function calls are:\n", + "Molecular phenotype matrices arrive keyed by feature ID alone -- an ENSEMBL gene ID, a UniProt accession, a leafcutter intron-cluster label -- but every downstream QTL step needs a genomic position to define a cis window. This module attaches those coordinates, turning a plain matrix into a coordinate-sorted, bgzipped and tabix-indexed `bed.gz` file.\n", "\n", - "```r\n", - " ensembl = useEnsembl(biomart = \"ensembl\", dataset = \"hsapiens_gene_ensembl\", version = \"$[ensembl_version]\")\n", - " ensembl_df <- getBM(attributes=c(\"ensembl_gene_id\",\"chromosome_name\", \"start_position\", \"end_position\"),mart=ensembl)\n", - "```\n", + "Coordinates come from a collapsed gene-model GTF, following the [GTEx pipeline](https://github.com/broadinstitute/gtex-pipeline/blob/master/qtl/src/eqtl_prepare_expression.py) convention, so the annotation used here matches the one used to build the GTF in the first place. Feature IDs that the GTF does not contain are dropped rather than guessed at, which is why the row count of the output can be lower than that of the input.\n", + "\n", + "Which route applies depends on how the features are named. Gene-level expression matrices match the GTF directly. Protein matrices carry `gene_id|UniProt` composite IDs and need an auxiliary mapping to reach a gene. Leafcutter intron clusters are not genes at all: they are genomic intervals that must first be mapped onto the genes they overlap, which also produces the phenotype-group file that grouped multiple-testing correction later consumes. Psichomics PSI output is already grouped by gene symbol, so it only needs that symbol translated to an ENSEMBL ID.\n", + "\n", + "An older `biomaRt` route is retained for reference. It places a single-base TSS interval rather than the full gene body and is obsolete; new analyses should use the GTF-based route.\n", "\n", - "We require ENSEMBL version to be specified explicitly in this pipeline. As of 2021 for the Brain xQTL project, we use ENSEMBL version 103." + "**When to run it.** After a molecular phenotype matrix has been assembled and normalised, and before any QTL association scan, since the association modules read the coordinates from this `bed.gz`." ] }, { @@ -53,18 +38,32 @@ "tags": [] }, "source": [ - "## Input Files\n", + "## Input\n", + "\n", + "- `--phenoFile` (required): the molecular phenotype matrix to annotate. Feature IDs live in the column named by `--phenotype-id-column`; all remaining columns are samples.\n", + "- `--coordinate-annotation` (required): the collapsed gene-model GTF (or, for the `biomaRt` route, the reference the annotation is drawn from) supplying chromosome, start and end per feature.\n", + "- `--phenotype-id-column` (default `gene_id`): name of the feature-ID column in `--phenoFile`.\n", + "- `--molecular-trait-type` (default `gene`): `gene` for expression, `protein` for proteomics; selects how the feature ID is parsed before the GTF lookup.\n", + "- `--auxiliary-id-mapping` (default `.`): two-column map used for the `protein` trait type to reach a gene from a UniProt accession.\n", + "- `--sample-participant-lookup` (default `.`): optional two-column sample-to-participant map; supply it to rename matrix columns to participant IDs in the output.\n", + "- `--ensembl-version`: ENSEMBL release passed to `biomaRt`; only the `annotate_coord_biomart` workflow reads it, and it must be set explicitly there.\n", + "- `--intron-count`: leafcutter intron-count table, read by `map_leafcutter_cluster_to_gene` to enumerate the clusters that need a gene assignment.\n", + "- `--map-stra` / `--cwd` / `--container` / `--entrypoint`: intron-to-gene matching mode for cluster mapping (default `site`), output directory (default `output`), and the software environment.\n", + "\n", + "Example inputs shipped with the protocol:\n", + "\n", + "- `input/rnaseq/protocol_example.rnaseq.bed.gz` -- toy gene-level bulk RNA-seq matrix.\n", + "- `input/rnaseq/protocol_example.rnaseq.gene_ID.tsv` -- the same matrix with a `gene_ID` column, for the `biomaRt` example.\n", + "- `input/proteomics/protocol_example.protein.no_coord.tsv` -- toy protein matrix, `gene_id|UniProt` IDs, no coordinates.\n", + "- `input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene` -- the collapsed gene model.\n", + "\n", + "First rows of the expression matrix:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/rnaseq/protocol_example.rnaseq.bed.gz` | Toy bulk RNA-seq expression matrix (gene-level). |\n", - "| `input/proteomics/protocol_example.protein.no_coord.tsv` | Toy protein matrix with `gene_id\\|UniProt` IDs, no coordinates. |\n", - "| `input/rnaseq/protocol_example.rnaseq.gene_ID.tsv` | Toy expression matrix with a `gene_ID` column, for the biomaRt example. |\n", - "| `input/rnaseq/protocol_example.leafcutter.intron_count.tsv` | Toy leafcutter intron-count table (IDs `chr:start:end:clu_N_strand`). |\n", - "| `input/rnaseq/protocol_example.leafcutter.phenotype.bed.gz` | Toy leafcutter intron-excision phenotype matrix. |\n", - "| `input/rnaseq/protocol_example.psichomics.phenotype.tsv` | Toy psichomics phenotype matrix (IDs end in `_`). |\n", - "| `input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` | Collapsed gene-model GTF (gene/protein annotation). |\n", - "| `input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf` | Full gene-model GTF with exons (leafcutter/psichomics). |\n" + "```\n", + "#chr\tstart\tend\tID\tSAMPLE_001\n", + "chr22\t10939387\t10961337\tENSG00000283047\t37.077\n", + "chr22\t15528191\t15529138\tENSG00000130538\t0.0\n", + "```" ] }, { @@ -74,13 +73,29 @@ "tags": [] }, "source": [ - "## Output Files\n", + "## Output\n", + "\n", + "- `.bed.gz` plus its `.tbi` index -- the annotated matrix, coordinate-sorted, with `#chr start end ID` prepended to the sample columns. Written by every annotation workflow.\n", + "- `.region_list.txt` -- one row per retained feature giving its coordinates, ID and the path of the `bed.gz` it came from; QTL modules read this to enumerate cis regions.\n", + "- `.gene_list.tsv` -- the feature IDs that were successfully matched to the GTF.\n", + "- `*.leafcutter.clusters_to_genes.txt` and `*.exon_list` -- from `map_leafcutter_cluster_to_gene`: the cluster-to-gene assignment and the exon table it was derived from.\n", + "- `*.phenotype_group.txt` -- from the leafcutter and psichomics isoform workflows: the isoform-to-gene grouping used by grouped multiple-testing correction.\n", + "\n", + "`output/gene_annotation/protocol_example.rnaseq.bed.bed.gz`:\n", + "\n", + "```\n", + "#chr\tstart\tend\tID\tstrand\tSAMPLE_001\n", + "chr22\t10939387\t10961337\tENSG00000283047\t-\t37.0768403309204\n", + "chr22\t15528191\t15529138\tENSG00000130538\t+\t0.0\n", + "```\n", "\n", - "| Output | Description |\n", - "|--------|-------------|\n", - "| Coordinate-annotated phenotype (`*.bed.gz`) | The input molecular phenotype matrix with genomic coordinates (`#chr start end ID`) prepended, ready for downstream QTL analysis. |\n", - "| Cluster-to-gene map (`*.leafcutter.clusters_to_genes.txt`) | (leafcutter) mapping of each intron cluster to its gene(s). |\n", - "| Phenotype group file (`*.phenotype_group.txt`) | (leafcutter/psichomics) mapping of each feature ID to its gene, for grouped QTL analysis. |\n" + "`output/gene_annotation/protocol_example.rnaseq.bed.region_list.txt` (the `path` column holds the absolute location of the `bed.gz`, abbreviated here):\n", + "\n", + "```\n", + "#chr\tstart\tend\tID\tstrand\tpath\n", + "chr22\t10939387\t10961337\tENSG00000283047\t-\t.../output/gene_annotation/protocol_example.rnaseq.bed.bed.gz\n", + "chr22\t15528191\t15529138\tENSG00000130538\t+\t.../output/gene_annotation/protocol_example.rnaseq.bed.bed.gz\n", + "```" ] }, { @@ -89,9 +104,9 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "## Minimal Working Example\n", "\n", - "The example below adds genomic coordinates to a molecular phenotype matrix using the collapsed gene-model GTF. We show two cases: gene expression and proteins.\n" + "Each block below is a self-contained route: pick the one that matches how the features in the matrix are named. All of them read from `input/` and write to `output/gene_annotation/`, and none depends on the others having been run." ] }, { @@ -109,16 +124,17 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min\n" + "Annotate a gene-level expression matrix. Each feature ID is an ENSEMBL gene ID that is matched directly against the GTF to obtain its chromosome, start and end coordinates." ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "Annotate a gene-level expression matrix. Each feature ID is an ENSEMBL gene ID that is matched directly against the GTF to obtain its chromosome, start and end coordinates." + "**Timing**: ~1 min (on toy dataset)" ] }, { @@ -160,7 +176,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <1 min\n" + "Annotate a protein matrix. Here each feature ID has the form `gene_id\\|UniProt`; the gene ID portion is matched against the GTF for coordinates and the UniProt portion is retained in the output feature ID. Use `--molecular-trait-type protein` to select this behaviour." ] }, { @@ -169,7 +185,7 @@ "kernel": "SoS" }, "source": [ - "Annotate a protein matrix. Here each feature ID has the form `gene_id\\|UniProt`; the gene ID portion is matched against the GTF for coordinates and the UniProt portion is retained in the output feature ID. Use `--molecular-trait-type protein` to select this behaviour." + "**Timing**: ~1 min (on toy dataset)" ] }, { @@ -203,7 +219,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <2 min\n" + "For leafcutter splicing data, intron clusters first need to be assigned to genes. The input is a leafcutter intron-count table whose feature IDs have the form `chr:start:end:clu_N_strand`; `--coordinate-annotation` is a full gene-model GTF (with exon records). The default `--map-stra site` maps introns to genes by matching splice-site coordinates to exon boundaries." ] }, { @@ -212,7 +228,7 @@ "kernel": "SoS" }, "source": [ - "For leafcutter splicing data, intron clusters first need to be assigned to genes. The input is a leafcutter intron-count table whose feature IDs have the form `chr:start:end:clu_N_strand`; `--coordinate-annotation` is a full gene-model GTF (with exon records). The default `--map-stra site` maps introns to genes by matching splice-site coordinates to exon boundaries." + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -240,15 +256,6 @@ "### Leafcutter isoforms" ] }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Timing: <2 min\n" - ] - }, { "cell_type": "markdown", "metadata": { @@ -281,6 +288,15 @@ "| 22:19149916:19150025:clu_14_-:ENSG00000063515 | ENSG00000063515 |" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: ~2 min (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -312,7 +328,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <2 min\n" + "For psichomics splicing quantifications, each event ID ends in `_`; the gene ID is matched against the GTF to obtain coordinates. The output is a coordinate-annotated phenotype BED plus a phenotype-group file." ] }, { @@ -321,7 +337,7 @@ "kernel": "SoS" }, "source": [ - "For psichomics splicing quantifications, each event ID ends in `_`; the gene ID is matched against the GTF to obtain coordinates. The output is a coordinate-annotated phenotype BED plus a phenotype-group file." + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -353,7 +369,7 @@ "kernel": "SoS" }, "source": [ - "Timing: <2 min (depends on network)\n" + "Instead of a local GTF, coordinates can be fetched from the Ensembl biomaRt web service. The phenotype matrix must have a `gene_ID` column of ENSEMBL gene IDs. `--ensembl-version` selects the Ensembl release; use a release whose server is reachable from your network (e.g. a current release). This step requires internet access to Ensembl." ] }, { @@ -362,7 +378,7 @@ "kernel": "SoS" }, "source": [ - "Instead of a local GTF, coordinates can be fetched from the Ensembl biomaRt web service. The phenotype matrix must have a `gene_ID` column of ENSEMBL gene IDs. `--ensembl-version` selects the Ensembl release; use a release whose server is reachable from your network (e.g. a current release). This step requires internet access to Ensembl." + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -379,6 +395,48 @@ " --ensembl-version 115\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "Markdown", + "tags": [] + }, + "source": [ + "chr | start | end | strand | gene_id | gene_name\n", + "------|---------|---------|----------|----------|--------------\n", + "chr1 | 29554 | 30039 | + | ENSG00000243485 | MIR1302-2HG\n", + "chr1 | 30564 | 30667 | + | ENSG00000243485 | MIR1302-2HG\n", + "chr1 | 30976 | 31097 | + | ENSG00000243485 | MIR1302-2HG\n", + "chr1 | 35721 | 36081 | - | ENSG00000237613 | FAM138A\n", + "chr1 | 35277 | 35481 | - | ENSG00000237613 | FAM138A\n", + "chr1 | 34554 | 35174 | - | ENSG00000237613 | FAM138A\n", + "chr1 | 65419 | 65433 | + | ENSG00000186092 | OR4F5\n", + "chr1 | 65520 | 65573 | + | ENSG00000186092 | OR4F5\n", + "chr1 | 69037 | 71585 | + | ENSG00000186092 | OR4F5" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "phenotype_group\n", + "\n", + "|X1|X2|\n", + "|-------------|---|\n", + "| 7:102476270:102478811:clu_309_-:ENSG00000005075 | ENSG00000005075 | \n", + "| 7:102476270:102478808:clu_309_-:ENSG00000005075 | ENSG00000005075 |\n", + "| X:47572961:47574002:clu_349_-:ENSG00000008056 | ENSG00000008056 |\n", + "| X:47572999:47574002:clu_349_-:ENSG00000008056 | ENSG00000008056 |\n", + "| 8:27236905:27239971:clu_322_-:ENSG00000015592 | ENSG00000015592 |\n", + "| 8:27239279:27239971:clu_322_-:ENSG00000015592 | ENSG00000015592 |\n", + "| 8:27241262:27241677:clu_323_-:ENSG00000015592 | ENSG00000015592 |\n", + "| 8:27241262:27242397:clu_323_-:ENSG00000015592 | ENSG00000015592 |\n", + "| 8:27241757:27242397:clu_323_-:ENSG00000015592 | ENSG00000015592 |\n", + "| 1:35558223:35559107:clu_4_+:ENSG00000020129 | ENSG00000020129 |" + ] + }, { "cell_type": "markdown", "metadata": { @@ -390,98 +448,109 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { "kernel": "Bash" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: sos run gene_annotation.ipynb\n", - " [workflow_name | -t targets] [options] [workflow_options]\n", - " workflow_name: Single or combined workflows defined in this script\n", - " targets: One or more targets to generate\n", - " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", - " workflow_options: Double-hyphen workflow-specific parameters\n", - "\n", - "Workflows:\n", - " region_list_generation\n", - " annotate_coord\n", - " annotate_coord_biomart\n", - " map_leafcutter_cluster_to_gene\n", - " annotate_leafcutter_isoforms\n", - " annotate_psichomics_isoforms\n", - "\n", - "Global Workflow Options:\n", - " --cwd output (as path)\n", - " Work directory & output directory\n", - " --phenoFile VAL (as path, required)\n", - " Molecular phenotype matrix\n", - " --job-size 1 (as int)\n", - " For cluster jobs, number commands to run per job\n", - " --walltime 5h\n", - " Wall clock time expected\n", - " --mem 16G\n", - " Memory expected\n", - " --numThreads 1 (as int)\n", - " Number of threads\n", - " --container ''\n", - "\n", - "Sections\n", - " region_list_generation:\n", - " annotate_coord:\n", - " Workflow Options:\n", - " --sample-participant-lookup . (as path)\n", - " A file to map sample ID from expression to genotype,\n", - " must contain two columns, sample_id and participant_id,\n", - " mapping IDs in the expression files to IDs in the\n", - " genotype (these can be the same).\n", - " --molecular-trait-type gene\n", - " Options: gene, protein, atac\n", - " --coordinate-annotation VAL (as path, required)\n", - " gtf annotation for RNA-seq data; other types of\n", - " annotation index for protein and atac-seq\n", - " --phenotype-id-column 'gene_id'\n", - " gene_id or gene_name for RNA-seq data, SOMAseqID for\n", - " proteins for example\n", - " --auxiliary-id-mapping . (as path)\n", - " Optional mapping file (protein_name_index for protein,\n", - " etc.)\n", - " --[no-]strip-id (default to False)\n", - " Optional processing flag\n", - " annotate_coord_biomart:\n", - " Workflow Options:\n", - " --ensembl-version VAL (as int, required)\n", - " map_leafcutter_cluster_to_gene:\n", - " Workflow Options:\n", - " --intron-count VAL (as path, required)\n", - " Extract the code in case psichromatic needs to be\n", - " processed the same way PheoFile in this step is the\n", - " intron_count file\n", - " --map-stra site\n", - " Defines the mapping strategy options: 'site' or\n", - " 'region', with 'site' as the default. The 'site'\n", - " strategy maps introns to the start and end of each exon.\n", - " The 'region' strategy, to be recommended in leafcutter2,\n", - " maps each intron based on it overlapping more than\n", - " overlap_ratio of a gene's region.\n", - " --overlap-ratio 0.8 (as float)\n", - " Define the overlap ratio as the proportion of the\n", - " cluster length that intersects with a gene, used to\n", - " determine mapping to the gene.\n", - " annotate_leafcutter_isoforms:\n", - " Workflow Options:\n", - " --sample-participant-lookup . (as path)\n", - " annotate_psichomics_isoforms:\n", - " Workflow Options:\n", - " --sample-participant-lookup . (as path)\n" - ] - } - ], + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, "source": [ - "sos run gene_annotation.ipynb -h" + "```\n", + "usage: sos run pipeline/gene_annotation.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " annotate_coord\n", + " annotate_coord_biomart\n", + " map_leafcutter_cluster_to_gene\n", + " annotate_leafcutter_isoforms\n", + " annotate_psichomics_isoforms\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " Work directory & output directory\n", + " --phenoFile VAL (as path, required)\n", + " Molecular phenotype matrix\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + " --container ''\n", + " --entrypoint ''\n", + "\n", + "Sections\n", + " annotate_coord:\n", + " Workflow Options:\n", + " --sample-participant-lookup . (as path)\n", + " A file to map sample ID from expression to genotype,\n", + " must contain two columns, sample_id and participant_id,\n", + " mapping IDs in the expression files to IDs in the\n", + " genotype (these can be the same).\n", + " --molecular-trait-type gene\n", + " Options: gene, protein, atac\n", + " --coordinate-annotation VAL (as path, required)\n", + " gtf annotation for RNA-seq data; other types of\n", + " annotation index for protein and atac-seq\n", + " --phenotype-id-column 'gene_id'\n", + " gene_id or gene_name for RNA-seq data, SOMAseqID for\n", + " proteins for example\n", + " --auxiliary-id-mapping . (as path)\n", + " Optional mapping file (protein_name_index for protein,\n", + " etc.)\n", + " --[no-]strip-id (default to False)\n", + " Optional processing flag\n", + " --sep '\\t'\n", + " annotate_coord_biomart:\n", + " Workflow Options:\n", + " --ensembl-version VAL (as int, required)\n", + " map_leafcutter_cluster_to_gene:\n", + " Workflow Options:\n", + " --intron-count VAL (as path, required)\n", + " Extract the code in case psichromatic needs to be\n", + " processed the same way PheoFile in this step is the\n", + " intron_count file\n", + " --coordinate-annotation VAL (as path, required)\n", + " gtf annotation with exons (the full gene model), used to\n", + " map intron splice sites to genes\n", + " --map-stra site\n", + " Defines the mapping strategy options: 'site' or\n", + " 'region', with 'site' as the default. The 'site'\n", + " strategy maps introns to the start and end of each exon.\n", + " The 'region' strategy, to be recommended in leafcutter2,\n", + " maps each intron based on it overlapping more than\n", + " overlap_ratio of a gene's region.\n", + " --overlap-ratio 0.8 (as float)\n", + " Define the overlap ratio as the proportion of the\n", + " cluster length that intersects with a gene, used to\n", + " determine mapping to the gene.\n", + " annotate_leafcutter_isoforms:\n", + " Workflow Options:\n", + " --sample-participant-lookup . (as path)\n", + " --coordinate-annotation VAL (as path, required)\n", + " gtf annotation with exons (the full gene model)\n", + " annotate_psichomics_isoforms:\n", + " Workflow Options:\n", + " --sample-participant-lookup . (as path)\n", + " --coordinate-annotation VAL (as path, required)\n", + " gtf annotation with exons (the full gene model)\n", + "```" ] }, { @@ -490,7 +559,7 @@ "kernel": "Bash" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation" ] }, { @@ -525,7 +594,7 @@ "kernel": "SoS" }, "source": [ - "## Implementation using `pyqtl`\n", + "### Implementation using `pyqtl`\n", "\n", "Implementation based on [GTEx pipeline](https://github.com/broadinstitute/gtex-pipeline/blob/master/qtl/src/eqtl_prepare_expression.py).\n", "\n", @@ -539,7 +608,40 @@ "kernel": "SoS" }, "outputs": [], - "source": "[annotate_coord]\n# A file to map sample ID from expression to genotype, must contain two columns, sample_id and participant_id, mapping IDs in the expression files to IDs in the genotype (these can be the same).\nparameter: sample_participant_lookup = path()\n# Options: gene, protein, atac\nparameter: molecular_trait_type = \"gene\" \n# gtf annotation for RNA-seq data; other types of annotation index for protein and atac-seq\nparameter: coordinate_annotation = path\n# gene_id or gene_name for RNA-seq data, SOMAseqID for proteins for example\nparameter: phenotype_id_column = \"gene_id\"\n# Optional mapping file (protein_name_index for protein, etc.)\nparameter: auxiliary_id_mapping = path()\n# Optional processing flag\nparameter: strip_id = False\nparameter: sep = \"\\t\"\n\ninput: phenoFile, coordinate_annotation\noutput: f'{cwd:a}/{_input[0]:bn}.bed.gz', f'{cwd:a}/{_input[0]:bn}.region_list.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n --step annotate_coord \\\n --phenoFile \"${_input[0]}\" \\\n --coordinate-annotation \"${_input[1]}\" \\\n --sample-participant-lookup \"${sample_participant_lookup}\" \\\n --molecular-trait-type \"${molecular_trait_type}\" \\\n --phenotype-id-column \"${phenotype_id_column}\" \\\n --auxiliary-id-mapping \"${auxiliary_id_mapping}\" \\\n --sep \"${sep}\" \\\n ${\"--strip-id\" if strip_id else \"\"} \\\n --output-bed \"${_output[0]}\" \\\n --output-region-list \"${_output[1]}\" \\\n --gene-list-output \"${cwd:a}/${_input[0]:bn}.gene_list.tsv\"" + "source": [ + "[annotate_coord]\n", + "# A file to map sample ID from expression to genotype, must contain two columns, sample_id and participant_id, mapping IDs in the expression files to IDs in the genotype (these can be the same).\n", + "parameter: sample_participant_lookup = path()\n", + "# Options: gene, protein, atac\n", + "parameter: molecular_trait_type = \"gene\" \n", + "# gtf annotation for RNA-seq data; other types of annotation index for protein and atac-seq\n", + "parameter: coordinate_annotation = path\n", + "# gene_id or gene_name for RNA-seq data, SOMAseqID for proteins for example\n", + "parameter: phenotype_id_column = \"gene_id\"\n", + "# Optional mapping file (protein_name_index for protein, etc.)\n", + "parameter: auxiliary_id_mapping = path()\n", + "# Optional processing flag\n", + "parameter: strip_id = False\n", + "parameter: sep = \"\\t\"\n", + "\n", + "input: phenoFile, coordinate_annotation\n", + "output: f'{cwd:a}/{_input[0]:bn}.bed.gz', f'{cwd:a}/{_input[0]:bn}.region_list.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n", + " --step annotate_coord \\\n", + " --phenoFile \"${_input[0]}\" \\\n", + " --coordinate-annotation \"${_input[1]}\" \\\n", + " --sample-participant-lookup \"${sample_participant_lookup}\" \\\n", + " --molecular-trait-type \"${molecular_trait_type}\" \\\n", + " --phenotype-id-column \"${phenotype_id_column}\" \\\n", + " --auxiliary-id-mapping \"${auxiliary_id_mapping}\" \\\n", + " --sep \"${sep}\" \\\n", + " ${\"--strip-id\" if strip_id else \"\"} \\\n", + " --output-bed \"${_output[0]}\" \\\n", + " --output-region-list \"${_output[1]}\" \\\n", + " --gene-list-output \"${cwd:a}/${_input[0]:bn}.gene_list.tsv\"" + ] }, { "cell_type": "markdown", @@ -548,7 +650,7 @@ "tags": [] }, "source": [ - "## Implementation using biomaRt\n", + "### Implementation using biomaRt\n", "This workflow adds the annotations of chr pos(TSS where start = end -1) and gene_ID to the `bed` file. **This workflow is obsolete**." ] }, @@ -581,7 +683,7 @@ "kernel": "SoS" }, "source": [ - "## Annotation of leafcutter isoform" + "### Annotation of leafcutter isoform" ] }, { @@ -589,7 +691,9 @@ "metadata": { "kernel": "SoS" }, - "source": "The gtf used here should be the collapsed gtf, i.e. the final output of reference_data gtf processing and the one used to called rnaseq." + "source": [ + "The gtf used here should be the collapsed gtf, i.e. the final output of reference_data gtf processing and the one used to called rnaseq." + ] }, { "cell_type": "code", @@ -598,7 +702,32 @@ "kernel": "SoS" }, "outputs": [], - "source": "[map_leafcutter_cluster_to_gene]\n## Extract the code in case psichromatic needs to be processed the same way\n## PheoFile in this step is the intron_count file\nparameter: intron_count = path\n# gtf annotation with exons (the full gene model), used to map intron splice sites to genes\nparameter: coordinate_annotation = path\n# Defines the mapping strategy options: 'site' or 'region', with 'site' as the default. \n# The 'site' strategy maps introns to the start and end of each exon. \n# The 'region' strategy, to be recommended in leafcutter2, maps each intron based on it overlapping more than overlap_ratio of a gene's region.\nparameter: map_stra = \"site\" \n# Define the overlap ratio as the proportion of the cluster length that intersects with a gene, used to determine mapping to the gene.\nparameter: overlap_ratio = 0.8\ninput: intron_count, coordinate_annotation\noutput: f'{cwd}/{_input[0]:b}.exon_list', f'{cwd}/{_input[0]:b}.leafcutter.clusters_to_genes.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n --step map_leafcutter_cluster_to_gene \\\n --intron-count \"${_input[0]}\" \\\n --annotation-gtf \"${_input[1]}\" \\\n --map-stra \"${map_stra}\" \\\n --overlap-ratio ${overlap_ratio} \\\n --output-exon-list \"${_output[0]}\" \\\n --output-cluster-map \"${_output[1]}\"" + "source": [ + "[map_leafcutter_cluster_to_gene]\n", + "## Extract the code in case psichromatic needs to be processed the same way\n", + "## PheoFile in this step is the intron_count file\n", + "parameter: intron_count = path\n", + "# gtf annotation with exons (the full gene model), used to map intron splice sites to genes\n", + "parameter: coordinate_annotation = path\n", + "# Defines the mapping strategy options: 'site' or 'region', with 'site' as the default. \n", + "# The 'site' strategy maps introns to the start and end of each exon. \n", + "# The 'region' strategy, to be recommended in leafcutter2, maps each intron based on it overlapping more than overlap_ratio of a gene's region.\n", + "parameter: map_stra = \"site\" \n", + "# Define the overlap ratio as the proportion of the cluster length that intersects with a gene, used to determine mapping to the gene.\n", + "parameter: overlap_ratio = 0.8\n", + "input: intron_count, coordinate_annotation\n", + "output: f'{cwd}/{_input[0]:b}.exon_list', f'{cwd}/{_input[0]:b}.leafcutter.clusters_to_genes.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n", + " --step map_leafcutter_cluster_to_gene \\\n", + " --intron-count \"${_input[0]}\" \\\n", + " --annotation-gtf \"${_input[1]}\" \\\n", + " --map-stra \"${map_stra}\" \\\n", + " --overlap-ratio ${overlap_ratio} \\\n", + " --output-exon-list \"${_output[0]}\" \\\n", + " --output-cluster-map \"${_output[1]}\"" + ] }, { "cell_type": "code", @@ -607,16 +736,23 @@ "kernel": "SoS" }, "outputs": [], - "source": "[annotate_leafcutter_isoforms]\nparameter: sample_participant_lookup = path()\n# gtf annotation with exons (the full gene model)\nparameter: coordinate_annotation = path\ninput: phenoFile, coordinate_annotation, output_from(\"map_leafcutter_cluster_to_gene\")\noutput: f'{cwd:a}/{_input[0]:bn}.formated.bed.gz', f'{cwd:a}/{_input[0]:bn}.phenotype_group.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n --step annotate_leafcutter_isoforms \\\n --phenoFile \"${_input[0]}\" \\\n --annotation-gtf \"${_input[1]}\" \\\n --cluster-map \"${_input[3]}\" \\\n --sample-participant-lookup \"${sample_participant_lookup}\" \\\n --output-bed \"${_output[0]}\" \\\n --output-phenotype-group \"${_output[1]}\"" - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, "source": [ - "## Processing of psichomics output\n", - "It occurs that the psichomatic by default grouped the isoforms by gene name, so only thing needs to be done is to extract this information and potentially renamed the gene symbol into ENSG ID" + "[annotate_leafcutter_isoforms]\n", + "parameter: sample_participant_lookup = path()\n", + "# gtf annotation with exons (the full gene model)\n", + "parameter: coordinate_annotation = path\n", + "input: phenoFile, coordinate_annotation, output_from(\"map_leafcutter_cluster_to_gene\")\n", + "output: f'{cwd:a}/{_input[0]:bn}.formated.bed.gz', f'{cwd:a}/{_input[0]:bn}.phenotype_group.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n", + " --step annotate_leafcutter_isoforms \\\n", + " --phenoFile \"${_input[0]}\" \\\n", + " --annotation-gtf \"${_input[1]}\" \\\n", + " --cluster-map \"${_input[3]}\" \\\n", + " --sample-participant-lookup \"${sample_participant_lookup}\" \\\n", + " --output-bed \"${_output[0]}\" \\\n", + " --output-phenotype-group \"${_output[1]}\"" ] }, { @@ -625,9 +761,8 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### Processing of psichomics output\n", + "It occurs that the psichomatic by default grouped the isoforms by gene name, so only thing needs to be done is to extract this information and potentially renamed the gene symbol into ENSG ID" ] }, { @@ -637,7 +772,23 @@ "kernel": "SoS" }, "outputs": [], - "source": "[annotate_psichomics_isoforms]\nparameter: sample_participant_lookup = path()\n# gtf annotation with exons (the full gene model)\nparameter: coordinate_annotation = path\ninput: phenoFile, coordinate_annotation\noutput: f'{cwd:a}/{_input[0]:bn}.formated.bed.gz', f'{cwd:a}/{_input[0]:bn}.phenotype_group.txt'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n --step annotate_psichomics_isoforms \\\n --phenoFile \"${_input[0]}\" \\\n --annotation-gtf \"${_input[1]}\" \\\n --sample-participant-lookup \"${sample_participant_lookup}\" \\\n --output-bed \"${_output[0]}\" \\\n --output-phenotype-group \"${_output[1]}\"" + "source": [ + "[annotate_psichomics_isoforms]\n", + "parameter: sample_participant_lookup = path()\n", + "# gtf annotation with exons (the full gene model)\n", + "parameter: coordinate_annotation = path\n", + "input: phenoFile, coordinate_annotation\n", + "output: f'{cwd:a}/{_input[0]:bn}.formated.bed.gz', f'{cwd:a}/{_input[0]:bn}.phenotype_group.txt'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/gene_annotation.R \\\n", + " --step annotate_psichomics_isoforms \\\n", + " --phenoFile \"${_input[0]}\" \\\n", + " --annotation-gtf \"${_input[1]}\" \\\n", + " --sample-participant-lookup \"${sample_participant_lookup}\" \\\n", + " --output-bed \"${_output[0]}\" \\\n", + " --output-phenotype-group \"${_output[1]}\"" + ] } ], "metadata": { @@ -676,4 +827,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/data_preprocessing/phenotype/phenotype_formatting.ipynb b/code/SoS/data_preprocessing/phenotype/phenotype_formatting.ipynb index 59bdffa41..236d7a610 100644 --- a/code/SoS/data_preprocessing/phenotype/phenotype_formatting.ipynb +++ b/code/SoS/data_preprocessing/phenotype/phenotype_formatting.ipynb @@ -9,7 +9,7 @@ "source": [ "# Phenotype Data Formatting\n", "\n", - "**FIXME: this entire pipeline needs to be improved**" + "Splits a molecular phenotype matrix by chromosome or by region so the association scan can be parallelised." ] }, { @@ -18,7 +18,13 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "Association testing and fine-mapping run per chromosome or per region, so the phenotype matrix has to be partitioned the same way before that work can be parallelised. These workflows split a phenotype BED by chromosome or by region, annotate features against TAD boundaries when region-based analysis is wanted, and accept GCT-format input as well as BED. Two further workflows trim inputs rather than split them: one subsets BAM files by coordinate, the other drops samples from a GCT matrix.\n", + "\n", + "The pipeline's author has flagged it as needing improvement, so treat the interface as unstable and re-check `-h` before relying on any option.\n", + "\n", + "**When to run it.** After phenotype QC, normalisation and imputation, and before covariate preprocessing and the association scan." ] }, { @@ -27,7 +33,36 @@ "kernel": "SoS" }, "source": [ - "We include a collection of workflows to format molecular phenotype data. These include workflows to separate phenotypes by chromosome, by user-provided regions, a workflow to subset bam files and a workflow to extract samples from phenotype files.\n" + "## Input\n", + "\n", + "- `--phenoFile`: the molecular phenotype data, required by every workflow. A tabix-indexed UCSC `bed.gz` for the BED workflows, a `gct.gz` for the GCT ones, and a list of BAM paths for `bam_subsetting`. Example `output/rnaseq/protocol_example.rnaseq.bed.bed.gz`:\n", + "\n", + " ```\n", + " #chr start end ID SAMPLE_001 SAMPLE_002\n", + " chr22 10939387 10961337 ENSG00000283047 37.0768403309204 0.0\n", + " ```\n", + "\n", + "- `--chrom`: the chromosomes to extract, taking one or more values. Used by `phenotype_by_chrom` and `phenotype_by_chrom_gct`.\n", + "- `--region-list`: a 4-column index of the regions to analyse, giving chr, start, end and region name. Used by `phenotype_by_region`. Example `input/reference_data/TAD/protocol_example_protein.enhanced_cis_chr22.bed`:\n", + "\n", + " ```\n", + " #chr start end gene_id\n", + " chr22 0 18960000 ENSG00000131100_P36543\n", + " ```\n", + "\n", + "- `--TAD-list`: the TAD boundary file for `phenotype_annotate_by_tad`, in the same 4-column shape. Example `input/reference_data/TAD/TADB_enhanced_cis.bed`.\n", + "- `--phenotype-per-tad`: the minimum number of features a TAD must contain to be kept, `2` by default.\n", + "- `--region`: coordinates passed through to `samtools view` by `bam_subsetting`, for example `--region chr21 chr22`.\n", + "- `--keep-samples`: for `gct_extract_samples`, a file listing the sample IDs to retain, one per line. Example `input/colocboost/keep_samples.txt`:\n", + "\n", + " ```\n", + " SAMPLE_001\n", + " SAMPLE_002\n", + " SAMPLE_003\n", + " ```\n", + "\n", + "- `--name`: the stem of the output files, derived from `--phenoFile` by default.\n", + "- `--cwd`: the directory outputs are written to." ] }, { @@ -36,12 +71,21 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", + "\n", + "- `{cwd}/{name}.{chrom}.bed.gz` - one phenotype BED per requested chromosome, with a tabix index, from `phenotype_by_chrom`.\n", + "- `{cwd}/{name}.phenotype_by_chrom_files.txt` and `{cwd}/{name}.phenotype_by_chrom_files.region_list.txt` - the manifest of those per-chromosome files and the matching region list, both written by the collecting substep. Example `output/phenotype_protein/protocol_example_protein.phenotype_by_chrom_files.region_list.txt`:\n", + "\n", + " ```\n", + " #chr start end ID path\n", + " chr22 17592135 17628748 ENSG00000131100_P36543 output/phenotype_protein/protocol_example_protein.chr22.bed.gz\n", + " ```\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` | Residualized molecular phenotype data as a bgzipped, tabix-indexed BED (`#chr`/`start`/`end`/`ID` + one column per sample). Output of upstream `covariate_preprocessing` / `gene_annotation`. |\n", - "| `output/rnaseq/protocol_example.rnaseq.bed.bed.gz.tbi` | Tabix index for the phenotype BED, required to extract records per chromosome. |" + "- `{cwd}/{region_list}_phenotype_by_region/{name}.{region}.bed.gz` and `{cwd}/{name}.phenotype_by_region_files.txt` - the per-region equivalents from `phenotype_by_region`.\n", + "- `{cwd}/{phenoFile}.{TAD_list}.{n}_pheno_per_region.region_list` - the TAD-grouped region list from `phenotype_annotate_by_tad`.\n", + "- `{cwd}/{name}.{chrom}.gct` - one GCT per chromosome, from `phenotype_by_chrom_gct`.\n", + "- `{cwd}/{bam}.subsetted.bam` - the coordinate-restricted BAM from `bam_subsetting`.\n", + "- `{phenoFile}.sample_matched.gct.gz` - the sample-filtered GCT from `gct_extract_samples`, written beside its input rather than under `--cwd`." ] }, { @@ -50,13 +94,46 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Minimal Working Example" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Partition a phenotype BED by chromosome\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/phenotype_uf/protocol_example..bed.gz` (+`.tbi`) | Per-chromosome phenotype BED (bed+index) annotated with genomic coordinates, suitable for TensorQTL analysis. |\n", - "| `output/phenotype_uf/protocol_example.phenotype_by_chrom_files.txt` | Two-column list mapping each chromosome to its per-chromosome phenotype BED. |\n", - "| `output/phenotype_uf/protocol_example.phenotype_by_chrom_files.region_list.txt` | Region list (`#chr`/`start`/`end`/`ID`/`path`) for downstream cis-QTL / fine-mapping. |" + "`phenotype_by_chrom` runs two substeps in sequence: `_1` pulls the records for each requested chromosome out of the tabix-indexed BED and writes a per-chromosome `bed.gz` with its index, and `_2` collects those into the `*_files.txt` and `*.region_list.txt` lists. This is the partitioning cis TensorQTL analysis needs. Only `chr22` is present in the toy phenotype data." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash", + "vscode": { + "languageId": "plaintext" + } + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_by_chrom \\\n", + " --cwd output/phenotype_uf \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --name protocol_example \\\n", + " --chrom chr22" ] }, { @@ -65,8 +142,9 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example Steps\n", - "The data and singularity image used are available on [Synapse](https://www.synapse.org/#!Synapse:syn69670658).\n" + "### Partition a GCT matrix by chromosome\n", + "\n", + "`phenotype_by_chrom_gct` does the same split for RNASeQC-style GCT input rather than BED, writing one `.gct` per chromosome." ] }, { @@ -75,7 +153,21 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** Partition phenotype by chromosome" + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_by_chrom_gct \\\n", + " --cwd output/phenotype_gct \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz \\\n", + " --chrom chr21 chr22" ] }, { @@ -84,7 +176,9 @@ "kernel": "SoS" }, "source": [ - "This is necessary for cis TensorQTL analysis." + "### Partition a phenotype BED by region\n", + "\n", + "`phenotype_by_region` splits on an explicit region list instead of whole chromosomes, giving one `bed.gz` per region under a directory named after the list. Like `phenotype_by_chrom` it runs two substeps in sequence: `_1` writes the per-region files and `_2` collects them into a `_files.txt` manifest." ] }, { @@ -93,25 +187,21 @@ "kernel": "SoS" }, "source": [ - "Timing < 1 min" + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash", - "vscode": { - "languageId": "plaintext" - } + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/phenotype_formatting.ipynb phenotype_by_chrom \\\n", - " --cwd output/phenotype_uf \\\n", + "sos run pipeline/phenotype_formatting.ipynb phenotype_by_region \\\n", + " --cwd output/phenotype_by_region \\\n", " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", - " --name protocol_example \\\n", - " --chrom chr22" + " --region-list input/reference_data/TAD/protocol_example_protein.enhanced_cis_chr22.bed" ] }, { @@ -120,7 +210,9 @@ "kernel": "SoS" }, "source": [ - "This runs the two `phenotype_by_chrom` substeps in sequence: substep `_1` extracts the records for each requested chromosome from the tabix-indexed BED and writes a per-chromosome `bed.gz` (+ index); substep `_2` collects those into the `*_files.txt` and `*.region_list.txt` lists. For this minimal example only `chr22` is present in the toy phenotype data." + "### Group features into TAD windows\n", + "\n", + "`phenotype_annotate_by_tad` assigns each feature to a TAD and emits a region list, so that region-based analysis works on TAD windows rather than fixed cis-windows. `--phenotype-per-tad` sets the minimum features a TAD must hold to be kept." ] }, { @@ -129,7 +221,22 @@ "kernel": "SoS" }, "source": [ - "## Troubleshooting" + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_annotate_by_tad \\\n", + " --cwd output/phenotype_by_region \\\n", + " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", + " --TAD-list input/reference_data/TAD/TADB_enhanced_cis.bed \\\n", + " --phenotype-per-tad 2" ] }, { @@ -138,11 +245,66 @@ "kernel": "SoS" }, "source": [ - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "|------|---------|---------|------------------|---------|\n", - "| | | | | |\n", + "### Extract samples from a GCT matrix\n", "\n", - "\n" + "`gct_extract_samples` keeps only the samples named in `--keep-samples`, which is how a GCT from RNASeQC is cut down to the cohort actually being analysed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb gct_extract_samples \\\n", + " --cwd output/phenotype_gct \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz \\\n", + " --keep-samples input/colocboost/keep_samples.txt" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Subset BAM files by region\n", + "\n", + "`bam_subsetting` runs `samtools view` over each BAM in `--phenoFile` and keeps only the given coordinates. No BAM ships with this repository, so the command below is a template rather than a runnable example." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb bam_subsetting \\\n", + " --cwd output/bam_subset \\\n", + " --phenoFile /bam_file_list.txt \\\n", + " --region chr21 chr22" ] }, { @@ -158,14 +320,86 @@ "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash", - "vscode": { - "languageId": "plaintext" - } + "kernel": "SoS" }, "outputs": [], "source": [ - "!sos run phenotype_formatting.ipynb -h" + "sos run pipeline/phenotype_formatting.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/phenotype_formatting.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " phenotype_by_chrom\n", + " phenotype_annotate_by_tad\n", + " phenotype_by_chrom_gct\n", + " phenotype_by_region\n", + " bam_subsetting\n", + " gct_extract_samples\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " Work directory & output directory\n", + " --container ''\n", + " The filename namefor output data\n", + " --entrypoint ''\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 20 (as int)\n", + " Number of threads\n", + " --phenoFile VAL (as path, required)\n", + " Path to the input molecular phenotype data.\n", + " --name str(phenoFile).removesuffix('.gz').removesuffix('.bed')\n", + "\n", + " name for the analysis output\n", + "\n", + "Sections\n", + " phenotype_by_chrom_1:\n", + " Workflow Options:\n", + " --chrom VAL VAL ... (as type, required)\n", + " list of chroms to extract\n", + " phenotype_by_chrom_2:\n", + " phenotype_annotate_by_tad:\n", + " Workflow Options:\n", + " --TAD-list VAL (as path, required)\n", + " --phenotype-per-tad 2 (as int)\n", + " phenotype_by_chrom_gct_1:\n", + " Workflow Options:\n", + " --chrom VAL VAL ... (as type, required)\n", + " list of chroms to extract\n", + " phenotype_by_region_1:\n", + " Workflow Options:\n", + " --region-list VAL (as path, required)\n", + " An index text file with 4 columns specifying the chr,\n", + " start, end and name of regions to analyze\n", + " phenotype_by_region_2:\n", + " bam_subsetting:\n", + " Workflow Options:\n", + " --region VAL VAL ... (as type, required)\n", + " Input to `samtools view` coordinates, for example,\n", + " --region chr21 chr22\n", + " gct_extract_samples: Extract samples from expression data generated by\n", + " RNASeQC\n", + " Workflow Options:\n", + " --keep-samples VAL (as path, required)\n", + "```" ] }, { @@ -174,7 +408,7 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation" ] }, { @@ -208,28 +442,6 @@ "parameter: name = str(phenoFile).removesuffix('.gz').removesuffix('.bed')" ] }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS", - "tags": [] - }, - "source": [ - "## Process of molecular phenotype file\n", - "This workflow produce a bed+tabix file for all the molecular pheno data that are included in the region list to feed into downstream analysis" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] - }, { "cell_type": "code", "execution_count": null, @@ -237,7 +449,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[phenotype_by_chrom_1]\n# list of chroms to extract \nparameter: chrom = list\nchrom = list(set(chrom))\n# Path to the input molecular phenotype data.\ninput: phenoFile, for_each = \"chrom\"\noutput: f'{cwd}/{name}.{_chrom}.bed.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_1 \\\n --cwd \"${cwd}\" \\\n --phenoFile \"${_input}\" \\\n --name \"${name}\" \\\n --chrom \"${_chrom}\" \\\n --output \"${_output}\" \\\n --numThreads ${numThreads}" + "source": [ + "[phenotype_by_chrom_1]\n", + "# list of chroms to extract \n", + "parameter: chrom = list\n", + "chrom = list(set(chrom))\n", + "# Path to the input molecular phenotype data.\n", + "input: phenoFile, for_each = \"chrom\"\n", + "output: f'{cwd}/{name}.{_chrom}.bed.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_1 \\\n", + " --cwd \"${cwd}\" \\\n", + " --phenoFile \"${_input}\" \\\n", + " --name \"${name}\" \\\n", + " --chrom \"${_chrom}\" \\\n", + " --output \"${_output}\" \\\n", + " --numThreads ${numThreads}" + ] }, { "cell_type": "code", @@ -246,7 +475,19 @@ "kernel": "SoS" }, "outputs": [], - "source": "[phenotype_by_chrom_2]\n# Path to the input molecular phenotype data.\ninput: group_by = \"all\"\noutput: f'{cwd}/{name}.{step_name[:-2]}_files.txt',f'{cwd}/{name}.{step_name[:-2]}_files.region_list.txt'\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_2 \\\n --cwd \"${cwd}\" \\\n --phenoFile \"${phenoFile}\" \\\n --inputs ${_input} \\\n --output-files \"${_output[0]}\" \\\n --output-region-list \"${_output[1]}\"" + "source": [ + "[phenotype_by_chrom_2]\n", + "# Path to the input molecular phenotype data.\n", + "input: group_by = \"all\"\n", + "output: f'{cwd}/{name}.{step_name[:-2]}_files.txt',f'{cwd}/{name}.{step_name[:-2]}_files.region_list.txt'\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_2 \\\n", + " --cwd \"${cwd}\" \\\n", + " --phenoFile \"${phenoFile}\" \\\n", + " --inputs ${_input} \\\n", + " --output-files \"${_output[0]}\" \\\n", + " --output-region-list \"${_output[1]}\"" + ] }, { "cell_type": "code", @@ -279,7 +520,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[phenotype_by_chrom_gct_1]\n# list of chroms to extract \nparameter: chrom = list\nchrom = list(set(chrom))\n# Path to the input molecular phenotype data.\ninput: phenoFile, for_each = \"chrom\"\noutput: f'{cwd:a}/{name}.{_chrom}.gct'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_gct_1 \\\n --cwd \"${cwd}\" \\\n --phenoFile \"${_input}\" \\\n --name \"${name}\" \\\n --chrom \"${_chrom}\" \\\n --output \"${_output}\" \\\n --numThreads ${numThreads}" + "source": [ + "[phenotype_by_chrom_gct_1]\n", + "# list of chroms to extract \n", + "parameter: chrom = list\n", + "chrom = list(set(chrom))\n", + "# Path to the input molecular phenotype data.\n", + "input: phenoFile, for_each = \"chrom\"\n", + "output: f'{cwd:a}/{name}.{_chrom}.gct'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_chrom_gct_1 \\\n", + " --cwd \"${cwd}\" \\\n", + " --phenoFile \"${_input}\" \\\n", + " --name \"${name}\" \\\n", + " --chrom \"${_chrom}\" \\\n", + " --output \"${_output}\" \\\n", + " --numThreads ${numThreads}" + ] }, { "cell_type": "code", @@ -288,7 +546,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[phenotype_by_region_1]\n# An index text file with 4 columns specifying the chr, start, end and name of regions to analyze\nparameter: region_list = path\nregions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\n# Path to the input molecular phenotype data.\ninput: phenoFile, for_each = \"regions\"\noutput: f'{cwd}/{region_list:bn}_phenotype_by_region/{name}.{_regions[3]}.bed.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_region_1 \\\n --cwd \"${cwd}\" \\\n --phenoFile \"${_input}\" \\\n --name \"${name}\" \\\n --region \"${_regions[0]}\" \"${_regions[1]}\" \"${_regions[2]}\" \"${_regions[3]}\" \\\n --output \"${_output}\" \\\n --numThreads ${numThreads}" + "source": [ + "[phenotype_by_region_1]\n", + "# An index text file with 4 columns specifying the chr, start, end and name of regions to analyze\n", + "parameter: region_list = path\n", + "regions = [x.strip().split() for x in open(region_list).readlines() if x.strip() and not x.strip().startswith('#')]\n", + "# Path to the input molecular phenotype data.\n", + "input: phenoFile, for_each = \"regions\"\n", + "output: f'{cwd}/{region_list:bn}_phenotype_by_region/{name}.{_regions[3]}.bed.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}' \n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_region_1 \\\n", + " --cwd \"${cwd}\" \\\n", + " --phenoFile \"${_input}\" \\\n", + " --name \"${name}\" \\\n", + " --region \"${_regions[0]}\" \"${_regions[1]}\" \"${_regions[2]}\" \"${_regions[3]}\" \\\n", + " --output \"${_output}\" \\\n", + " --numThreads ${numThreads}" + ] }, { "cell_type": "code", @@ -297,7 +572,16 @@ "kernel": "SoS" }, "outputs": [], - "source": "[phenotype_by_region_2]\ninput: group_by = \"all\"\noutput: f'{cwd}/{name}.{step_name[:-2]}_files.txt'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_region_2 \\\n --cwd \"${cwd}\" \\\n --inputs ${_input} \\\n --output \"${_output}\"" + "source": [ + "[phenotype_by_region_2]\n", + "input: group_by = \"all\"\n", + "output: f'{cwd}/{name}.{step_name[:-2]}_files.txt'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step phenotype_by_region_2 \\\n", + " --cwd \"${cwd}\" \\\n", + " --inputs ${_input} \\\n", + " --output \"${_output}\"" + ] }, { "cell_type": "code", @@ -306,7 +590,21 @@ "kernel": "SoS" }, "outputs": [], - "source": "[bam_subsetting]\n# Input to `samtools view` coordinates, for example, --region chr21 chr22\nparameter: region = list\n# Path to the input molecular phenotype data.\nparameter: phenoFile = paths\ninput: phenoFile , group_by = 1\noutput: f'{cwd}/{_input:bn}.subsetted.bam'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container=container, entrypoint=entrypoint\n Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step bam_subsetting \\\n --phenoFile \"${_input}\" \\\n --region ${' '.join(region)} \\\n --output \"${_output}\"" + "source": [ + "[bam_subsetting]\n", + "# Input to `samtools view` coordinates, for example, --region chr21 chr22\n", + "parameter: region = list\n", + "# Path to the input molecular phenotype data.\n", + "parameter: phenoFile = paths\n", + "input: phenoFile , group_by = 1\n", + "output: f'{cwd}/{_input:bn}.subsetted.bam'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout', container=container, entrypoint=entrypoint\n", + " Rscript ${modular_script_dir}/data_preprocessing/phenotype/phenotype_formatting.R --step bam_subsetting \\\n", + " --phenoFile \"${_input}\" \\\n", + " --region ${' '.join(region)} \\\n", + " --output \"${_output}\"" + ] }, { "cell_type": "code", @@ -364,4 +662,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/data_preprocessing/phenotype/phenotype_imputation.ipynb b/code/SoS/data_preprocessing/phenotype/phenotype_imputation.ipynb index 391a633a0..8aa073f9f 100644 --- a/code/SoS/data_preprocessing/phenotype/phenotype_imputation.ipynb +++ b/code/SoS/data_preprocessing/phenotype/phenotype_imputation.ipynb @@ -8,16 +8,8 @@ }, "source": [ "# Phenotype data imputation\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" + "\n", + "Imputes missing values in a molecular phenotype matrix, so downstream models see a complete matrix." ] }, { @@ -26,7 +18,13 @@ "kernel": "SoS" }, "source": [ - "Empirical Bayes Matrix Factorization (EBMF) is the primary imputation method we use to impute molecular phenotype data [[cf. Qi et al., medRxiv, 2023](https://doi.org/10.1101/2023.11.29.23299181)]. We also provide a collection of other methods to impute missing omics data values including missing forest, XGboost, k-nearest neighbors, soft impute, mean imputation, and limit of detection." + "## Overview\n", + "\n", + "Molecular phenotype matrices are rarely complete: a feature can be unmeasured in a sample for technical reasons, and the models downstream generally require a full matrix. Dropping every feature with a missing entry throws away real signal, so this step imputes the gaps instead.\n", + "\n", + "Empirical Bayes matrix factorisation is the primary method here, `EBMF` for a single matrix and `gEBMF` when the data are grouped, following [Qi et al., medRxiv 2023](https://doi.org/10.1101/2023.11.29.23299181). Seven alternatives are also provided - missForest, missXGBoost, k-nearest neighbours, SoftImpute, mean imputation and limit-of-detection imputation - so a method can be matched to the assay.\n", + "\n", + "**When to run it.** After phenotype QC and normalisation, before covariate preprocessing and the association scan." ] }, { @@ -35,7 +33,20 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~varies on typical compute infrastructure." + "## Input\n", + "\n", + "- `--phenoFile`: the molecular phenotype matrix in BED layout, the first four columns being `#chr`, `start`, `end` and `ID` and the rest one column per sample, with missing entries written as `NA`. Example `input/proteomics/protocol_example.protein.missing.bed.gz`, a toy matrix with roughly 10% of values set to missing so the methods have gaps to fill:\n", + "\n", + " ```\n", + " #chr start end ID SAMPLE_001 SAMPLE_002\n", + " chr12 752578 752579 chr12_ENSG00000060237_Q9H4A3 0.238966360190167 -0.611171227886468\n", + " chr12 990508 990509 chr12_ENSG00000082805_Q8IUD2 NA -1.86313205860919\n", + " ```\n", + "\n", + "- `--num_factor`: the number of factors for the `EBMF` and `gEBMF` models. It must be smaller than the number of samples; the toy set has 60, so the examples use `30`.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--save_flash`: off by default. When set, `gEBMF` also writes the fitted flashier factor object.\n", + "- `--no-qc-prior-to-impute`: leaves quality control on by default. Passing it skips QC, which also means the QC matrix is not available to the output." ] }, { @@ -44,11 +55,16 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", + "\n", + "- `{cwd}/{phenoFile}.imputed.bed.gz` - the imputed matrix in the same BED layout as the input, bgzipped and tabix-indexed, with a `.tbi` beside it. Example `output/phenotype_imputation_uf/protocol_example.protein.missing.bed.imputed.bed.gz`, where the gaps shown in the input preview above are filled:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/proteomics/protocol_example.protein.missing.bed.gz` | Toy molecular phenotype matrix in BED format (first four columns `#chr`/`start`/`end`/`ID`, remaining columns one per sample) with ~10% values set to missing (`NA`) so the imputation methods have gaps to fill. |\n" + " ```\n", + " #chr\tstart\tend\tID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMP\n", + " chr12\t752578\t752579\tchr12_ENSG00000060237_Q9H4A3\t0.238966360190167\t-0.611171227886468\t1.\n", + " chr12\t990508\t990509\tchr12_ENSG00000082805_Q8IUD2\t-0.762712503460405\t-1.86313205860919\t1.\n", + " ```\n", + "- `{cwd}/{phenoFile}.gEBMF_factors.rds` - the saved flashier factor object from a `gEBMF` fit, written only when `--save_flash True` is given. It is a binary R object, so it has no text preview; load it with `readRDS`. Example `output/phenotype_imputation_uf/protocol_example.protein.missing.bed.gEBMF_factors.rds`." ] }, { @@ -57,12 +73,9 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Minimal Working Example\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/phenotype_imputation_uf/protocol_example.protein.missing.bed.imputed.bed.gz` (+ `.tbi`) | Imputed molecular phenotype matrix in the same BED layout, bgzipped and tabix-indexed. |\n", - "| `output/phenotype_imputation_uf/protocol_example.protein.missing.bed.gEBMF_factors.rds` | Saved flashier factor object from the gEBMF fit (written only when `--save_flash True`). |\n" + "Eight imputation methods plus a filter that drops features too sparse to impute. Pick one method. Two practical notes for the toy data: `--num_factor` for the EBMF and gEBMF factor models must be smaller than the number of samples, which is 60 here, so the examples use `--num_factor 30`; and leave quality control enabled, that is do not pass `--no-qc-prior-to-impute`, so the QC matrix used for the output is available to every method." ] }, { @@ -71,23 +84,19 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "### Grouped Empirical Bayes Matrix Factorization (gEBMF)\n", "\n", - "The pipeline offers several imputation methods. Any one of them can be run on the toy file below; each writes an imputed BED next to the `--cwd` output directory. Two practical notes for the toy data:\n", - "\n", - "- `--num_factor` for the EBMF / gEBMF factor models must be smaller than the number of samples (the toy set has 60 samples), so the examples use `--num_factor 30`.\n", - "- Leave quality control enabled (do not pass `--no-qc-prior-to-impute`) so that the QC matrix used for the output is available to every method.\n" + "Grouped Empirical Bayes Matrix Factorization. Extends EBMF by fitting factors within row groups (here, by chromosome), so structure shared across molecular features in the same group is borrowed when filling in missing values. This is the recommended default for the protocol.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### gEBMF (grouped Empirical Bayes Matrix Factorization)\n", - "\n", - "Grouped Empirical Bayes Matrix Factorization. Extends EBMF by fitting factors within row groups (here, by chromosome), so structure shared across molecular features in the same group is borrowed when filling in missing values. This is the recommended default for the protocol.\n" + "**Timing**: TBD (on toy dataset)" ] }, { @@ -110,11 +119,21 @@ "kernel": "SoS" }, "source": [ - "### EBMF (Empirical Bayes Matrix Factorization)\n", + "### Empirical Bayes Matrix Factorization (EBMF)\n", "\n", "Empirical Bayes Matrix Factorization. Decomposes the phenotype matrix into a small number of latent factors with adaptive shrinkage priors, then reconstructs the matrix to impute missing entries. Captures global low-rank structure across all samples and features.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -140,6 +159,16 @@ "A non-parametric, iterative random-forest imputation. Each feature with missing values is predicted in turn from the other features using a random forest, repeating until the imputed values stabilize. Handles non-linear relationships but is computationally heavier.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -164,6 +193,16 @@ "Iterative imputation using gradient-boosted trees (XGBoost) as the per-feature predictor instead of random forests. Often faster and more accurate than missForest on large matrices while still modeling non-linear dependencies between features.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -188,6 +227,16 @@ "k-Nearest-Neighbours imputation. A missing entry is filled with a (distance-weighted) average of the corresponding values from the k most similar samples. Simple and fast, and works well when samples cluster into similar profiles.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -212,6 +261,16 @@ "Matrix-completion via iterative soft-thresholded singular value decomposition. Assumes the phenotype matrix is approximately low-rank and recovers missing entries by repeatedly shrinking the singular values. A good linear baseline for structured data.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -236,6 +295,16 @@ "Mean imputation. Each missing value is replaced by the mean of the observed values for that feature. The simplest baseline; fast but ignores correlations between samples and features.\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -260,6 +329,16 @@ "Limit-of-detection imputation. Missing values are replaced with a low constant derived from the smallest observed values, appropriate when missingness is driven by measurements falling below an assay's detection threshold (e.g., low-abundance proteins/metabolites).\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -273,6 +352,39 @@ " --cwd output/phenotype_imputation_uf\n" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Drop features that are too sparse to impute\n", + "\n", + "`bed_filter_na` removes rows whose missing fraction is above the threshold, so that the imputation methods are not asked to invent values for features with almost no data. Run it before a method rather than instead of one." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_imputation.ipynb bed_filter_na \\\n", + " --cwd output/phenotype_imputation_uf \\\n", + " --phenoFile input/proteomics/protocol_example.protein.missing.bed.gz" + ] + }, { "cell_type": "markdown", "metadata": { @@ -286,11 +398,11 @@ "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run phenotype_imputation.ipynb -h" + "sos run pipeline/phenotype_imputation.ipynb -h" ] }, { @@ -300,7 +412,7 @@ }, "source": [ "```\n", - "usage: sos run phenotype_imputation.ipynb\n", + "usage: sos run pipeline/phenotype_imputation.ipynb\n", " [workflow_name | -t targets] [options] [workflow_options]\n", " workflow_name: Single or combined workflows defined in this script\n", " targets: One or more targets to generate\n", @@ -319,6 +431,7 @@ " bed_filter_na\n", "\n", "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", " --cwd output (as path)\n", " Work directory & output directory\n", " --phenoFile VAL (as path, required)\n", @@ -334,6 +447,7 @@ " --numThreads 20 (as int)\n", " Number of threads\n", " --container ''\n", + " --entrypoint ''\n", "\n", "Sections\n", " EBMF:\n", @@ -361,8 +475,11 @@ " --lambda-hyp 30 (as int)\n", " --impute-method soft\n", " --tol-missing 0.05 (as float)\n", - " Tolerance of missingness rows with missing rate larger than tol_missing will be removed, with missing rate smaller than tol_missing will be mean_imputed. Say if\n", - " we want to keep rows with less than 5% missing, then we use 0.05 as tol_missing.\n", + " Tolerance of missingness rows with missing rate larger\n", + " than tol_missing will be removed, with missing rate\n", + " smaller than tol_missing will be mean_imputed. Say if we\n", + " want to keep rows with less than 5% missing, then we use\n", + " 0.05 as tol_missing.\n", "```" ] }, @@ -372,7 +489,7 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation" ] }, { @@ -629,40 +746,6 @@ " --tol-missing ${tol_missing} \\\n", " --numThreads ${numThreads}\n" ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS", - "tags": [], - "vscode": { - "languageId": "plaintext" - } - }, - "source": [ - "The resource usage for softimputing 450K methylation data are as followed:\n", - "\n", - "``` \n", - "time elapsed: 880.90s\n", - "peak first occurred: 152.11s\n", - "peak last occurred: 175.41s\n", - "max vms_memory: 38.95GB\n", - "max rss_memory: 34.35GB\n", - "memory check interval: 1s\n", - "return code: 0\n", - "```" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] } ], "metadata": { @@ -693,4 +776,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/data_preprocessing/phenotype_preprocessing.ipynb b/code/SoS/data_preprocessing/phenotype_preprocessing.ipynb index f76da6c36..a26996452 100644 --- a/code/SoS/data_preprocessing/phenotype_preprocessing.ipynb +++ b/code/SoS/data_preprocessing/phenotype_preprocessing.ipynb @@ -6,10 +6,11 @@ "kernel": "SoS" }, "source": [ - "# Phenotype Preprocessing\n", + "# Phenotype preprocessing\n", "\n", - "This notebook is a minimal working example (MWE) of the phenotype preprocessing section of the xQTL protocol. It chains the phenotype worker pipelines on the bundled toy dataset (60 samples, `protocol_example.*`) so the whole section runs end-to-end without editing." - ] + "Prepare molecular-phenotype matrices for xQTL analysis by imputing missing values when needed, adding genomic annotations, and formatting data for chromosome-, region-, TAD-, or sample-specific analyses.\n" + ], + "id": "4189c8e9" }, { "cell_type": "markdown", @@ -17,16 +18,13 @@ "kernel": "SoS" }, "source": [ - "## Description\n", - "\n", - "The phenotype preprocessing section takes a molecular phenotype matrix through genomic-coordinate annotation, missing-value imputation, and partition by chromosome, producing a BED-formatted phenotype ready for QTL association testing. It chains three worker pipelines:\n", + "#### Miniprotocol Timing\n", "\n", - "- `gene_annotation.ipynb` — add genomic coordinate annotation and convert to `.bed`\n", - "- `phenotype_imputation.ipynb` — impute missing values (gEBMF and other methods)\n", - "- `phenotype_formatting.ipynb` — partition the phenotype by chromosome\n", + "This is the total duration for the standard toy-data route; module-specific timings appear on their respective pages.\n", "\n", - "**Timing:** < 12 min for the toy dataset on a single node." - ] + "Timing: <12 min (on the toy dataset)\n" + ], + "id": "9baa6527" }, { "cell_type": "markdown", @@ -34,14 +32,13 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Overview\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `input/rnaseq/protocol_example.rnaseq.bed.gz` | Gene-level molecular phenotype matrix (60 samples) |\n", - "| `input/proteomics/protocol_example.protein.missing.bed.gz` | Protein phenotype with missing values (for imputation) |\n", - "| `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` | GENCODE/Ensembl gene coordinate annotation |" - ] + "This mini-protocol walks through how molecular-phenotype matrices are prepared for downstream xQTL analysis. Each step calls a workflow from [`phenotype_imputation.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_imputation.html), [`gene_annotation.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html), or [`phenotype_formatting.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html).\n", + "\n", + "The commands are selectable routes rather than one mandatory chain. Impute only matrices containing missing values. Choose the annotation workflow matching gene, protein, LeafCutter, or psichomics identifiers, then choose the formatting workflow required by the downstream analysis unit. GCT sample extraction and BAM subsetting are independent utilities.\n" + ], + "id": "416d15c6" }, { "cell_type": "markdown", @@ -49,14 +46,27 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "## Steps\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/rnaseq/protocol_example.rnaseq.bed.bed.gz` | Coordinate-annotated phenotype in BED format |\n", - "| `output/phenotype_imputation_uf/*.imputed.*` | Imputed phenotype matrix |\n", - "| `output/phenotype_uf/*.chr22.bed.gz` | Per-chromosome phenotype, ready for TensorQTL |" - ] + "Choose a route before running commands; the 12 commands are not one mandatory chain.\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Gene-expression or protein phenotype by chromosome | 2 \u2192 7 | `input/rnaseq/protocol_example.rnaseq.bed.gz`; `input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` |\n", + "| Phenotype with missing values by chromosome | 1 \u2192 2 \u2192 7 | `input/proteomics/protocol_example.protein.missing.bed.gz`; gene-coordinate GTF above |\n", + "| Retrieve gene coordinates from Ensembl BioMart | 3 | `input/rnaseq/protocol_example.rnaseq.gene_ID.tsv`; internet access |\n", + "| LeafCutter clusters mapped to genes | 4 | `input/rnaseq/protocol_example.leafcutter.phenotype.bed.gz`; `input/rnaseq/protocol_example.leafcutter.intron_count.tsv`; `input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf` |\n", + "| LeafCutter isoforms annotated for QTL analysis | 5 | `input/rnaseq/protocol_example.leafcutter.phenotype.bed.gz`; `input/rnaseq/protocol_example.leafcutter.intron_count.tsv`; `input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf` |\n", + "| psichomics isoforms annotated for QTL analysis | 6 | `input/rnaseq/protocol_example.psichomics.phenotype.tsv`; `input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf` |\n", + "| Partition a GCT matrix by chromosome | 8 | `input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz` |\n", + "| Partition a BED phenotype by predefined regions | 2 \u2192 9 | `input/rnaseq/protocol_example.rnaseq.bed.gz`; gene-coordinate GTF above; `input/reference_data/TAD/protocol_example_protein.enhanced_cis_chr22.bed` |\n", + "| Define TAD-based phenotype regions | 2 \u2192 10 | `input/rnaseq/protocol_example.rnaseq.bed.gz`; gene-coordinate GTF above; `input/reference_data/TAD/TADB_enhanced_cis.bed` |\n", + "| Extract selected samples from a GCT matrix | 11 | `input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz`; `input/colocboost/keep_samples.txt` |\n", + "| Subset BAM files to selected genomic regions | 12 | `input/rnaseq/bam_file_list.txt`; referenced BAM files; no example BAM is currently bundled |\n", + "\n", + "Run only the row matching the intended analysis goal, following its commands in numerical order. Other imputation methods are available through `phenotype_imputation.ipynb` and its Command Interface." + ], + "id": "6628e5e0" }, { "cell_type": "markdown", @@ -64,10 +74,26 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "### 1. [Impute missing phenotype values](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_imputation.html)\n", "\n", - "Run the commands below in order from the toy example root. Each one invokes the corresponding worker pipeline through the `pipeline/` symlinks." - ] + "**What it does:** Use generalized empirical Bayes matrix factorization to complete the example protein matrix.\n" + ], + "id": "a7c33119" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_imputation.ipynb gEBMF \\\n", + " --phenoFile input/proteomics/protocol_example.protein.missing.bed.gz \\\n", + " --cwd output/phenotype_imputation_uf \\\n", + " --num_factor 30\n" + ], + "id": "c79f6386" }, { "cell_type": "markdown", @@ -75,10 +101,11 @@ "kernel": "SoS" }, "source": [ - "### Annotate phenotype with genomic coordinates\n", + "### 2. [Add genomic coordinates to gene or protein phenotypes](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", "\n", - "Add gene-level genomic coordinates to the molecular phenotype matrix and convert it to BED format, using the gene annotation GTF." - ] + "**What it does:** Join phenotype identifiers to a supplied coordinate annotation and write a coordinate-aware BED matrix.\n" + ], + "id": "6c5a94f3" }, { "cell_type": "code", @@ -89,11 +116,12 @@ "outputs": [], "source": [ "sos run pipeline/gene_annotation.ipynb annotate_coord \\\n", - " --cwd output/rnaseq \\\n", + " --cwd output/gene_annotation \\\n", " --phenoFile input/rnaseq/protocol_example.rnaseq.bed.gz \\\n", " --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", - " --phenotype-id-column gene_id" - ] + " --phenotype-id-column gene_id\n" + ], + "id": "dc78fd7a" }, { "cell_type": "markdown", @@ -101,10 +129,11 @@ "kernel": "SoS" }, "source": [ - "### Impute missing values\n", + "### 3. [Retrieve gene coordinates from Ensembl BioMart](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", "\n", - "Impute missing entries in the phenotype matrix. Here the gEBMF (greedy Empirical Bayes Matrix Factorization) method is used on the toy protein phenotype; other methods (EBMF, missForest, missXGBoost, knn, soft, mean, lod) are also available in the worker pipeline." - ] + "**What it does:** Query the selected Ensembl release when a local coordinate annotation is unavailable.\n" + ], + "id": "4a64a987" }, { "cell_type": "code", @@ -114,11 +143,12 @@ }, "outputs": [], "source": [ - "sos run pipeline/phenotype_imputation.ipynb gEBMF \\\n", - " --phenoFile input/proteomics/protocol_example.protein.missing.bed.gz \\\n", - " --cwd output/phenotype_imputation_uf \\\n", - " --num_factor 30" - ] + "sos run pipeline/gene_annotation.ipynb annotate_coord_biomart \\\n", + " --cwd output/gene_annotation \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.gene_ID.tsv \\\n", + " --ensembl-version 115\n" + ], + "id": "7401792f" }, { "cell_type": "markdown", @@ -126,10 +156,28 @@ "kernel": "SoS" }, "source": [ - "### Partition phenotype by chromosome\n", + "### 4. [Map LeafCutter clusters to genes](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", "\n", - "Split the annotated phenotype into per-chromosome files (here chromosome 22), the format expected by the QTL association steps." - ] + "**What it does:** Assign LeafCutter clusters to genes using splice-site overlap with the gene annotation.\n" + ], + "id": "e7409492" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb map_leafcutter_cluster_to_gene \\\n", + " --cwd output/gene_annotation \\\n", + " --phenoFile input/rnaseq/protocol_example.leafcutter.phenotype.bed.gz \\\n", + " --intron-count input/rnaseq/protocol_example.leafcutter.intron_count.tsv \\\n", + " --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf \\\n", + " --map-stra site\n" + ], + "id": "355635fc" }, { "cell_type": "markdown", @@ -137,10 +185,67 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", + "### 5. [Annotate LeafCutter isoforms](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] + "**What it does:** Convert LeafCutter intron-cluster phenotypes into annotated isoform features for QTL analysis.\n" + ], + "id": "16afacb2" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb annotate_leafcutter_isoforms \\\n", + " --cwd output/gene_annotation \\\n", + " --phenoFile input/rnaseq/protocol_example.leafcutter.phenotype.bed.gz \\\n", + " --intron-count input/rnaseq/protocol_example.leafcutter.intron_count.tsv \\\n", + " --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf \\\n", + " --map-stra site\n" + ], + "id": "72809d29" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 6. [Annotate psichomics isoforms](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", + "\n", + "**What it does:** Add genomic and gene annotations to psichomics-derived splicing phenotypes.\n" + ], + "id": "acfd2814" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb annotate_psichomics_isoforms \\\n", + " --cwd output/gene_annotation \\\n", + " --phenoFile input/rnaseq/protocol_example.psichomics.phenotype.tsv \\\n", + " --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.gtf\n" + ], + "id": "e6d20f6d" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 7. [Partition a BED phenotype by chromosome](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Split a coordinate-annotated BED phenotype into chromosome-specific files.\n" + ], + "id": "557f48cf" }, { "cell_type": "code", @@ -151,11 +256,213 @@ "outputs": [], "source": [ "sos run pipeline/phenotype_formatting.ipynb phenotype_by_chrom \\\n", - " --cwd output/phenotype/phenotype_by_chrom_for_cis \\\n", - " --phenoFile output/rnaseq/protocol_example.rnaseq.bed.bed.gz \\\n", - " --name bulk_rnaseq \\\n", - " --chrom chr22" - ] + " --cwd output/phenotype_uf \\\n", + " --phenoFile output/gene_annotation/protocol_example.rnaseq.bed.bed.gz \\\n", + " --name protocol_example \\\n", + " --chrom chr22\n" + ], + "id": "7c3143df" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 8. [Partition a GCT phenotype by chromosome](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Split a coordinate-aware GCT matrix into chromosome-specific GCT files.\n" + ], + "id": "ff8a1cbe" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_by_chrom_gct \\\n", + " --cwd output/phenotype_gct \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz \\\n", + " --chrom chr21 chr22\n" + ], + "id": "7f114e77" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 9. [Partition a phenotype by predefined regions](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Extract phenotype features falling within each region in a supplied region list.\n" + ], + "id": "90267404" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_by_region \\\n", + " --cwd output/phenotype_by_region \\\n", + " --phenoFile output/gene_annotation/protocol_example.rnaseq.bed.bed.gz \\\n", + " --region-list input/reference_data/TAD/protocol_example_protein.enhanced_cis_chr22.bed\n" + ], + "id": "cb9b0cde" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 10. [Define TAD-based phenotype regions](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Assign phenotype features to TAD windows and generate a region list for downstream analysis.\n" + ], + "id": "cfce416b" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb phenotype_annotate_by_tad \\\n", + " --cwd output/phenotype_by_region \\\n", + " --phenoFile output/gene_annotation/protocol_example.rnaseq.bed.bed.gz \\\n", + " --TAD-list input/reference_data/TAD/TADB_enhanced_cis.bed \\\n", + " --phenotype-per-tad 2\n" + ], + "id": "107d5715" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 11. [Extract selected samples from a GCT matrix](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Retain only samples listed in a supplied keep file.\n" + ], + "id": "03c6b4ce" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb gct_extract_samples \\\n", + " --cwd output/phenotype_gct \\\n", + " --phenoFile input/rnaseq/protocol_example.rnaseq.gene_tpm.gct.gz \\\n", + " --keep-samples input/colocboost/keep_samples.txt\n" + ], + "id": "addabe04" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 12. [Subset BAM files by genomic region](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_formatting.html)\n", + "\n", + "**What it does:** Extract selected chromosomes or regions from every BAM listed in the input manifest.\n" + ], + "id": "720706d3" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_formatting.ipynb bam_subsetting \\\n", + " --cwd output/bam_subset \\\n", + " --phenoFile input/rnaseq/bam_file_list.txt \\\n", + " --region chr21 chr22\n" + ], + "id": "d5c0f358" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Route or step | Products and relative paths |\n", + "| --- | --- |\n", + "| Step 1 | `output/phenotype_imputation_uf/protocol_example.protein.missing.bed.imputed.bed.gz` |\n", + "| Step 2 | `output/gene_annotation/protocol_example.rnaseq.bed.bed.gz`; `output/gene_annotation/protocol_example.rnaseq.bed.region_list.txt` |\n", + "| Step 3 | `output/gene_annotation/protocol_example.rnaseq.gene_ID.bed.gz` |\n", + "| Step 4 | `output/gene_annotation/protocol_example.leafcutter.phenotype.bed.gz.exon_list`; `output/gene_annotation/protocol_example.leafcutter.phenotype.bed.gz.leafcutter.clusters_to_genes.txt` |\n", + "| Step 5 | `output/gene_annotation/protocol_example.leafcutter.phenotype.bed.formated.bed.gz`; `output/gene_annotation/protocol_example.leafcutter.phenotype.phenotype_group.txt` |\n", + "| Step 6 | `output/gene_annotation/protocol_example.psichomics.phenotype.formated.bed.gz`; `output/gene_annotation/protocol_example.psichomics.phenotype.phenotype_group.txt` |\n", + "| Step 7 | `output/phenotype_uf/protocol_example.chr22.bed.gz`; `output/phenotype_uf/protocol_example.phenotype_by_chrom_files.txt`; its region list |\n", + "| Step 8 | `output/phenotype_gct/protocol_example.rnaseq.gene_tpm.chr21.gct`; `output/phenotype_gct/protocol_example.rnaseq.gene_tpm.chr22.gct` |\n", + "| Step 9 | `output/phenotype_by_region/protocol_example_protein.enhanced_cis_chr22_phenotype_by_region/*.bed.gz`; `output/phenotype_by_region/*.phenotype_by_region_files.txt` |\n", + "| Step 10 | `output/phenotype_by_region/*_pheno_per_region.region_list`; TAD-annotated region list under `output/phenotype_by_region/` |\n", + "| Step 11 | `output/phenotype_gct/protocol_example.rnaseq.gene_tpm.sample_matched.gct.gz` |\n", + "| Step 12 | `output/bam_subset/*.subsetted.bam` |" + ], + "id": "48f58267" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", + "\n", + "The selected route produces a molecular-phenotype matrix with the genomic annotation and layout required by its downstream xQTL analysis. Standard gene-expression routes typically end with chromosome-specific BED files; splicing routes end with gene- or isoform-annotated phenotypes; region and TAD routes end with per-region files and their manifest.\n", + "\n", + "Continue with covariate preprocessing and then the appropriate association-testing workflow.\n" + ], + "id": "c7bd9755" + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface\n", + "\n", + "List the workflows and parameters available in each module used by this mini-protocol.\n" + ], + "id": "08582e7a" + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_imputation.ipynb -h\n", + "sos run pipeline/gene_annotation.ipynb -h\n", + "sos run pipeline/phenotype_formatting.ipynb -h\n" + ], + "id": "a71cd0bd" } ], "metadata": { @@ -193,5 +500,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 -} + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/enrichment/enrichment_validation.ipynb b/code/SoS/enrichment/enrichment_validation.ipynb new file mode 100644 index 000000000..4e03b858e --- /dev/null +++ b/code/SoS/enrichment/enrichment_validation.ipynb @@ -0,0 +1,539 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "04a8e344", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "# Enrichment and functional validation mini-protocol\n", + "Evaluate prioritized genes and variants using pathway, genomic-annotation, and heritability-enrichment analyses." + ] + }, + { + "cell_type": "markdown", + "id": "3f291c0c", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Miniprotocol Timing\n", + "This is the total duration for the selected route; module-specific timings appear on their respective pages.\n", + "Timing: TBD" + ] + }, + { + "cell_type": "markdown", + "id": "88fb2296", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", + "This mini-protocol provides alternative functional follow-up routes. Step 1 calls [`gsea.ipynb`](https://statfungen.github.io/xqtl-protocol/code/enrichment/gsea.html), step 2 calls [`eoo_enrichment.ipynb`](https://statfungen.github.io/xqtl-protocol/code/enrichment/eoo_enrichment.html), steps 3\u20135 call [`gregor.ipynb`](https://statfungen.github.io/xqtl-protocol/code/enrichment/gregor.html), and steps 6\u20139 call [`sldsc_enrichment.ipynb`](https://statfungen.github.io/xqtl-protocol/code/enrichment/sldsc_enrichment.html).\n", + "Pathway analysis, enrichment-over-odds, GREGOR, and S-LDSC use different inputs and null models. Select the route matching the scientific question; only the numbered commands within the GREGOR and S-LDSC routes form ordered chains." + ] + }, + { + "cell_type": "markdown", + "id": "457c0bdf", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Steps\n", + "Choose a route before running commands; the commands are not one mandatory chain.\n", + "\n", + "| Analysis goal | Commands to run, in order | Inputs |\n", + "|---|---:|---|\n", + "| Test pathway and GO-term enrichment of gene groups | 1 | `input/enrichment/protocol_example.pathway_genes.tsv` |\n", + "| Test annotation enrichment using variant-level odds | 2 | `input/enrichment/protocol_example.eoo_significant_variants.tsv.gz`; `input/enrichment/protocol_example.eoo_baseline_annotation.tsv` |\n", + "| Test overlap of index SNPs with genomic annotations using matched controls | 3 \u2192 4 \u2192 5 | `input/ld/protocol_example.index.snps.txt`; `input/enrichment/protocol_example.bed.file.index`; `input/enrichment/protocol_example.gregor_ref` |\n", + "| Partition GWAS heritability across annotations | 6 \u2192 7 \u2192 8 | `input/enrichment/sldsc/colocboost_test_annotation_path.txt`; `input/enrichment/sldsc/reference_annotation0.txt`; `input/enrichment/sldsc/genome_reference_bfile.txt`; `input/enrichment/sldsc/sumstats_test_all.txt` |\n", + "| Re-meta-analyze a selected subset of S-LDSC traits | 8 \u2192 9 | `output/sldsc_postprocess/protocol_example.sldsc_postprocess.rds`; `input/enrichment/sldsc/sumstats_test_category1.txt` |\n", + "\n", + "Run only the route appropriate for the scientific question. GREGOR steps 3\u20135 and S-LDSC steps 6\u20138 are ordered workflows; step 9 is an optional follow-up." + ] + }, + { + "cell_type": "markdown", + "id": "29ba5b87", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 1. [Test pathway and GO enrichment](https://statfungen.github.io/xqtl-protocol/code/enrichment/gsea.html)\n", + "\n", + "**What it does:** Maps grouped genes to ENTREZ identifiers and tests KEGG and GO BP/CC/MF over-representation for each group." + ] + }, + { + "cell_type": "markdown", + "id": "6e5ecb92", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3599443d", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gsea.ipynb pathway_analysis \\\n", + " --genes_file input/enrichment/protocol_example.pathway_genes.tsv \\\n", + " --name protocol_example \\\n", + " --pvalue_cutoff 1 --organism hsa \\\n", + " --cwd output/gsea" + ] + }, + { + "cell_type": "markdown", + "id": "a14ba77d", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 2. [Estimate enrichment over odds](https://statfungen.github.io/xqtl-protocol/code/enrichment/eoo_enrichment.html)\n", + "\n", + "**What it does:** Estimates annotation odds ratios and enrichment with chromosome block-jackknife uncertainty." + ] + }, + { + "cell_type": "markdown", + "id": "9aa362ed", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f7bfbd12", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/eoo_enrichment.ipynb enrichment \\\n", + " --significant_variants_path input/enrichment/protocol_example.eoo_significant_variants.tsv.gz \\\n", + " --baseline_anno_path input/enrichment/protocol_example.eoo_baseline_annotation.tsv \\\n", + " --trait protocol_example \\\n", + " --annotation-name baseline \\\n", + " --cwd output/eoo_enrichment" + ] + }, + { + "cell_type": "markdown", + "id": "2792f907", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 3. [Create a GREGOR configuration](https://statfungen.github.io/xqtl-protocol/code/enrichment/gregor.html)\n", + "\n", + "**What it does:** Writes the configuration connecting index SNPs, annotation BED files, population settings, and the GREGOR reference database." + ] + }, + { + "cell_type": "markdown", + "id": "ee641232", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dbc59c74", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gregor.ipynb gregor_conf \\\n", + " --gregor_db input/enrichment/protocol_example.gregor_ref \\\n", + " --index_snp_file input/ld/protocol_example.index.snps.txt \\\n", + " --bed_file_index input/enrichment/protocol_example.bed.file.index \\\n", + " --pop EUR \\\n", + " --cwd output/gregor" + ] + }, + { + "cell_type": "markdown", + "id": "744b6b9e", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 4. [Run GREGOR enrichment](https://statfungen.github.io/xqtl-protocol/code/enrichment/gregor.html)\n", + "\n", + "**What it does:** Compares annotation overlap for index SNPs with overlap among LD- and frequency-matched control variants." + ] + }, + { + "cell_type": "markdown", + "id": "64a0fbe7", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d02841c6", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gregor.ipynb gregor \\\n", + " --gregor_db input/enrichment/protocol_example.gregor_ref \\\n", + " --index_snp_file input/ld/protocol_example.index.snps.txt \\\n", + " --bed_file_index input/enrichment/protocol_example.bed.file.index \\\n", + " --pop EUR \\\n", + " --cwd output/gregor" + ] + }, + { + "cell_type": "markdown", + "id": "75dd60d5", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 5. [Plot GREGOR Fisher enrichment](https://statfungen.github.io/xqtl-protocol/code/enrichment/gregor.html)\n", + "\n", + "**What it does:** Compares annotation odds ratios from two GREGOR result sets." + ] + }, + { + "cell_type": "markdown", + "id": "67ff5909", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3140197", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gregor.ipynb gregor_fisher_plot \\\n", + " --fisher1 input/enrichment/protocol_example.trait1_enrichment_results.txt \\\n", + " --fisher2 input/enrichment/protocol_example.trait2_enrichment_results.txt \\\n", + " --cwd output/gregor" + ] + }, + { + "cell_type": "markdown", + "id": "d3b0606c", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 6. [Build annotation LD scores](https://statfungen.github.io/xqtl-protocol/code/enrichment/sldsc_enrichment.html)\n", + "\n", + "**What it does:** Converts genomic annotations into chromosome-level annotation and LD-score files for stratified LD-score regression." + ] + }, + { + "cell_type": "markdown", + "id": "d3a1b8e5", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9cbb86f", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/sldsc_enrichment.ipynb make_annotation_files_ldscore \\\n", + " --annotation_file input/enrichment/sldsc/colocboost_test_annotation_path.txt \\\n", + " --reference_anno_file input/enrichment/sldsc/reference_annotation0.txt \\\n", + " --genome_ref_file input/enrichment/sldsc/genome_reference_bfile.txt \\\n", + " --annotation_name protocol_example \\\n", + " --plink_name reference. --baseline_name annotations. --weight_name weights. \\\n", + " --cwd output/sldsc_ldscore -j 4\n" + ] + }, + { + "cell_type": "markdown", + "id": "6a54b97a", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 7. [Estimate stratified SNP heritability](https://statfungen.github.io/xqtl-protocol/code/enrichment/sldsc_enrichment.html)\n", + "\n", + "**What it does:** Runs S-LDSC for each trait and annotation target to estimate annotation-specific heritability enrichment." + ] + }, + { + "cell_type": "markdown", + "id": "be08e2ff", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "42145dab", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/sldsc_enrichment.ipynb get_heritability \\\n", + " --target_anno_dirs output/sldsc_ldscore/protocol_example_single_1 \\\n", + " --all_traits_file input/enrichment/sldsc/sumstats_test_all.txt \\\n", + " --sumstat_dir input/enrichment/sldsc \\\n", + " --baseline_ld_dir input/enrichment/sldsc \\\n", + " --weights_dir input/enrichment/sldsc \\\n", + " --plink_name reference. --baseline_name annotations. --weight_name weights. \\\n", + " --annotation_name protocol_example \\\n", + " --maf_cutoff 0 --cwd output/sldsc_heritability -j 4\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "id": "302f7aaf", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 8. [Postprocess and meta-analyze S-LDSC results](https://statfungen.github.io/xqtl-protocol/code/enrichment/sldsc_enrichment.html)\n", + "\n", + "**What it does:** Standardizes per-trait results and computes random-effects meta-analyses across traits." + ] + }, + { + "cell_type": "markdown", + "id": "8118eb74", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7a141410", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/sldsc_enrichment.ipynb postprocess \\\n", + " --traits_file input/enrichment/sldsc/sumstats_test_all.txt \\\n", + " --heritability_cwd output/sldsc_heritability \\\n", + " --target_categories ANNOT_0 --target_categories_label protocol_example_annotation \\\n", + " --target_anno_dir output/sldsc_ldscore/protocol_example_single_1 \\\n", + " --annotation_name protocol_example \\\n", + " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4\n" + ] + }, + { + "cell_type": "markdown", + "id": "be7580d5", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 9. [Re-meta-analyze a trait subset](https://statfungen.github.io/xqtl-protocol/code/enrichment/sldsc_enrichment.html)\n", + "\n", + "**What it does:** Reuses postprocessed S-LDSC results to estimate enrichment for a selected subset without rerunning regression." + ] + }, + { + "cell_type": "markdown", + "id": "c1e0a694", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9293044", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/sldsc_enrichment.ipynb meta_subset \\\n", + " --postprocess_rds output/sldsc_postprocess/protocol_example.sldsc_postprocess.rds \\\n", + " --subset_traits_file input/enrichment/sldsc/sumstats_test_category1.txt \\\n", + " --subset_name category1 --target_categories ANNOT_0 \\\n", + " --annotation_name protocol_example \\\n", + " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4" + ] + }, + { + "cell_type": "markdown", + "id": "f945efcd", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Step | Relative path | Contents |\n", + "|---:|---|---|\n", + "| 1 | `output/gsea/pathway_analysis/protocol_example.combined_pathway_results.rds` | Standardized KEGG and GO enrichment results for all gene groups |\n", + "| 2 | `output/eoo_enrichment/enrichment/protocol_example.baseline.enrichment_results.rds` | Odds ratios, enrichment estimates, and block-jackknife uncertainty |\n", + "| 3 | `output/gregor/protocol_example.index.gregor.conf` | GREGOR configuration |\n", + "| 4 | `output/gregor/_gregor_output/StatisticSummaryFile.txt` | Raw GREGOR overlap statistics |\n", + "| 4 | `output/gregor/_variant_counts.txt` | Parsed annotation overlap counts |\n", + "| 4 | `output/gregor/_enrichment_results.txt` | Fisher-test enrichment estimates |\n", + "| 5 | `output/gregor/_vs__enrichment.pdf` | GREGOR odds-ratio comparison |\n", + "| 6 | `output/sldsc_ldscore//*.{annot.gz,l2.ldscore.parquet,l2.M}` | Annotation and LD-score products |\n", + "| 7 | `output/sldsc_heritability//.results` | Trait- and annotation-specific S-LDSC results |\n", + "| 8 | `output/sldsc_postprocess/.sldsc_postprocess.rds` | Per-trait results and cross-trait meta-analysis |\n", + "| 9 | `output/sldsc_postprocess/*` | Trait-subset meta-analysis tables |" + ] + }, + { + "cell_type": "markdown", + "id": "b30bbec7", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", + "\n", + "Pathway analysis summarizes biological processes represented by prioritized genes. Enrichment-over-odds and GREGOR test whether prioritized variants overlap functional annotations more than expected under their respective background models. S-LDSC tests whether GWAS heritability is disproportionately concentrated in annotations while accounting for LD.\n", + "\n", + "Interpret enrichment in light of the selected background, annotation coverage, population-matched reference data, multiple testing, and uncertainty. Enrichment supports functional relevance but does not by itself validate a causal gene, variant, or mechanism." + ] + }, + { + "cell_type": "markdown", + "id": "9da187fe", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d0ad6a66", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gsea.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee662ec8", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/eoo_enrichment.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "044f27f1", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gregor.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8859ff76", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/sldsc_enrichment.ipynb -h" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SoS", + "language": "sos", + "name": "sos" + }, + "language_info": { + "codemirror_mode": "sos", + "file_extension": ".sos", + "mimetype": "text/x-sos", + "name": "sos", + "nbconvert_exporter": "sos_notebook.converter.SoS_Exporter", + "pygments_lexer": "sos" + }, + "sos": { + "kernels": [ + [ + "SoS", + "sos", + "sos", + "", + "" + ] + ], + "version": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/enrichment/eoo_enrichment.ipynb b/code/SoS/enrichment/eoo_enrichment.ipynb index dc7a9fc08..c5eec7bc2 100644 --- a/code/SoS/enrichment/eoo_enrichment.ipynb +++ b/code/SoS/enrichment/eoo_enrichment.ipynb @@ -6,16 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Chromosome-Specific Enrichment Analysis of Annotations Using Block Jackknife" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" + "# Chromosome-Specific Enrichment Analysis of Annotations Using Block Jackknife\n", + "\n", + "Tests how strongly a set of significant variants overlaps a genomic annotation relative to the genome, with block-jackknife standard errors." ] }, { @@ -24,7 +17,13 @@ "kernel": "SoS" }, "source": [ - "Chromosome-specific enrichment analysis for genomic annotations using a block jackknife. For each annotation it computes an odds ratio (OR) and an enrichment statistic, leaving out one chromosome at a time to obtain block-jackknife standard errors. This quantifies how strongly significant variants overlap each annotation relative to the genome.\n" + "## Overview\n", + "\n", + "A variant set that overlaps an annotation more often than chance would predict is evidence that the annotation marks functional sequence. Counting the overlap is easy; putting an error bar on it is not, because variants are correlated along the genome and so cannot be resampled independently.\n", + "\n", + "This module computes an odds ratio and an enrichment statistic for each annotation, then leaves out one chromosome at a time and recomputes, using the spread across those 22 leave-one-out estimates as a block-jackknife standard error. Blocking by chromosome keeps correlated variants together rather than splitting them across resamples.\n", + "\n", + "**When to run it.** Run this module after chromosome-level enrichment inputs are available when a combined enrichment estimate and block-jackknife standard error are needed.\n" ] }, { @@ -36,7 +35,7 @@ } }, "source": [ - "## Definitions and Test Statistics\n", + "### Definitions and test statistics\n", "\n", "### Odds Ratio (OR)\n", "Strength of association between significant variants and an annotation:\n", @@ -55,8 +54,7 @@ "### Standard Error (LOCO block jackknife)\n", "Standard errors are estimated by removing one chromosome at a time and recomputing the statistic, capturing variability due to genomic structure. With $\\theta_i$ the statistic ($OR_i$ or $\\text{Enrichment}_i$) excluding chromosome $i$, $\\bar{\\theta}$ its mean, and $N$ the number of chromosomes (22 for autosomes):\n", "\n", - "$$\\text{SE}(\\theta) = \\sqrt{\\frac{\\sum_{i=1}^{N} (\\theta_i - \\bar{\\theta})^2}{N \\cdot (N-1)}}$$\n", - "" + "$$\\text{SE}(\\theta) = \\sqrt{\\frac{\\sum_{i=1}^{N} (\\theta_i - \\bar{\\theta})^2}{N \\cdot (N-1)}}$$\n" ] }, { @@ -68,14 +66,14 @@ }, "outputs": [ { - "output_type": "display_data", - "metadata": {}, "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAACEkAAAaHCAYAAACDgqBnAAAAOnRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjEwLjgsIGh0dHBzOi8vbWF0cGxvdGxpYi5vcmcvwVt1zgAAAAlwSFlzAAAXEgAAFxIBZ5/SUgABAABJREFUeJzs3Qd4XGeZ9vF7inrvlmzZcu/djhM7vfeEJISWQGBZOsvC7sLusvXbZQsLy9JDCYQACYGEBKd3J7ZT3HsvsixZvXdpyne970iyyows2erz//k618ycc2bm6MxodDzvfZ7H4ff7/QIAAAAAAAAAAAAAAJjgnKO9AQAAAAAAAAAAAAAAACOBkAQAAAAAAAAAAAAAAAgLhCQAAAAAAAAAAAAAAEBYICQBAAAAAAAAAAAAAADCAiEJAAAAAAAAAAAAAAAQFghJAAAAAAAAAAAAAACAsEBIAgAAAAAAAAAAAAAAhAVCEgAAAAAAAAAAAAAAICwQkgAAAAAAAAAAAAAAAGGBkAQAAAAAAAAAAAAAAAgLhCQAAAAAAAAAAAAAAEBYICQBAAAAAAAAAAAAAADCAiEJAAAAAAAAAAAAAAAQFghJAAAAAAAAAAAAAACAsEBIAgAAAAAAAAAAAAAAhAVCEgAAAAAAAAAAAAAAICwQkgAAAAAAAAAAAAAAAGGBkAQAAAAAAAAAAAAAAAgLhCQAAAAAAAAAAAAAAEBYICQBAAAAAAAAAAAAAADCAiEJAAAAAAAAAAAAAAAQFghJAAAAAAAAAAAAAACAsEBIAgA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5/ouquv1N/99V8qPS11RLfnnjtv04M/f1jVNTVd8w4dOapnnn9Jd9x604huCwAAAAAMNU7zAAAAADCh7N1/QHfce5894zVUQCIUn8+njZvf0a8f+/2wbR8wFv3+j0/rzz77pZCD1OfS2Nik1tY2hbMf/OTnfebdeN01ykhPH9TjHDp8VEeOHj/neuuff1ETwVh47/3koYfV0tKqscb8TXrp1dd15wfut++LkRQVFaX333V7n/k//vkvbcgQAAAAAMYzQhIAAAAAJoyn1j+nj/7554etDQUwEZkKCP/+3/9r2x3g/GzfuTtoW4XzqU4w0PDDi6+81qe1x3gzVt57pkLFo78fuy2Gampr9akvflkVFZUj+rz33nVnn9YapvLGcy+9MqLbAQAAAABDjXYbAAAAACaEtza/o3/5j2/akuWhJCcl6eKLViknO0sx0TF24KnoTLF27NqtuvoGjSemX3xDQ+htNgNZTzz9TNBl119zpRbMmxvyvvHx8UOyjRgf/uf/fmDPWA9mwbw5WrxwgdLT0uztuvp6FRUX27PaCSOd9cijj/fZd9OnTR10Owzz+fX8S68OaN26unrbdsK0YxivxtJ776FHfqv333WHEkbg8y8xId5+hncyGZGq6mptfneLTpzMD3qfquoafffHP9W//ePfaaRMysrUmtUr9c57W3vM/81jf9Adt9ByAwAAAMD4RUgCAAAAwLhXUFikv/n6P4cMSKSmpugvP/9p3XnrzX3OijXMIN27W7fr0cef6NHrfiw71xnqW7bvCBmSuHzdWt15283DtGUYb787+w8e6jM/KipS3//2f2vtmtUh71tcUqINb23W8y+/qp279ypclZaV6423NvWZf/MN1w36scwgeUXlwKsFrH/uxXEbkhhr773a2jr98teP6i8++ykNNxNE++QD9/eZbypq/PAnD+nBhx4Oer/nXnxFf/fXf6nYmBiNlFtvvL5PSOLg4SPatWffoENAAAAAADBWEJIAAAAAMO794MGf2b70wUzJydbPfvh/yp0yOeT9TXDCDMiZaev2nXr7vS1Dtm2LVl8adP4vHvyeLlq5QuNBu8ej48dPav+hwzp46LCOn8xXWXm5qqpq1NLaKr/Pp9i4WCXGx2v69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AAAAAAAgLRAkgQAAAAAAAAAAAAAAEgLJEkAAAAAAAAAAAAAAIC0QJIEAAAAAAAAAAAAAABICyRJAAAAAAAAAAAAAACAtECSBAAAAAAAAAAAAAAASAskSQAAAAAAAAAAAAAAgLRAkgQAAAAAAAAAAAAAAEgLJEkAAAAAAAAAAAAAAIC0QJIEAAAAAAAAAAAAAABICyRJAAAAAAAAAAAAAACAtECSBAAAAAAAAAAAAAAASAskSQAAAAAAAAAAAAAAgLRAkgQAAAAAAAAAAAAAAEgLJEkAAAAAAAAAAAAAAIC0QJIEAAAAAAAAAAAAAABICyRJAAAAAAAAAAAAAACAtECSBAAAAAAAAAAAAAAASAtlL/cKAAAAfN1OnjxlU2fPtrUbN9rho0ft/PnzVjMz05549JFieTBefutt27pjh917663WukVzK4kuXLhgcxcttmWrVtm+gwft7Nmz7v//6ZvftGpVqxTY52zYvNlef3+MNapf375x7z12uT353PN29Ngx++7DD1ntmjVz/XzxihW2cNky27tvv50+c8b938Oj77J9Bw7YJ19MtE7t2trt119/GdYcRb3toPhJh2t9qg4ePmx/fvElq1ihgv3r975rRdG5c+fsV39+2r3+6RPfs3Llyl3uVSpxvpoxw6bPmWv9e/a0UUOHXO7VKdZWr19vcxctsp2797jni4sXL9qt115jXTp0uNyrltZ0Hfn108+45+Kffv8JK1+EryPF5Tnkpbfesm07dtq9t91qrZtfurcuXLrMPpmoZ+l2dvv1113WdQQAAEDhIEkCAACkFSVE/P2992z33r1WoXx5q1e7tpUpU8aaNGpoRdHSlavswKFDLthdp1atqL+zZ/9+971u7dpWUn321SRbsHSplS5d2u0HdQorwFSQCRKye9++IrMvlcyjzmW1TyXxRJoxd559OX26e619ouCg1KtTx1auXlNktiMVSog5cfKk9ezaxapWSe0YK1FEbWbT1m126MgRF1ioXKmSVc3IsEYNGliLJk2sXetWVqpUqdB7ps+da19Nn+Fe161Vy7790INxg50KGj3+wP1un3vLs7JszKef5XpP2TJlrEZmdWvfuo0N7NO7UAMbebUdFN71OFXpeK0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3nMuE/d8VFVkv49e4YCU3Lg4CEXuA/+X9ztiNF2gtuoa2HHNm3cOeWPq4Koah865xTESabctz5L56s69YOBHXXmvzdunAs2LVy+PKxqgAJTasui67JGuaoSi29/0+bMdUFataHIJAkfAFZyhIJPjz/wQGiaBSWhvPz2224/r1izxvr16BF6nwIXSnbS+5UEc93IES6QLkr8UUKQgjRfzZhh140YkdT1OJX9UNKu9QlXkViQU0Wid/6rSASveQqG6dqvoL4SDn170HHVMZ8wZYoLvAWp/d97661uH5Qrd+nad+rUKfv4i4kuuXH2/AV27Ygrw96nqg+qhqH3X3vlcLeP/HVG66DjHBw9HW1Usq65CkzpmtKhTWu7+eqrw85zXWfe+Whszs/buHuZP1/Xb9psb330kQukRw+WZe8TBcN1HdW57gOtui/q+qRzUOe8vuseqfLvfvnap0pIUPKcrvWaoujS/s7elgYxkhF0nikYHy9Ammy7cwl7H3zoAqo9unS2EYMHW6WcYOeyVatcgoO/diRTScJfS7S9SkjRfccH4oOJdoV1busz3v1knNteveea4cND92XtRyXQqKrSp19+5RIlEpXKdUHXWd07fvPMs+7f99x6S1ggNRFqx3p2jkyO0X1F7VXPunodrPLj26qCt6oAo8RL3X99wuP748a5a/2iZctzJ3uleE9z7fuDD925quCvqjT4Z3IFhd/68EMXrG/bqmWoco/uzapi9punn3FtQJ8VawqVZPdDosu+lCxXt0Ces9X+VMVF9CzXu3s3V5XFP+P6c0ttMLvqWHiCQXF/DtF9VfdXrWNk5Qc/hVMylSQyc65lut5/NH6C258N6tVLKNnD7xeflKFzQMdM1SmCSRL+OVPndmQSaOQyIqlNq634pPxU/14CAAAoSaiVBQAA0kaowytK55HvdBIFRNVZHAwo+Y5yBdQUyA0GjEUdcurk1O8poKHOQU9BGnVA6f9uueaa7HLugUCI3qMASIe2bUL/p04sjdyJtb7BdVYQItgBp9Fx6hxXsOWBO+4IdY779VRJXY1AU8epOuajjezWqK67b74pbPSsRjG2yalWoFKsiVJATB23Wk/N0RsMzGsUsTrl/IhelctNZI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9NuAAAAAAAAAAAAAADwNTtz5qyt3bAp9O+mjRpYRuVKxeI4lLp48eLFy70SAAAAAAAAAAAAAAAAha3YVJIAAAAAAAAAAAAAAADID5IkAAAAAAAAAAAAAABAWiBJAgAAAAAAAAAAAAAApAWSJAAAAAAAAAAAAAAAQFogSQIAAAAAAAAAAAAAAKQFkiQAAAAAAAAAAAAAAEBaIEkCAAAAAAAAAAAAAACkBZIkAAAAAAAAAAAAAABAWiBJAgAAAAAAAAAAAAAApAWSJAAAAAAAAAAAAAAAQFogSQIAAAAAAAAAAAAAAKQFkiQAAAAAAAAAAAAAAEBaIEkCAAAAAAAAAAAAAACkBZIkAAAAAAAAAAAAAACApYP/H3pLKT/rlYOtAAAAAElFTkSuQmCC", "text/plain": [ "
" ] - } + }, + "metadata": {}, + "output_type": "display_data" } ], "source": [ @@ -181,49 +179,7 @@ "kernel": "SoS" }, "source": [ - "## Input" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS", - "tags": [] - }, - "source": [ - " 1. `significant_variants_path`\n", - "- **Format**: RDS file containing significant variants. This must contain some variants that are not in the `baseline_anno_path` input. \n", - "- **Columns**:\n", - " - `chr`: Chromosome number (integer, required).\n", - " - `pos`: Genomic position (integer, required).\n", - "- **Example**:\n", - " ```r\n", - " chr pos\n", - " 1 12345\n", - " 1 67890\n", - "\n", - " ``` \n", - "2. `baseline_anno_path`\n", - "\n", - "- **Format**: RDS file containing a tabular data frame with baseline annotations. This must contain some variants that are not in the `significant_variants_path` input.\n", - "- **Columns**:\n", - " - **CHR**: Chromosome number (integer, required).\n", - " - **BP**: Genomic base pair position (integer, required).\n", - " - **SNP**: SNP ID (character, optional).\n", - " - **CM**: Centimorgan position (numeric, optional).\n", - " - **base**: Base-level information (integer, optional).\n", - " - **Annotation columns**: Binary columns (0/1, required) for various genomic annotations (e.g., `Coding_UCSC`, `Conserved_LindbladToh`, `CTCF_Hoffman`, etc.). Multiple such annnotation columns may exist in the input file. The columns start index of this file is given in the `--annotations-start` argument.\n", - "- **Example**:\n", - " \n", - " ```r\n", - " CHR BP SNP CM base Coding_UCSC Coding_UCSC.flanking.500 ⋯ Human_Enhancer_Villar Human_Enhancer_Villar.flanking.500\n", - " 1 11008 rs575272151 0 1 0 0 ⋯ 0 0\n", - " 1 11012 rs544419019 0 1 0 0 ⋯ 0 0\n", - " 1 13110 rs540538026 0 1 0 0 ⋯ 0 0\n", - " 1 13116 rs62635286 0 1 0 0 ⋯ 0 0\n", - " ```\n", - " \n", - "\n" + "**When to run it.** After a significant variant set exists and an annotation is available to test it against." ] }, { @@ -232,7 +188,28 @@ "kernel": "SoS" }, "source": [ - "## Output" + "## Input\n", + "\n", + "- `--significant-variants-path`: the variant set being tested, two columns `chr` and `pos` with a header. Required. Example `input/enrichment/protocol_example.eoo_significant_variants.tsv.gz`:\n", + "\n", + " ```\n", + " chr pos\n", + " 1 100015157\n", + " 1 1000291\n", + " ```\n", + "\n", + "- `--baseline-anno-path`: the annotation table covering the genome, one row per variant, with the annotation columns starting at `--annotations-start`. Required. Example `input/enrichment/protocol_example.eoo_baseline_annotation.tsv`:\n", + "\n", + " ```\n", + " chr BP ref alt rsid maf ANNO_baseline\n", + " 1 10000654 A C rs1_0 0.3734 0\n", + " 1 10100228 C T rs1_1 0.0602 0\n", + " ```\n", + "\n", + "- `--annotations-start`: the 1-based column index at which the annotation columns begin, `7` by default. Everything left of it is treated as variant identity and frequency.\n", + "- `--trait` and `--annotation-name`: labels, both required. They carry no analytic meaning; the output file is named `{trait}.{annotation-name}.enrichment_results.rds`.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--numThreads`: threads for the jackknife, `8` by default." ] }, { @@ -241,35 +218,25 @@ "kernel": "SoS" }, "source": [ + "## Output\n", "\n", - "1. `enrichment_results.rds`\n", - "\n", - "- **Format**: RDS file containing the following components:\n", - " - **`summary`**: A data frame summarizing the OR, OR_SE, Enrichment, and Enrichment_SE for each annotation column.\n", - " \n", - " ```r\n", - " Annotation OR OR_SE Enrichment Enrichment_SE\n", - " Coding_UCSC 1.23 0.12 0.85 0.10\n", - " Conserved_LindbladToh 0.98 0.08 1.12 0.05\n", - " Human_Enhancer_Villar 1.45 0.15 1.30 0.12\n", - " \n", - " ```\n", - " \n", - " - **`OR_blockJacknife`**: A matrix (22 rows for chromosomes × annotation columns) of log2-transformed OR values.\n", - " \n", - " ```r\n", - " Coding_UCSC Conserved_LindbladToh Human_Enhancer_Villar\n", - " 0.12 -0.02 0.25\n", - " 0.15 0.01 0.18\n", - " ⋮ ⋮ ⋮\n", - " ```\n", - " \n", - " - **`Enrichment_blockJacknife`**: A matrix (22 rows for chromosomes × annotation columns) of enrichment values.\n", - " - **`OR`**: A numeric vector of mean log2-transformed OR values across chromosomes for each annotation column.\n", - " - **`Enrichment`**: A numeric vector of mean enrichment values across chromosomes for each annotation column.\n", - " - **`OR_sd`**: A numeric vector of standard errors for OR values across chromosomes for each annotation column.\n", - " - **`Enrichment_sd`**: A numeric vector of standard errors for enrichment values across chromosomes for each annotation column.\n", - " - **`annotations`**: A list of annotation column names." + "- `{cwd}/enrichment/{trait}.{annotation-name}.enrichment_results.rds` - a list of 10 holding the point estimates, their block-jackknife standard errors and the per-chromosome estimates they derive from. Example `output/eoo_enrichment/enrichment/protocol_example.baseline.enrichment_results.rds`:\n", + "\n", + " ```\n", + " List of 10\n", + " $ summary :'data.frame': 2 obs. of 13 variables:\n", + " ..$ Annotation : chr [1:2] \"maf\" \"ANNO_baseline\"\n", + " ..$ OR : num [1:2] 1 1\n", + " ..$ OR_SE : num [1:2] 0 0\n", + " ..$ Enrichment : num [1:2] 1 1\n", + " ..$ Enrichment_SE : num [1:2] 0 0\n", + " $ OR_blockJacknife : num [1:22, 1:2] 1 1 1 1 1 1 1 1 1 1 ...\n", + " $ Enrichment_blockJacknife: num [1:22, 1:2] 1 1 1 1 1 1 1 1 1 1 ...\n", + " $ OR : Named num [1:2] 0 0\n", + " $ Enrichment : Named num [1:2] 1 1\n", + " ```\n", + "\n", + " `summary` carries one row per annotation column, here `maf` and `ANNO_baseline`. The two `blockJacknife` matrices are 22 by 2: one row per chromosome left out, one column per annotation, and the spread down each column is what the standard errors are computed from. On this toy annotation every variant scores 0, so the odds ratios come back at 1 with zero standard error; that is the expected result for an annotation with no signal, not a failed run." ] }, { @@ -278,7 +245,9 @@ "kernel": "SoS" }, "source": [ - "## Steps\n" + "## Minimal Working Example\n", + "\n", + "One workflow, `enrichment`, run once per annotation. `--trait` and `--annotation-name` are labels only; together they name the output file." ] }, { @@ -287,9 +256,7 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Run the chromosome-specific enrichment analysis (`enrichment`).\n", - "\n", - "Compares the significant-variant set against the baseline annotation, computing per-annotation odds ratios and enrichment with a 22-chromosome block-jackknife for standard errors. Writes `.enrichment_results.rds` plus a summary `.tsv.gz`." + "**Timing**: TBD (on toy dataset)" ] }, { @@ -314,31 +281,58 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "Writes `.enrichment_results.rds` (per-annotation OR, Enrichment, and their block-jackknife standard errors) plus a `.tsv.gz` summary. Annotations with a higher proportion of significant variants than expected show OR and Enrichment above 1.\n" + "## Command Interface" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash" }, + "outputs": [], "source": [ - "## Command interface\n", - "\n", - "List the workflow and its options:\n" + "sos run pipeline/eoo_enrichment.ipynb -h" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/eoo_enrichment.ipynb -h" + "```\n", + "\u001b[91mERROR\u001b[0m: \u001b[91mNotebook JSON is invalid: %s\u001b[0m\n", + "usage: sos run code/SoS/enrichment/eoo_enrichment.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " enrichment\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Path to the work directory of the analysis.\n", + " --modular-script-dir code/script (as path)\n", + " --significant-variants-path VAL (as path, required)\n", + " --baseline-anno-path VAL (as path, required)\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --trait VAL (as str, required)\n", + " For cluster jobs, number commands to run per job\n", + " --annotation-name VAL (as str, required)\n", + " --job-size 1 (as int)\n", + " --walltime 12h\n", + " --mem 16G\n", + "\n", + "Sections\n", + " enrichment:\n", + " Workflow Options:\n", + " --annotations-start 7 (as int)\n", + "```" ] }, { @@ -357,7 +351,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\n# Path to the work directory of the analysis.\nparameter: cwd = path('output')\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n\nparameter: significant_variants_path = path\nparameter: baseline_anno_path = path\n# Number of threads\nparameter: numThreads = 8\n# For cluster jobs, number commands to run per job\nparameter: trait = str\nparameter: annotation_name = str\nname = f\"{trait}.{annotation_name}\"\nparameter: job_size = 1\nparameter: walltime = '12h'\nparameter: mem = '16G'" + "source": [ + "[global]\n", + "# Path to the work directory of the analysis.\n", + "parameter: cwd = path('output')\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "\n", + "parameter: significant_variants_path = path\n", + "parameter: baseline_anno_path = path\n", + "# Number of threads\n", + "parameter: numThreads = 8\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: trait = str\n", + "parameter: annotation_name = str\n", + "name = f\"{trait}.{annotation_name}\"\n", + "parameter: job_size = 1\n", + "parameter: walltime = '12h'\n", + "parameter: mem = '16G'" + ] }, { "cell_type": "code", @@ -366,7 +377,19 @@ "kernel": "SoS" }, "outputs": [], - "source": "[enrichment]\nparameter: annotations_start = 7\noutput: enrichment = f'{cwd:a}/{step_name}/{name}.enrichment_results.rds'\n\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bnn}'\nbash: expand = '${ }', stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout'\n Rscript ${modular_script_dir}/enrichment/eoo_enrichment.R \\\n --significant-variants-path ${significant_variants_path} \\\n --baseline-anno-path ${baseline_anno_path} \\\n --annotations-start ${annotations_start} \\\n --output ${_output['enrichment']}" + "source": [ + "[enrichment]\n", + "parameter: annotations_start = 7\n", + "output: enrichment = f'{cwd:a}/{step_name}/{name}.enrichment_results.rds'\n", + "\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bnn}'\n", + "bash: expand = '${ }', stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout'\n", + " Rscript ${modular_script_dir}/enrichment/eoo_enrichment.R \\\n", + " --significant-variants-path ${significant_variants_path} \\\n", + " --baseline-anno-path ${baseline_anno_path} \\\n", + " --annotations-start ${annotations_start} \\\n", + " --output ${_output['enrichment']}" + ] } ], "metadata": { @@ -412,4 +435,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/enrichment/gregor.ipynb b/code/SoS/enrichment/gregor.ipynb index 8a9dae7bf..10a2080fc 100644 --- a/code/SoS/enrichment/gregor.ipynb +++ b/code/SoS/enrichment/gregor.ipynb @@ -8,20 +8,22 @@ "source": [ "# GREGOR enrichment analysis\n", "\n", - "## Description\n", - "\n", - "**Aim.** Evaluate the global enrichment of a set of trait-associated (positive) variants within experimentally annotated epigenomic regulatory features, relative to a matched negative set, using [GREGOR (Genomic Regulatory Elements and Gwas Overlap algoRithm)](https://genome.sph.umich.edu/wiki/GREGOR).\n", - "\n", - "## Methods overview\n", + "Tests whether a set of trait-associated variants falls inside annotated regulatory features more often than a matched control set does." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", "\n", - "GREGOR performs enrichment analysis for given positive set of variants against matched negative set, matched by: \n", + "A set of trait-associated variants is more interpretable if you can say what kind of sequence they fall in. Enrichment testing asks whether they overlap a class of genomic feature - an annotation, a chromatin state, a set of regulatory elements - more often than chance allows, where chance has to account for the fact that variants are not exchangeable: they differ in minor allele frequency, in the number of LD proxies they carry, and in distance to the nearest gene. [GREGOR](https://genome.sph.umich.edu/wiki/GREGOR) builds matched control variants on exactly those properties - minor allele frequency, LD proxy count, distance to the nearest TSS, and local gene density - so the comparison is fair.\n", "\n", - "- MAF\n", - "- LD proxy\n", - "- distance to TSS\n", - "- Gene density\n", + "GREGOR's own `PValue` column, defined in the [GREGOR paper](https://pubmed.ncbi.nlm.nih.gov/25886982/), sometimes comes back greater than 1, and a p-value says less about a result than the size of the enrichment does. This module therefore parses GREGOR's intermediate output into a 2x2 table - inside versus outside the annotation peak, positive set versus matched negative set - and runs Fisher's exact test on it to recover both a p-value and an odds ratio.\n", "\n", - "Methods to obtain the column \"PValue\" from GREGOR software can be found in the GREGOR paper: https://pubmed.ncbi.nlm.nih.gov/25886982/. We have noticed some PValue are greater than 1. Also, p-value itself is not as informative compared to odds ratios of enrichment. We therefore parse intermediate outputs from GREGOR to get a 2 by 2 table where the rows are within annotation peak vs outside; the columns are positive set vs matched negative set. We perform Fisher's exact test to get both p-value and odds ratios." + "**When to run it.** After you have a variant set worth characterising - fine-mapped credible sets, or GWAS hits - and an annotation you want to test them against." ] }, { @@ -29,7 +31,38 @@ "metadata": { "kernel": "SoS" }, - "source": "## Input\n\n- `--gregor_db`: a GREGOR reference database.\n- `--index_snp_file`: an index SNP file of the positive variant set.\n- `--bed_file_index`: a bed-file index listing the annotation `bed` files.\n\n> **Note.** `gregor_conf` (Step 1) only *writes* a configuration file from the supplied paths. Step 2 (`gregor`) invokes the GREGOR `perl` tool (`GREGOR`, on `PATH`) and parses its output; it needs a GREGOR reference database. The full reference (per-chromosome LD databases, ~20 GB) is distributed under the University of Michigan license and is not bundled here, but a downsized chr22 EUR slice is committed under `tests/fixtures/gregor/` so the pipeline is smoke-tested end-to-end. Index SNPs must be `chr:pos` (hg19), and `LDWINDOWSIZE` must match the window the reference was built with (1 Mb for the standard r²≥0.7 databases). The `gregor_fisher_plot` workflow (Step 3) is self-contained R and only needs two enrichment-result tables.\n" + "source": [ + "## Input\n", + "\n", + "- `--index_snp_file`: the positive variant set, one `chr:pos` per line with no header, on the same build as the reference database (hg19 for the standard ones). Example `input/ld/protocol_example.index.snps.txt`:\n", + "\n", + " ```\n", + " chr1:752566\n", + " chr1:776546\n", + " chr2:233567\n", + " ```\n", + "\n", + "- `--bed_file_index`: a two-column tab-separated index naming each annotation and pointing at its `bed` file. Example `input/enrichment/protocol_example.bed.file.index`:\n", + "\n", + " ```\n", + " annotationA /annotationA.bed\n", + " annotationB /annotationB.bed\n", + " annotationC /annotationC.bed\n", + " ```\n", + "\n", + "- `--gregor_db`: the GREGOR reference database directory, one SQLite `CUBE` table per chromosome. The full per-population reference is around 20 GB and is distributed under the University of Michigan license, so it is not bundled here and `input/enrichment/protocol_example.gregor_ref` is a placeholder. A downsized chr22 EUR slice is committed under `tests/fixtures/gregor/EUR` so the notebook can be smoke-tested end to end.\n", + "- `--pop`: the reference population, `EUR` by default. It has to match the population the database was built for.\n", + "- `--r2_threshold` and `--ld_window_size`: what counts as an LD buddy, `0.7` and `10000` by default. Both have to match the values the reference database was built with, 1 Mb for the standard r2 >= 0.7 databases.\n", + "- `--fisher1` and `--fisher2`, used by `gregor_fisher_plot` only: two enrichment-result tables to plot against each other, in the form the `gregor` workflow writes. Example `input/enrichment/protocol_example.trait1_enrichment_results.txt`:\n", + "\n", + " ```\n", + " Bed_File odds low high p_fisher\n", + " Promoter_UCSC.bed 1.377 0.751 2.011 0.0653\n", + " Enhancer_Hoffman.bed 1.886 1.15 2.307 0.4567\n", + " ```\n", + "\n", + "- `--cwd`: the directory outputs are written to." + ] }, { "cell_type": "markdown", @@ -39,12 +72,22 @@ "source": [ "## Output\n", "\n", - "All files are written under `--cwd`, prefixed by the run name:\n", + "- `{cwd}/{index_snp_file}.gregor.conf` - the GREGOR configuration file built from the supplied paths and parameters. The key lines of `output/gregor/protocol_example.index.gregor.conf`:\n", + "\n", + " ```\n", + " INDEX_SNP_FILE = input/ld/protocol_example.index.snps.txt\n", + " BED_FILE_INDEX = input/enrichment/protocol_example.bed.file.index\n", + " REF_DIR = input/enrichment/protocol_example.gregor_ref\n", + " R2THRESHOLD = 0.7 ## must be greater than 0.7\n", + " LDWINDOWSIZE = 10000 ## must be less than this window; these two values define LD buddies\n", + " POPULATION = EUR ## define the population, you can specify EUR, AFR, AMR or ASN\n", + " ```\n", + "\n", + "- `{name}_gregor_output/StatisticSummaryFile.txt` - GREGOR's raw overlap statistics, one row per annotation `bed` file.\n", + "- `{name}_variant_counts.txt` and `{name}_enrichment_results.txt` - the parsed 2x2 counts (inside versus outside the annotation peak, positive versus matched-negative set) and the per-annotation Fisher exact-test p-values and odds ratios.\n", + "- `{cwd}/{fisher1}_vs_{fisher2}_enrichment.pdf` - the odds-ratio comparison plot across annotations.\n", "\n", - "- `{name}.gregor.conf` — the GREGOR configuration file generated from the supplied paths (Step 1).\n", - "- `{name}_gregor_output/StatisticSummaryFile.txt` — GREGOR's raw overlap statistics for the annotation set (Step 2).\n", - "- `{name}_variant_counts.txt` and `{name}_enrichment_results.txt` — the parsed 2×2 counts (annotation peak vs outside, positive vs matched-negative variant set) and the per-annotation Fisher exact-test p-values and odds ratios (Step 3).\n", - "- `{name}_vs_{ref}_enrichment.pdf` — an odds-ratio comparison plot across annotations.\n" + "Only the configuration file ships with the repository. Carrying the example past step 1 needs the full GREGOR reference database, so `output/gregor` holds the `.conf` and GREGOR's generated job scripts but no summary, counts, or results tables." ] }, { @@ -53,7 +96,9 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example\n", + "\n", + "Steps 1 and 2 need the GREGOR reference database and the GREGOR `perl` software; step 3 runs on the two example result tables alone." ] }, { @@ -62,7 +107,7 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Build the GREGOR configuration file from the index SNP file and bed-file index (`gregor_conf`). This step only writes a `.gregor.conf` file from the supplied paths/parameters and does not invoke the external GREGOR software, so it runs end-to-end with the toy inputs below." + "### GREGOR enrichment scan" ] }, { @@ -71,7 +116,18 @@ "kernel": "SoS" }, "source": [ - "**Timing:** Requires external GREGOR tool on typical compute infrastructure." + "#### Configuration file only\n", + "\n", + "`gregor_conf` only *writes* a `.gregor.conf` from the supplied paths and parameters and never invokes GREGOR." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -96,7 +152,18 @@ "kernel": "SoS" }, "source": [ - "**Step 2.** Run the full GREGOR enrichment pipeline (config -> run GREGOR -> Fisher test) (`gregor`). Requires the GREGOR `perl` software and reference database." + "#### The full chain\n", + "\n", + "`gregor` repeats the configuration step, then runs GREGOR and Fisher-tests its output. It expects the GREGOR `perl` tool as `GREGOR` on `PATH` and a reference database." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -121,7 +188,18 @@ "kernel": "SoS" }, "source": [ - "**Step 3.** Plot an odds-ratio comparison from two enrichment-result tables (`gregor_fisher_plot`). Self-contained R; runnable from `*_enrichment_results.txt` tables alone." + "### Plot an odds-ratio comparison\n", + "\n", + "`gregor_fisher_plot` is self-contained R and runs from two `*_enrichment_results.txt` tables alone, with no reference database or GREGOR install needed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -144,29 +222,63 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "Produces a `*_enrichment_results.txt` table of per-annotation Fisher p-values and odds ratios, and (via `gregor_fisher_plot`) an odds-ratio comparison PDF. Annotations enriched in the positive variant set show odds ratios above 1.\n" + "## Command Interface" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Command interface" + "sos run pipeline/gregor.ipynb -h" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/gregor.ipynb -h" + "```\n", + "usage: sos run pipeline/gregor.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " gregor_conf\n", + " gregor\n", + " gregor_fisher_plot\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " working directory\n", + " --container ''\n", + " Software container option\n", + "\n", + "Sections\n", + " gregor_conf, gregor_1: make configuration file for GREGOR\n", + " Workflow Options:\n", + " --gregor-db VAL (as path, required)\n", + " --pop EUR\n", + " --index-snp-file VAL (as path, required)\n", + " --bed-file-index VAL (as path, required)\n", + " --r2-threshold 0.7 (as float)\n", + " --ld-window-size 10000 (as int)\n", + " --min-neighbor 10 (as int)\n", + " --job-number 10 (as int)\n", + " gregor_2: run GREGOR\n", + " gregor_3: Fisher test of enrichment\n", + " gregor_fisher_plot: enrichment plot with fisher test results\n", + " Workflow Options:\n", + " --fisher1 VAL (as path, required)\n", + " --fisher2 VAL (as path, required)\n", + "```" ] }, { @@ -257,7 +369,7 @@ "sudo apt-get install libdbi-perl libswitch-perl libdbd-sqlite3-perl\n", "```\n", "\n", - "With our docker image:\n", + "With the docker image:\n", "\n", "```\n", "cd GREGOR_folder\n", @@ -274,7 +386,13 @@ "kernel": "SoS" }, "outputs": [], - "source": "# run GREGOR\n[gregor_2]\noutput: f'{_input:nn}_gregor_output/StatisticSummaryFile.txt'\nbash: expand = True, container = container, stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n GREGOR --conf {_input} && touch {_output}" + "source": [ + "# run GREGOR\n", + "[gregor_2]\n", + "output: f'{_input:nn}_gregor_output/StatisticSummaryFile.txt'\n", + "bash: expand = True, container = container, stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'\n", + " GREGOR --conf {_input} && touch {_output}" + ] }, { "cell_type": "code", diff --git a/code/SoS/enrichment/gsea.ipynb b/code/SoS/enrichment/gsea.ipynb index 0a1dc68ea..6a8fd6f83 100644 --- a/code/SoS/enrichment/gsea.ipynb +++ b/code/SoS/enrichment/gsea.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Pathway Analysis" + "# Pathway Analysis\n", + "\n", + "Tests groups of genes for over-representation in KEGG pathways and Gene Ontology terms." ] }, { @@ -15,17 +17,15 @@ "kernel": "SoS" }, "source": [ - "## Description\n", - "\n", - "Pathway enrichment analysis over groups of genes using both the KEGG database and all three Gene Ontology (GO) ontologies, via the `clusterProfiler` R package. It identifies the biologically significant pathways and functional categories associated with each gene group, and supports multi-group comparison (e.g. cell types, conditions, treatments) with a single unified output.\n", + "## Overview\n", "\n", - "## Methods\n", + "A list of genes is hard to interpret on its own. Over-representation testing asks whether a group contains more members of some pathway or ontology term than chance would give, turning a list of identifiers into statements about biology.\n", "\n", - "**Gene ID conversion.** Input ENSEMBL gene IDs are converted to ENTREZ IDs using `org.Hs.eg.db`; genes without a valid ENTREZ mapping are dropped, and group associations are preserved through the conversion.\n", + "This module tests each group against the KEGG database and all three Gene Ontology branches using `clusterProfiler`. Input ENSEMBL gene IDs are first converted to ENTREZ IDs via `org.Hs.eg.db`; genes without a valid ENTREZ mapping are dropped, and group associations are preserved through the conversion. KEGG over-representation then runs through `enrichKEGG()` and GO through `enrichGO()` for Biological Process, Cellular Component and Molecular Function, both applying a hypergeometric test with Benjamini-Hochberg FDR correction.\n", "\n", - "**Enrichment testing.** KEGG over-representation uses `enrichKEGG()` (organism `hsa`); GO uses `enrichGO()` against `org.Hs.eg.db` for Biological Process (BP), Cellular Component (CC), and Molecular Function (MF). Both apply a hypergeometric test with Benjamini-Hochberg FDR correction.\n", + "Every group is analysed in the same run, and results from all analysis types are harmonised into one column schema - metadata columns for analysis type and ontology category, plus a category to subcategory to term classification - then combined into a single data frame saved as a compressed RDS. That shared schema is what lets groups such as cell types, conditions or treatments be compared side by side.\n", "\n", - "**Output standardization.** Results from all analysis types are harmonized into one column schema with metadata columns (analysis type, ontology category) and a hierarchical category -> subcategory -> term classification, then combined into a single data frame and saved as a compressed RDS file with per-group summary statistics.\n" + "**When to run it.** After a set of genes of interest has been grouped, to ask which pathways and ontology terms those groups are enriched for." ] }, { @@ -36,29 +36,22 @@ "source": [ "## Input\n", "\n", - "### Gene List (TSV format)\n", - "\n", - "A table containing grouped genes with the following structure:\n", + "- `--genes-file`: a TSV of grouped genes with two required columns, `group` naming the category a gene belongs to and `gene_id` giving its ENSEMBL identifier. Every group present is tested. Example `input/enrichment/protocol_example.pathway_genes.tsv`:\n", "\n", - "**Required columns:**\n", + " ```\n", + " group gene_id\n", + " AD ENSG00000139618\n", + " AD ENSG00000091831\n", + " TL1 ENSG00000196839\n", + " TL1 ENSG0000008123\n", + " ```\n", "\n", - "- `group`: The group/category to which a gene belongs (e.g., `AD_A_cauchy`, `TL1_C_cauchy`)\n", - "- `gene_id`: ENSEMBL gene IDs for the corresponding genes\n", - "\n", - "**Example:**\n", - "```\n", - "group gene_id\n", - "AD ENSG00000139618\n", - "AD ENSG00000091831\n", - "TL1 ENSG00000196839\n", - "TL1 ENSG0000008123\n", - "```\n", - "### Parameters:\n", - "\n", - "- `pvalue_cutoff`: Cutoff for pathway enrichment significance (default: 1)\n", - "- `organism`: KEGG organism code (default: `hsa` for humans)\n", - "\n", - "---" + "- `--name`: the stem of the output file. Required.\n", + "- `--organism`: the KEGG organism code, `hsa` (human) by default.\n", + "- `--pvalue-cutoff`: the enrichment p-value threshold, `1` by default, which keeps every term so filtering can be done downstream.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--modular-script-dir`: the `code/script` directory holding the analysis scripts.\n", + "- `--numThreads`, `--job-size`, `--walltime` and `--mem`: job resources." ] }, { @@ -69,26 +62,27 @@ "source": [ "## Output\n", "\n", - "### Combined Pathway Results File\n", - "\n", - "A compressed RDS file (`.rds`) containing standardized enrichment results from all analyses.\n", + "- `{cwd}/pathway_analysis/{name}.combined_pathway_results.rds` - one compressed RDS holding the KEGG and GO results for every gene group in a single data frame, 2842 rows and 17 columns on the example. SoS always inserts the step name, so results land in a `pathway_analysis/` subdirectory of whatever `--cwd` is given. Example `output/gsea/pathway_analysis/protocol_example.combined_pathway_results.rds`:\n", "\n", - "**Key columns in the results:**\n", + " ```\n", + " 'data.frame': 2842 obs. of 17 variables:\n", + " $ ID : chr \"hsa01524\" \"hsa04115\" \"hsa05210\" \"hsa05162\" ...\n", + " $ Description : chr \"Platinum drug resistance\" \"p53 signaling pathway\" \"Colorectal cancer\" \"Measles\" ...\n", + " $ GeneRatio : chr \"7/9\" \"6/9\" \"6/9\" \"6/9\" ...\n", + " $ BgRatio : chr \"75/9416\" \"75/9416\" \"87/9416\" \"136/9416\" ...\n", + " $ RichFactor : num 0.0933 0.08 0.069 0.0441 0.0438 ...\n", + " $ FoldEnrichment: num 97.6 83.7 72.2 46.2 45.8 ...\n", + " ```\n", "\n", - "- `ID`: Pathway/GO term identifier\n", - "- `Description`: Pathway/GO term name/description\n", - "- `GeneRatio`: Ratio of input genes found in the pathway/term\n", - "- `BgRatio`: Background ratio of all genes in the database for this pathway/term\n", - "- `pvalue`: Raw enrichment p-value\n", - "- `p.adjust`: Adjusted p-value (Benjamini-Hochberg)\n", - "- `qvalue`: Q-value for FDR control\n", - "- `group`: Name of the gene group analyzed\n", - "- `analysis_type`: Type of analysis (`KEGG` or `GO`)\n", - "- `ont_category`: Ontology category (`PATHWAY`, `BP`, `CC`, or `MF`)\n", - "- `category`: High-level category classification\n", - "- `subcategory`: Detailed subcategory classification\n", + "The 17 columns are the same for every analysis type, which is what makes groups directly comparable:\n", "\n", - "---" + "- `ID` and `Description`: the pathway or GO term identifier and its name.\n", + "- `GeneRatio` and `BgRatio`: input genes found in the term, against all database genes in that term.\n", + "- `RichFactor` and `FoldEnrichment`: the ratio of the two, raw and fold-scaled.\n", + "- `pvalue`, `p.adjust` and `qvalue`: the raw hypergeometric p-value, the Benjamini-Hochberg adjusted value, and the q-value for FDR control.\n", + "- `group`: which gene group the row came from.\n", + "- `analysis_type` and `ont_category`: `KEGG` or `GO`, and `PATHWAY`, `BP`, `CC` or `MF`.\n", + "- `category` and `subcategory`: the high-level and detailed classification of the term. Both are `NA` for KEGG rows in this example." ] }, { @@ -97,7 +91,7 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example" ] }, { @@ -106,7 +100,7 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Run KEGG + GO over-representation (pathway) analysis on the grouped gene sets (`pathway_analysis`). Genes are mapped ENSEMBL→ENTREZ, then `enrichKEGG`/`enrichGO` are run per group and the results are combined into one RDS. _Note: KEGG enrichment queries the online KEGG API, so this step needs network access; GO enrichment uses the local `org.Hs.eg.db`._" + "KEGG enrichment queries the online KEGG API, so this step needs network access. GO enrichment uses the local `org.Hs.eg.db` and works offline." ] }, { @@ -115,7 +109,7 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~1-2 min on typical compute infrastructure." + "**Timing**: ~1-2 min (on toy dataset)" ] }, { @@ -130,7 +124,7 @@ " --genes_file input/enrichment/protocol_example.pathway_genes.tsv \\\n", " --name protocol_example \\\n", " --pvalue_cutoff 1 --organism hsa \\\n", - " --cwd output/pathway_analysis" + " --cwd output/gsea" ] }, { @@ -139,18 +133,7 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "Writes a single compressed `.rds` with standardized KEGG and GO (BP/CC/MF) enrichment results across all gene groups, sharing one column schema for downstream comparison. Each group yields the pathways and ontology terms over-represented among its genes.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -164,6 +147,42 @@ "sos run pipeline/gsea.ipynb -h" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "```\n", + "usage: sos run code/SoS/enrichment/gsea.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " pathway_analysis\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Path to the work directory of the analysis.\n", + " --modular-script-dir code/script (as path)\n", + " --genes-file . (as path)\n", + " --name VAL (as str, required)\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 12h\n", + " --mem 16G\n", + "\n", + "Sections\n", + " pathway_analysis:\n", + " Workflow Options:\n", + " --pvalue-cutoff 1 (as int)\n", + " --organism hsa\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { @@ -180,7 +199,21 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\n# Path to the work directory of the analysis.\nparameter: cwd = path('output')\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n\nparameter: genes_file = path() # TSV file with columns: group, gene_id\nparameter: name = str\n# Number of threads\nparameter: numThreads = 8\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\nparameter: walltime = '12h'\nparameter: mem = '16G'" + "source": [ + "[global]\n", + "# Path to the work directory of the analysis.\n", + "parameter: cwd = path('output')\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "\n", + "parameter: genes_file = path() # TSV file with columns: group, gene_id\n", + "parameter: name = str\n", + "# Number of threads\n", + "parameter: numThreads = 8\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "parameter: walltime = '12h'\n", + "parameter: mem = '16G'" + ] }, { "cell_type": "code", @@ -189,7 +222,20 @@ "kernel": "SoS" }, "outputs": [], - "source": "[pathway_analysis]\nparameter: pvalue_cutoff = 1\nparameter: organism = 'hsa'\noutput: pathway_results = f'{cwd:a}/{step_name}/{name}.combined_pathway_results.rds'\n\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bnn}'\nbash: expand = '${ }', stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout'\n Rscript ${modular_script_dir}/enrichment/gsea.R \\\n --genes-file ${genes_file} \\\n --organism ${organism} \\\n --pvalue-cutoff ${pvalue_cutoff} \\\n --output ${_output['pathway_results']}" + "source": [ + "[pathway_analysis]\n", + "parameter: pvalue_cutoff = 1\n", + "parameter: organism = 'hsa'\n", + "output: pathway_results = f'{cwd:a}/{step_name}/{name}.combined_pathway_results.rds'\n", + "\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[0]:bnn}'\n", + "bash: expand = '${ }', stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout'\n", + " Rscript ${modular_script_dir}/enrichment/gsea.R \\\n", + " --genes-file ${genes_file} \\\n", + " --organism ${organism} \\\n", + " --pvalue-cutoff ${pvalue_cutoff} \\\n", + " --output ${_output['pathway_results']}" + ] } ], "metadata": { @@ -228,4 +274,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/enrichment/sldsc_enrichment.ipynb b/code/SoS/enrichment/sldsc_enrichment.ipynb index c19911dc1..d25d32bd9 100644 --- a/code/SoS/enrichment/sldsc_enrichment.ipynb +++ b/code/SoS/enrichment/sldsc_enrichment.ipynb @@ -8,9 +8,7 @@ "source": [ "# Stratified LD Score Regression (S-LDSC) Enrichment\n", "\n", - "Minimal working-example driver for the S-LDSC functional-enrichment pipeline. The **Steps** section below gives one ready-to-run `sos run` command per workflow, using the toy inputs symlinked under `input/`.\n", - "\n", - "> **Environment note.** Steps 1–2 (`make_annotation_files_ldscore`, `get_heritability`) wrap the external **polyfun** toolkit (`compute_ldscores`, `ldsc`, `munge_polyfun_sumstats`) and require pre-computed reference-panel files (baseline-LD scores, LD weights, `.frq`, and PLINK `.bed/.bim/.fam`). polyfun is **not installed in this environment** and the reference panel is not shipped with the toy example, so those two steps cannot be executed here; their commands are provided for use on a system where polyfun and a matching panel are available. Steps 3–4 (`postprocess`, `meta_subset`) use `pecotmr::sldscPostprocessingPipeline` (available here) and read the `.results`/`.log` files produced by Step 2.\n" + "Per-SNP heritability enrichment of genome annotations from GWAS summary statistics alone." ] }, { @@ -19,21 +17,33 @@ "kernel": "SoS" }, "source": [ - "## Description\n", - "This notebook implements the pipeline of [S-LDSC](https://www.nature.com/articles/ng.3404) for LD score and functional enrichment analysis.\n", - "\n", - "**Important: the S-LDSC implementation comes from the [polyfun](https://github.com/omerwe/polyfun/tree/master) package, not the original LDSC from `bulik/ldsc` GitHub repo.**" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "Markdown" - }, - "source": [ - "Uses GWAS summary statistics together with annotation and LD reference-panel data to compute per-SNP heritability enrichment for each annotation. It supports single-annotation (individual contribution) and joint multi-annotation (independent contribution) analysis.\n", - "\n", - "**Background.** LD Score Regression (Bulik-Sullivan et al. 2015) distinguishes confounding (e.g. population stratification) from true polygenic signal by regressing GWAS chi-square statistics on LD scores: SNPs tagging more variation (high LD score) show higher chi-square under true polygenicity, whereas confounding inflates statistics independently of LD. S-LDSC (Finucane et al. 2015) partitions heritability across overlapping annotation categories; standardized tau accounts for negative selection (Gazal et al. 2017). The model details and the tau*/EnrichStat definitions follow below.\n" + "## Overview\n", + "\n", + "Heritability is not spread evenly over the genome. This module asks whether a functional category -- a\n", + "chromatin state, a set of regulatory elements, an xQTL annotation -- carries more heritability than its\n", + "share of SNPs would predict, using GWAS summary statistics alone.\n", + "\n", + "The reasoning is short. A variant's association statistic reflects every causal variant it tags, so\n", + "under real polygenic signal a SNP that tags more variation has a higher expected chi-square, whereas\n", + "confounding such as population stratification inflates chi-square independently of LD; regressing\n", + "chi-square on LD score separates the two ([Bulik-Sullivan et al. 2015](https://doi.org/10.1038/ng.3211)). Computing a\n", + "separate LD score per annotation category turns that one slope into one slope per category, each\n", + "estimating the per-SNP heritability that category contributes ([Finucane et al. 2015](https://doi.org/10.1038/ng.3404)).\n", + "Categories may overlap, so every regression conditions on a baseline-LD model -- without it an estimate\n", + "reflects LD-related architecture the annotation merely correlates with.\n", + "\n", + "Two numbers come out, for different reasons. *Enrichment*, the proportion of heritability over the\n", + "proportion of SNPs, reads easily but is defined only for binary annotations and is not comparable across\n", + "annotations of different size. *Standardized tau* ($\\tau^*$) is the per-SNP effect of a\n", + "one-standard-deviation increase in the annotation, conditional on every other annotation in the model;\n", + "it is comparable across annotations and across traits and extends to continuous annotations\n", + "([Gazal et al. 2017](https://doi.org/10.1038/ng.3954)). Both are reported.\n", + "\n", + "The regression itself comes from [polyfun](https://github.com/omerwe/polyfun/tree/master), **not** the\n", + "original LDSC in `bulik/ldsc`; standardization and the across-trait meta-analysis are done in\n", + "[`pecotmr`](https://github.com/StatFunGen/pecotmr).\n", + "\n", + "**When to run it.** Run this module after GWAS summary statistics and the required LD-score annotations are available to estimate annotation-specific heritability enrichment and its uncertainty.\n" ] }, { @@ -42,24 +52,23 @@ "kernel": "SoS" }, "source": [ - "## Methods - Workflow Overview\n", - "\n", - "The pipeline runs in three stages: (1) annotation preparation and the S-LDSC regression (polyfun), (2) post-processing into standardized $\\tau^*$ and meta-analysis (the `pecotmr` package), and (3) optional re-meta on user-defined trait subsets. The concrete commands for stages 1-2 are in the **Steps** section below.\n", + "### Pipeline stages\n", "\n", - "**Stage 1 - polyfun.** Three SoS workflows wrap polyfun: `make_annotation_files_ldscore` converts target annotations into polyfun `.annot.gz` and runs `compute_ldscores` (toggles `compute_single` and `compute_joint`, both default `True`; the joint dir is only emitted when $N \\geq 2$); `munge_sumstats_polyfun` preprocesses each GWAS into LDSC format; `get_heritability` runs polyfun's `ldsc` once per `--target-anno-dir`, enforcing the MAF cutoff via `--frqfile-chr` (`maf_cutoff` accepts only `0` or `0.05`).\n", + "The pipeline runs in three stages.\n", "\n", - "**Stage 2 - pecotmr post-processing.** A single `pecotmr::sldscPostprocessingPipeline` call consumes all polyfun outputs: it extracts $\\tau$, $E$, $h^2_g$, EnrichStat p-value and per-block jackknife $\\tau$ values; computes $sd_C$ and $M_{\\mathrm{ref}}$ over the regression's MAF-cutoff SNP set; standardizes $\\tau \\to \\tau^*$ for single and joint modes; auto-detects binary vs continuous annotations; and runs a DerSimonian-Laird random-effects meta-analysis across traits, producing three meta tables ($\\tau^*$ cross-type comparable, $E$ within-binary, EnrichStat within-binary). Output is an R list with `per_trait` and `meta` entries.\n", + "**Stage 1 -- polyfun.** Three SoS workflows wrap polyfun: `make_annotation_files_ldscore` converts\n", + "target annotations into polyfun `.annot.gz` and computes LD scores, `munge_sumstats_polyfun`\n", + "preprocesses each GWAS into LDSC format, and `get_heritability` runs polyfun's `ldsc` once per\n", + "(trait, target directory) pair.\n", "\n", - "**Stage 3 - subset meta-analysis.** `pecotmr::metaSldscRandom` re-runs the meta on a trait subset without re-running the regression (lightweight, interactive):\n", + "**Stage 2 -- pecotmr post-processing.** A single `pecotmr::sldscPostprocessingPipeline` call consumes\n", + "all polyfun outputs: it extracts $\\tau$, $E$, $h^2_g$, EnrichStat p-value and per-block jackknife\n", + "$\\tau$ values; standardizes $\\tau \\to \\tau^*$ for both single- and joint-tau modes; auto-detects\n", + "binary versus continuous annotations; and runs a DerSimonian-Laird random-effects meta-analysis across\n", + "traits. The result is an R list with `per_trait` and `meta` entries.\n", "\n", - "```r\n", - "res <- readRDS(\"sldsc_results.rds\")\n", - "neuro <- c(\"AD_GWAX\", \"PD_meta\", \"ALS_meta\")\n", - "view_neuro <- pecotmr:::.sldscViewForMeta(res$per_trait[neuro], \"single\")\n", - "meta_neuro_taustar <- pecotmr::metaSldscRandom(\n", - " view_neuro, category = \"my_target_anno\", quantity = \"tauStar\"\n", - ")\n", - "```\n" + "**Stage 3 -- subset meta-analysis.** `pecotmr::metaSldscRandom` re-runs the meta over a trait subset\n", + "from the cached `.sldsc_postprocess.rds`, without re-running the regression." ] }, { @@ -68,18 +77,7 @@ "kernel": "SoS" }, "source": [ - "## Theory\n", - "\n", - "The statistical model behind the pipeline is summarized below. Because the same framework underlies several of the workflow steps, the model, its stratified extension, and the tau-estimation / enrichment definitions are described together here rather than repeated per step." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### LDSC model\n", + "### Model\n", "\n", "Under a polygenic assumption, in which effect sizes for variants are drawn independently from distributions with variance proportional to $1/(p(1-p))$ where $p$ is the minor allele frequency (MAF), the expected $\\chi^2$ statistic of variant $j$ is:\n", "\n", @@ -87,22 +85,8 @@ "\n", "where $N$ is the sample size; $M$ is the number of SNPs, so that $h^2/M$ is the average heritability per SNP; $a$ measures the contribution of confounding biases such as cryptic relatedness and population stratification; and $\\ell_j = \\sum_k r^2_{jk}$ is the LD Score of variant $j$, which measures the amount of genetic variation tagged by $j$. A full derivation is given in the Supplementary Note of Bulik-Sullivan et al. (2015); an alternative derivation appears in the Supplementary Note of Zhu and Stephens (2017) AoAS.\n", "\n", - "Equation (1) shows that LD Score regression can compute SNP-based heritability for a phenotype from GWAS summary statistics alone, without requiring individual-level genotype data as REML and related methods do." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### Stratified LDSC\n", - "\n", - "Heritability is the proportion of phenotypic variation that is due to variation in genetic values, and it can also be partitioned over disjoint or overlapping categories of SNPs.\n", - "\n", - "Stratified LD Score Regression (S-LDSC) partitions heritability by leveraging both LD-score information and SNPs that have not reached genome-wide significance. S-LDSC exploits the fact that the $\\chi^2$ statistic for a given SNP reflects the cumulative effects of all SNPs tagged by it: in regions of high LD, the focal SNP captures the contribution of a group of nearby SNPs.\n", - "\n", - "S-LDSC declares an annotation enriched for heritability if SNPs with high LD to that annotation have higher $\\chi^2$ statistics than SNPs with low LD to it.\n", + "Equation (1) computes SNP heritability from summary statistics alone, with no individual-level\n", + "genotypes.\n", "\n", "Let $a_{jC}$ denote the value of annotation $C$ at SNP $j$:\n", "\n", @@ -121,9 +105,7 @@ "\n", "Interpretation of $\\tau_C$:\n", "- **Binary $C$**: $\\tau_C$ is the *additive increase in per-SNP heritability* for SNPs in category $C$, on top of the contributions from any other annotations they belong to.\n", - "- **Continuous $C$**: $\\tau_C$ is the *additive change in per-SNP heritability per unit increase* in the value of annotation $C$.\n", - "\n", - "For application to real data and comparisons to other methods, see the three papers cited at the top of this notebook." + "- **Continuous $C$**: $\\tau_C$ is the *additive change in per-SNP heritability per unit increase* in the value of annotation $C$." ] }, { @@ -132,47 +114,32 @@ "kernel": "SoS" }, "source": [ - "### Tau Estimation and Enrichment Analysis\n", - "\n", - "Goal: quantify the contribution of functional annotations to trait heritability and assess statistical significance, accounting for LD structure and (for continuous annotations) annotation scale.\n", - "\n", - "The pipeline has two computational layers:\n", - "\n", - "- **Regression layer** — the S-LDSC regression itself, performed by the [polyfun](https://github.com/omerwe/polyfun) engine. We do not re-implement this.\n", - "- **Post-processing layer** — standardization, differential per-SNP heritability, binary/continuous detection, and random-effects meta-analysis across traits. Implemented in the [`pecotmr`](https://github.com/StatFunGen/pecotmr) R package (`R/sldsc_wrapper.R`).\n", - "\n", - "The notation below tags each modeling quantity as **(polyfun)** or **(pecotmr)**.\n", + "### Tau estimation and enrichment analysis\n", "\n", "#### Notation\n", "\n", - "For each annotation $C$ we use:\n", + "For each annotation $C$:\n", "\n", "- $\\pi^{h^2}_C$ = proportion of trait heritability $h^2_g$ assigned to annotation $C$.\n", "- $\\pi^{M}_C$ = proportion of (effective) SNPs in annotation $C$. For binary annotations this is $M_C / M_{\\mathrm{ref}}$; for continuous annotations it is the share of total annotation weight in $C$.\n", "\n", - "#### Reference panel and MAF cutoff\n", - "\n", - "All LD-derived quantities — partitioned LD scores for the 97 baseline annotations and for our $K$ target annotations, the LD-score-regression weights, allele frequencies, and the SNP set — are computed against our own LD reference panel. We do not mix in pre-computed quantities from external panels (e.g. 1000G); $M_{\\mathrm{ref}}$ throughout this notebook denotes the number of common SNPs in our panel.\n", - "\n", - "By default we restrict to MAF $> 5\\%$ per the sLDSC recommendation: rare-variant LD is unstable and HapMap3-style regression weights are common-variant by construction. The cutoff is exposed as the SoS parameter `maf_cutoff` (default $0.05$); the regression, the standardized $sd_C$, and $M_{\\mathrm{ref}}$ are all evaluated on the same MAF $>$ cutoff SNP set. If allele-frequency files are not available the pipeline fails; the user must explicitly set `maf_cutoff = 0` to opt out (not recommended).\n", - "\n", "#### Quantities from the regression layer (polyfun)\n", "\n", - "Solving Equation (2) jointly across annotations, with 200-block genomic jackknife for inference, is performed by polyfun's `ldsc`. From each polyfun run we obtain, per annotation:\n", + "Solving Equation (2) jointly across annotations, with 200-block genomic jackknife for inference, is performed by polyfun's `ldsc`. Each polyfun run yields, per annotation:\n", "\n", "- $\\tau_C$ and its standard error — **(polyfun)**.\n", "- $\\pi^{h^2}_C$ and $\\pi^{M}_C$ — **(polyfun)**.\n", "- $E_C = \\pi^{h^2}_C / \\pi^{M}_C$ and its standard error — **(polyfun)**.\n", "- The p-value of the differential per-SNP heritability test (defined below) — **(polyfun)**, computed internally with the full coefficient covariance matrix.\n", "\n", - "We also obtain, per run:\n", + "Also obtained, per run:\n", "\n", "- The total trait heritability $h^2_g$ — **(polyfun)**.\n", "- The 200-block jackknife delete-values of $\\tau_C$ — **(polyfun)**.\n", "\n", "#### Quantities from the post-processing layer (pecotmr)\n", "\n", - "From the polyfun outputs above plus our reference panel, the post-processing layer computes:\n", + "From the polyfun outputs above plus the reference panel, the post-processing layer computes:\n", "\n", "- $sd_C$ — per-annotation standard deviation over MAF $>$ cutoff SNPs — **(pecotmr: `compute_sldsc_annot_sd`)**.\n", "- $M_{\\mathrm{ref}}$ — reference SNP count at the MAF cutoff — **(pecotmr: `compute_sldsc_M_ref`)**.\n", @@ -185,7 +152,7 @@ "\n", "#### Standardized tau ($\\tau^*$) — (pecotmr)\n", "\n", - "$\\tau_C$ has units that depend on the scale of the annotation and on the total heritability of the trait, so raw $\\tau$ is not directly comparable across annotations or across traits. We compute the standardized version (Gazal et al. 2017)\n", + "$\\tau_C$ has units that depend on the scale of the annotation and on the total heritability of the trait, so raw $\\tau$ is not directly comparable across annotations or across traits; the standardized version is computed instead (Gazal et al. 2017)\n", "\n", "$$\\tau^*_C \\;=\\; \\tau_C \\cdot \\frac{sd_C \\cdot M_{\\mathrm{ref}}}{h^2_g}$$\n", "\n", @@ -231,7 +198,7 @@ "\n", "#### Joint analysis — (polyfun runs the regression; pecotmr standardizes both modes)\n", "\n", - "For **joint analysis** (multiple annotations fit together), both $\\tau$ and $E$ are conditional on the other annotations in the model. We report joint $\\tau^*_C$ as the independent contribution of annotation $C$ after controlling for the others. The annotation-prep step exposes two independent toggles, `compute_single` and `compute_joint` (both default `True`), so the user can produce the $N$ single-target outputs, the joint output, or both in one invocation. With both defaults the post-processing layer reads all $N+1$ regression outputs per trait and presents single + joint side-by-side. When the joint subset is decided after looking at single-target results (exploratory $\\rightarrow$ conditional workflow), the user runs the annotation-prep step a second time with `compute_single=False` on the curated subset.\n", + "For **joint analysis** (multiple annotations fit together), both $\\tau$ and $E$ are conditional on the other annotations in the model; joint $\\tau^*_C$ is reported as the independent contribution of annotation $C$ after controlling for the others. The annotation-prep step exposes two independent toggles, `compute_single` and `compute_joint` (both default `True`), so the user can produce the $N$ single-target outputs, the joint output, or both in one invocation. With both defaults the post-processing layer reads all $N+1$ regression outputs per trait and presents single + joint side-by-side. When the joint subset is decided after looking at single-target results (exploratory $\\rightarrow$ conditional workflow), the user runs the annotation-prep step a second time with `compute_single=False` on the curated subset.\n", "\n", "### Meta-Analysis across Traits (Random Effects) — (pecotmr)\n", "\n", @@ -245,7 +212,7 @@ "- **For $E_C$ meta**: $SE_i$ is the polyfun-reported `Enrichment_std_error`.\n", "- **For EnrichStat meta**: $SE_i$ is the back-solved SE from polyfun's `Enrichment_p`.\n", "\n", - "For binary-annotation enrichment reporting we use a two-channel meta: the **effect size and SE** come from the meta on $E_C$ (interpretable on the original enrichment-fold scale), while the **p-value** comes from the meta on EnrichStat (the appropriate hypothesis test). The pipeline produces a default meta over all supplied traits; users can re-run meta on any subset of traits without re-running the regression layer.\n", + "Binary-annotation enrichment reporting uses a two-channel meta: the **effect size and SE** come from the meta on $E_C$ (interpretable on the original enrichment-fold scale), while the **p-value** comes from the meta on EnrichStat (the appropriate hypothesis test). The pipeline produces a default meta over all supplied traits; users can re-run meta on any subset of traits without re-running the regression layer.\n", "\n", "$$Z_{\\mathrm{meta}} \\;=\\; \\frac{\\hat\\theta_{\\mathrm{meta}}}{SE_{\\mathrm{meta}}}, \\qquad p \\;=\\; 2\\,\\Phi(-|Z_{\\mathrm{meta}}|)$$" ] @@ -256,9 +223,162 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example (MWE)\n", + "**When to run it.** Once GWAS summary statistics and an annotation worth testing are in hand. S-LDSC characterises a trait against a whole category; when the question is about a specific variant set, use `gregor` instead." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Input\n", + "\n", + "Every path-list input is a two-column index file (`#id`, `path`), one row per chromosome, so the\n", + "pipeline can fan out per chromosome. Example index files live in `input/enrichment/sldsc/`.\n", + "\n", + "Required throughout:\n", + "\n", + "- `--annotation-name` (required): prefix for every output directory and file of this run.\n", + "- `--cwd` (default `output`): work directory for the analysis.\n", + "- `--modular-script-dir` (default `code/script`): directory holding the modular R wrapper scripts.\n", + "- `--maf-cutoff` (default `0.05`): MAF cutoff, per the S-LDSC recommendation, since rare-variant LD is\n", + " unstable and HapMap3-style regression weights are common-variant by construction. `0` opts out of MAF\n", + " filtering (not recommended); any other value requires recomputing LD scores at that cutoff.\n", + "\n", + "`make_annotation_files_ldscore` -- build annotation and LD-score files:\n", + "\n", + "- `--annotation-file`: index of the target annotation files to test. Binary and continuous annotations\n", + " are both supported and the type is auto-detected per column. Multiple target annotations may be given\n", + " in one file (columns `path`, `path1`, `path2`, ...); single-target and joint-target analyses are then\n", + " produced in the same pass.\n", + "- `--reference-anno-file`: index of the baseline annotations, typically a baseline-LD\n", + " baseline-LD model in `.annot.gz` form: v1.1 of Gazal et al. 2017 carries 75 annotations, v2.2 carries\n", + " 97. The baseline conditions every regression.\n", + "- `--genome-ref-file`: index of the PLINK-format genome reference.\n", + "- `--chromosome`: restrict to a subset of chromosomes.\n", + "- `--snp-list`: HapMap3-style SNP list. Its presence switches the polyfun call: given a list, `ldsc\n", + " --l2 --print-snps` writes `.l2.ldscore.gz`; without one, `compute_ldscores` writes\n", + " `.l2.ldscore.parquet`. It also changes the LD-score column name that `postprocess` matches on, so\n", + " `--target-categories` may need to be passed explicitly.\n", + "- `--ld-wind-kb` (default `0`) / `--ld-wind-cm` (default `1.0`): LD window. Using the cM window\n", + " requires genetic-map positions in the `.bim` fourth column; switch to `--ld-wind-kb` if it holds 0.\n", + "- `--compute-single` / `--no-compute-single` and `--compute-joint` / `--no-compute-joint` (both default\n", + " on): whether to emit the per-annotation single-target and the joint directories. The joint directory\n", + " is only emitted for two or more annotations.\n", + "- `--score-column` (default `3`) and `--is-range` / `--no-is-range` (default off): which column carries\n", + " the annotation score, and whether the annotation file is interval- or position-based.\n", + "\n", + "With `--no-is-range`, one row per position and an optional score column, defaulting to 1:\n", + "\n", + " ```\n", + " chr\tpos\tscore\n", + " 1\t10001\t1\n", + " 1\t10002\t1\n", + " ```\n", + "\n", + "With `--is-range`, one row per interval:\n", + "\n", + " ```\n", + " chr\tstart\tend\tscore\n", + " 1\t10001\t20001\t1\n", + " 1\t30001\t40001\t1\n", + " ```\n", + "\n", + "`get_heritability` -- run the S-LDSC regression. All LD-derived inputs (baseline LD scores, target LD\n", + "scores, regression weights, allele frequencies) must be computed against the same reference panel as\n", + "`--genome-ref-file`; files from different panels (1000G versus ADSP, say) must not be mixed:\n", + "\n", + "- `--all-traits-file`: list of munged summary statistics to run, one per line.\n", + "- `--sumstat-dir`: directory holding those summary statistics.\n", + "- `--target-anno-dir` / `--target-anno-dirs`: the LD-score directory or directories written by\n", + " `make_annotation_files_ldscore`. Each (trait, target directory) pair is one polyfun call.\n", + "- `--baseline-ld-dir` and `--baseline-name` (default `baseline_chr`): baseline LD scores and their\n", + " per-chromosome file prefix.\n", + "- `--frqfile-dir` and `--plink-name` (default `ADSP_chr`): PLINK `.frq` allele frequencies, used to\n", + " enforce the MAF cutoff.\n", + "- `--weights-dir` and `--weight-name` (default `weights_chr`): LD-score regression weights.\n", + "- `--n-blocks` (default `200`): jackknife blocks for the standard errors.\n", + "- `--all-traits`: run every trait found rather than the list.\n", + "\n", + "`munge_sumstats_polyfun` -- optional preprocessing, run before `get_heritability`:\n", + "\n", + "- `--sumstats` (required): raw GWAS summary statistics to convert to LDSC format.\n", + "- `--n`: sample size, when the file does not carry one.\n", + "- `--min-info` (default `0.6`), `--min-maf` (default `0.001`), `--chi2-cut` (default `30`): quality and\n", + " outlier filters.\n", + "- `--keep-hla` / `--no-keep-hla` (default off): retain the HLA region.\n", + "\n", + "`postprocess` -- standardize tau and meta-analyse across traits:\n", + "\n", + "- `--traits-file`: traits to include.\n", + "- `--heritability-cwd`: the `get_heritability` output directory to read.\n", + "- `--target-categories` and `--target-categories-label`: which `.results` `Category` rows are the\n", + " target annotation, and how to label them. Auto-detected unless `--snp-list` changed the column name.\n", + "\n", + "`meta_subset` -- optional re-meta over a trait subset, no regression re-run:\n", + "\n", + "- `--postprocess-rds`: the cached `.sldsc_postprocess.rds`.\n", + "- `--subset-traits-file` and `--subset-name` (required): the trait subset and its output label.\n", + "- `--target-categories`: as above.\n", + "\n", + "Cluster resources: `--numThreads` (default `16`), `--job-size`, `--walltime`, `--mem`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output\n", + "\n", + "- `/` under the LD-score directory -- from `make_annotation_files_ldscore`: polyfun\n", + " `.annot.gz` files plus per-annotation LD scores (`.l2.ldscore.parquet` or `.l2.ldscore.gz`, `.l2.M`,\n", + " `.l2.M_5_50`). One single-target directory per annotation, plus a joint directory when there is more\n", + " than one. Recomputable from the annotation and reference panel, and read by every regression.\n", + "- `.` -- from `get_heritability`: the S-LDSC regression output,\n", + " one set per trait per target directory. The `.results` `Category` column carries the annotation name\n", + " with a `_` suffix.\n", + "- `.sldsc_postprocess.rds` -- from `postprocess`: a single object holding per-trait\n", + " tables (Gazal-style tau*, EnrichStat with back-solved jackknife SE) and three DerSimonian-Laird\n", + " random-effects meta tables (tau*, E, EnrichStat).\n", + "- `` tables -- from `meta_subset`: a re-meta of the cached `.sldsc_postprocess.rds` over a\n", + " user-defined trait subset. Lightweight: no regression is re-run.\n", + "\n", + "Each stage writes into its own `--cwd`, and leaves a `.stdout` / `.stderr` log and the generated shell\n", + "or R script beside its targets.\n", + "\n", + "LD scores for the example annotation, under `output/sldsc_ldscore/protocol_example_single_1/`:\n", + "\n", + "```\n", + "protocol_example_single_1.19.annot.gz\n", + "protocol_example_single_1.19.l2.ldscore.parquet\n", + "protocol_example_single_1.19.l2.M\n", + "protocol_example_single_1.19.l2.ldscore.parquet.log\n", + "```\n", + "\n", + "The regression result, `output/sldsc_heritability/protocol_example_single_1/sumstats.parquet.results`\n", + "(first four columns of each row shown; the file also carries `Enrichment`, `Enrichment_std_error`,\n", + "`Enrichment_p`, `Coefficient`, `Coefficient_std_error` and `Coefficient_z-score`):\n", + "\n", + "```\n", + "Category\tProp._SNPs\tProp._h2\tProp._h2_std_error\n", + "ANNOT_0\t1.6443e-02\t4.1714e-01\t2.9297e-01\n", + "Coding_UCSC_common_1\t5.2671e-03\t1.5724e-01\t1.0492e-01\n", + "```\n", "\n", - "The steps below run the four pipeline workflows end to end on the example data. Each step lists what it does, then the `sos run` command to execute it.\n" + "`postprocess` and `meta_subset` have no example output committed: `output/sldsc_postprocess/` holds only\n", + "the generated R script and its log, so no `.sldsc_postprocess.rds` was produced for the toy data." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example" ] }, { @@ -267,7 +387,7 @@ "kernel": "SoS" }, "source": [ - "## Step 1. `make_annotation_files_ldscore`\n", + "#### Step 1. `make_annotation_files_ldscore`\n", "\n", "*Annotation preparation and S-LDSC regression (polyfun).* This step accepts a single annotation file for a single-tau analysis (one annotation as input) or several annotation files for a joint-tau analysis (multiple annotations as input)." ] @@ -278,90 +398,16 @@ "kernel": "SoS" }, "source": [ - "#### **Inputs**\n", - "\n", - "##### 1. Target Annotation File\n", - "\n", - "- **Purpose**: Specifies the user-provided (\"target\") genome annotation files. The pipeline supports both binary and continuous annotations; the type is auto-detected per annotation column.\n", - "- **Formats**:\n", - " - Text file (`.txt`) listing per-chromosome paths to annotation files. Annotation files can be `.rds`/`.tsv`/`.txt`.\n", - " - Alternatively, files for specific chromosomes can be provided directly.\n", - " - **Multiple target annotations** are supported in one input file (one column per annotation, prefixed `path`, `path1`, `path2`, ...). Single-target and joint-target analyses are produced automatically in one pipeline pass.\n", - " - **Format** (the score column is optional; if absent, score is set to 1):\n", - " - `is_range = False`:\n", - " ```\n", - " chr pos score\n", - " 1 10001 1\n", - " 1 10002 1\n", - " ```\n", - " - `is_range = True`:\n", - " ```\n", - " chr start end score\n", - " 1 10001 20001 1\n", - " 1 30001 40001 1\n", - " ```\n", - "\n", - "##### 2. Reference Annotation File (baseline-LD)\n", - "\n", - "- **Purpose**: Provides the baseline annotations (typically the 97-annotation baseline-LD model from Gazal et al. 2017) in `.annot.gz` format for each chromosome. The baseline conditions every regression.\n", - "- **Formats**:\n", - " - Text file listing baseline annotation files for all chromosomes.\n", - " - Alternatively, files for specific chromosomes can be provided directly.\n", - "\n", - "##### 3. Genome Reference File\n", - "\n", - "- **Purpose**: PLINK-format `.bed/.bim/.fam` files for our LD reference panel, per chromosome. This is the panel against which all LD-derived quantities (target LD scores, baseline LD scores, regression weights, allele frequencies) must be computed. **Do not mix files derived from different panels** (e.g. 1000G vs ADSP).\n", - "- **Formats**:\n", - " - Text file listing per-chromosome reference files, or files for specific chromosomes.\n", - "\n", - "##### 4. SNP List\n", - "\n", - "- **Purpose**: Specifies the SNPs to include in LDSC analysis (typically a HapMap3-style list).\n", - "- **Format**: A list of `rsid`s, one per line.\n", - "\n" + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", - " import pkg_resources\n", - "INFO: Running \u001b[32mmake_annotation_files_ldscore\u001b[0m: \n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=1) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=3) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=2) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=0) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=5) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=6) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=4) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=7) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=9) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=10) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=8) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=11) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=14) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=13) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=12) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=15) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=18) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=16) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=17) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=19) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=21) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m (index=20) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmake_annotation_files_ldscore\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_ldscore/protocol_example_single_1/protocol_example_single_1.1.annot.gz /restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_ldscore/protocol_example_single_1/protocol_example_single_1.1.l2.ldscore.parquet... (66 items in 22 groups)\u001b[0m\n", - "INFO: Workflow make_annotation_files_ldscore (ID=weae0ca3fdf468fd8) is executed successfully with 1 completed step and 22 completed substeps.\n" - ] - } - ], + "outputs": [], "source": [ "sos run pipeline/sldsc_enrichment.ipynb make_annotation_files_ldscore \\\n", " --annotation_file input/enrichment/sldsc/colocboost_test_annotation_path.txt \\\n", @@ -369,7 +415,6 @@ " --genome_ref_file input/enrichment/sldsc/genome_reference_bfile.txt \\\n", " --annotation_name protocol_example \\\n", " --plink_name reference. --baseline_name annotations. --weight_name weights. \\\n", - " \\\n", " --cwd output/sldsc_ldscore -j 4\n" ] }, @@ -379,7 +424,7 @@ "kernel": "SoS" }, "source": [ - "### Munge summary statistics (preprocessing, run before Step 2)\n", + "#### Munge summary statistics (preprocessing, run before Step 2)\n", "\n", "Before estimating heritability, each raw GWAS summary-statistics file must be converted into the LDSC-compatible format consumed by `get_heritability`. Run `munge_sumstats_polyfun` once per trait; the munged files are then collected in the directory passed to `get_heritability` via `--sumstat_dir`.\n" ] @@ -407,7 +452,7 @@ "kernel": "SoS" }, "source": [ - "## Step 2. `get_heritability`\n" + "#### Step 2. `get_heritability`\n" ] }, { @@ -416,51 +461,16 @@ "kernel": "SoS" }, "source": [ - "**Inputs**\n", - "\n", - "##### 1. Allele Frequency Files (`.frq`, our panel)\n", - "\n", - "- **Purpose**: PLINK `.frq` files for the reference panel, used to enforce the MAF cutoff. **Required** when `maf_cutoff > 0` (default `0.05`); the pipeline fails if missing unless `maf_cutoff = 0` is explicitly set.\n", - "\n", - "##### 2. GWAS Summary Statistics\n", - "\n", - "- **Purpose**: One munged sumstats file per trait, listed in a text file (`all_traits_file`). The pipeline runs the regression once per trait per single/joint mode.\n", - "- **Format**:\n", - " ```\n", - " CAD_META.filtered.sumstats.gz\n", - " UKB.Lym.BOLT.sumstats.gz\n", - " ```\n", - "\n" + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", - " import pkg_resources\n", - "INFO: Running \u001b[32mget_heritability\u001b[0m: \n", - "maf_cutoff = 0: skipping MAF filter (--not-M-5-50)\n", - "maf_cutoff = 0: skipping MAF filter (--not-M-5-50)\n", - "maf_cutoff = 0: skipping MAF filter (--not-M-5-50)\n", - "python: can't open file '/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/../polyfun/ldsc.py': [Errno 2] No such file or directory\n", - "python: can't open file '/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/../polyfun/ldsc.py': [Errno 2] No such file or directory\n", - "python: can't open file '/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/../polyfun/ldsc.py': [Errno 2] No such file or directory\n", - "INFO: \u001b[32mget_heritability\u001b[0m (index=1) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mget_heritability\u001b[0m (index=0) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mget_heritability\u001b[0m (index=2) is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mget_heritability\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_heritability/protocol_example_single_1/sumstats.parquet.log /restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_heritability/protocol_example_single_1/sumstats.parquet.results... (6 items in 3 groups)\u001b[0m\n", - "INFO: Workflow get_heritability (ID=wa79eac1662f5dd2d) is executed successfully with 1 completed step and 3 completed substeps.\n" - ] - } - ], + "outputs": [], "source": [ "sos run pipeline/sldsc_enrichment.ipynb get_heritability \\\n", " --target_anno_dirs output/sldsc_ldscore/protocol_example_single_1 \\\n", @@ -480,50 +490,35 @@ "kernel": "SoS" }, "source": [ - "## Step 3. `Post-processing (pecotmr) and meta-analysis`\n", - "\n", - "*Post-Processing (`pecotmr::sldscPostprocessingPipeline`)*\n", + "#### Step 3. `Post-processing (pecotmr) and meta-analysis`\n", "\n", - "A single R function call consumes all polyfun outputs for the run and produces the final tables:\n", + "Reads every polyfun output under `--heritability-cwd` and calls\n", + "`pecotmr::sldscPostprocessingPipeline` to produce the per-trait standardized tables and the default\n", + "random-effects meta across all traits.\n", "\n", - "- Reads each polyfun output and extracts $\\tau$, $E$, $h^2_g$, EnrichStat p-value, and per-block jackknife $\\tau$ values.\n", - "- Computes annotation $sd_C$ and $M_{\\mathrm{ref}}$ over the same MAF $>$ cutoff SNP set as the regression.\n", - "- Standardizes $\\tau \\to \\tau^*$ for both single-tau and joint-tau modes, including the per-block versions for jackknife SE.\n", - "- Auto-detects whether each annotation is binary or continuous and tags every output row accordingly.\n", - "- Reports the number and names of baseline annotations encountered (via `message()`) for transparency.\n", - "- Runs the default DerSimonian-Laird random-effects meta-analysis across all supplied traits, producing three meta tables: $\\tau^*$ (cross-type comparable), $E$ (within-binary), and EnrichStat (within-type).\n", - "\n", - "Outputs are returned as an R list with two top-level entries: `per_trait` (one tidy data frame per trait, single + joint estimates side-by-side per target) and `meta` (three tables, one per quantity, with rows = target annotations and columns = single/joint mean/SE/p plus an `is_binary` flag).\n", - "\n", - "The `[postprocess]` step reads all polyfun outputs under `heritability_cwd`\n", - "(which contains the $N$ single-target subdirectories and optionally the\n", - "joint subdirectory) and calls `pecotmr::sldscPostprocessingPipeline()`\n", - "to produce per-trait standardized tables and the default random-effects\n", - "meta across all traits.\n", - "\n", - "Use `--target-categories-label` (same order as `--target-categories`) to give the target annotations friendly names in the output — e.g. `--target-categories ANNOT_1_0 ANNOT_2_0 --target-categories-label quantile_eQTL eQTL` makes the `target` column read `quantile_eQTL` / `eQTL` instead of `ANNOT_1_0` / `ANNOT_2_0` (the original names are kept in `params$target_categories_orig`). Omit it to keep the polyfun `.results` names.\n" + "`--target-categories-label` (same order as `--target-categories`) gives the target annotations\n", + "friendly names in the output -- `--target-categories ANNOT_1_0 ANNOT_2_0 --target-categories-label\n", + "quantile_eQTL eQTL` makes the `target` column read `quantile_eQTL` / `eQTL` rather than `ANNOT_1_0` /\n", + "`ANNOT_2_0`. The original names stay in `params$target_categories_orig`; omit the flag to keep the\n", + "polyfun `.results` names." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", - " import pkg_resources\n", - "INFO: Running \u001b[32mpostprocess\u001b[0m: \n", - "INFO: \u001b[32mpostprocess\u001b[0m is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mpostprocess\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_postprocess/protocol_example.sldsc_postprocess.rds\u001b[0m\n", - "INFO: Workflow postprocess (ID=wb64dc2b84958960c) is executed successfully with 1 completed step.\n" - ] - } - ], + "outputs": [], "source": [ "sos run pipeline/sldsc_enrichment.ipynb postprocess \\\n", " --traits_file input/enrichment/sldsc/sumstats_test_all.txt \\\n", @@ -531,8 +526,7 @@ " --target_categories ANNOT_0 --target_categories_label protocol_example_annotation \\\n", " --target_anno_dir output/sldsc_ldscore/protocol_example_single_1 \\\n", " --annotation_name protocol_example \\\n", - " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4\n", - "\n" + " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4\n" ] }, { @@ -541,10 +535,11 @@ "kernel": "SoS" }, "source": [ - "## Step 4. `Subset Meta-Analysis (`pecotmr::metaSldscRandom`)` (optional)\n", - "\n", - "The default meta in Step 2 pools all traits the user supplied. To re-run the meta on a subset (e.g., neurodegenerative traits only, or autoimmune traits only) without re-running the regression layer:\n", + "#### Step 4. `Subset Meta-Analysis (`pecotmr::metaSldscRandom`)` (optional)\n", "\n", + "Step 3 pools every trait passed to `postprocess`. To re-meta a subset -- neurodegenerative traits\n", + "only, say -- without re-running the regression or the per-trait standardization, `meta_subset` works\n", + "from the cached `.sldsc_postprocess.rds`. It is light enough to run interactively:\n", "\n", "```r\n", "res <- readRDS(\"sldsc_results.rds\")\n", @@ -553,42 +548,7 @@ "meta_neuro_taustar <- pecotmr::metaSldscRandom(\n", " view_neuro, category = \"my_target_anno\", quantity = \"tauStar\"\n", ")\n", - "```\n", - "\n", - "This step is light-weight and can be run interactively.\n", - "\n", - "\n", - "The default meta in step 3 pools all traits supplied to `[postprocess]`. Use `[meta_subset]` to re-run the meta on a user-defined trait subset (e.g., neurodegenerative traits only, autoimmune traits only) without re-running the regression or the per-trait standardization. The subset operates on the cached `.sldsc_postprocess.rds` output; it is light-weight and can be run interactively or in batch.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "metadata": { - "kernel": "Bash" - }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", - " import pkg_resources\n", - "INFO: Running \u001b[32mmeta_subset\u001b[0m: \n", - "INFO: \u001b[32mmeta_subset\u001b[0m is \u001b[32mcompleted\u001b[0m.\n", - "INFO: \u001b[32mmeta_subset\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/jaempawi/xqtl-protocol/output/sldsc_postprocess/protocol_example.category1.meta.rds\u001b[0m\n", - "INFO: Workflow meta_subset (ID=w09a2a0530119f1d2) is executed successfully with 1 completed step.\n" - ] - } - ], - "source": [ - "sos run pipeline/sldsc_enrichment.ipynb meta_subset \\\n", - " --postprocess_rds output/sldsc_postprocess/protocol_example.sldsc_postprocess.rds \\\n", - " --subset_traits_file input/enrichment/sldsc/sumstats_test_category1.txt \\\n", - " --subset_name category1 --target_categories ANNOT_0 \\\n", - " --annotation_name protocol_example \\\n", - " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4\n" + "```" ] }, { @@ -597,33 +557,23 @@ "kernel": "SoS" }, "source": [ - "## Output\n", - "\n", - "### Output summary\n", - "\n", - "| Stage | Cached on disk | Recomputable from | Purpose |\n", - "|---|---|---|---|\n", - "| Target LD scores | per-annotation, once | annotation + reference panel | input to every regression |\n", - "| polyfun `.results` per (trait, mode) | yes | regression run | $\\tau$, $E$, EnrichStat |\n", - "| Per-trait standardized table | yes (RDS) | polyfun outputs + $sd_C$ + $M_{\\mathrm{ref}}$ | reporting + meta |\n", - "| Default meta tables | yes (RDS) | per-trait standardized | headline figures |\n", - "| Subset meta | re-run on demand | per-trait standardized | custom analyses |\n" + "**Timing**: TBD (on toy dataset)" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "### Per-stage outputs\n", - "\n", - "Each workflow writes into its `--cwd`:\n", - "\n", - "- **make_annotation_files_ldscore** — polyfun `.annot.gz` files plus per-annotation LD-score directories (`.l2.ldscore.{gz,parquet}`, `.l2.M`, `.l2.M_5_50`). One single-target directory per annotation, plus (when more than one annotation) a joint directory.\n", - "- **get_heritability** — per trait and per target directory, the S-LDSC regression outputs `.{results,log,part_delete}`. The `.results` `Category` column carries the annotation name with a `_` suffix.\n", - "- **postprocess** — a single `.sldsc_postprocess.rds` containing per-trait tables (Gazal-style tau*, EnrichStat with back-solved jackknife SE) and three DerSimonian–Laird random-effects meta tables (tau*, E, EnrichStat).\n", - "- **meta_subset** — a re-meta of the cached `.sldsc_postprocess.rds` over a user-defined trait subset (lightweight; no regression re-run).\n" + "sos run pipeline/sldsc_enrichment.ipynb meta_subset \\\n", + " --postprocess_rds output/sldsc_postprocess/protocol_example.sldsc_postprocess.rds \\\n", + " --subset_traits_file input/enrichment/sldsc/sumstats_test_category1.txt \\\n", + " --subset_name category1 --target_categories ANNOT_0 \\\n", + " --annotation_name protocol_example \\\n", + " --maf_cutoff 0 --cwd output/sldsc_postprocess -j 4" ] }, { @@ -632,31 +582,176 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "Produces per-annotation enrichment statistics (tau, enrichment, p-value) from stratified LD score regression." + "## Command Interface" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Command interface\n", - "\n", - "List all workflows and their options:\n" + "sos run pipeline/sldsc_enrichment.ipynb -h" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/sldsc_enrichment.ipynb -h" + "```\n", + "usage: sos run pipeline/sldsc_enrichment.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " make_annotation_files_ldscore\n", + " get_heritability\n", + " munge_sumstats_polyfun\n", + " postprocess\n", + " meta_subset\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Path to the work directory of the analysis.\n", + " --annotation-name VAL (as str, required)\n", + " Prefix for the analysis output\n", + " --modular-script-dir code/script (as path)\n", + " Directory holding the modular R wrapper scripts\n", + " (code/script).\n", + " --maf-cutoff 0.05 (as float)\n", + " MAF cutoff for sLDSC. Default 0.05 per sLDSC\n", + " recommendation (rare-variant LD is unstable and\n", + " HapMap3-style regression weights are common-variant by\n", + " construction). Set to 0 to opt out of MAF filtering (NOT\n", + " recommended; only use if you understand the\n", + " implications). Other values would require recomputing LD\n", + " scores at that cutoff.\n", + " --annotation-file . (as path)\n", + " for make_annotation_files_ldscore workflow:\n", + " --reference-anno-file . (as path)\n", + " --genome-ref-file . (as path)\n", + " --chromosome (as list)\n", + " --snp-list . (as path)\n", + " --ld-wind-kb 0 (as int)\n", + " --ld-wind-cm 1.0 (as float)\n", + " --all-traits-file . (as path)\n", + " for get_heritability workflow. Note: all LD-derived\n", + " inputs (baseline LD scores, target LD scores, regression\n", + " weights, allele frequencies) must be computed against\n", + " the same reference panel as `genome_ref_file`. Do not\n", + " mix files derived from different reference panels (e.g.,\n", + " 1000G vs ADSP).\n", + " --sumstat-dir . (as path)\n", + " --target-anno-dir . (as path)\n", + " --baseline-ld-dir . (as path)\n", + " --frqfile-dir . (as path)\n", + " --plink-name 'ADSP_chr'\n", + " --weights-dir . (as path)\n", + " --baseline-name 'baseline_chr'\n", + " --weight-name 'weights_chr'\n", + " --n-blocks 200 (as int)\n", + " --numThreads 16 (as int)\n", + " Number of threads\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 12h\n", + " --mem 16G\n", + "\n", + "Sections\n", + " make_annotation_files_ldscore:\n", + " Workflow Options:\n", + " --[no-]compute-single (default to True)\n", + " --- snplist (--snp_list) vs no-snplist: which polyfun\n", + " script, output format, column name, and the CM\n", + " requirement --- --snp_list given -> ldsc --l2 --print-\n", + " snps -> output .l2.ldscore.gz --snp_list absent ->\n", + " compute_ldscores -> output .l2.ldscore.parquet\n", + " LD-score column name (this is what becomes the .results\n", + " \"Category\" in [get_heritability], with a \"_\" suffix appended there): * compute_ldscores\n", + " ALWAYS keeps the annot column name(s): single annot\n", + " column \"ANNOT\" -> ldscore column \"ANNOT\" joint\n", + " annot columns \"ANNOT_1\",\"ANNOT_2\",... ->\n", + " \"ANNOT_1\",\"ANNOT_2\",... * ldsc --l2 has a quirk: with\n", + " EXACTLY ONE annotation (n_annot == 1) it HARD-CODES the\n", + " ldscore column name to \"L2\" and DROPS the annot's\n", + " original column name. With >=2 annotations it uses\n", + " \"L2\" (\"ANNOT_1L2\",\"ANNOT_2L2\",...). => a\n", + " single-target snplist run reports \"L2_0\" in .results,\n", + " while a single-target no-snplist run reports \"ANNOT_0\".\n", + " [postprocess] auto- detects either; only matters if you\n", + " pass --target-categories explicitly. CM column\n", + " requirement for snplist: ldsc --l2 --print-snps\n", + " requires the target annot to (a) carry a \"CM\"\n", + " (centimorgan) column and (b) line up with the plink .bim\n", + " (same SNP set, same row order). This step handles both\n", + " internally (normalize_for_ldsc: takes CM from the .bim\n", + " 4th column, re-expands the annot onto the .bim rows,\n", + " filling 0). Therefore the plink .bim files MUST carry\n", + " genetic-map (cM) positions when using --ld-wind-cm (the\n", + " default); if your .bim has 0 in the cM column, switch to\n", + " --ld-wind-kb instead.\n", + " --[no-]compute-joint (default to True)\n", + " --score-column 3 (as int)\n", + " --[no-]is-range (default to False)\n", + " get_heritability:\n", + " Workflow Options:\n", + " --target-anno-dirs paths()\n", + "\n", + " --- about the \".results\" Category column and the \"_0 /\n", + " _1\" suffix --- Each (trait, target_dir) pair is ONE\n", + " polyfun call; its `ldsc --ref-ld-chr` always gets\n", + " exactly two LD-score sources, in this order:\n", + " \"/.\" (index 0) ,\n", + " \"/\" (index 1) With --overlap-\n", + " annot, every annotation column in the .results\n", + " \"Category\" is named _: index 0 = the target file -> \"ANNOT_0\" (no-\n", + " snplist; compute_ldscores keeps the annot col name) ->\n", + " \"L2_0\" (snplist + single annot; ldsc hard-codes \"L2\",\n", + " see below) -> \"ANNOT_1_0\",\"ANNOT_2_0\" (no-snplist\n", + " joint dir, N>=2 annot cols) ->\n", + " \"ANNOT_1L2_0\",\"ANNOT_2L2_0\" (snplist joint dir, N>=2 ->\n", + " \"L2\") index 1 = the baseline file ->\n", + " \"base_1\",\"Coding_UCSC_1\", ... (the 97 baseline annots)\n", + " So in this pipeline the suffix is only ever 0 (target)\n", + " or 1 (baseline); it would continue 0,1,2,... only if you\n", + " handed `ldsc --ref-ld-chr` more than two sources. (Why\n", + " ANNOT_0 vs L2_0: see the [make_annotation_files_ldscore]\n", + " header — ldsc's \"n_annot == 1 -> column name 'L2'\" quirk\n", + " vs compute_ldscores keeping the annot column name.)\n", + " [postprocess] auto-detects the target Category; if you\n", + " instead pass --target-categories, the names must match\n", + " this column exactly.\n", + " --all-traits (as list)\n", + " munge_sumstats_polyfun:\n", + " Workflow Options:\n", + " --sumstats VAL (as path, required)\n", + " --n 0 (as int)\n", + " --min-info 0.6 (as float)\n", + " --min-maf 0.001 (as float)\n", + " --[no-]keep-hla (default to False)\n", + " --chi2-cut 30 (as int)\n", + " postprocess:\n", + " Workflow Options:\n", + " --traits-file . (as path)\n", + " --heritability-cwd . (as path)\n", + " --target-categories (as list)\n", + " --target-categories-label (as list)\n", + " meta_subset:\n", + " Workflow Options:\n", + " --postprocess-rds . (as path)\n", + " --subset-traits-file . (as path)\n", + " --subset-name VAL (as str, required)\n", + " --target-categories (as list)\n", + "```" ] }, { @@ -730,7 +825,7 @@ "kernel": "Python 3 (ipykernel)" }, "source": [ - "## Make Annotation File" + "### Make Annotation File" ] }, { @@ -961,7 +1056,7 @@ "kernel": "Python 3 (ipykernel)" }, "source": [ - "## Calculate Functional Enrichment using Annotations" + "### Calculate Functional Enrichment using Annotations" ] }, { diff --git a/code/SoS/mnm_analysis/mnm_methods/colocboost.ipynb b/code/SoS/mnm_analysis/mnm_methods/colocboost.ipynb index a1d30209e..38f326a4e 100644 --- a/code/SoS/mnm_analysis/mnm_methods/colocboost.ipynb +++ b/code/SoS/mnm_analysis/mnm_methods/colocboost.ipynb @@ -6,27 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Multi-trait colocalization using ColocBoost" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Prerequisites\n", + "# Multi-trait colocalization using ColocBoost\n", "\n", - "Requires fine-mapping outputs (`.susie.rds` files) from `mnm_regression` or `rss_analysis`." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" + "Multi-trait colocalization across molecular contexts and against GWAS, using ColocBoost." ] }, { @@ -35,7 +17,26 @@ "kernel": "SoS" }, "source": [ - "We use ColocBoost to perform colocalization analyses [cf. Cao et al (2025)](https://www.medrxiv.org/content/10.1101/2025.04.17.25326042v1). In short, ColocBoost performs colocalization while accounting for multiple causal variants within a genomic region of interest and can scale to hundreds of traits. We allow users to include or omit GWAS summary statistics. Required inputs are individual xQTL data from the same cohort (multiple phenotypes, same genotype). Linkage disequilibrium reference data is required if GWAS summary statistics are used." + "## Overview\n", + "\n", + "Two signals at the same locus - a QTL and a GWAS hit, or QTLs in two cell types - may share\n", + "a causal variant or merely sit in the same LD block. Colocalization tries to tell those\n", + "apart. Classical pairwise methods assume one causal variant per trait and compare traits\n", + "two at a time, which loses power when a region has several independent signals or when the\n", + "shared signal is weak in any single pair.\n", + "\n", + "ColocBoost treats it as a multi-task problem instead: a gradient boosting framework that\n", + "couples traits as it selects causal variants, so evidence that is weak in isolation can\n", + "still support a shared signal across many contexts. It scales to hundreds of traits and\n", + "allows multiple causal variants per region ([Cao et al., 2025](https://doi.org/10.1101/2025.04.17.25326042)).\n", + "\n", + "Requires fine-mapping outputs (`.susie.rds` files) from `mnm_regression` or `rss_analysis`.\n", + "\n", + "ColocBoost performs colocalization analyses ([Cao et al., 2025](https://doi.org/10.1101/2025.04.17.25326042)). In short, ColocBoost performs colocalization while accounting for multiple causal variants within a genomic region of interest and can scale to hundreds of traits. GWAS summary statistics may be included or omitted. Required inputs are individual xQTL data from the same cohort (multiple phenotypes, same genotype). Linkage disequilibrium reference data is required if GWAS summary statistics are used.\n", + "\n", + "**When to run it.** After QTL association testing, when you have several contexts to\n", + "compare, or a GWAS to integrate against. Colocalization is integration, not fine-mapping:\n", + "run `mnm_regression` if what you want is credible sets for one trait." ] }, { @@ -47,50 +48,38 @@ "source": [ "## Input\n", "\n", - "1. A list of regions to be analyzed (optional); the last column of this file should be region name.\n", - "2. Either a list of per chromosome genotype files, or one file for genotype data of the entire genome. Genotype data has to be in PLINK `bed` format. \n", - "3. Vector of lists of phenotype files per region to be analyzed, in UCSC `bed.gz` with index in `bed.gz.tbi` formats.\n", - "4. Vector of covariate files corresponding to the lists above.\n", - "5. Customized association windows file for variants (cis or trans). If it is not provided, a fixed sized window will be used around the region (a cis-window)\n", - "6. Optionally a vector of names of the phenotypic conditions in the form of `cond1 cond2 cond3` separated with whitespace.\n", - "7. Optionally summary statistics meta-data file and LD reference meta-data file.\n", + "Both entry points read per-region fine-mapping outputs (`.susie.rds`) produced by `mnm_regression` or `rss_analysis`. Individual-level genotype data must be in PLINK `bed` format; summary statistics come in through the GWAS and LD meta-data files instead.\n", "\n", - "Input 2 and 3 should be outputs from `genotype_per_region` and `annotate_coord` modules in previous preprocessing steps. 4 should be output of `covariate_preprocessing` pipeline that contains genotype PC, phenotypic hidden confounders and fixed covariates." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS", - "tags": [] - }, - "source": [ - "### Example genotype, phenotype and association analysis windows \n", + "- `--name colocboost_xqtl` (tag used in output filenames and as the study name)\n", + "- `--cwd output/colocboost_xqtl` (working directory all outputs are written under. Defaults to `output`.)\n", "\n", - "See [this page](mnm_regression) for example inputs of these information." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### Example summary statistics and LD reference\n", + "**Individual-level xQTL inputs.**\n", "\n", - "See [rss_analysis](rss_analysis) for LD reference formats (pre-computed blocks and PLINK genotype files),\n", - "per-study LD reference via the `ld_meta_data` column in GWAS meta-data, and mixture LD panels.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### About indels\n", + "- `--genoFile` **`input/colocboost/example.chr22.bed`**\n", + "(genotype data in PLINK `bed` format; either one file for the whole genome or a list of per-chromosome files)\n", + "- `--phenoFile` **`input/colocboost/pheno_manifest_multicontext.tsv`**\n", + "(a manifest of phenotype files per region, one row per region and context, in UCSC `bed.gz` format with a `bed.gz.tbi` index)\n", + "- `--covFile` **`input/colocboost/example_covariates.tsv`**\n", + "(covariate files matching the phenotype list)\n", + "- `--transpose-covariates` (set when the covariate file has samples in columns rather than rows)\n", + "\n", + "**Region selection.**\n", + "\n", + "- `--customized-association-windows` **`input/colocboost/association_windows.bed`**\n", + "(association windows for variants, cis or trans. Without it a fixed-size window of `--cis-window` (default 1000000) is used around each region.)\n", + "- `--region-name ENSG00000130538` (restrict the analysis to named regions. If dropped, the union of all regions across all phenotype region lists is analyzed.)\n", + "- `--region-list` (a file of regions to analyze; the last column must be the region name)\n", + "\n", + "**Summary-statistics inputs (GWAS integration).**\n", + "\n", + "- `--gwas-meta-data` (GWAS summary statistics meta-data file)\n", + "- `--ld-meta-data` (LD reference meta-data file. See [rss_analysis](rss_analysis) for the expected formats.)\n", "\n", - "Use `--no-indel` to remove indel variants from analysis. This applies to both individual-level genotype loading and summary statistics QC. Default keeps indels.\n" + "**Analysis mode.**\n", + "\n", + "- `--xqtl-coloc` (colocalize across the xQTL contexts; on by default)\n", + "- `--separate-gwas` / `--no-separate-gwas` (treat each GWAS as its own outcome, or pool them. `--separate-gwas` is the default; the xQTL-only example passes `--no-separate-gwas`.)\n", + "- `--no-indel` (drop indel variants. Applies to both individual-level genotype loading and summary-statistics QC; indels are kept by default.)" ] }, { @@ -103,44 +92,75 @@ "source": [ "## Output\n", "\n", - "For each analysis region the pipeline fits ColocBoost and saves the model in RDS format \u2014 one RDS per gene of interest (and per GWAS, when GWAS integration is used). Each RDS contains:\n", + "- **`/qtl_dataset/.qtl_dataset.rds`** (`colocboost_1`)\n", + "(the assembled QTL dataset for the study, built once and reused by the colocalization steps. Not present in the example output.)\n", + "- **`/colocboost/.colocboost_manifest.tsv`** (`colocboost_2`)\n", + "(manifest listing the per-region result files produced for this run. Not present in the example output.)\n", + "- **`/colocboost/..colocboost.rds`** (`colocboost_3`)\n", + "(the fitted ColocBoost model, one RDS per analysis region -- per gene of interest, and per GWAS when GWAS integration is used)\n", "\n", - "- `ucos_summary` \u2014 a summary table of the colocalization events.\n", - "- `vpa` \u2014 the variable colocalized probability for each variant (the probability of a variant being colocalized with at least one trait).\n", - "- `data_info` \u2014 information on the input data.\n", - "- `model_info` \u2014 information on the fitted ColocBoost model.\n", - "- `ucos_details` \u2014 trait-specific (uncolocalized) effects information.\n", - "- `region_info` \u2014 information on the region(s) of interest.\n", - "- `computing_time` \u2014 time taken for each step (loading, QC and analysis).\n", + "```\n", + "List of 1\n", + "$ ENSG00000283047: List of 7 \n", + " ..$ ucos_summary: NULL\n", + " ..$ vpa: NULL\n", + " ..$ data_info: List of 6\n", + " .. ..$ n_outcomes: integer [1:1] 1\n", + " .. ..$ n_variables: integer [1:1] 184\n", + " .. ..$ outcome_info: List of 4 \n", + " .. .. ..$ outcome_names: ...\n", + " .. .. ..$ sample_size: ...\n", + " .. .. ..$ is_sumstats: ...\n", + " .. .. ..$ is_focal: ...\n", + " .. ..$ variables: character [1:184] chr22:10685239:C:T chr22:10761227:G:A chr22:11285239:C:T chr22:11601805:G:A chr22:11791698:G:T ...\n", + " .. ..$ coef: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " .. ..$ z: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " ..$ model_info: List of 9\n", + " .. ..$ model_coveraged: logical [1:1] TRUE\n", + " .. ..$ n_updates: integer [1:1] 352\n", + " .. ..$ profile_loglik: numeric [1:352] 1 0.973943746514459 0.964750650763505 0.955751398118438 0.946916816050365 ...\n", + " .. ..$ outcome_profile_loglik: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " .. ..$ outcome_proximity_obj: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " .. ..$ outcome_coupled_best_update_obj: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " .. ..$ outcome_model_coveraged: List of 1\n", + " .. .. ..$ trait_A_ENSG00000283047: ...\n", + " .. ..$ outcome_n_updates: integer [1:1] 352\n", + " .. ..$ jk_star: matrix [351, 1] 125 125 125 131 125 ...\n", + " ..$ ucos_details: NULL\n", + " ..$ region_info: List of 3\n", + " .. ..$ region_coord: List of 3 \n", + " .. .. ..$ chrom: ...\n", + " .. .. ..$ start: ...\n", + " .. .. ..$ end: ...\n", + " .. ..$ grange: List of 3 \n", + " .. .. ..$ chrom: ...\n", + " .. .. ..$ start: ...\n", + " .. .. ..$ end: ...\n", + " .. ..$ region_name: character [1:2] ENSG00000283047 ENSG00000283047\n", + " ..$ computing_time: List of 3\n", + " .. ..$ Loading: difftime [1:1] 10.3424470424652 \n", + " .. ..$ QC: difftime [1:1] 0.0479960441589355 \n", + " .. ..$ Analysis: List of 3\n", + " .. .. ..$ xqtl_coloc: ...\n", + " .. .. ..$ joint_gwas: ...\n", + " .. .. ..$ separate_gwas: ...\n", + "```\n", "\n", - "**Note:** the suggested output naming convention is `cohort_...`.\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Minimal Working Example Steps" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Timing: ~X min" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### xQTL only analysis" + "The example files on disk are named `..cb_xqtl.rds`, not `.colocboost.rds` as the step declares. The code is authoritative; the example data predates the current naming. In this example `ucos_summary` and `vpa` are `NULL` because a single outcome yields no colocalization events.\n", + "\n", + "Each RDS contains:\n", + "\n", + "- `ucos_summary` -- a summary table of the colocalization events.\n", + "- `vpa` -- the variable colocalized probability for each variant (the probability of a variant being colocalized with at least one trait).\n", + "- `data_info` -- information on the input data.\n", + "- `model_info` -- information on the fitted ColocBoost model.\n", + "- `ucos_details` -- trait-specific (uncolocalized) effects information.\n", + "- `region_info` -- information on the analysis region." ] }, { @@ -149,9 +169,13 @@ "kernel": "SoS" }, "source": [ - "Below we duplicate the examples for phenotype and covariates to demonstrate that when there are multiple phenotypes for the same genotype it is possible to use this pipeline to analyze all of them (more than two is accepted as well).\n", + "## Minimal Working Example\n", + "\n", + "The phenotype and covariate examples are duplicated below to show that when there are multiple phenotypes for the same genotype it is possible to use this pipeline to analyze all of them (more than two is accepted as well).\n", "\n", - "Here using `--region-name` we focus the analysis on 3 genes. In practice if this parameter is dropped, the union of all regions in all phenotype region lists will be analyzed. It is possible for some of the regions there are no genotype data, in which case the pipeline will output RDS files with a warning message to indicate the lack of genotype data to analyze." + "Here `--region-name` focuses the analysis on 3 genes. In practice if this parameter is dropped, the union of all regions in all phenotype region lists will be analyzed. It is possible for some of the regions there are no genotype data, in which case the pipeline will output RDS files with a warning message to indicate the lack of genotype data to analyze.\n", + "\n", + "**Note:** Suggested output naming convention is cohort_modality, eg ROSMAP_snRNA_pseudobulk." ] }, { @@ -160,7 +184,9 @@ "kernel": "SoS" }, "source": [ - "**Note:** Suggested output naming convention is cohort_modality, eg ROSMAP_snRNA_pseudobulk." + "### ColocBoost with xQTL only\n", + "\n", + "This is the minimal working example and **runs end-to-end on the toy gene-expression data**, producing a `*.cb_xqtl.rds` colocalization result for the region. The same command also accepts peaks or any other molecular phenotype - just swap in the phenotype `.bed.gz`/manifest." ] }, { @@ -169,10 +195,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** ColocBoost with xQTL only\n", - "\n", - "This is the minimal working example and **runs end-to-end on the toy gene-expression data**, producing a `*.cb_xqtl.rds` colocalization result for the region. The same command also accepts peaks or any other molecular phenotype - just swap in the phenotype `.bed.gz`/manifest." - ] + "**Timing**: TBD (on toy dataset)" + ], + "id": "1e51346c" }, { "cell_type": "code", @@ -185,9 +210,6 @@ }, "outputs": [], "source": [ - "# Toy gene-expression example (run from the toy_example root).\n", - "# xQTL-only ColocBoost: builds one QtlDataset, then per-gene ColocBoost into\n", - "# {name}.{gene}.colocboost.rds.\n", "sos run pipeline/colocboost.ipynb colocboost \\\n", " --name colocboost_xqtl --cwd output/colocboost_xqtl \\\n", " --genoFile input/colocboost/example.chr22.bed \\\n", @@ -204,11 +226,21 @@ "kernel": "SoS" }, "source": [ - "### **Step 2.** ColocBoost with GWAS\n", + "### ColocBoost with GWAS\n", "\n", "Adds GWAS summary statistics (via `--gwas-meta-data`) and an LD reference (via `--ld-meta-data`). The xQTL ColocBoost completes, but the separate GWAS-xQTL colocalization is **still under development** with the installed package (see the note in the command cell)." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "73abb479" + }, { "cell_type": "code", "execution_count": null, @@ -217,9 +249,6 @@ }, "outputs": [], "source": [ - "# Toy example with GWAS (separate-focal coloc per study), from toy_example root.\n", - "# Per gene a region GwasSumStats is built, then xQTL + separate-GWAS coloc are\n", - "# written to one combined {name}.{gene}.colocboost.rds.\n", "sos run pipeline/colocboost.ipynb colocboost \\\n", " --name colocboost_gwas --cwd output/colocboost_gwas \\\n", " --genoFile input/colocboost/example.chr22.bed \\\n", @@ -238,11 +267,20 @@ "kernel": "SoS" }, "source": [ - "### **Step 3.** ColocBoost with multiple LD references (multi-ancestry)\n", - "\n", + "### ColocBoost with multiple LD references (multi-ancestry)\n", "Uses a per-study LD reference declared in the GWAS meta-data. It shares the separate-GWAS code path with Step 2 and is therefore **still under development** on the toy dataset." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "85dd4373" + }, { "cell_type": "code", "execution_count": null, @@ -251,10 +289,6 @@ }, "outputs": [], "source": [ - "# Multi-ancestry template: each study uses the per-study LD reference named in\n", - "# the gwas meta ld_meta_data column (gwas_sumstats_construct.R resolves a single\n", - "# shared panel per region, so genuinely distinct per-study panels are not merged\n", - "# here). Same separate-GWAS code path as the example above.\n", "sos run pipeline/colocboost.ipynb colocboost \\\n", " --name colocboost_multi_ld --cwd output/colocboost_multi_ld \\\n", " --genoFile input/colocboost/example.chr22.bed \\\n", @@ -264,7 +298,7 @@ " --gwas-meta-data input/colocboost/gwas_meta.txt \\\n", " --ld-meta-data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", " --region-name ENSG00000130538 \\\n", - " --separate-gwas --xqtl-coloc -j1\n" + " --separate-gwas --xqtl-coloc -j1" ] }, { @@ -273,7 +307,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -284,18 +318,17 @@ }, "outputs": [], "source": [ - "sos run pipeline/colocboost.ipynb -h\n" + "sos run pipeline/colocboost.ipynb -h" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ "```\n", - "usage: sos run /restricted/projectnb/xqtl/xqtl_protocol/xqtl-protocol/code/mnm_analysis/mnm_methods/colocboost.ipynb\n", + "usage: sos run pipeline/colocboost.ipynb\n", " [workflow_name | -t targets] [options] [workflow_options]\n", " workflow_name: Single or combined workflows defined in this script\n", " targets: One or more targets to generate\n", @@ -303,102 +336,105 @@ " workflow_options: Double-hyphen workflow-specific parameters\n", "\n", "Workflows:\n", - " get_analysis_regions\n", - " get_rss_analysis_regions\n", " colocboost\n", "\n", "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", " --name VAL (as str, required)\n", " It is required to input the name of the analysis\n", " --cwd output (as path)\n", " --genoFile VAL (as path, required)\n", - " A list of file paths for genotype data, or the genotype data itself.\n", + " PLINK1 genotype: pass the .bed file (.bim/.fam are read\n", + " automatically).\n", " --phenoFile paths\n", "\n", - " One or multiple lists of file paths for phenotype data.\n", + " QtlDataset phenotype manifest TSV. Columns: ID, #chr,\n", + " start, end, path, cond, and an optional cov_path (per-\n", + " context covariates). The first path is used. Replaces\n", + " the legacy list-of-phenotype-BEDs input.\n", " --phenoIDFile paths()\n", "\n", - " One or multiple lists of file paths for phenotype ID mapping file. The first column should be the original ID, the 2nd column should be the ID to be mapped to.\n", - " --covFile paths\n", + " Legacy phenotype ID-mapping file(s); accepted for CLI\n", + " compatibility but not consumed by the manifest-based\n", + " flow (the manifest carries the IDs).\n", + " --covFile paths()\n", "\n", - " Covariate file path\n", + " Uniform covariate file applied across all contexts\n", + " (QTLtools-format rows=covariates supported via\n", + " --transpose-covariates). Per-context covariates instead\n", + " come from the manifest cov_path column.\n", " --gwas-meta-data . (as path)\n", - " Summary statistics interface, see `rss_analysis.ipynb` for details\n", + " GWAS summary-statistics meta TSV. Columns: study_id,\n", + " chrom, file_path; optional n_sample, n_case, n_control,\n", + " ld_meta_data, column_mapping_file.\n", " --ld-meta-data . (as path)\n", - " --gwas-name (as list)\n", - " --gwas-data (as list)\n", - " --column-mapping (as list)\n", + " Default LD-reference meta (#chr, start, end, path). Per-\n", + " study overrides come from the gwas meta ld_meta_data\n", + " column.\n", " --region-list . (as path)\n", - " Optional: if a region list is provide the analysis will be focused on provided region. The LAST column of this list will contain the ID of regions to focus on when\n", - " region_name is given Otherwise, all regions with both genotype and phenotype files will be analyzed\n", + " Optional region list whose LAST column lists region/gene\n", + " IDs to analyze.\n", " --region-name (as list)\n", - " Optional: if a region name is provided the analysis would be focused on the union of provides region list and region names\n", - " --keep-samples . (as path)\n", - " Only focus on a subset of samples\n", - " --keep-variants . (as path)\n", - " Only focus on a subset of variants\n", + " Region/gene IDs to analyze (space separated on the CLI).\n", " --customized-association-windows . (as path)\n", - " An optional list documenting the custom association window for each region to analyze, with four column, chr, start, end, region ID (eg gene ID). If this list is not\n", - " provided, the default `window` parameter (see below) will be used.\n", - " --cis-window -1 (as int)\n", - " Specify the cis window for the up and downstream radius to analyze around the region of interest in units of bp When this is set to negative, we will rely on using\n", - " customized_association_windows\n", + " Optional per-gene association windows (BED: #chr start\n", + " end ID) overriding the default cis_window for the GWAS\n", + " extraction window.\n", + " --cis-window 1000000 (as int)\n", + " cis window (bp) on each side of the gene for fine-\n", + " mapping and the default GWAS extraction window.\n", " --[no-]save-data (default to False)\n", - " save data object or not\n", - " --phenotype-names [f'{x:bn}' for x in phenoFile]\n", - "\n", - " Name of phenotypes\n", - " --[no-]trans-analysis (default to False)\n", - " And indicator whether it is trans-analysis, ie, not using phenotypic coordinate information\n", + " Save the per-gene colocboost input bundle (currently\n", + " unused; reserved).\n", + " --study study\n", + " QtlDataset study label and covariate handling (legacy\n", + " CLI retained).\n", + " --[no-]transpose-covariates (default to False)\n", + " --genotype-covariates . (as path)\n", " --imiss 1.0 (as float)\n", - " remove a variant if it has more than imiss missing individual level data\n", + " Remove a variant if it has more than imiss fraction\n", + " missing genotypes.\n", " --maf 0.0025 (as float)\n", - " MAF and variance of X cutoff\n", + " MAF and variance-of-X cutoffs.\n", " --xvar-cutoff 0.0 (as float)\n", " --mac 5 (as int)\n", - " MAC cutoff, on top of MAF cutoff\n", + " MAC cutoff, on top of the MAF cutoff.\n", " --[no-]indel (default to True)\n", - " Remove indels if indel = False\n", - " --event-filter-rules . (as path)\n", + " Keep indels when True.\n", + " --keep-samples . (as path)\n", + " Only keep a subset of samples / variants\n", + " (whitespace/newline-separated IDs).\n", + " --keep-variants . (as path)\n", " --skip-analysis-pip-cutoff (as list)\n", - " If this value is not 0, then an initial single effect analysis will be performed to determine if follow up analysis will be continued or to simply return NULL If this is\n", - " negative we use a default way to determine this cutoff which is conservative but still useful\n", + " Per-context single-effect skip cutoff passed to\n", + " colocboost.R (--pip-cutoff-to-skip): a scalar applied to\n", + " every context, or one or more context=value items\n", + " (negative -> data-driven 3/ncol(X); empty -> 0).\n", " --skip-sumstats-analysis-pip-cutoff -1.0 (as float)\n", + " Summary-stats single-effect skip cutoff passed to\n", + " summaryStatsQc via gwas_sumstats_construct.R.\n", " --[no-]xqtl-coloc (default to True)\n", - " Perform xQTL colocalization\n", + " ColocBoost variants to run.\n", " --[no-]joint-gwas (default to False)\n", - " Perform joint colocalization with many traits\n", " --[no-]separate-gwas (default to True)\n", - " Perform separate GWAS targeted anlaysis one at a time\n", - " --[no-]impute (default to False)\n", - " Whether to impute the sumstat for all the snp in LD but not in sumstat.\n", - " --rcond 0.01 (as float)\n", - " --lamb 0.01 (as float)\n", - " --R2-threshold 0.6 (as float)\n", - " --minimum-ld 5 (as int)\n", - " --qc-method NULL\n", - " summary stats QC methods: slalom, dentist\n", - " --extract-sumstats-region-name NULL\n", - " --sumstats-region-name-col NULL\n", - " Either an index number in str format or \"NULL\" as a string\n", - " --comment-string NULL\n", - " --ld-data-name (as list)\n", + " --qc-method none\n", + " Summary-stats LD-mismatch QC method (none | slalom |\n", + " dentist).\n", " --container ''\n", - " Analysis environment settings\n", + " Analysis environment settings.\n", + " --entrypoint ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "\n", " --job-size 200 (as int)\n", - " For cluster jobs, number commands to run per job\n", + " For cluster jobs, number of commands to run per job.\n", " --walltime 1h\n", - " Wall clock time expected\n", " --mem 20G\n", - " Memory expected\n", " --numThreads 1 (as int)\n", - " Number of threads\n", "\n", "Sections\n", - " get_analysis_regions:\n", - " get_rss_analysis_regions:\n", - " colocboost:\n", - " ```" + " colocboost_1:\n", + " colocboost_2:\n", + " colocboost_3:\n", + "```" ] }, { @@ -565,7 +601,7 @@ "kernel": "SoS" }, "source": [ - "## ColocBoost analysis" + "### ColocBoost analysis" ] }, { @@ -621,37 +657,6 @@ " --pip-cutoff-to-skip \"${\",\".join([str(x) for x in skip_analysis_pip_cutoff])}\" \\\n", " --output ${_output}\n" ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Troubleshooting" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "|------|---------|---------|------------------|---------|\n", - "| | | | | |\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n\nOutput file: `{cwd}/colocboost/{name}.{region_id}.colocboost.rds`\n\nEach RDS is a named list with one slot per analysis mode. The structure is the same for all steps \u2014 only which slots are populated differs:\n\n| Top-level key | Step 1 (xQTL-only) | Step 2 (xQTL + GWAS) |\n|--------------|---------------------|----------------------|\n| `xqtl_coloc` | `colocboost`-class object | `colocboost`-class object |\n| `joint_gwas` | `NULL` (not run) | `NULL` (off by default) |\n| `separate_gwas` | `NULL` (not run) | empty `list()` (run, no events) |\n| `computing_time` | per-step wall time | per-step wall time |\n\n```r\nres <- readRDS(\"colocboost_xqtl_positive.GENE.colocboost.rds\")\nnames(res) # [1] \"xqtl_coloc\" \"joint_gwas\" \"separate_gwas\" \"computing_time\"\n```\n\nEach active mode slot is a `colocboost`-class object:\n\n```r\ncb <- res$xqtl_coloc\nclass(cb) # \"colocboost\"\nnames(cb) # \"cos_summary\" \"vcp\" \"cos_details\" \"data_info\" \"model_info\" \"ucos_details\"\n\n# data_info: input summary\ncb$data_info$outcome_info\n# outcome_names sample_size is_sumstats is_focal\n# y1 Y1 200 FALSE FALSE\n# y2 Y2 200 FALSE FALSE\n\n# model_info: convergence\ncb$model_info$model_coveraged # TRUE\ncb$model_info$n_updates # 450\n```\n\n**`cos_summary`** \u2014 one row per colocalization event detected:\n\n```r\ncb$cos_summary\n# focal_outcome colocalized_outcomes cos_id purity top_variable top_variable_vcp\n# 1 FALSE Y1; Y2 cos1:y1_y2 1 chr1:10250:A:T 1\n# cos_npc min_npc_outcome n_variables colocalized_index colocalized_variables\n# 1 1 1 1 250 chr1:10250:A:T\n# colocalized_variables_vcp\n# 1 0.99999999997293\n```\n\n| Column | Description |\n|--------|-------------|\n| `colocalized_outcomes` | Traits sharing this colocalization event (`Y1; Y2` = both contexts) |\n| `cos_id` | Event ID (e.g. `cos1:y1_y2` = 1st event, shared by y1 and y2) |\n| `purity` | Purity of the credible set (1 = a single dominant variant) |\n| `top_variable` | Variant with highest VCP in this event |\n| `top_variable_vcp` | VCP of the top variant (1.0 = near-certain) |\n| `cos_npc` | CoS non-null probability (\u2265 0.2 threshold) |\n| `colocalized_variables` | All variants in the credible set for this event |\n| `focal_outcome` | `TRUE` if a GWAS focal trait is involved |\n\n**`vcp`** \u2014 named numeric vector, one entry per variant:\n\n```r\n# vcp = per-variant colocalization probability (named numeric vector)\nlength(cb$vcp) # 500 (one per variant in the region)\nsort(cb$vcp, decreasing = TRUE)[1:3]\n# chr1:10250:A:T chr1:10103:A:T chr1:10148:A:T\n# 1.000000e+00 1.260847e-11 6.503242e-12\n```\n\nThe causal variant (`chr1:10250:A:T`) has VCP = 1.0; all others are essentially 0. In real data, multiple variants may share non-trivial VCP within a credible set.\n\n> **Note**: The toy pipeline data (ENSG00000130538, n=49) produces `cos_summary = NULL` and `vcp = NULL` due to insufficient sample size. The example above uses a simulated dataset (n=200, 2 contexts, strong shared causal signal) to illustrate the output format." - ] } ], "metadata": { diff --git a/code/SoS/mnm_analysis/mnm_methods/mnm_regression.ipynb b/code/SoS/mnm_analysis/mnm_methods/mnm_regression.ipynb index ad326982f..183b96bb0 100644 --- a/code/SoS/mnm_analysis/mnm_methods/mnm_regression.ipynb +++ b/code/SoS/mnm_analysis/mnm_methods/mnm_regression.ipynb @@ -8,7 +8,7 @@ "source": [ "# Advanced regression models for association analysis with individual-level data\n", "\n", - "This is a new-user-friendly minimal working example (MWE) of the `mnm_regression` pipeline. It runs end-to-end on the bundled chr22 toy dataset (60 samples) and shows how to compute SuSiE fine-mapping results and multi-method TWAS weights for a list of molecular-phenotype regions, then build the ensemble (multi-context) TWAS weights." + "Fits univariate and multi-context fine-mapping models to individual-level genotype and molecular phenotype data, and derives TWAS weights." ] }, { @@ -17,7 +17,37 @@ "kernel": "SoS" }, "source": [ - "## Prerequisites\n", + "## Overview\n", + "\n", + "An association scan tells you a region matters; it does not tell you which variant in it is\n", + "responsible, because variants in linkage disequilibrium carry nearly the same signal.\n", + "\n", + "SuSiE\n", + "reframes the question as variable selection: it fits a sum of single effects and returns\n", + "credible sets - small groups of variants, each likely to contain one causal variant -\n", + "together with posterior inclusion probabilities ([Wang et al., 2020](https://doi.org/10.1111/rssb.12388)).\n", + "\n", + "When the same locus is measured across several contexts - tissues, cell types, conditions -\n", + "fine-mapping each separately throws away the shared structure. mvSuSiE learns the patterns\n", + "of sharing from the data and uses them to sharpen credible sets ([Zou et al., 2026](https://doi.org/10.1038/s41588-025-02486-7)).\n", + "\n", + "The same fit also yields **TWAS weights**, the per-variant effects used later to predict\n", + "expression into a GWAS cohort - which is why fine-mapping and weights come from one command\n", + "rather than two, with `skip_twas_weights` defaulting to `False`. In practice the pipeline\n", + "runs per region: `susie_twas` performs univariate fine-mapping and trains weights with\n", + "several methods, writing one `*.univariate_twas_weights.rds` per region; run it with\n", + "`--save-data` so the combined fine-mapping object is kept. `mnm` then consumes that output\n", + "through a `--fine-mapping-meta` table and produces the multi-context ensemble weights, one\n", + "`*.multicontext_bvsr.rds` per gene.\n", + "\n", + "Two input modes take identical commands: a bulk RNA-seq matrix keyed by Ensembl gene ID\n", + "with association windows at TSS +/- 500 kb, or a list of peaks or any other molecular\n", + "phenotype - swap the phenotype BED and its manifest. `mnm_genes` (multi-gene),\n", + "`fsusie`/`mvfsusie` (functional) and `mvsusie` (multivariate) are supported as well ([Wang et al., 2020](https://doi.org/10.1111/rssb.12388); [Zou et al., 2026](https://doi.org/10.1038/s41588-025-02486-7)).\n", + "\n", + "\n", + "**When to run it.** After QTL association testing, with individual-level genotypes,\n", + "phenotypes and covariates in hand. From summary statistics only, use `rss_analysis`.\n", "\n", "Requires processed genotype (PLINK/VCF) and phenotype files from `data_preprocessing`. For TWAS, also requires the LD reference generated by `rss_ld_sketch`." ] @@ -28,21 +58,94 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Input\n", + "\n", + "**Gene-expression mode (`input/colocboost/`) - the example below:**\n", + "\n", + "- `--genoFile` **`input/colocboost/example.chr22.bed`**\n", + "(PLINK1 binary genotype set. Pass the `.bed`; the `.bim` and `.fam` are read automatically. chr22, 1,995 variants and 49 samples.)\n", + "\n", + "- `--phenoFile` **`input/colocboost/pheno_manifest_multicontext.tsv`**\n", + "(phenotype list, one row per region and context. Columns `#chr start end ID path cond cov_path`: `path` is the bgzipped and tabixed phenotype matrix, `cond` names the context, `cov_path` the per-context covariates. 32 rows in the toy file.)\n", + "\n", + "```\n", + "#chr\tstart\tend\tID\tpath\tcond\tcov_path\n", + "chr22\t10939387\t10961338\tENSG00000283047\tinput_geneexpr/example_geneexpr.bed.gz\tcontext1\tinput_geneexpr/example_covariates.tsv\n", + "chr22\t10939387\t10961338\tENSG00000283047\tinput_geneexpr/example_geneexpr_ctx2.bed.gz\tcontext2\tinput_geneexpr/example_covariates.tsv\n", + "```\n", + "\n", + "- `--covFile` **`input/colocboost/example_covariates.tsv`**\n", + "(covariates, one row per covariate and one column per sample; passed with `--transpose-covariates`.)\n", + "\n", + "```\n", + "ID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\t...\n", + "sex\t1\t1\t1\t...\n", + "age\t67.06\t82.92\t87.76\t...\n", + "```\n", "\n", - "This pipeline fits advanced statistical models for QTL association analysis using individual-level genotype and molecular-phenotype data. For each region in a phenotype list it runs univariate SuSiE fine-mapping and trains TWAS prediction weights with several methods, then combines them into an **ensemble** weight.\n", + "- `--customized-association-windows` **`input/colocboost/association_windows.bed`**\n", + "(analysis window per region, columns `#chr start end ID`: the gene TSS +/- 500 kb, clamped at the chromosome edges. 16 regions.)\n", "\n", - "**The primary example below uses gene expression** as the molecular phenotype, running end-to-end on the same chr22 toy genotype:\n", - "- **Gene-expression input** (`input/colocboost/`, Mode A): the phenotype is a bulk RNA-seq matrix with Ensembl `gene_id`s; association windows are gene TSS +/- 500 kb. This is the main, fully verified example.\n", - "- **Peak / chromatin input** (`input/`, Mode B): the *same* pipeline also accepts a list of chr22 peaks (or any other molecular phenotype) - the command is identical, you just swap in the phenotype BED and its manifest.\n", + "```\n", + "#chr\tstart\tend\tID\n", + "chr22\t10439387\t11461338\tENSG00000283047\n", + "chr22\t15028191\t16029139\tENSG00000130538\n", + "```\n", "\n", - "**Workflows used here:**\n", - "- `susie_twas` -- univariate SuSiE fine-mapping plus multi-method TWAS weights (one `*.univariate_twas_weights.rds` per region). Run with `--save-data` so the combined fine-mapping object is written for the next step.\n", - "- `mnm` -- multi-context fine-mapping (mvSuSiE + mr.mash) that consumes the `susie_twas --save-data` output through a `--fine-mapping-meta` table and produces the ensemble weights (one `*.multicontext_twas_weights.rds` per gene).\n", + "**Peak mode (`input/`) - same interface, alternative input:**\n", "\n", - "The notebook also documents the `mnm_genes` (multi-gene), `mvfsusie`/`fsusie` (functional), and `mvsusie` (multivariate) workflows that the pipeline supports, but the MWE focuses on the univariate (`susie_twas`) + multi-context (`mnm`) path that is runnable on the toy data.\n", + "- `--genoFile` **`input/genotype/protocol_example.genotype.chr22.bed`**\n", + "(same PLINK1 layout, a different cohort: chr22, 1,995 variants and 1,287 samples with `S####` identifiers.)\n", "\n", - "**Note on data:** this example uses a small synthetic chr22 toy dataset (60 samples, 1,995 variants after subsetting). No access-controlled individual-level human data is used." + "- `--phenoFile` **`input/phenotype/protocol_example.pheno_manifest.tsv`**\n", + "(peak list, 5 columns `#chr start end ID path`; one row per peak, `path` pointing at the per-peak bgzipped matrix.)\n", + "\n", + "```\n", + "#chr\tstart\tend\tID\tpath\n", + "chr22\t10662152\t10664678\tC22P107555\tinput/proteomics/protocol_example.peaks_split/C22P107555.bed.gz\n", + "chr22\t16094161\t16096165\tC22P107557\tinput/proteomics/protocol_example.peaks_split/C22P107557.bed.gz\n", + "```\n", + "\n", + "- `--covFile` **`input/covariate/protocol_example.covariates.tsv`**\n", + "(same shape as the gene-expression covariates, keyed by `#id`.)\n", + "\n", + "```\n", + "#id\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\t...\n", + "sex\t1\t1\t1\t...\n", + "age\t90.97\t80.24\t83.9\t...\n", + "```\n", + "\n", + "- `--customized-association-windows` **`input/finemapping/protocol_example.association_windows.bed`**\n", + "(cis window per peak, same four columns and no header row.)\n", + "\n", + "```\n", + "chr22\t0\t19959512\tC22P107555\n", + "chr22\t0\t19959512\tC22P107557\n", + "```\n", + "\n", + "**Key requirement:** the 4th-column `ID` of the association-windows file must match the 4th-column `ID` of the phenotype list, otherwise the window for that region is not found and the region is skipped.\n", + "\n", + "The key is that the 4th column ID should match with the 4th column ID in the phenotype list. Otherwise the association-window to analyze will not be found.\n", + "\n", + "### About indels\n", + "\n", + "Option `--no-indel` will remove indel from analysis.\n", + "\n", + "These apply across the workflows:\n", + "\n", + "- `--cwd output/mnm` (working directory all outputs are written under. Defaults to `output`.)\n", + "- `--name protocol_example` (tag used in every output filename)\n", + "- `--customized-association-windows` **`input/colocboost/association_windows.bed`**\n", + "(association windows per region. Without it a fixed window of `--cis-window` is used.)\n", + "- `--cis-window 1000000` (half-width of the fixed association window used when no window file is given)\n", + "- `--region-name ENSG00000283047` (restrict the run to named regions; the union of all regions is used if omitted)\n", + "- `--save-data` (keep the assembled per-region dataset alongside the fine-mapping result)\n", + "- `--transpose-covariates` (set when the covariate file has samples in columns rather than rows)\n", + "- `--keep-samples` (a file of sample IDs to retain before fine-mapping)\n", + "- `--max-cv-variants 5000` (cap on the variants carried into cross-validated TWAS weights; `-1` for no cap)\n", + "- `--pheno-id-map-file` (maps phenotype IDs to the IDs used in the region list, when the two differ)\n", + "- `--fine-mapping-meta` **`output/mnm/fine_mapping_meta_mnm.tsv`**\n", + "(the manifest of per-region fine-mapping results, consumed by the multi-gene and fSuSiE workflows)" ] }, { @@ -51,40 +154,109 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", + "**qtl_dataset_construct** \n", + "\n", + "- **`output/mnm/qtl_dataset/protocol_example.qtl_dataset.rds`** (the assembled `QtlDataset`: a genotype handle plus per-region phenotype and covariate data, reused by every method downstream.)\n", "\n", - "All paths below are relative to the `toy_example/` root (where you launch the commands).\n", + "```\n", + "S4 object \n", + "$ keepIndel: logical [1:1] TRUE\n", + "$ study: character [1:1] protocol_example\n", + "$ genotypes: S4 object \n", + " ..$ chromPaths: character [1:0] \n", + " ..$ path: character [1:1] input/colocboost/example.chr22\n", + " ..$ format: character [1:1] plink1\n", + " ..$ snpInfo: List of 5 \n", + " .. ..$ SNP: character [1:1995] chr22:10414272:A:T chr22:10416111:A:T chr22:10416669:A:T chr22:10420511:A:T chr22:10424460:A:T ...\n", + " .. ..$ CHR: character [1:1995] 22 22 22 22 22 ...\n", + " .. ..$ BP: integer [1:1995] 10414272 10416111 10416669 10420511 10424460 ...\n", + " .. ..$ A1: character [1:1995] A A A A A ...\n", + "... (truncated)\n", + "```\n", "\n", - "**Shared genotype (both modes):**\n", - "- **Genotype** (`--genoFile`): PLINK1 binary set. Pass the `.bed` file; the `.bim`/`.fam` are read automatically. Gene-expression mode (`input/colocboost/`) uses `example.chr22.{bed,bim,fam}`; peak mode (`input/`) uses `protocol_example.genotype.chr22.{bed,bim,fam}` (chr22, 1,995 variants).\n", - "- **Covariates** (`--covFile`): a TSV with covariate rows and one column per sample (gene-expression mode: `input/colocboost/example_covariates.tsv`; peak mode: `input/covariate/protocol_example.covariates.tsv`).\n", + "**susie_twas**\n", + "- **`output/mnm/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds`** (from `susie_twas`, the SuSiE fine-mapping result)\n", "\n", - "**Gene-expression mode (`input/colocboost/`) - primary example:**\n", - "- **Phenotype list** (`--phenoFile`): `input/colocboost/pheno_manifest_1gene.tsv` (a single gene, fastest) or `input/colocboost/pheno_manifest.tsv` (16 in-range chr22 genes). The `path` column points to the bgzipped + tabixed RNA-seq matrix `input/colocboost/example/colocboost.bed.gz` whose 4th column is the Ensembl `gene_id`.\n", - "- **Association windows** (`--customized-association-windows`): `input/colocboost/association_windows.bed` (or `_1gene.bed`) -- gene TSS +/- 500 kb, clamped to the genotype variant range.\n", + "```\n", + "QtlFineMappingResult: S4 DataFrame, 2 rows x 5 columns\n", + "$ study: character [1:2] protocol_example protocol_example\n", + "$ context: character [1:2] context1 context2\n", + "$ trait: character [1:2] ENSG00000130538 ENSG00000130538\n", + "$ method: character [1:2] susie susie\n", + "$ entry: S4 object \n", + " ..$ listData: List of 2\n", + " .. ..$ : S4 object \n", + " .. .. ..$ variantIds: ...\n", + " .. .. ..$ susieFit: ...\n", + " .. .. ..$ topLoci: ...\n", + " .. .. ..$ cvResult: ...\n", + "... (truncated)\n", + "```\n", "\n", - "**Peak mode (`input/`) - same format, alternative input:**\n", - "- **Phenotype list** (`--phenoFile`): `input/phenotype/protocol_example.pheno_manifest.tsv` -- 5 columns `#chr start end ID path`, one row per peak (10 peaks). Each `path` points to a bgzipped per-peak phenotype BED under `input/proteomics/protocol_example.peaks_split/` (samples use the anonymized genotype IDs, e.g. `S0561`, matching the shared PLINK `.fam`).\n", - "- **Association windows** (`--customized-association-windows`): `input/finemapping/protocol_example.association_windows.bed` -- the cis window to analyze for each peak `ID`.\n", + "- **`output/mnm/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds`** (from `susie_twas`, per-variant TWAS weights from each method, with cross-validation performance)\n", "\n", - "**Key requirement:** the 4th-column `ID` of the association-windows file must match the 4th-column `ID` of the phenotype list, otherwise the window for that region is not found and the region is skipped." + "```\n", + "TwasWeights: S4 DataFrame, 22 rows x 5 columns\n", + "$ study: character [1:22] protocol_example protocol_example protocol_example protocol_example protocol_example ...\n", + "$ context: character [1:22] context1 context1 context1 context1 context1 ...\n", + "$ trait: character [1:22] ENSG00000130538 ENSG00000130538 ENSG00000130538 ENSG00000130538 ENSG00000130538 ...\n", + "$ method: character [1:22] mrash susie susie_inf enet lasso ...\n", + "$ entry: S4 object \n", + " ..$ listData: List of 22\n", + " .. ..$ : S4 object \n", + " .. .. ..$ variantIds: ...\n", + " .. .. ..$ weights: ...\n", + " .. .. ..$ fits: ...\n", + " .. .. ..$ cvPerformance: ...\n", + "... (truncated)\n", + "```\n", + "\n", + "**mnm** \n", + "- **`multivariate_fine_mapping/{name}.{region}.multicontext_bvsr.rds`** (the multi-context fit, one per region.)\n", + "\n", + "```\n", + "QtlFineMappingResult: S4 DataFrame, 2 rows x 5 columns\n", + "$ study: character [1:2] protocol_example protocol_example\n", + "$ context: character [1:2] context1 context2\n", + "$ trait: character [1:2] ENSG00000130538 ENSG00000130538\n", + "$ method: character [1:2] mvsusie mvsusie\n", + "$ entry: S4 object \n", + " ..$ listData: List of 2\n", + " .. ..$ : S4 object \n", + " .. .. ..$ variantIds: ...\n", + " .. .. ..$ susieFit: ...\n", + " .. .. ..$ topLoci: ...\n", + " .. .. ..$ cvResult: ...\n", + " .. ..$ : S4 object \n", + "... (truncated)\n", + "```\n", + "\n", + "**mnm_genes**\n", + "- **`multivariate_fine_mapping/{name}.mnm_genes_region_manifest.tsv`**\n", + "- **`multivariate_fine_mapping/{name}.{region_id}.multigene_bvsr.rds`**\n", + "\n", + "**fsusie**\n", + "- **`fsusie/{name}.fsusie_region_manifest.tsv`**\n", + "- **`fsusie/{name}.{region_id}.fsusie.rds`**\n", + "\n", + "**mvfsusie**\n", + "- **`{name}.{region}.mvfsusie_{prior}.rds`**" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Steps\n", - "\n", - "Run the two steps in order. **Step 1** (`susie_twas`) produces the per-region univariate TWAS weights; **Step 2** (`mnm`) reads those weights and adds the multi-context ensemble. The pipeline notebook is referenced as `../../pipeline/mnm_regression.ipynb`.\n", - "\n", - "**Step 1.** SuSiE fine-mapping + multi-method TWAS weights for every region in the phenotype list. Run with `--save-data` so the combined fine-mapping object is written for Step 2.\n", - "\n", - "**Step 2.** Build the ensemble (multi-context) TWAS weight from the Step-1 output with `mnm`. The ensemble is computed by default on the toy data (the `ensemble_r2_threshold` is relaxed so no method is silently dropped).\n", - "\n", - "_Memory note:_ run multi-region loops with `-j1`. Running many regions in parallel (`-j4`) -- or even all of them serially in one process -- can exhaust memory on heavier regions and trigger `ERROR: One of the local workers has been killed`. If that happens, re-run the remaining heavy regions one at a time using a single-region phenotype list." + "library(pecotmr)\n", + "w <- readRDS('output/mnm/multivariate_fine_mapping/protocol_example.ENSG00000130538.multicontext_bvsr.rds')\n", + "w$context # contexts fitted, one row each\n", + "w$method # e.g. \"mvsusie\"\n", + "str(w$entry[[1]], max.level = 1) # variantIds / susieFit / topLoci / cvResult" ] }, { @@ -93,11 +265,10 @@ "kernel": "SoS" }, "source": [ - "### Mode A: gene-expression input (primary example)\n", - "\n", - "This is the main example: cis xQTL fine-mapping on gene expression. Two steps, pointed at the `input/colocboost/` files. Use the 1-gene phenotype list for the fastest run; swap in `pheno_manifest.tsv` / `association_windows.bed` to analyze all 16 in-range genes.\n", + "## Minimal Working Example\n", + "### Univariate SuSiE fine-mapping and TWAS weights (`susie_twas`) - gene expression\n", "\n", - "**Step 1 (gene expression): SuSiE + TWAS weights.**" + "This is the main example: cis xQTL fine-mapping on gene expression. Two steps, pointed at the `input/colocboost/` files. Use the 1-gene phenotype list for the fastest run; swap in `pheno_manifest.tsv` / `association_windows.bed` to analyze all 16 in-range genes." ] }, { @@ -106,9 +277,7 @@ "kernel": "SoS" }, "source": [ - "**Timing** (toy chr22 dataset, 60 samples):\n", - "- `susie_twas`: ~3 min (chr22 toy, 1 gene)\n", - "- `mnm`: ~30 sec" + "**Timing**: ~3 min (on toy dataset)" ] }, { @@ -134,9 +303,20 @@ "kernel": "SoS" }, "source": [ - "**Step 2 (gene expression): multi-context fine-mapping + ensemble TWAS weights (mnm).**" + "#### Step 2. Multi-context fine-mapping and ensemble TWAS weights\n", + "This reads those weights and adds the multi-context ensemble. " ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "08156b31" + }, { "cell_type": "code", "execution_count": null, @@ -161,29 +341,18 @@ "kernel": "SoS" }, "source": [ - "### Mode B: peak / other molecular phenotypes (same pipeline, different input)\n", - "\n", - "The same pipeline also accepts peaks (chromatin/epigenomic) or any other molecular phenotype - just swap in the phenotype `.bed.gz` and its manifest; the command is otherwise identical to Mode A. Example below uses the 10 toy chr22 peaks.\n", - "\n", - "**Step 1 (peak): SuSiE + TWAS weights for the 10 peaks.**" + "### Univariate SuSiE fine-mapping and TWAS weights (`susie_twas`) - peak" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb susie_twas \\\n", - " --name protocol_example \\\n", - " --cwd output_10peaks \\\n", - " --genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", - " --phenoFile input/phenotype/protocol_example.pheno_manifest.tsv \\\n", - " --covFile input/covariate/protocol_example.covariates.tsv \\\n", - " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", - " -j1" + "The same pipeline also accepts peaks (chromatin/epigenomic) or any other molecular phenotype - just swap in the phenotype `.bed.gz` and its manifest; the command is otherwise identical to Mode A. Example below uses the 10 toy chr22 peaks.\n", + "\n", + "#### Step 1. SuSiE + TWAS weights" ] }, { @@ -192,8 +361,9 @@ "kernel": "SoS" }, "source": [ - "**Step 2 (peak): multi-context fine-mapping + ensemble TWAS weights (mnm).**" - ] + "**Timing**: TBD (on toy dataset)" + ], + "id": "44f99ba1" }, { "cell_type": "code", @@ -203,16 +373,13 @@ }, "outputs": [], "source": [ - "# Step 2 (10 peaks): multi-context fine-mapping + ensemble TWAS weights (mnm).\n", - "# As above, mnm consumes the Step-1 univariate outputs via --fine-mapping-meta.\n", - "sos run pipeline/mnm_regression.ipynb mnm \\\n", + "sos run pipeline/mnm_regression.ipynb susie_twas \\\n", " --name protocol_example \\\n", " --cwd output_10peaks \\\n", " --genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", " --phenoFile input/phenotype/protocol_example.pheno_manifest.tsv \\\n", " --covFile input/covariate/protocol_example.covariates.tsv \\\n", " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", - " --fine-mapping-meta output_10peaks/fine_mapping_meta.tsv \\\n", " -j1" ] }, @@ -222,40 +389,7 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", - "\n", - "Under `--cwd` (e.g. `output_10peaks/` or `output_uni/`):\n", - "- `twas_weights/{name}..univariate_twas_weights.rds` -- Step 1 (`susie_twas`) output, one per region: the SuSiE fine-mapping result plus TWAS weights from each method (e.g. lasso, enet, mrash, susie), variant names, region info and CV performance.\n", - "- `multivariate_twas_weights/{name}..multicontext_twas_weights.rds` -- Step 2 (`mnm`) output, one per gene: the multi-context model with the added ensemble. The ensemble is stored under an `ensemble` entry alongside `method_coef`, the ensemble weights, and `method_performance`.\n", - "\n", - "Fine-mapping objects are also written under the `fine_mapping/` subfolder, and per-region `.stdout`/`.stderr` logs accompany each run." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "For the 10-peak run you should get 10 `*.univariate_twas_weights.rds` (one per peak) and 10 `*.multicontext_twas_weights.rds` from the `mnm` step. For the 1-gene gene-expression run you get one file of each type.\n", - "\n", - "You can sanity-check a multi-context ensemble weight in R:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [ - "# In R: inspect one multi-context (mnm) ensemble output\n", - "w <- readRDS('output_uni/multivariate_twas_weights/protocol_example.ENSG00000130538.multicontext_twas_weights.rds')\n", - "names(w) # available genes / contexts\n", - "str(w, max.level = 2) # weights + per-method performance" + "#### Step 2. Multi-context fine-mapping and ensemble TWAS weights" ] }, { @@ -264,10 +398,9 @@ "kernel": "SoS" }, "source": [ - "## Command interface\n", - "\n", - "Show all workflows and options of the pipeline:" - ] + "**Timing**: TBD (on toy dataset)" + ], + "id": "6abc252f" }, { "cell_type": "code", @@ -277,7 +410,15 @@ }, "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb -h" + "sos run pipeline/mnm_regression.ipynb mnm \\\n", + " --name protocol_example \\\n", + " --cwd output_10peaks \\\n", + " --genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", + " --phenoFile input/phenotype/protocol_example.pheno_manifest.tsv \\\n", + " --covFile input/covariate/protocol_example.covariates.tsv \\\n", + " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", + " --fine-mapping-meta output_10peaks/fine_mapping_meta.tsv \\\n", + " -j1" ] }, { @@ -286,14 +427,9 @@ "kernel": "SoS" }, "source": [ - "## Other workflows\n", + "### Multivariate analysis with mvSuSiE and mr.mash (`mnm`)\n", "\n", - "The same pipeline notebook also provides:\n", - "- `mvsusie` -- multivariate SuSiE with mr.mash TWAS weights (for jointly analyzing multiple phenotypes that share a genotype).\n", - "- `mnm_genes` -- multi-gene multivariate fine-mapping across genes sharing a window.\n", - "- `fsusie` -- functional SuSiE for functional/high-resolution modalities (e.g. methylation), with a `--fsusie-post-processing` option (`TI`, `HMM`, or `none`; `TI` is recommended).\n", - "\n", - "These follow the same `--genoFile` / `--phenoFile` / `--covFile` interface; they are documented here for completeness but the verified MWE above uses `susie_twas` + `mnm`." + "Fine-maps multiple molecular phenotypes jointly across a shared window using mvSuSiE with mr.mash priors. This step needs **multiple contexts** (e.g. the same genes measured under two or more conditions). The toy set ships a single context, so this MWE adds a **second, synthetic context** (`example/colocboost_ctx2.bed.gz`, derived from context 1 with added noise \u2014 *demo data only, not a real measurement*) and a multi-context phenotype manifest. With that in place the `mnm` step now runs end-to-end on the toy data and produces `multicontext_bvsr.rds`, `multicontext_bvsr.rds`, and `multicontext_data.rds` per gene." ] }, { @@ -302,19 +438,9 @@ "kernel": "SoS" }, "source": [ - "The notebook also bundles the original protocol's multivariate (`mnm`, `mnm_genes`) and functional (`fsusie`, `mvfsusie`) fine-mapping workflows, which operate on the same `regional_data` produced by `get_analysis_regions`. Of these, **`susie_twas` (univariate), `fsusie`, `mnm`, and `mnm_genes` now run end-to-end on the toy data** (`mnm` and `mnm_genes` use a synthetic second context, see below). `mnm_genes` consumes the univariate fine-mapping summary statistics (`combined_data_sumstats`) written by `susie_twas --save-data` together with the `mnm` outputs, wired together through a `--fine_mapping_meta` table; on the toy set it correctly returns NULL multigene results (no multi-gene/trans signal). **`mvfsusie`** remains **still under development** in the original protocol, so its command is given as a template for completeness." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### Multivariate analysis: mvSuSiE and mr.mash (`mnm`)\n", - "\n", - "Fine-maps multiple molecular phenotypes jointly across a shared window using mvSuSiE with mr.mash priors. This step needs **multiple contexts** (e.g. the same genes measured under two or more conditions). The toy set ships a single context, so for this MWE we add a **second, synthetic context** (`example/colocboost_ctx2.bed.gz`, derived from context 1 with added noise \u2014 *demo data only, not a real measurement*) and a multi-context phenotype manifest. With that in place the `mnm` step now runs end-to-end on the toy data and produces `multicontext_bvsr.rds`, `multicontext_twas_weights.rds`, and `multicontext_data.rds` per gene." - ] + "**Timing**: TBD (on toy dataset)" + ], + "id": "c9ce1e11" }, { "cell_type": "code", @@ -324,13 +450,6 @@ }, "outputs": [], "source": [ - "# Runs end-to-end on the toy dataset using a synthetic 2-context manifest.\n", - "# Notes for new users:\n", - "# - mnm needs >=2 contexts; pheno_manifest_multicontext.tsv supplies context1 (real)\n", - "# and context2 (example/colocboost_ctx2.bed.gz, synthetic demo data).\n", - "# - Use the gene-expression genotype (input/colocboost/example.chr22.bed, sample IDs\n", - "# SAMPLE_001..) so genotype and phenotype/covariate samples match.\n", - "# - Requires the mr.mashr R package (provided by mr.mash.alpha in this env).\n", "sos run pipeline/mnm_regression.ipynb mnm \\\n", " --name protocol_example --cwd output_mnm3 \\\n", " --genoFile input/colocboost/example.chr22.bed \\\n", @@ -346,11 +465,21 @@ "kernel": "SoS" }, "source": [ - "### xQTL fine-mapping across multiple genes (`mnm_genes`)\n", + "### Multi-gene / trans fine-mapping (`mnm_genes`)\n", "\n", - "Multivariate fine-mapping treating each gene as a separate condition across a shared window. **Verified end-to-end on the toy dataset** using the univariate (`susie_twas --save-data`) and `mnm` outputs wired together through a `--fine_mapping_meta` table. On the toy set every region returns a NULL `multigene_bvsr` (no multi-gene/trans signal), which is the correct, honest result for these independent single-gene regions." + "Multivariate fine-mapping treating each gene as a separate condition across a shared window. On the toy set every region returns a NULL `multigene_bvsr` (no multi-gene/trans signal), which is the correct, honest result for these independent single-gene regions." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "0075bbe0" + }, { "cell_type": "code", "execution_count": null, @@ -359,14 +488,6 @@ }, "outputs": [], "source": [ - "# Multi-gene / trans fine-mapping (mnm_genes) - VERIFIED end-to-end on the toy data.\n", - "# Run from the toy_example root. Requires:\n", - "# --pheno_id_map_file : maps phenotype IDs across the two contexts\n", - "# --fine_mapping_meta : per-region table pointing to the univariate (susie_twas, run above\n", - "# with --save-data) and multivariate (mnm) fine-mapping outputs\n", - "# --keep-samples : sample IDs to retain (matches the gene-expression genotype)\n", - "# On this toy set all regions return a NULL multigene_bvsr (no multi-gene/trans signal),\n", - "# which is the correct, honest result for independent single-gene toy regions.\n", "sos run pipeline/mnm_regression.ipynb mnm_genes \\\n", " --name protocol_example --cwd output_mnmgenes \\\n", " --genoFile input/colocboost/example.chr22.bed \\\n", @@ -385,11 +506,21 @@ "kernel": "SoS" }, "source": [ - "### Functional regression fSuSiE for epigenomic QTL fine-mapping (`fsusie`)\n", + "### Functional regression fSuSiE for epigenomic QTL (`fsusie`)\n", "\n", - "Functional SuSiE for fine-mapping a functional phenotype across genomic positions in a region. This workflow **runs end-to-end on the toy peak data** and produces a `*.fsusie_mixture_normal_TI__top_pc_weights.rds` weight file." + "Functional SuSiE for fine-mapping a functional phenotype across genomic positions in a region. This workflow produces a `*.fsusie_mixture_normal_TI__top_pc_weights.rds` weight file." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "c0c5fe72" + }, { "cell_type": "code", "execution_count": null, @@ -398,8 +529,6 @@ }, "outputs": [], "source": [ - "# Functional SuSiE (fsusie) - VERIFIED end-to-end on the toy peak data.\n", - "# Run from the toy_example root. Produces *.fsusie_mixture_normal_TI__top_pc_weights.rds.\n", "sos run pipeline/mnm_regression.ipynb fsusie \\\n", " --name protocol_example --cwd output/fsusie \\\n", " --genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", @@ -415,11 +544,21 @@ "kernel": "SoS" }, "source": [ - "### Functional regression fSuSiE with other modality (`mvfsusie`)\n", + "### Functional regression fSuSiE with another modality (`mvfsusie`)\n", "\n", "Multivariate functional SuSiE (mvfSuSiE). **Still under development** for the toy dataset." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "62d2817e" + }, { "cell_type": "code", "execution_count": null, @@ -428,8 +567,6 @@ }, "outputs": [], "source": [ - "# Still under development on the toy dataset (the mvfSuSiE R step errors out).\n", - "# Command template:\n", "sos run pipeline/mnm_regression.ipynb mvfsusie \\\n", " --name protocol_example --cwd output/mvfsusie \\\n", " --genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", @@ -445,17 +582,272 @@ "kernel": "SoS" }, "source": [ - "## Troubleshooting\n", + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_regression.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/mnm_regression.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", "\n", - "| Step | Problem | Possible Reason | Solution |\n", - "| --- | --- | --- | --- |\n", - "| susie_twas | A region is skipped / no window found | 4th-column `ID` in the association-windows file does not match the phenotype list `ID` | Make the `ID` columns match exactly. |\n", - "| susie_twas | `susie_twas: pass --region-name ` | No region selected | Pass `--region-name ` (e.g. `ENSG00000130538`) or a `--region-list`. |\n", - "| susie_twas | `ERROR: One of the local workers has been killed` | Out-of-memory: too many regions in one process (`-j4`, or all 10 serially) | Use `-j1`; re-run heavy regions one at a time with a single-region phenotype list. |\n", - "| mnm | `Target unavailable: ...qtl_dataset.rds` | `qtl_dataset_construct` not run first | Chain it: `qtl_dataset_construct+susie_twas`, then `mnm`. |\n", - "| mnm | `--phenotype-manifest missing required column(s): cond` | Single-context manifest used | Use the multi-context manifest (`pheno_manifest_multicontext.tsv`). |\n", - "| both | `No shared samples between phenotype and phenotype-covariate` | Covariates are in QTLtools (transposed) layout | Add `--transpose-covariates`. |\n", - "| both | Sample IDs do not overlap between genotype/covariates and phenotype | Genotype `.fam` IDs differ from the phenotype matrix sample names | Rename one side so they match (e.g. the gene-expression mode renames genotype/covariate IDs to `SAMPLE_001..060`). |" + "Workflows:\n", + " qtl_dataset_construct\n", + " susie_twas\n", + " mnm\n", + " mnm_genes\n", + " fsusie\n", + " mvfsusie\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --name VAL (as str, required)\n", + " It is required to input the name of the analysis\n", + " --cwd output (as path)\n", + " --genoFile VAL (as path, required)\n", + " A list of file paths for genotype data, or the genotype\n", + " data itself.\n", + " --phenoFile paths\n", + "\n", + " One or multiple lists of file paths for phenotype data.\n", + " --phenoIDFile paths()\n", + "\n", + " One or multiple lists of file paths for phenotype ID\n", + " mapping file. The first column should be the original\n", + " ID, the 2nd column should be the ID to be mapped to.\n", + " --covFile paths\n", + "\n", + " Covariate file path\n", + " --region-list . (as path)\n", + " Optional: if a region list is provide the analysis will\n", + " be focused on provided region. The LAST column of this\n", + " list will contain the ID of regions to focus on\n", + " Otherwise, all regions with both genotype and phenotype\n", + " files will be analyzed\n", + " --region-name (as list)\n", + " Optional: if a region name is provided the analysis\n", + " would be focused on the union of provides region list\n", + " and region names\n", + " --keep-samples . (as path)\n", + " Only focus on a subset of samples\n", + " --keep-variants . (as path)\n", + " Only focus on a subset of variants\n", + " --customized-association-windows . (as path)\n", + " An optional list documenting the custom association\n", + " window for each region to analyze, with four column,\n", + " chr, start, end, region ID (eg gene ID). If this list is\n", + " not provided, the default `window` parameter (see below)\n", + " will be used.\n", + " --cis-window -1 (as int)\n", + " Specify the cis window for the up and downstream radius\n", + " to analyze around the region of interest in units of bp\n", + " When this is set to negative, we will rely on using\n", + " customized_association_windows\n", + " --[no-]save-data (default to False)\n", + " save data object or not\n", + " --phenotype-names [f'{x:bn}' for x in phenoFile]\n", + "\n", + " Name of phenotypes\n", + " --[no-]trans-analysis (default to False)\n", + " And indicator whether it is trans-analysis, ie, not\n", + " using phenotypic coordinate information\n", + " --seed 999 (as int)\n", + " --init-L 8 (as int)\n", + " association analysis paramters initial number of single\n", + " effects for SuSiE\n", + " --L 30 (as int)\n", + " maximum number of single effects to use for SuSiE\n", + " --[no-]estimate-residual-variance (default to True)\n", + " --imiss 1.0 (as float)\n", + " remove a variant if it has more than imiss missing\n", + " individual level data\n", + " --maf 0.0025 (as float)\n", + " MAF and variance of X cutoff\n", + " --xvar-cutoff 0.0 (as float)\n", + " --mac 5 (as int)\n", + " MAC cutoff, on top of MAF cutoff\n", + " --[no-]indel (default to True)\n", + " Remove indels if indel = False\n", + " --pip-cutoff 0.025 (as float)\n", + " --coverage 0.95 0.7 0.5 (as list)\n", + " --skip-analysis-pip-cutoff (as list)\n", + " If this value is not 0, then an initial single effect\n", + " analysis will be performed to determine if follow up\n", + " analysis will be continued or to simply return NULL If\n", + " this is negative we use a default way to determine this\n", + " cutoff which is conservative but still useful\n", + " --[no-]skip-fine-mapping (default to False)\n", + " Skip fine-mapping\n", + " --[no-]skip-twas-weights (default to False)\n", + " Skip TWAS weights computation\n", + " --twas-cv-folds 5 (as int)\n", + " Perform K folds valiation CV for TWAS Set it to zero if\n", + " this is to be skipped\n", + " --twas-cv-threads twas_cv_folds\n", + "\n", + " --max-cv-variants -1 (as int)\n", + " maximum number of variants to consider for CV We will\n", + " randomly pick a subset of it for CV purpose We can set\n", + " it to eg 8000 to save computational burden althought may\n", + " risk overfitting for methods comparison purpose When set\n", + " to -1 we don't use this feature\n", + " --ld-reference-meta-file . (as path)\n", + " --container ''\n", + " Analysis environment settings\n", + " --entrypoint ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "\n", + " --job-size 200 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 1h\n", + " Wall clock time expected\n", + " --mem 20G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " qtl_dataset_construct:\n", + " Workflow Options:\n", + " --study study\n", + " Build one pecotmr::QtlDataset from the phenotype\n", + " manifest + shared genotype and serialize to RDS,\n", + " replacing the legacy get_analysis_regions /\n", + " regional_data loader. No fan-out: downstream per-gene\n", + " fine-mapping / TWAS load this single RDS and select\n", + " contexts/genes at analysis time. Manifest schema\n", + " (qtl_dataset_construct.R): columns ID, path, cond and an\n", + " optional cov_path; extra columns (e.g. #chr/start/end)\n", + " are ignored. The toy MWE pheno_manifest_multicontext.tsv\n", + " already matches -- a single-context analysis just points\n", + " at a one-`cond` manifest (or selects the context\n", + " downstream). QTLtools-format covariate TSVs (rows =\n", + " covariates) need --transpose-covariates.\n", + " --[no-]transpose-covariates (default to False)\n", + " Set for QTLtools-format covariate TSVs (rows =\n", + " covariates, cols = samples); required for the toy MWE\n", + " covariates.\n", + " --genotype-covariates . (as path)\n", + " Optional genotype-derived covariates applied uniformly\n", + " across contexts; per-context covariates come from the\n", + " manifest cov_path column.\n", + " --maf-cutoff 0.0 (as float)\n", + " Construct-time variant/sample QC (stored on the\n", + " QtlDataset; cutoff 0 = off).\n", + " --mac-cutoff 0.0 (as float)\n", + " --imiss-cutoff 0.0 (as float)\n", + " --[no-]drop-indel (default to False)\n", + " Drop indel variants (default keeps them, matching\n", + " QtlDataset()).\n", + " susie_twas:\n", + " Workflow Options:\n", + " --fine-mapping-methods susie\n", + " --twas-methods 'susie,mrash,enet,lasso,mcp,scad,l0learn,bayes_r,bayes_c'\n", + " --fine-mapping-coverage 0.95 (as float)\n", + " --contexts ''\n", + " Comma-separated context names to restrict both passes\n", + " to; empty = all contexts.\n", + " --pip-cutoff-to-skip 0.0 (as float)\n", + " Fine-mapping SER pre-screen (0 = off, <0 = adaptive\n", + " 3/nVariants).\n", + " --twas-maf-cutoff 0.01 (as float)\n", + " TWAS weight-learning knobs. TWAS learns weights applied\n", + " out-of-sample; keep an explicit MAF / X-variance cutoff\n", + " for the TWAS pass (passed via the shared --maf-\n", + " cutoff/--xvar-cutoff).\n", + " --twas-xvar-cutoff 0.01 (as float)\n", + " --cv-folds 5 (as int)\n", + " --cv-threads 1 (as int)\n", + " --maf-cutoff -1.0 (as float)\n", + " Opt-in per-analysis overrides of the QtlDataset's\n", + " construct-time filters, applied to both passes.\n", + " Sentinels: a negative cutoff / drop_indel False / \".\"\n", + " path = leave the dataset's stored value untouched.\n", + " --mac-cutoff -1.0 (as float)\n", + " --imiss-cutoff -1.0 (as float)\n", + " --[no-]drop-indel (default to False)\n", + " --fine-mapping-method-args ''\n", + " Optional JSON of per-method kwargs forwarded to the\n", + " pipelines, e.g. '{\"susie\":{\"L\":10}}' for fine-mapping or\n", + " '{\"lasso\":{\"nfolds\":10}}' for TWAS.\n", + " --twas-method-args ''\n", + " mnm:\n", + " Workflow Options:\n", + " --mvsusie-max-iter 200 (as int)\n", + " --pip-cutoff-to-skip 0.0 (as float)\n", + " --contexts ''\n", + " Comma-separated context names to restrict to; empty =\n", + " all contexts.\n", + " --prior-twas-weights . (as path)\n", + " Optional TwasWeights RDS (preceding mr.mash run)\n", + " supplying the data-driven prior.\n", + " --prior-weights-min 1e-10 (as float)\n", + " --mvsusie-method-args ''\n", + " Optional JSON of extra mvsusie kwargs (overrides the\n", + " max_iter default), e.g. '{\"mvsusie\":{\"max_iter\":500}}'.\n", + " mnm_genes_1:\n", + " mnm_genes_2:\n", + " Workflow Options:\n", + " --mvsusie-max-iter 200 (as int)\n", + " Cross-gene (multi-trait) mvSuSiE per locus: region mode\n", + " + jointSpecification=\"trait\" joins the genes whose\n", + " coordinates overlap the locus. Optional mr.mash data-\n", + " driven prior via --prior-twas-weights (canonical\n", + " otherwise). Replaces the legacy multigene combine +\n", + " multigene_udr machinery.\n", + " --pip-cutoff-to-skip 0.0 (as float)\n", + " --contexts ''\n", + " --prior-twas-weights . (as path)\n", + " --prior-weights-min 1e-10 (as float)\n", + " --mvsusie-method-args ''\n", + " fsusie_1:\n", + " fsusie_2:\n", + " Workflow Options:\n", + " --prior 'mixture_normal'\n", + " Functional SuSiE per locus (fsusieR::susiF) over the\n", + " pre-built QtlDataset. fsusie-specific knobs ride on\n", + " --method-args; --susie-top-pc>0 additionally fine-maps\n", + " each context's top principal components with univariate\n", + " SuSiE (usePCA; ports the legacy fsusie.R\n", + " susie_on_top_pc). Replaces fsusie.R.\n", + " --max-scale 10 (as int)\n", + " --min-purity 0.5 (as float)\n", + " --post-processing TI\n", + " --max-SNP-EM 100 (as int)\n", + " --[no-]small-sample-correction (default to False)\n", + " --susie-top-pc 0 (as int)\n", + " >0 -> also fine-map the top `susie_top_pc` PCs per\n", + " context with univariate SuSiE.\n", + " --pip-cutoff-to-skip 0.0 (as float)\n", + " --contexts ''\n", + " --fsusie-method-args ''\n", + " Optional JSON overriding the assembled fsusie kwargs,\n", + " e.g. '{\"fsusie\":{\"prior\":\"mixture_normal_per_scale\"}}'.\n", + " mvfsusie:\n", + " Workflow Options:\n", + " --prior 'mixture_normal_per_scale'\n", + " prior can be either of [\"mixture_normal\",\n", + " \"mixture_normal_per_scale\"]\n", + " --max-SNP-EM 1000 (as int)\n", + "```" ] }, { @@ -974,6 +1366,25 @@ " data.format=\"list_df\")\n", " saveRDS(fitted, ${_output:ar})" ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Troubleshooting\n", + "\n", + "| Step | Problem | Possible Reason | Solution |\n", + "| --- | --- | --- | --- |\n", + "| susie_twas | A region is skipped / no window found | 4th-column `ID` in the association-windows file does not match the phenotype list `ID` | Make the `ID` columns match exactly. |\n", + "| susie_twas | `susie_twas: pass --region-name ` | No region selected | Pass `--region-name ` (e.g. `ENSG00000130538`) or a `--region-list`. |\n", + "| susie_twas | `ERROR: One of the local workers has been killed` | Out-of-memory: too many regions in one process (`-j4`, or all 10 serially) | Use `-j1`; re-run heavy regions one at a time with a single-region phenotype list. |\n", + "| mnm | `Target unavailable: ...qtl_dataset.rds` | `qtl_dataset_construct` not run first | Chain it: `qtl_dataset_construct+susie_twas`, then `mnm`. |\n", + "| mnm | `--phenotype-manifest missing required column(s): cond` | Single-context manifest used | Use the multi-context manifest (`pheno_manifest_multicontext.tsv`). |\n", + "| both | `No shared samples between phenotype and phenotype-covariate` | Covariates are in QTLtools (transposed) layout | Add `--transpose-covariates`. |\n", + "| both | Sample IDs do not overlap between genotype/covariates and phenotype | Genotype `.fam` IDs differ from the phenotype matrix sample names | Rename one side so they match (e.g. the gene-expression mode renames genotype/covariate IDs to `SAMPLE_001..060`). |" + ] } ], "metadata": { @@ -1016,4 +1427,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/mnm_analysis/mnm_methods/rss_analysis.ipynb b/code/SoS/mnm_analysis/mnm_methods/rss_analysis.ipynb index b1f523569..8bdca6b5b 100644 --- a/code/SoS/mnm_analysis/mnm_methods/rss_analysis.ipynb +++ b/code/SoS/mnm_analysis/mnm_methods/rss_analysis.ipynb @@ -8,55 +8,106 @@ "source": [ "# RSS Fine-mapping with GWAS Summary Statistics\n", "\n", - "End-to-end SuSiE-RSS fine-mapping over GWAS summary statistics, per study × per LD block, using\n", - "the current pecotmr S4 API (`GwasSumStats` / `summaryStatsQc()` / `fineMappingPipeline()`). Four SoS\n", - "steps:\n", + "End-to-end SuSiE-RSS fine-mapping over GWAS summary statistics, one fit per study per LD block." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", + "\n", + "Fine-mapping asks which variants in a region are causal, not merely correlated with a causal one. Doing that properly needs individual-level genotypes, which for GWAS are usually unavailable. SuSiE-RSS fits the same sum-of-single-effects model to what can be obtained -- per-variant z-scores plus an LD matrix from a reference panel -- and returns credible sets and posterior inclusion probabilities rather than a single lead SNP per locus ([Zou et al., 2022](https://doi.org/10.1371/journal.pgen.1010299)).\n", + "\n", + "Because the LD reference stands in for the study own genotypes, results are only as good as the match between the two. Allele flips and z-score outliers relative to the panel are the usual source of spurious credible sets, which is why the QC options exist: SLALOM or DENTIST screening flags suspicious variants, and RAISS can impute variants that are missing from the study but present in the panel. The LD reference must be genotype-backed (PLINK2/PLINK1/GDS/VCF); a precomputed `.cor.xz` correlation matrix is not supported here, because the QC steps need the genotypes themselves.\n", + "\n", + "The module takes a list of LD reference blocks and a list of GWAS summary statistics files and runs four SoS steps, which chain in the order below:\n", + "\n", + "| Workflow | What it does |\n", + "|---|---|\n", + "| `generate_manifest` | Pair each study with the LD blocks it covers |\n", + "| `generate_gwas_sumstats` | Harmonise, QC and optionally impute summary statistics per block |\n", + "| `gwas_fine_mapping` | Fit SuSiE-RSS per block |\n", + "| `gwas_rss_plot` | Diagnostic plots for the fitted regions |\n", + "\n", + "`generate_manifest` resolves `--gwas-meta` or `--gwas-tsv-list` against `--region-list` or `--regions` into one manifest TSV with a row per study x region. `generate_gwas_sumstats` then builds one QC-d `GwasSumStats` RDS per study x LD block, harmonising variants to the LD-panel ID convention. `gwas_fine_mapping` dispatches to `pecotmr::fineMappingPipeline()`, and `gwas_rss_plot` renders a PIP plot unless `--no-plot` is given. The results feed TWAS and PRS weight construction downstream.\n", + "\n", + "This chain replaces the legacy two-step `get_analysis_regions` + `univariate_rss` workflow, which called the now-removed `rss_analysis_pipeline()`.\n", + "\n", + "**When to run it.** After GWAS summary statistics and a genotype-backed LD reference panel are in\n", + "place, and before TWAS or PRS weight construction, which read the `GwasFineMappingResult` objects\n", + "written here. This is the summary-statistics-only route: with individual-level genotypes and\n", + "phenotypes, use `mnm_regression` instead." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Input\n", + "\n", + "GWAS inputs -- supply either form:\n", + "\n", + "- `--gwas-meta input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv` TSV with columns `study_id`, `path` (relative to the meta file, or absolute) and an optional `column_mapping` naming a per-study YAML. One row per study.\n", + "\n", + " ```\n", + " study_id\tpath\tcolumn_mapping\n", + " AD_Bellenguez_2022\tprotocol_example.gwas_sumstats.chr22.tsv.gz\tprotocol_example.gwas_column_mapping.fixed.yml\n", + " ```\n", + "\n", + " In this file `path` resolves to `input/rss_analysis/protocol_example.gwas_sumstats.chr22.tsv.gz`\n", + " and `column_mapping` to `input/rss_analysis/protocol_example.gwas_column_mapping.fixed.yml`.\n", + "\n", + "- `--gwas-tsv-list S1=path1 ...`: explicit `STUDY=PATH` pairs; no per-study column mapping is possible this way.\n", "\n", - "1. **`[generate_manifest]`** — `gwas_rss_manifest.R` resolves `--gwas-meta` + `--gwas-tsv-list` against\n", - " `--region-list` + `--regions` into one manifest TSV (one row per study × region).\n", - "2. **`[generate_gwas_sumstats]`** — `gwas_sumstats_construct.R` builds one `GwasSumStats` RDS per\n", - " study × LD block, running `summaryStatsQc()` (optional SLALOM/DENTIST QC + RAISS imputation;\n", - " harmonization re-keys variants to the LD-panel id convention).\n", - "3. **`[gwas_fine_mapping]`** — `fine_mapping.R` dispatches to\n", - " `pecotmr::fineMappingPipeline(gwasSumStats, methods = ...)` (SuSiE-RSS).\n", - "4. **`[gwas_rss_plot]`** (opt-out via `--no-plot`) — `gwas_rss_plot.R` renders a PIP plot.\n", + "Each summary statistics file is tab-delimited, with `chrom`, `pos`, `A1`, `A2` as the first four columns. A column-mapping YAML lets other layouts be read: it must resolve `chrom`, `pos`, `A1`, `A2`, either `z` or both `beta` and `se`, and `n_sample` or the pair `n_case` / `n_control` (for a case-control study, give one or the other and fill the unused field with 0). `var_y` is optional.\n", "\n", - "This replaces the legacy two-step workflow (`get_analysis_regions` + `univariate_rss`, which called the\n", - "removed `rss_analysis_pipeline()`). The LD reference must be **genotype-backed** (PLINK2/PLINK1/GDS/VCF);\n", - "a precomputed `.cor.xz` LD matrix is not supported for the `GwasSumStats` path.\n", + "Region inputs -- supply either form:\n", "\n", - "## Inputs\n", + "- `--region-list`: BED-like TSV of LD blocks.\n", + "- `--regions chr:start-end ...`: explicit regions.\n", "\n", - "- `--gwas-meta` — TSV with columns `study_id`, `path` (relative to the meta file or absolute), and\n", - " optional `column_mapping` (per-study YAML). One row per study.\n", - "- `--gwas-tsv-list S1=path1 ...` — explicit STUDY=PATH pairs (alternative to `--gwas-meta`; no\n", - " per-study column mapping).\n", - "- `--region-list` — BED-like TSV of LD blocks; and/or `--regions chr:start-end ...`.\n", - "- `--ld-meta` — LD-reference meta TSV (`#chr`, `start`, `end`, `path` -> genotype prefix). One LD block\n", - " per row (or one row with `start=end=0` for a whole chromosome).\n", + "LD reference and genome:\n", "\n", - "## QC knobs (forwarded to `gwas_sumstats_construct.R` -> `summaryStatsQc()`)\n", + "- `--ld-meta` (required): LD-reference meta TSV with columns `#chr`, `start`, `end`, `path`, where `path` is a genotype prefix. One LD block per row, or a single row with `start=end=0` for a whole chromosome. The reference must be genotype-backed (PLINK2/PLINK1/GDS/VCF).\n", + " The protocol ships `input/ld_reference/protocol_example.ld_meta_file.tsv`, whose prefixes point\n", + " into `input/ld_reference/chr*/`:\n", "\n", - "- `--qc-method` — `none` (default), `slalom`, or `dentist`.\n", - "- `--impute` — enable RAISS sumstat imputation.\n", - "- `--qc-args '{\"key\":value,...}'` — JSON passthrough for any other `summaryStatsQc()` kwarg (e.g.\n", - " `{\"mafCutoff\":0.01,\"nCutoff\":0,\"alleleFlipKriging\":true}`).\n", - "- `--maf` — MAF cutoff (`mafCutoff`). Default **0.0025**; 0 disables.\n", - "- `--skip-regions chr:start-end …` — drop variants overlapping these window(s) (`skipRegion`).\n", - "- `--skip-analysis-pip-cutoff` — skip a region whose single-effect max PIP is below this (`pipCutoffToSkip`). Default **0.025**; 0 disables.\n", + " ```\n", + " #chr\tstart\tend\tpath\n", + " chr1\t16103\t2888443\tchr1/protocol_example.LD.chr1\n", + " chr1\t2888443\t4320284\tchr1/protocol_example.LD.chr1\n", + " ```\n", "\n", - "## Fine-mapping knobs (forwarded to `fine_mapping.R`)\n", + "- `--genome` (default `GRCh38`): genome build label carried into the output objects.\n", "\n", - "- `--methods` (default `susie`), `--coverage` (0.95), `--secondary-coverage` (`0.7,0.5`).\n", - "- `--min-abs-corr` (0.8), `--median-abs-corr` (off; OR-logic purity), `--pip-cutoff` (0.025).\n", - "- `--L` (20) / `--L-greedy` (5) — SuSiE fit defaults; `--method-args '{\"susie\":{...}}'` overrides per key.\n", + "QC knobs, forwarded to `gwas_sumstats_construct.R` and on to `summaryStatsQc()`:\n", "\n", - "## Outputs\n", + "- `--qc-method` (default `none`): `none`, `slalom` or `dentist`.\n", + "- `--impute` / `--no-impute` (default off): enable RAISS imputation of variants present in the panel but missing from the study.\n", + "- `--qc-args`: JSON passthrough for any other `summaryStatsQc()` argument, e.g. `{\"mafCutoff\":0.01,\"nCutoff\":0,\"alleleFlipKriging\":true}`.\n", + "- `--maf` (default `0.0025`; `0` disables): MAF cutoff, i.e. `mafCutoff`.\n", + "- `--allele-flip-kriging` / `--no-allele-flip-kriging` (default off) and `--effective-n` / `--no-effective-n` (default on): individual `summaryStatsQc()` switches.\n", + "- `--skip-regions chr:start-end ...`: drop variants overlapping these windows, i.e. `skipRegion`.\n", + "- `--skip-analysis-pip-cutoff` (default `0.025`; `0` disables): skip a region whose single-effect max PIP falls below this, i.e. `pipCutoffToSkip`.\n", "\n", - "- `{cwd}/{manifest_name}.manifest.tsv`\n", - "- `{cwd}/sumstats/{study}.{chrN_S_E}.gwas_sumstats.rds`\n", - "- `{cwd}/fine_mapping/{study}.{chrN_S_E}.gwas_finemap.rds` — one `GwasFineMappingResult` per (study, block).\n", - "- `{cwd}/plots/{study}.{chrN_S_E}.pip_plot.png` (unless `--no-plot`).\n" + "Fine-mapping knobs, forwarded to `fine_mapping.R`:\n", + "\n", + "- `--methods` (default `susie`), `--coverage` (`0.95`), `--secondary-coverage` (`0.7,0.5`).\n", + "- `--min-abs-corr` (`0.8`), `--median-abs-corr` (off; sets OR-logic purity), `--pip-cutoff` (`0.025`).\n", + "- `--L` (`20`) and `--L-greedy` (`5`): SuSiE fit defaults.\n", + "- `--method-args`: JSON overriding any of the above per method, e.g. `{\"susie\":{\"L\":10}}`.\n", + "- `--ser-fallback` / `--no-ser-fallback` (default on), `--r-finite`, `--r-mismatch` (`eb_mix`), `--rss-control`: numerical safeguards for the RSS likelihood.\n", + "\n", + "Other:\n", + "\n", + "- `--no-plot`: skip `gwas_rss_plot`.\n", + "- `--manifest-name` (default `gwas_rss`): output prefix for the manifest file.\n", + "- `--cwd` (default `output`), `--modular-script-dir` (default `code/script`), `--container`, `--job-size`, `--walltime`, `--mem`, `--numThreads`." ] }, { @@ -65,9 +116,68 @@ "kernel": "SoS" }, "source": [ - "## Minimal working example\n", + "## Output\n", + "\n", + "- `gwas_rss.manifest.tsv` -- one row per study x region, recording which summary statistics file and\n", + " column mapping were paired with which LD block. Every later step reads it; the `gwas_rss` prefix\n", + " comes from `--manifest-name`. The example command produces a single row, since it runs one study\n", + " over one LD block, and `gwas_tsv` / `column_mapping` hold absolute paths, abbreviated here:\n", + "\n", + " ```\n", + " study_id\tgwas_tsv\tcolumn_mapping\tchr\tstart\tend\tregion_id\tgwas_tsv_basename\n", + " AD_Bellenguez_2022\t.../input/rss_analysis/protocol_example.gwas_sumstats.chr22.tsv.gz\t.../input/rss_analysis/protocol_example.gwas_column_mapping.fixed.yml\tchr22\t49355984\t50799822\tchr22_49355984_50799822\tprotocol_example.gwas_sumstats.chr22\n", + " ```\n", + "\n", + "- `sumstats/..gwas_sumstats.rds` -- a `GwasSumStats` object per study x block: the\n", + " QC-d, optionally imputed summary statistics, with variant IDs harmonised to the LD panel. The\n", + " step reports how many variants survived into the object:\n", + "\n", + " ```\n", + " Wrote QC'd GwasSumStats for study 'AD_Bellenguez_2022' over chr22:49355984-50799822 (7609 variants in)\n", + " ```\n", "\n", - "#### Genotype-LD MWE (AD_Bellenguez chr22 toy data under `input/`). There is no single combined workflow" + "- `fine_mapping/..gwas_finemap.rds` -- a `GwasFineMappingResult` object per study x\n", + " block, holding the SuSiE-RSS fit under `MethodNames` (`susie` by default): credible sets, PIPs,\n", + " single-effect posterior summaries, and the QC provenance of the variants that went in:\n", + "\n", + " ```\n", + " Wrote fineMapping result for GwasSumStats (1 row(s))\n", + " ```\n", + "\n", + "- `plots/..pip_plot.png` -- diagnostic PIP plot, unless `--no-plot` was given.\n", + "- a `.stdout` and a `.stderr` log beside each of the targets above.\n", + "\n", + "Everything is written under `--cwd`. `` is the `study_id` from the GWAS meta file and\n", + "`` is the LD block written as `chrN_start_end`, which for the example command above are\n", + "`AD_Bellenguez_2022` and `chr22_49355984_50799822` -- one file of each kind." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", + "### Default fine-mapping, no summary-statistics QC" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "This fine-maps one study x one LD block and writes the manifest, the QC-d `GwasSumStats`, the `GwasFineMappingResult`, and a PIP plot under `output/rss_analysis/`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -78,7 +188,6 @@ }, "outputs": [], "source": [ - "cd /restricted/projectnb/xqtl/jaempawi/xqtl-protocol\n", "sos run pipeline/rss_analysis.ipynb \\\n", " generate_manifest+generate_gwas_sumstats+gwas_fine_mapping+gwas_rss_plot \\\n", " --cwd output/rss_analysis --modular-script-dir code/script \\\n", @@ -93,10 +202,16 @@ "kernel": "SoS" }, "source": [ - "This fine-maps one study × one LD block and writes the manifest, the QC'd `GwasSumStats`, the\n", - "`GwasFineMappingResult`, and a PIP plot under `output/rss_analysis/`.\n", - "\n", - "#### With SLALOM QC + RAISS imputation + per-method tuning:" + "### SLALOM QC, RAISS imputation and per-method tuning" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -123,7 +238,7 @@ "kernel": "SoS" }, "source": [ - "### Command interface" + "## Command Interface" ] }, { @@ -133,7 +248,172 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\nparameter: cwd = path('output')\nparameter: modular_script_dir = path('code/script')\n# --- per-study GWAS inputs (use either or both) ---------------------\nparameter: gwas_meta = path('.')\nparameter: gwas_tsv_list = [] # list of STUDY=PATH items\n# --- region inputs (use either or both) -----------------------------\nparameter: region_list = path('.')\nparameter: regions = [] # list of chr:start-end strings\n# --- LD reference + genome ------------------------------------------\nparameter: ld_meta = path\nparameter: genome = 'GRCh38'\n# --- QC knobs (forwarded to gwas_sumstats_construct.R) --------------\nparameter: qc_method = 'none' # none | slalom | dentist\nparameter: impute = False\nparameter: qc_args = '' # JSON object spliced into summaryStatsQc()\nparameter: maf = 0.0025 # MAF cutoff (summaryStatsQc mafCutoff); 0 disables\nparameter: skip_regions = [] # chr:start-end window(s) whose variants are dropped (skipRegion)\nparameter: skip_analysis_pip_cutoff = 0.025 # skip a region below this max PIP (pipCutoffToSkip); 0 disables\nparameter: allele_flip_kriging = False # kriging allele-flip QC: sign-flip switched z (logLR>2 & |z|>2); off by default\nparameter: effective_n = True # case/control: use effective sample size 4/(1/n_case+1/n_control) as N (summaryStatsQc effectiveN); False -> raw N\n# --- fine-mapping knobs (forwarded to fine_mapping.R) ---------------\nparameter: methods = 'susie'\nparameter: coverage = 0.95\nparameter: secondary_coverage = '0.7,0.5'\nparameter: min_abs_corr = 0.8\nparameter: median_abs_corr = '' # empty -> off (OR-logic purity; needs pecotmr step-1)\nparameter: pip_cutoff = 0.025\nparameter: L = 20\nparameter: L_greedy = 5\nparameter: method_args = '' # nested per-method JSON object\n# GWAS SuSiE-RSS fine-mapping: SER fallback is ON by default (reproduces the single-panel notebook):\n# fit finite-sample R + EB LD-mismatch SuSiE-RSS and fall back to the single-effect (SER) result for\n# regions susieR flags as unreliable. ser_fallback and r_mismatch are orthogonal: ser_fallback = False\n# only disables the SER fallback (EB LD-mismatch stays on); pass r_mismatch = 'none' too for the\n# pre-change plain multi-effect fit. Requires susieR >= 0.16.6 (which moved R_mismatch_method /\n# check_prior into susie_rss_control(); pass those and other control settings via rss_control).\nparameter: ser_fallback = True # fall back to single-effect (SER) when susieR flags R unreliable\nparameter: r_finite = '' # finite-sample R size; empty -> auto (LD-panel sample size)\nparameter: r_mismatch = 'eb_mix' # LD-mismatch correction: 'none' | 'eb' | 'eb_mix' (residual-mixture EB, default)\nparameter: rss_control = '' # JSON object of susie_rss_control() settings, e.g. '{\"check_prior\":true,\"mismatch_estimator\":\"map\"}'; empty -> defaults\n# --- plot opt-out ---------------------------------------------------\nparameter: no_plot = False\n# --- output prefix for the manifest file ----------------------------\nparameter: manifest_name = 'gwas_rss'\n# --- infrastructure -------------------------------------------------\nparameter: container = ''\nparameter: job_size = 1\nparameter: walltime = '2h'\nparameter: mem = '16G'\nparameter: numThreads = 1" + "source": [ + "sos run pipeline/rss_analysis.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/rss_analysis.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " generate_manifest\n", + " generate_gwas_sumstats\n", + " gwas_fine_mapping\n", + " gwas_rss_plot\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " --gwas-meta . (as path)\n", + " --- per-study GWAS inputs (use either or both)\n", + " ---------------------\n", + " --gwas-tsv-list (as list)\n", + " --region-list . (as path)\n", + " --- region inputs (use either or both)\n", + " -----------------------------\n", + " --regions (as list)\n", + " --ld-meta VAL (as path, required)\n", + " --- LD reference + genome\n", + " ------------------------------------------\n", + " --genome GRCh38\n", + " --qc-method none\n", + " --- QC knobs (forwarded to gwas_sumstats_construct.R)\n", + " --------------\n", + " --[no-]impute (default to False)\n", + " --qc-args ''\n", + " --maf 0.0025 (as float)\n", + " --skip-regions (as list)\n", + " --skip-analysis-pip-cutoff 0.025 (as float)\n", + " --[no-]allele-flip-kriging (default to False)\n", + " --[no-]effective-n (default to True)\n", + " --methods susie\n", + " --- fine-mapping knobs (forwarded to fine_mapping.R)\n", + " ---------------\n", + " --coverage 0.95 (as float)\n", + " --secondary-coverage '0.7,0.5'\n", + " --min-abs-corr 0.8 (as float)\n", + " --median-abs-corr ''\n", + " --pip-cutoff 0.025 (as float)\n", + " --L 20 (as int)\n", + " --L-greedy 5 (as int)\n", + " --method-args ''\n", + " --[no-]ser-fallback (default to True)\n", + " GWAS SuSiE-RSS fine-mapping: SER fallback is ON by\n", + " default (reproduces the single-panel notebook): fit\n", + " finite-sample R + EB LD-mismatch SuSiE-RSS and fall back\n", + " to the single-effect (SER) result for regions susieR\n", + " flags as unreliable. ser_fallback and r_mismatch are\n", + " orthogonal: ser_fallback = False only disables the SER\n", + " fallback (EB LD-mismatch stays on); pass r_mismatch =\n", + " 'none' too for the pre-change plain multi-effect fit.\n", + " Requires susieR >= 0.16.6 (which moved R_mismatch_method\n", + " / check_prior into susie_rss_control(); pass those and\n", + " other control settings via rss_control).\n", + " --r-finite ''\n", + " --r-mismatch 'eb_mix'\n", + " --rss-control ''\n", + " --[no-]no-plot (default to False)\n", + " --- plot opt-out\n", + " ---------------------------------------------------\n", + " --manifest-name 'gwas_rss'\n", + " --- output prefix for the manifest file\n", + " ----------------------------\n", + " --container ''\n", + " --- infrastructure\n", + " -------------------------------------------------\n", + " --job-size 1 (as int)\n", + " --walltime 2h\n", + " --mem 16G\n", + " --numThreads 1 (as int)\n", + "\n", + "Sections\n", + " generate_manifest:\n", + " generate_gwas_sumstats:\n", + " gwas_fine_mapping:\n", + " gwas_rss_plot:\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "[global]\n", + "parameter: cwd = path('output')\n", + "parameter: modular_script_dir = path('code/script')\n", + "# --- per-study GWAS inputs (use either or both) ---------------------\n", + "parameter: gwas_meta = path('.')\n", + "parameter: gwas_tsv_list = [] # list of STUDY=PATH items\n", + "# --- region inputs (use either or both) -----------------------------\n", + "parameter: region_list = path('.')\n", + "parameter: regions = [] # list of chr:start-end strings\n", + "# --- LD reference + genome ------------------------------------------\n", + "parameter: ld_meta = path\n", + "parameter: genome = 'GRCh38'\n", + "# --- QC knobs (forwarded to gwas_sumstats_construct.R) --------------\n", + "parameter: qc_method = 'none' # none | slalom | dentist\n", + "parameter: impute = False\n", + "parameter: qc_args = '' # JSON object spliced into summaryStatsQc()\n", + "parameter: maf = 0.0025 # MAF cutoff (summaryStatsQc mafCutoff); 0 disables\n", + "parameter: skip_regions = [] # chr:start-end window(s) whose variants are dropped (skipRegion)\n", + "parameter: skip_analysis_pip_cutoff = 0.025 # skip a region below this max PIP (pipCutoffToSkip); 0 disables\n", + "parameter: allele_flip_kriging = False # kriging allele-flip QC: sign-flip switched z (logLR>2 & |z|>2); off by default\n", + "parameter: effective_n = True # case/control: use effective sample size 4/(1/n_case+1/n_control) as N (summaryStatsQc effectiveN); False -> raw N\n", + "# --- fine-mapping knobs (forwarded to fine_mapping.R) ---------------\n", + "parameter: methods = 'susie'\n", + "parameter: coverage = 0.95\n", + "parameter: secondary_coverage = '0.7,0.5'\n", + "parameter: min_abs_corr = 0.8\n", + "parameter: median_abs_corr = '' # empty -> off (OR-logic purity; needs pecotmr step-1)\n", + "parameter: pip_cutoff = 0.025\n", + "parameter: L = 20\n", + "parameter: L_greedy = 5\n", + "parameter: method_args = '' # nested per-method JSON object\n", + "# GWAS SuSiE-RSS fine-mapping: SER fallback is ON by default (reproduces the single-panel notebook):\n", + "# fit finite-sample R + EB LD-mismatch SuSiE-RSS and fall back to the single-effect (SER) result for\n", + "# regions susieR flags as unreliable. ser_fallback and r_mismatch are orthogonal: ser_fallback = False\n", + "# only disables the SER fallback (EB LD-mismatch stays on); pass r_mismatch = 'none' too for the\n", + "# pre-change plain multi-effect fit. Requires susieR >= 0.16.6 (which moved R_mismatch_method /\n", + "# check_prior into susie_rss_control(); pass those and other control settings via rss_control).\n", + "parameter: ser_fallback = True # fall back to single-effect (SER) when susieR flags R unreliable\n", + "parameter: r_finite = '' # finite-sample R size; empty -> auto (LD-panel sample size)\n", + "parameter: r_mismatch = 'eb_mix' # LD-mismatch correction: 'none' | 'eb' | 'eb_mix' (residual-mixture EB, default)\n", + "parameter: rss_control = '' # JSON object of susie_rss_control() settings, e.g. '{\"check_prior\":true,\"mismatch_estimator\":\"map\"}'; empty -> defaults\n", + "# --- plot opt-out ---------------------------------------------------\n", + "parameter: no_plot = False\n", + "# --- output prefix for the manifest file ----------------------------\n", + "parameter: manifest_name = 'gwas_rss'\n", + "# --- infrastructure -------------------------------------------------\n", + "parameter: container = ''\n", + "parameter: job_size = 1\n", + "parameter: walltime = '2h'\n", + "parameter: mem = '16G'\n", + "parameter: numThreads = 1" + ] }, { "cell_type": "code", @@ -166,7 +446,39 @@ "kernel": "SoS" }, "outputs": [], - "source": "[generate_gwas_sumstats]\n# Fan out over the manifest's rows: one (study, region) GwasSumStats per\n# row. Manifest columns: study_id, gwas_tsv, column_mapping, chr, start,\n# n_case, n_control, n_sample (optional), end, region_id, gwas_tsv_basename.\n# n_sample is the study-level total N: the level-4 fallback used when a study\n# has no per-variant n_case/n_control and no per-variant N column.\nimport csv\njobs = list(csv.DictReader(open(f\"{cwd}/{manifest_name}.manifest.tsv\"), delimiter='\\t'))\ninput: for_each = 'jobs'\noutput: f\"{cwd}/sumstats/{_jobs['study_id']}.{_jobs['region_id']}.gwas_sumstats.rds\"\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f\"{step_name}_{_output:bn}\"\nbash: expand = '${ }', stderr = f\"{_output}.stderr\", stdout = f\"{_output}.stdout\", container = container\n Rscript ${modular_script_dir}/pecotmr_integration/gwas_sumstats_construct.R \\\n --study ${_jobs['study_id']} \\\n --gwas-tsv ${_jobs['gwas_tsv']} \\\n --ld-block ${_jobs['chr']}:${_jobs['start']}-${_jobs['end']} \\\n --ld-meta ${ld_meta} \\\n --genome ${genome} \\\n ${('--column-mapping ' + _jobs['column_mapping']) if _jobs['column_mapping'] else ''} \\\n --qc-method ${qc_method} \\\n --maf ${maf} \\\n --pip-cutoff-to-skip ${skip_analysis_pip_cutoff} \\\n ${('--skip-region ' + ','.join(str(x) for x in skip_regions)) if skip_regions else ''} \\\n ${'--impute' if impute else ''} \\\n ${('--qc-args ' + repr(qc_args)) if qc_args else ''} \\\n ${'--allele-flip-kriging' if allele_flip_kriging else ''} \\\n --effective-n ${'TRUE' if effective_n else 'FALSE'} \\\n ${('--n-case ' + _jobs['n_case']) if _jobs.get('n_case','') not in ('', 'NA') else ''} \\\n ${('--n-control ' + _jobs['n_control']) if _jobs.get('n_control','') not in ('', 'NA') else ''} \\\n ${('--n-sample ' + _jobs['n_sample']) if _jobs.get('n_sample','') not in ('', 'NA') else ''} \\\n --output ${_output}" + "source": [ + "[generate_gwas_sumstats]\n", + "# Fan out over the manifest's rows: one (study, region) GwasSumStats per\n", + "# row. Manifest columns: study_id, gwas_tsv, column_mapping, chr, start,\n", + "# n_case, n_control, n_sample (optional), end, region_id, gwas_tsv_basename.\n", + "# n_sample is the study-level total N: the level-4 fallback used when a study\n", + "# has no per-variant n_case/n_control and no per-variant N column.\n", + "import csv\n", + "jobs = list(csv.DictReader(open(f\"{cwd}/{manifest_name}.manifest.tsv\"), delimiter='\\t'))\n", + "input: for_each = 'jobs'\n", + "output: f\"{cwd}/sumstats/{_jobs['study_id']}.{_jobs['region_id']}.gwas_sumstats.rds\"\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f\"{step_name}_{_output:bn}\"\n", + "bash: expand = '${ }', stderr = f\"{_output}.stderr\", stdout = f\"{_output}.stdout\", container = container\n", + " Rscript ${modular_script_dir}/pecotmr_integration/gwas_sumstats_construct.R \\\n", + " --study ${_jobs['study_id']} \\\n", + " --gwas-tsv ${_jobs['gwas_tsv']} \\\n", + " --ld-block ${_jobs['chr']}:${_jobs['start']}-${_jobs['end']} \\\n", + " --ld-meta ${ld_meta} \\\n", + " --genome ${genome} \\\n", + " ${('--column-mapping ' + _jobs['column_mapping']) if _jobs['column_mapping'] else ''} \\\n", + " --qc-method ${qc_method} \\\n", + " --maf ${maf} \\\n", + " --pip-cutoff-to-skip ${skip_analysis_pip_cutoff} \\\n", + " ${('--skip-region ' + ','.join(str(x) for x in skip_regions)) if skip_regions else ''} \\\n", + " ${'--impute' if impute else ''} \\\n", + " ${('--qc-args ' + repr(qc_args)) if qc_args else ''} \\\n", + " ${'--allele-flip-kriging' if allele_flip_kriging else ''} \\\n", + " --effective-n ${'TRUE' if effective_n else 'FALSE'} \\\n", + " ${('--n-case ' + _jobs['n_case']) if _jobs.get('n_case','') not in ('', 'NA') else ''} \\\n", + " ${('--n-control ' + _jobs['n_control']) if _jobs.get('n_control','') not in ('', 'NA') else ''} \\\n", + " ${('--n-sample ' + _jobs['n_sample']) if _jobs.get('n_sample','') not in ('', 'NA') else ''} \\\n", + " --output ${_output}" + ] }, { "cell_type": "code", @@ -175,7 +487,29 @@ "kernel": "SoS" }, "outputs": [], - "source": "[gwas_fine_mapping]\n# Per-RDS fan-out: one fine-mapping task per (study, region) GwasSumStats.\noutput: f\"{cwd}/fine_mapping/{_input:bnn}.gwas_finemap.rds\", group_by = 1\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f\"{step_name}_{_output:bn}\"\nbash: expand = '${ }', stderr = f\"{_output}.stderr\", stdout = f\"{_output}.stdout\", container = container\n Rscript ${modular_script_dir}/pecotmr_integration/fine_mapping.R \\\n --gwas-sumstats ${_input} \\\n --methods ${methods} \\\n --coverage ${coverage} \\\n --secondary-coverage ${secondary_coverage} \\\n --min-abs-corr ${min_abs_corr} \\\n --pip-cutoff ${pip_cutoff} \\\n --L ${L} \\\n --L-greedy ${L_greedy} \\\n ${('--median-abs-corr ' + str(median_abs_corr)) if str(median_abs_corr) != '' else ''} \\\n ${('--method-args ' + repr(method_args)) if method_args else ''} \\\n --ser-fallback ${'TRUE' if ser_fallback else 'FALSE'} \\\n --r-mismatch ${r_mismatch} \\\n ${('--r-finite ' + str(r_finite)) if str(r_finite) != '' else ''} \\\n ${('--rss-control ' + repr(rss_control)) if rss_control else ''} \\\n --output ${_output}" + "source": [ + "[gwas_fine_mapping]\n", + "# Per-RDS fan-out: one fine-mapping task per (study, region) GwasSumStats.\n", + "output: f\"{cwd}/fine_mapping/{_input:bnn}.gwas_finemap.rds\", group_by = 1\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f\"{step_name}_{_output:bn}\"\n", + "bash: expand = '${ }', stderr = f\"{_output}.stderr\", stdout = f\"{_output}.stdout\", container = container\n", + " Rscript ${modular_script_dir}/pecotmr_integration/fine_mapping.R \\\n", + " --gwas-sumstats ${_input} \\\n", + " --methods ${methods} \\\n", + " --coverage ${coverage} \\\n", + " --secondary-coverage ${secondary_coverage} \\\n", + " --min-abs-corr ${min_abs_corr} \\\n", + " --pip-cutoff ${pip_cutoff} \\\n", + " --L ${L} \\\n", + " --L-greedy ${L_greedy} \\\n", + " ${('--median-abs-corr ' + str(median_abs_corr)) if str(median_abs_corr) != '' else ''} \\\n", + " ${('--method-args ' + repr(method_args)) if method_args else ''} \\\n", + " --ser-fallback ${'TRUE' if ser_fallback else 'FALSE'} \\\n", + " --r-mismatch ${r_mismatch} \\\n", + " ${('--r-finite ' + str(r_finite)) if str(r_finite) != '' else ''} \\\n", + " ${('--rss-control ' + repr(rss_control)) if rss_control else ''} \\\n", + " --output ${_output}" + ] }, { "cell_type": "code", @@ -225,4 +559,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/mnm_analysis/mnm_miniprotocol.ipynb b/code/SoS/mnm_analysis/mnm_miniprotocol.ipynb index d434e9072..26646e90d 100644 --- a/code/SoS/mnm_analysis/mnm_miniprotocol.ipynb +++ b/code/SoS/mnm_analysis/mnm_miniprotocol.ipynb @@ -2,248 +2,207 @@ "cells": [ { "cell_type": "markdown", - "id": "3ee1c5f8-3015-41d3-bdcb-38b63861bffe", + "id": "019555d7", "metadata": {}, "source": [ - "# Integrative Analysis with High-Dimensional Regression\n", + "# Fine-mapping and TWAS analysis\n", "\n", - "This notebook shows the various fine-mapping, prediction, multivariate analysis and colocalization methods available in our pipeline." + "This mini-protocol selects among univariate, multivariate, multigene, functional and summary-statistic fine-mapping routes according to the available data and analysis goal." ] }, { "cell_type": "markdown", - "id": "e03da35b", - "metadata": {}, - "source": [ - "## Input Files\n", - "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/genotype_by_chrom/wgs.merged.plink_qc.*.bed` | Per-chromosome QC-passed genotype PLINK files |\n", - "| `output/phenotype/*.region_list.txt` | Phenotype region lists (one per molecular phenotype) |\n", - "| `output/covariate/*.gz` | Covariate matrices (known + hidden factors) |\n", - "| `reference_data/TAD/TADB_enhanced_cis.bed` | TAD-based association windows |\n" - ] - }, - { - "cell_type": "markdown", - "id": "497a0361-7646-4bdc-967f-0cd3ad55b301", + "id": "722e60a4", "metadata": {}, "source": [ "#### Miniprotocol Timing\n", - "This represents the total duration for all miniprotocol phases. While module-specific timings are provided separately on their respective pages, they are also included in this overall estimate. \n", "\n", - "**Timing (toy data, chr22):** < 10 minutes total. Measured wall-clock: univariate SuSiE / SuSiE-RSS fine-mapping ~1.5 minutes per region; fSuSiE and multivariate (mvSuSiE/mr.mash) fine-mapping are comparable on the toy single-region data. On real data, fine-mapping scales with region size, number of variants, and number of conditions." + "Timing: TBD" ] }, { "cell_type": "markdown", - "id": "b179d380-7ed1-48ba-9d94-39c1e83733f0", + "id": "b8153dee", "metadata": {}, "source": [ - "## Description\n", + "## Overview\n", "\n", - "Each of these parts are independent of one another.\n", + "The [MNM regression module](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html) analyzes individual-level genotype and molecular-phenotype data. `qtl_dataset_construct+susie_twas` performs univariate SuSiE fine-mapping and estimates TWAS weights; `mnm` jointly analyzes multiple molecular traits with multivariate priors; `mnm_genes` extends the multivariate model across genes; and `fsusie` fine-maps functional or epigenomic phenotypes.\n", "\n", - "1. `mnm_regression.ipynb susie_twas`: Univariate Fine-Mapping and TWAS with SuSiE\n", - "2. `mnm_regression.ipynb mnm_genes`: Multivariate Fine-Mapping for multiple genes\n", - "3. `mnm_regression.ipynb fsusie`: Univariate Fine-Mapping of Functional (Epigenomic) Data with fSuSiE\n", - "4. `mnm_regression.ipynb mnm`: Multivariate Fine-Mapping with mvSuSiE and mr.mash\n", - "5. `rss_analysis.ipynb univariate_rss`: Regression with Summary Statistics (RSS) Fine-Mapping and TWAS with SuSiE" + "The [RSS module](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/rss_analysis.html) instead combines GWAS summary statistics with an external LD reference. These five commands are alternative analysis routes rather than a mandatory chain." ] }, { "cell_type": "markdown", - "id": "f1e1cd1a-d341-45de-876e-773e04789244", + "id": "c68e6e0a", "metadata": {}, "source": [ - "## Steps" + "## Steps\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Univariate molecular-QTL fine-mapping and TWAS weights | 1 | Genotype BED set, phenotype manifest, covariates and association windows under `input/colocboost/` |\n", + "| Multivariate fine-mapping across molecular traits | 2 | Step 1 inputs plus `input/colocboost/fine_mapping_meta.tsv` |\n", + "| Multigene multivariate fine-mapping | 3 | Multivariate inputs plus phenotype-ID map and retained-sample list under `input/colocboost/` |\n", + "| Fine-map functional or epigenomic phenotypes | 4 | `input/genotype/protocol_example.genotype.chr22.bed`; phenotype manifest, covariates and windows |\n", + "| GWAS summary-statistic fine-mapping | 5 | `input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv`; `input/ld_reference/protocol_example.ld_meta_file.tsv` |\n", + "\n", + "Run only the command matching the analysis goal." ] }, { "cell_type": "markdown", - "id": "293e2b0c-fe45-4500-b5d8-98f84b4f1883", + "id": "14f54de1", "metadata": {}, "source": [ - "### i. [Univariate Fine-Mapping and TWAS with SuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/univariate_fine_mapping_twas_vignette.html)" + "### [1. Univariate fine-mapping and TWAS](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", + "\n", + "**What it does:** `qtl_dataset_construct+susie_twas` builds the regional dataset, fits SuSiE and saves fine-mapping results and cross-validated TWAS weights." ] }, { "cell_type": "code", "execution_count": null, - "id": "2af1a144-4717-456d-8b45-6962f4d68ea0", + "id": "38e33d9f", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb susie_twas \\\n", - " --name test_susie_twas \\\n", - " --genoFile output/genotype_by_chrom/wgs.merged.plink_qc.1.bed \\\n", - " --phenoFile output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.region_list.txt \\\n", - " --covFile output/covariate/bulk_rnaseq_tmp_matrix.low_expression_filtered.outlier_removed.tmm.expression.covariates.wgs.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", - " --customized-association-windows reference_data/TAD/TADB_enhanced_cis.bed \\\n", - " --phenotype-names test_pheno \\\n", - " --max-cv-variants 5000 --ld_reference_meta_file data/ld_meta_file_with_bim.tsv \\\n", - " --region-name ENSG00000049246 ENSG00000054116 ENSG00000116678 \\\n", - " --save-data \\\n", - " --cwd output/mnm_regression/susie_twas" + "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+susie_twas --name protocol_example --cwd output/mnm/univariate --genoFile input/colocboost/example.chr22.bed --phenoFile input/colocboost/pheno_manifest_multicontext.tsv --covFile input/colocboost/example_covariates.tsv --customized-association-windows input/colocboost/association_windows.bed --region-name ENSG00000130538 --transpose-covariates --save-data -j1" ] }, { "cell_type": "markdown", - "id": "4b91d378-e96f-4f20-a54a-7df411b73875", + "id": "bb824285", "metadata": {}, "source": [ - "### ii. [Multivariate Fine-Mapping for multiple genes](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/multivariate_multigene_fine_mapping_vignette.html)" + "### [2. Multivariate fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", + "\n", + "**What it does:** `mnm` jointly fine-maps multiple molecular traits using the analyses and prior settings specified by the fine-mapping metadata." ] }, { "cell_type": "code", "execution_count": null, - "id": "a2e60016-d265-4e53-bc4c-3b415f430c33", + "id": "5075e2e6", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb mnm_genes \\\n", - " --name ROSMAP_Ast_mega_eQTL \\\n", - " --genoFile data/mnm_genes/ROSMAP_NIA_WGS.leftnorm.bcftools_qc.plink_qc.11.bed \\\n", - " --phenoFile data/mnm_genes/snuc_pseudo_bulk.Ast.mega.normalized.log2cpm.region_list.txt \\\n", - " --covFile data/mnm_genes/snuc_pseudo_bulk.Ast.mega.normalized.log2cpm.rosmap_cov.ROSMAP_NIA_WGS.leftnorm.bcftools_qc.plink_qc.snuc_pseudo_bulk_mega.related.plink_qc.extracted.pca.projected.Marchenko_PC.gz \\\n", - " --customized-association-windows data/mnm_genes/extended_TADB.bed \\\n", - " --phenotype-names Ast_mega_eQTL \\\n", - " --max-cv-variants 5000 \\\n", - " --ld_reference_meta_file data/ld_meta_file_with_bim.tsv \\\n", - " --independent_variant_list data/mnm_genes/ld_pruned_variants.txt.gz \\\n", - " --fine_mapping_meta data/mnm_genes/combined_data_updated.tsv \\\n", - " --phenoIDFile data/mnm_genes/phenoIDFile_extended_TADB.bed \\\n", - " --region-name chr11_77324757_82556425 \\\n", - " --skip-analysis-pip-cutoff 0 \\\n", - " --maf 0.01 \\\n", - " --coverage 0.95 \\\n", - " --pheno_id_map_file data/mnm_genes/pheno_id_map_file.txt \\\n", - " --prior-canonical-matrices \\\n", - " --twas-cv-folds 0 \\\n", - " --trans-analysis \\\n", - " --cwd output/mnm_regression/mnm_genes -s build" + "sos run pipeline/mnm_regression.ipynb mnm --name protocol_example --cwd output/mnm/multivariate --genoFile input/colocboost/example.chr22.bed --phenoFile input/colocboost/pheno_manifest_multicontext.tsv --covFile input/colocboost/example_covariates.tsv --customized-association-windows input/colocboost/association_windows.bed --fine-mapping-meta input/colocboost/fine_mapping_meta.tsv --transpose-covariates --save-data -j1" ] }, { "cell_type": "markdown", - "id": "af4443c5-6534-4bc5-9c88-6ab444d17b25", + "id": "16a9100b", "metadata": {}, "source": [ - "### iii. [Univariate Fine-Mapping of Functional (Epigenomic) Data with fSuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/univariate_fine_mapping_fsusie_vignette.html)" + "### [3. Multigene multivariate fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", + "\n", + "**What it does:** `mnm_genes` coordinates multivariate fine-mapping across genes while preserving phenotype identifiers and a common retained-sample set." ] }, { "cell_type": "code", "execution_count": null, - "id": "932ef298-5c45-4e18-abb6-89c15253bbd6", + "id": "92a38f2b", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb fsusie \\\n", - " --cwd output/fsusie/ \\\n", - " --name test_fsusie \\\n", - " --genoFile output/genotype_by_chrom/wgs.merged.plink_qc.genotype_by_chrom_files.txt \\\n", - " --phenoFile output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.region_list.txt \\\n", - " --covFile output/covariate/bulk_rnaseq_tpm_matrix.low_expression_filtered.outlier_removed.tmm.expression.covariates.wgs.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", - " --numThreads 8 \\\n", - " --customized-association-windows reference_data/TAD/TADB_enhanced_cis.bed \\\n", - " --save-data \\\n", - " --region-name ENSG00000049246 ENSG00000054116 ENSG00000116678 ENSG00000073921 ENSG00000186891" + "sos run pipeline/mnm_regression.ipynb mnm_genes --name protocol_example --cwd output/mnm/multigene --genoFile input/colocboost/example.chr22.bed --phenoFile input/colocboost/pheno_manifest_multicontext.tsv --covFile input/colocboost/example_covariates.tsv --customized-association-windows input/colocboost/association_windows.bed --pheno-id-map-file input/colocboost/pheno_id_map.tsv --fine-mapping-meta input/colocboost/fine_mapping_meta.tsv --keep-samples input/colocboost/keep_samples.txt --save-data -j1" ] }, { "cell_type": "markdown", - "id": "58229f81-0bdd-4d2f-bf8c-28f542b7e6d3", + "id": "30bd5556", "metadata": {}, "source": [ - "### iv. [Multivariate Fine-Mapping with mvSuSiE and mr.mash](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/multivariate_fine_mapping_vignette.html)" + "### [4. Functional fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", + "\n", + "**What it does:** `fsusie` applies functional SuSiE to epigenomic or other functional phenotypes and saves posterior fine-mapping results and residual data." ] }, { "cell_type": "code", "execution_count": null, - "id": "4dc2dfdc-e39b-49cb-8bd1-e1d4927d39d0", + "id": "93829c34", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/mnm_regression.ipynb mnm \\\n", - " --name test_mnm --cwd output/mnm \\\n", - " --genoFile output/genotype_by_chrom/wgs.merged.plink_qc.genotype_by_chrom_files.txt \\\n", - " --phenoFile output/phenotype/phenotype_by_chrom_for_cis/bulk_rnaseq.phenotype_by_chrom_files.region_list.txt \\\n", - " --covFile output/covariate/bulk_rnaseq_tpm_matrix.low_expression_filtered.outlier_removed.tmm.expression.covariates.wgs.merged.plink_qc.plink_qc.prune.pca.Marchenko_PC.gz \\\n", - " --customized-association-windows reference_data/TAD/TADB_enhanced_cis.bed \\\n", - " --region-name ENSG00000073921 --save-data --no-skip-twas-weights \\\n", - " --phenotype-names test_pheno \\\n", - " --mixture_prior output/multivariate_mixture/MWE_ed_bovy.EE.prior.rds \\\n", - " --max_cv_variants 5000 \\\n", - "\t--ld_reference_meta_file data/ld_meta_file.tsv " + "sos run pipeline/mnm_regression.ipynb fsusie --name protocol_example --cwd output/mnm/fsusie --genoFile input/genotype/protocol_example.genotype.chr22.bed --phenoFile input/phenotype/protocol_example.pheno_manifest.tsv --covFile input/covariate/protocol_example.covariates.tsv --customized-association-windows input/finemapping/protocol_example.association_windows.bed --cis-window 0 --max-cv-variants 5000 --save-data -j1" ] }, { "cell_type": "markdown", - "id": "323e3000-dd8c-4e52-b371-95226789c791", + "id": "28ac41b4", "metadata": {}, "source": [ - "### v. [Regression with Summary Statistics (RSS) Fine-Mapping and TWAS with SuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/summary_stats_finemapping_vignette.html)" + "### [5. Summary-statistic fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/rss_analysis.html)\n", + "\n", + "**What it does:** the RSS chain harmonizes regional GWAS summary statistics with the LD reference, runs SuSiE-RSS fine-mapping and produces a regional diagnostic plot." ] }, { "cell_type": "code", "execution_count": null, - "id": "304423fc-7070-483c-9ff3-ef0e9f95e8b2", + "id": "fed95103", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/rss_analysis.ipynb univariate_rss \\\n", - " --ld-meta-data data/ld_meta_file_with_bim.tsv \\\n", - " --gwas-meta-data data/mnm_regression/gwas_meta_data.txt \\\n", - " --qc_method \"rss_qc\" --impute \\\n", - " --finemapping_method \"susie_rss\" \\\n", - " --cwd output/rss_analysis \\\n", - " --skip_analysis_pip_cutoff 0 \\\n", - " --skip_regions 6:25000000-35000000 \\\n", - " --region_name 22:49355984-50799822" + "sos run pipeline/rss_analysis.ipynb generate_manifest+generate_gwas_sumstats+gwas_fine_mapping+gwas_rss_plot --cwd output/mnm/rss --modular-script-dir code/script --gwas-meta input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv --regions chr22:49355984-50799822 --ld-meta input/ld_reference/protocol_example.ld_meta_file.tsv" ] }, { "cell_type": "markdown", - "id": "99ef76cd-184b-4107-a8fe-523daa10a09c", + "id": "9ad16d51", "metadata": {}, "source": [ - "## Anticipated Results" + "## Output Files\n", + "\n", + "| Route | Output filename and relative path | Description |\n", + "| --- | --- | --- |\n", + "| Univariate | `output/mnm/univariate/**/*.univariate_bvsr.rds`; `output/mnm/univariate/**/*.twas_weights.rds` | SuSiE posterior and TWAS-weight objects |\n", + "| Multivariate | `output/mnm/multivariate/**/*.multivariate_bvsr.rds`; `output/mnm/multivariate/**/*.twas_weights.rds` | Joint multivariate posterior and weights |\n", + "| Multigene | `output/mnm/multigene/**/*` | Per-region, per-gene multivariate results and metadata |\n", + "| Functional | `output/mnm/fsusie/**/*.fsusie.rds`; saved residual objects | Functional fine-mapping posterior and residual data |\n", + "| RSS | `output/mnm/rss/fine_mapping/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_finemap.rds`; regional plot under `output/mnm/rss/plots/` | Summary-statistic fine-mapping result and diagnostic plot |" ] }, { "cell_type": "markdown", - "id": "c2211dbf", + "id": "5b52900e", "metadata": {}, "source": [ - "## Output Files\n", + "## Anticipated Results\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/mnm_regression/*.univariate_bvsr.rds` | Univariate fine-mapping results (SuSiE) |\n", - "| `output/mnm_regression/*.twas_weights.rds` | TWAS weights per gene |\n", - "| `output/mnm_genes/*` | Multivariate fine-mapping results across multiple genes |\n" + "Each route produces posterior inclusion probabilities and credible-set information for the selected region and analysis model. Routes that estimate prediction weights also save TWAS-weight objects. The RSS route additionally records the harmonized regional summary statistics and LD-based diagnostics." ] }, { "cell_type": "markdown", - "id": "c46afb81-7a8e-4b9b-ad3c-ebf409b33824", + "id": "16144133", "metadata": {}, "source": [ - "Univariate finemapping will produce a file containing results for the top hits and a file containing twas weights produced by susie. Multigene finemapping with mvSuSiE will produce a file for each gene and region containing results for the top hits and a file containing twas weights produced by susie. Univariate finemapping for functional data with fSuSiE will produce a file containing results for the top hits and a file containing residuals from SuSiE. Multivariate finemapping will produce a file containing results for the top hits for each gene and a file containing twas weights produced by susie. Summary statistics fine-mapping produces a results file for each region and gwas of interest." + "## Command interface" ] }, { "cell_type": "code", "execution_count": null, - "id": "34729ce0-94f8-4f78-8961-e3c3dc365f2e", + "id": "e8df299c", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "sos run pipeline/mnm_regression.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c9dc6ea2", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/rss_analysis.ipynb -h" + ] } ], "metadata": { diff --git a/code/SoS/mnm_analysis/mnm_postprocessing.ipynb b/code/SoS/mnm_analysis/mnm_postprocessing.ipynb index e495554d7..7ff38c7cf 100644 --- a/code/SoS/mnm_analysis/mnm_postprocessing.ipynb +++ b/code/SoS/mnm_analysis/mnm_postprocessing.ipynb @@ -2,199 +2,891 @@ "cells": [ { "cell_type": "markdown", - "id": "a5f6e2e3", + "id": "d8817355", "metadata": { "kernel": "SoS" }, "source": [ "# Fine-mapping result post-processing\n", "\n", - "This is a new-user-friendly minimal working example (MWE) of the `mnm_postprocessing` pipeline (the original `SuSiE_post_processing` notebook). It post-processes SuSiE fine-mapping results into flat, human-readable TSV tables. It runs end-to-end on the bundled chr22 toy dataset." + "Turns per-region fine-mapping objects into flat TSV tables, diagnostic plots, VCFs and QTL-GWAS overlap summaries." ] }, { "cell_type": "markdown", - "id": "a34af82b", + "id": "fba6b747", "metadata": { "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "The full pipeline consolidates fine-mapping output into text tables, generates PIP/UpSet plots, exports VCFs, and overlaps QTL with GWAS results. Most of those steps need GWAS summary statistics, region/plot-recipe files, and a singularity container that the toy dataset does not ship.\n", + "Fine-mapping leaves you with per-region R objects, which are the wrong shape for almost\n", + "everything that comes next - inspecting results, sharing them, or intersecting them with\n", + "a GWAS. This module reads those objects and re-expresses them as text: `susie_to_tsv`\n", + "writes a per-variant table (PIP, credible-set membership, posterior mean and sd), a\n", + "wide per-variant by per-effect log-Bayes-factor table, and a per-credible-set effect\n", + "table. The remaining workflows build on those tables - collapsing them across regions,\n", + "drawing PIP landscape and UpSet plots, annotating variants, exporting VCFs, and\n", + "overlapping QTL credible sets with GWAS signals.\n", "\n", - "This MWE focuses on the core, genuinely runnable step, **`susie_to_tsv`**, which reads each per-region SuSiE object and writes three tables: a per-variant table (PIP, credible-set membership, posterior mean/sd), a log-Bayes-factor table, and an effect table. The remaining workflows are kept as documented command templates." + "The export step consumes a `FineMappingResult` object rather than a raw `susieR` fit,\n", + "so the three tables are views onto that object: `variant.tsv` is its `topLoci` view,\n", + "`lbf.tsv` its `lbf` view and `effect.tsv` its `cs_summary` view. Because the object\n", + "carries its own region and trait, `--region-list` is accepted for CLI compatibility but\n", + "is no longer used.\n", + "\n", + "**When to run it.** After fine-mapping, on the outputs of `susie_twas` or `fsusie`, and\n", + "before any downstream reporting or GWAS integration. Most of the workflows beyond\n", + "`susie_to_tsv` additionally need GWAS summary statistics, plot-recipe files or a\n", + "singularity container." ] }, { "cell_type": "markdown", - "id": "970bb4c9", + "id": "569ef74c", "metadata": { "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Input\n", + "\n", + "- `--rds_path` **`input/mnm_postprocessing/protocol_example.ENSG00000283047.fine_mapping.rds`**\n", + "(one or more `FineMappingResult` RDS files written by `mnm_regression`; each carries its own region and trait, and the step runs once per file)\n", + "\n", + "```\n", + "QtlFineMappingResult: S4 DataFrame, 2 rows x 7 columns\n", + "$ study: character [1:2] test_study test_study\n", + "$ context: character [1:2] context1 context2\n", + "$ trait: character [1:2] ENSG00000283047 ENSG00000283047\n", + "$ method: character [1:2] susie susie\n", + "$ entry: S4 object \n", + " ..$ listData: List of 2\n", + " .. ..$ : S4 object \n", + " .. .. ..$ variantIds: ...\n", + " .. .. ..$ susieFit: ...\n", + " .. .. ..$ topLoci: ...\n", + " .. .. ..$ cvResult: ...\n", + " .. ..$ : S4 object \n", + " .. .. ..$ variantIds: ...\n", + " .. .. ..$ susieFit: ...\n", + " .. .. ..$ topLoci: ...\n", + " .. .. ..$ cvResult: ...\n", + " ..$ elementType: character [1:1] ANY\n", + " ..$ elementMetadata: name [1:1] \u0001NULL\u0001\n", + " ..$ metadata: List of 0\n", + "... (truncated)\n", + "```\n", + "\n", + "- `--study toy` (tag used as `name` in output filenames and in intermediate RDS names. Required.)\n", + "- `--cwd output_postproc` (working directory all outputs are written under. Defaults to `output`.)\n", + "- `--container` (an empty string runs the step natively in the project environment instead of through a singularity image)\n", + "- `--region-list` (accepted for CLI compatibility and ignored. The `FineMappingResult` carries its own region and trait, so no external region list is needed.)\n", "\n", - "All paths are relative to the working directory `data/example_10peaks_susie_twas/` (run commands from there).\n", + "The same directory also holds `protocol_example.fsusie.fine_mapping.rds` and\n", + "`protocol_example.mvsusie.fine_mapping.rds`, for the `fsusie_to_tsv` and `mv_susie_2`\n", + "workflows.\n", "\n", - "- **SuSiE objects** (`--rds_path`): per-region fine-mapping RDS files. The toy inputs in `input_postproc/cs..uni.bvsr.rds` are produced by the prep step below, which reshapes the genuine `output_uni/fine_mapping/*.univariate_bvsr.rds` results (from the `mnm_regression` MWE) into the flat `susie` object structure `susie_to_tsv` expects. This only reshapes real fine-mapping output; it does not fabricate any values.\n", - "- **Region list** (`--region-list`): a TSV with columns `#chr, start, end, gene_id` describing each region. `input_postproc/region_list.tsv` is written by the same prep step." + "The `export_top_loci` workflow consolidates results across regions and takes a different\n", + "set of inputs, none of which the example data ships:\n", + "\n", + "- `--file_path` (directory holding the per-region fine-mapping RDS files)\n", + "- `--prefix`, `--suffix` (the filename parts before and after the region id, so each region resolves to `/..` - for example `ROSMAP_AC_eQTL.ENSG00000012779.univariate_bvsr.rds`)\n", + "- `--qtl_type cis` (one of `cis`, `trans` or `trans_`; appears in the combined output filename)\n", + "- `--region_file` (BED file listing the regions to consolidate)\n", + "\n", + "The remaining workflows take these additional flags:\n", + "\n", + "- `--tsv_path output_postproc/*.lbf.tsv` (per-region LBF tables to concatenate; `susie_tsv_collapse`)\n", + "- `--annot_tibble ` (annotation tibble used to label variants; `susie_pip_landscape_plot` and `fsusie_extract_effect`)\n", + "- `--trait_to_select 1` (how many traits the credible-set UpSet diagram shows; `susie_upsetR_cs_plot`)\n", + "- `--SNP_list ` (variants to annotate; `tmp_annotatation_of_snps`)\n", + "- `--annotation_rds ` (annotation reference the variants are looked up against; `tmp_annotatation_of_snps`)\n", + "- `--geno_ref ` (genotype reference used to resolve variant identifiers; `export_top_loci`)\n", + "- `--min_corr 0.8` (minimum correlation for a variant to join a top-loci block; `export_top_loci`)\n", + "- `--condition_meta ` (GWAS meta file naming the conditions to overlap; `overlap_qtl_gwas`)" ] }, { "cell_type": "markdown", - "id": "ac6cd03c", + "id": "1f12093a", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps\n", + "## Output\n", + "**Per-region TSV export** (`susie_to_tsv`, `sQTL_susie_to_tsv`, `fsusie_to_tsv`), one set per input SuSiE object:\n", + "\n", + "- `.variant.tsv` -- one row per variant: PIP, credible-set order and id, posterior mean and sd.\n", + "- `.lbf.tsv` -- per-variant log Bayes factors for each single-effect.\n", + "- `.effect.tsv` -- per-effect summary (`susie_to_tsv` and `sQTL_susie_to_tsv` only).\n", + "- `.all_variants.tsv` -- variants pooled across regions (`fsusie_to_tsv` only).\n", + "\n", + "**Collapsed tables** (`susie_tsv_collapse`):\n", + "\n", + "- `.chr.unisusie_rss.lbf.tsv` -- per-region lbf tables concatenated by chromosome.\n", + "\n", + "**Diagnostic plots**:\n", + "\n", + "- `.pip_landscape_plot.pdf` (`susie_pip_landscape_plot`)\n", + "- `.UpSetR.pdf` and `.UpSetR_cs.pdf` (`susie_upsetR_plot`, `susie_upsetR_cs_plot`)\n", + "\n", + "**Variant annotation** (`tmp_annotatation_of_snps`):\n", + "\n", + "- `.annotated.rds` and `.annotated_rev.rds`\n", + "\n", + "**fSuSiE effect extraction**:\n", + "\n", + "- `.estimated_effect.tsv` (`fsusie_extract_effect`)\n", + "- `.affected_region.tsv` (`fsusie_affected_region`)\n", "\n", - "### Prep: build the toy inputs (one-off)\n", + "**VCF export** (`mv_susie_2`):\n", "\n", - "Reshape the univariate SuSiE results into flat per-region `susie` RDS files and a matching region list. Run from the toy_example root." + "- `..vcf.bgz`\n", + "\n", + "**cis and GWAS consolidation**:\n", + "\n", + "- `_cache/_.tsv`, collapsed into `.cis_results_db.tsv` (or `.block_results_db.tsv` for GWAS input) -- `cis_results_export`\n", + "- `.union_export.tsv.gz` -- `gwas_results_export`\n", + "- `summary/.top_loci.bed.gz`, collapsed into `summary/..top_loci.bed.gz` -- `export_top_loci`\n", + "\n", + "**QTL and GWAS overlap** (`overlap_qtl_gwas`):\n", + "\n", + "- `gwas_qtl/cache/_gwas_batch_meta_.tsv`\n", + "- `.overlapped.gwas.tsv`\n", + "\n", + "No example output ships with the repository: `output_postproc/` is empty and the pipeline cannot be re-run here, so no structure dumps are shown. The filenames above come from each step `output:` statement." + ] + }, + { + "cell_type": "markdown", + "id": "ab9e91bd", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", + "### Export fine-mapping results to per-variant, LBF and effect tables\n", + "\n", + "`susie_to_tsv` reads each `FineMappingResult` object and writes its three text views." + ] + }, + { + "cell_type": "markdown", + "id": "08b3aad0", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65c8d622-ac64-43f7-9eb9-9e0abba73704", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb susie_to_tsv \\\n", + " --cwd output_postproc --study toy \\\n", + " --rds_path input/mnm_postprocessing/protocol_example.ENSG00000283047.fine_mapping.rds \\\n", + " --container '' -j1" ] }, { "cell_type": "markdown", - "id": "47df52aa", + "id": "24086557", "metadata": { "kernel": "SoS" }, "source": [ - "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." + "### fSuSiE and sQTL exports\n", + "`fsusie_to_tsv` and `sQTL_susie_to_tsv` perform the same export for fSuSiE and sQTL objects." ] }, { "cell_type": "markdown", - "id": "525edba0", + "id": "cb487f2a-b879-421e-8fb2-d07e23328ebd", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "727843ad-29bf-430c-b56b-4e8493ef71fe", "metadata": { - "kernel": "R" + "kernel": "SoS" }, + "outputs": [], "source": [ - "# Required CLI args (substitute placeholders <...> with your real values):\n", - "# --file_path dir containing fine-mapping RDS files\n", - "# --prefix filename part BEFORE the region id\n", - "# --suffix filename part AFTER the region id\n", - "# expected per-region path:\n", - "# {file_path}/{prefix}.{region}.{suffix}\n", - "# example: ROSMAP_AC_eQTL.ENSG00000012779.univariate_bvsr.rds\n", - "# \\__ prefix __/ \\___ region ___/ \\___ suffix ___/\n", - "# --study tag used in output filenames and intermediate RDS names\n", - "# (final output: {cwd}/summary/{name}.{qtl_type}.top_loci.bed.gz)\n", - "# --qtl_type cis | trans | trans_ appears in the combined filename\n", - "# --region_file bed of regions (chr, start, end, region_id) to enumerate\n", - "# --geno_ref tabix-indexed bim.gz for allele-flipping checks\n", - "#\n", - "# Outputs produced:\n", - "# {cwd}/{name}.{region}.cis_results_db.rds per-region intermediate RDS\n", - "# {cwd}/summary/{name}.{region}.top_loci.bed.gz per-region top_loci\n", - "# {cwd}/summary/{name}.{qtl_type}.top_loci.bed.gz combined public-facing file\n", - "\n", - "# Full run: export all regions via SLURM and combine into one study-level file.\n", - "sos run ./mnm_postprocessing.ipynb export_top_loci \\\n", - " --region_file ./TADB_enhanced_cis.coding.bed \\\n", - " --file_path /path/to/fine_mapping \\\n", - " --prefix \\\n", - " --suffix \\\n", - " --study \\\n", - " --min_corr 0.8 \\\n", - " --geno_ref ./Fungen_xQTL.ROSMAP_NIA_WGS.ROSMAP_NIA_WGS.MSBB_WGS_ADSP_hg38.MiGA.MAP_Brain-xQTL_Gwas_geno_0.STARNET.aligned.bim.gz \\\n", - " --qtl_type cis \\\n", - " --cwd ~/tmp/export_run \\\n", - " --mem 14G --walltime 72h \\\n", - " -q slurm -j 100 -s build\n" + "sos run pipeline/mnm_postprocessing.ipynb fsusie_to_tsv \\\n", + " --cwd output_postproc --study \\\n", + " --rds_path input/mnm_postprocessing/protocol_example.fsusie.fine_mapping.rds \\\n", + " --container '' -j1" ] }, { "cell_type": "markdown", - "id": "c25affda", + "id": "7fd91dcf-e082-4be6-ad16-8829a70f2008", "metadata": { "kernel": "SoS" }, "source": [ - "### Step 1: `susie_to_tsv` (VERIFIED end-to-end on the toy data)\n", - "\n", - "Convert the SuSiE objects to per-variant / lbf / effect TSV tables. The `--container` argument is left empty so the step runs natively in the project environment.\n", + "### Collapse per-region tables\n", + "`susie_tsv_collapse` concatenates the per-region LBF tables into one table per chromosome." + ] + }, + { + "cell_type": "markdown", + "id": "f877232b-7fdb-455c-9c9e-beba4f7e0a82", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "637d4821", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb susie_tsv_collapse \\\n", + " --cwd output_postproc --study \\\n", + " --tsv_path output_postproc/*.lbf.tsv \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "9ca18e40-ace0-42a8-aa12-e4fc4246c8f6", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Diagnostic plots\n", + "`susie_pip_landscape_plot` draws the PIP landscape; `susie_upsetR_plot` and `susie_upsetR_cs_plot` draw UpSet diagrams of credible-set overlap. The landscape plot needs an annotation tibble; `--trait_to_select` picks how many traits the credible-set diagram shows." + ] + }, + { + "cell_type": "markdown", + "id": "b7d407f7-acb4-4221-8f7b-950f2ae7bc71", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbf7b676", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb susie_pip_landscape_plot \\\n", + " --cwd output_postproc --study \\\n", + " --rds_path /*.fine_mapping.rds \\\n", + " --annot_tibble \\\n", + " --container '' -j1\n", "\n", - "*Note: the preserved `susie_to_tsv` code (last cell) was written for full, untrimmed SuSiE objects. Four small compatibility fixes were applied in this userfriendly copy so it runs on the trimmed `output_uni` objects: keep variant IDs as character when parsing chr/pos; derive ref/alt from the `:`-separated variant ID; align `coef.susie()` length to the variant count; and use a per-effect summary of `lbf_variable` when a true per-effect `$lbf` is absent. These only reshape/realign genuine values - no results are fabricated. The original notebook is unchanged.*" + "sos run pipeline/mnm_postprocessing.ipynb susie_upsetR_cs_plot \\\n", + " --cwd output_postproc --study \\\n", + " --rds_path /*.fine_mapping.rds \\\n", + " --trait_to_select 1 \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "d7c58c86-c02d-4b54-8e00-930f3671caca", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Variant annotation\n", + "`tmp_annotatation_of_snps` annotates a variant list against a reference RDS, then writes the reverse mapping." + ] + }, + { + "cell_type": "markdown", + "id": "52422638-2f5d-4c94-9ce9-a7defa55baa4", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, - "id": "76af8671", + "id": "6df77104", "metadata": { "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/mnm_postprocessing.ipynb susie_to_tsv \\\n", - " --cwd output_postproc --study toy \\\n", - " --rds_path input_postproc/cs.*.uni.bvsr.rds \\\n", - " --region-list input_postproc/region_list.tsv \\\n", - " --container \"\" -j1" + "sos run pipeline/mnm_postprocessing.ipynb tmp_annotatation_of_snps \\\n", + " --cwd output_postproc --study \\\n", + " --SNP_list \\\n", + " --annotation_rds \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "7b0d420c", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### fSuSiE effect extraction\n", + "`fsusie_extract_effect` writes the estimated effect curve per region; `fsusie_affected_region` writes the intervals a signal spans." + ] + }, + { + "cell_type": "markdown", + "id": "48bfb469-3d81-408c-a9ea-7d00022ddd6a", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d777cc1-69ac-495f-ac90-87b24553fcd4", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb fsusie_extract_effect \\\n", + " --cwd output_postproc --study \\\n", + " --rds_path input/mnm_postprocessing/protocol_example.fsusie.fine_mapping.rds \\\n", + " --annot_tibble \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "47b3dbd5", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### VCF export\n", + "`mv_susie_2` writes multivariate results as bgzipped VCF, one file per region and context." + ] + }, + { + "cell_type": "markdown", + "id": "867a26e2-3f0c-4f68-8565-bfadcb2cd5a4", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9622aa82-9ac3-4de0-bef5-4ca2b0b292e4", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb mv_susie \\\n", + " --cwd output_postproc --study \\\n", + " --rds_path input/mnm_postprocessing/protocol_example.mvsusie.fine_mapping.rds \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "78adbaad", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### cis and GWAS consolidation\n", + "`cis_results_export` collects per-region results into a results database, `gwas_results_export` does the same for GWAS blocks, `combine_export_meta` merges the per-chunk caches, and `export_top_loci` writes the combined top-loci BED. All four resolve each region as `/..` and need a GWAS meta file." + ] + }, + { + "cell_type": "markdown", + "id": "9d73d793-0adb-408f-8177-32369315fe17", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ac99a21-0b36-4b79-9292-d7b7f7d8017c", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb export_top_loci \\\n", + " --cwd output_postproc --study \\\n", + " --region_file \\\n", + " --file_path \\\n", + " --prefix --suffix \\\n", + " --qtl_type cis --min_corr 0.8 \\\n", + " --geno_ref \\\n", + " --container '' -j1" + ] + }, + { + "cell_type": "markdown", + "id": "148f96af", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### QTL and GWAS overlap\n", + "`overlap_qtl_gwas` intersects QTL credible sets with GWAS results, caching a batch meta file per chunk before writing the overlap table." + ] + }, + { + "cell_type": "markdown", + "id": "380f0b5e-25cd-433f-8f39-07b6a4f783c2", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7163df29-7096-4633-8706-c0bd282d3cb9", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb overlap_qtl_gwas \\\n", + " --cwd output_postproc --study \\\n", + " --region_file \\\n", + " --file_path \\\n", + " --prefix --suffix \\\n", + " --condition_meta \\\n", + " --container '' -j1" ] }, { "cell_type": "markdown", - "id": "29c7f8f4", + "id": "9d07f8fe", "metadata": { "kernel": "SoS" }, "source": [ - "## Output Files\n", + "The meta file consumed by the consolidation workflows is produced by:\n", + "```\n", + "get_condition <- function(conditions, Author, qtl_type){\n", + " strings <- c()\n", + " for(condition in conditions){\n", + " string = paste(condition, Author, qtl_type, sep = \"_\") \n", + " string = paste(unique(unlist(strsplit(string, \"_\"))), collapse = \"_\")\n", + " strings <- c(strings, string)\n", + " }\n", + " return(strings)\n", + "}\n", "\n", - "Under `--cwd` (e.g. `output_postproc/`), per input SuSiE object:\n", + "raw_name<- c(\"Mic\",\"Ast\",\"Oli\",\"OPC\",\"Exc\",\"Inh\",\"DLPFC\",\"PCC\",\"AC\")\n", + "raw_name_kellis<- c(\"Mic_Kellis\",\"Ast_Kellis\",\"Oli_Kellis\",\"OPC_Kellis\",\"Exc_Kellis\",\"Inh_Kellis\",\"Ast.10\",\"Mic.12\",\"Mic.13\")\n", "\n", - "- `.variant.tsv` - one row per variant: PIP, credible-set order/id, posterior mean and sd.\n", - "- `.lbf.tsv` - per-variant log Bayes factors for each single-effect.\n", - "- `.effect.tsv` - per-effect summary." + "dejager_name <- get_condition(raw_name, \"De_Jager\",\"eQTL\")\n", + "kellis_name <- get_condition(raw_name_kellis, \"Kellis\",\"eQTL\")\n", + "eQTL_meta <- data.frame(raw_name = c(raw_name, raw_name_kellis), new_name = c(dejager_name, kellis_name))\n", + "write_delim(eQTL_meta, \"output/mnm_postprocessing/eQTL_meta.tsv\")\n", + "```" ] }, { "cell_type": "markdown", - "id": "942466f1", + "id": "87d334dd", "metadata": { "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "You should get three TSV files per region (16 regions on the toy gene-expression set). On this small toy dataset most regions contain no strong credible set, so the credible-set columns are mostly empty - that is the correct, honest result for these independent single-gene toy regions." + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cli-cmd-mnm_postprocessing", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/mnm_postprocessing.ipynb -h" ] }, { "cell_type": "markdown", - "id": "0e81642c", + "id": "cli-out-mnm_postprocessing", "metadata": { "kernel": "SoS" }, "source": [ - "## Other workflows (command templates)\n", - "\n", - "The original notebook defines many more post-processing workflows that need inputs the toy dataset does not ship (GWAS summary statistics, plot recipe files, singularity container, sQTL/fSuSiE-specific objects). They are kept here as documented templates for completeness and are **not** verified on the toy data:\n", - "\n", - "- `fsusie_to_tsv`, `sQTL_susie_to_tsv` - same idea for fSuSiE / sQTL objects.\n", - "- `susie_tsv_collapse` - collapse per-region TSVs into one table.\n", - "- `susie_pip_landscape_plot`, `susie_upsetR_plot`, `susie_upsetR_cs_plot` - plotting (need a plot-recipe file).\n", - "- `tmp_annotatation_of_snps_1/2` - SNP annotation.\n", - "- `fsusie_extract_effect`, `fsusie_affected_region` - fSuSiE effect extraction.\n", - "- `mv_susie_2` - export results to VCF.\n", - "- `cis_results_export_*`, `gwas_results_export_*`, `combine_export_meta`, `export_top_loci` - cis/GWAS consolidation (need GWAS meta files).\n", - "- `overlap_qtl_gwas_1/2` - overlap QTL and GWAS results (need GWAS data)." + "```\n", + "usage: sos run pipeline/mnm_postprocessing.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " susie_to_tsv\n", + " sQTL_susie_to_tsv\n", + " fsusie_to_tsv\n", + " susie_tsv_collapse\n", + " susie_pip_landscape_plot\n", + " susie_upsetR_plot\n", + " susie_upsetR_cs_plot\n", + " tmp_annotatation_of_snps\n", + " fsusie_extract_effect\n", + " fsusie_affected_region\n", + " mv_susie\n", + " cis_results_export\n", + " gwas_results_export\n", + " export_top_loci\n", + " combine_export_meta\n", + " overlap_qtl_gwas\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " A region list file documenting the chr_pos_ref_alt of a\n", + " susie_object\n", + " --study VAL (as str, required)\n", + " --container ''\n", + " Path to work directory where output locates Containers\n", + " that contains the necessary packages\n", + " --modular-script-dir code/script (as path)\n", + " --entrypoint ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 96h\n", + " Wall clock time expected\n", + " --mem 6G\n", + " Memory expected\n", + " --numThreads 2 (as int)\n", + " Number of threads\n", + " --windows 1000000 (as int)\n", + "\n", + "Sections\n", + " susie_to_tsv_1:\n", + " Workflow Options:\n", + " --region-list . (as path)\n", + " Migrated: consumes a FineMappingResult RDS\n", + " (fine_mapping.R output) instead of a raw susieR object.\n", + " The three legacy outputs map to fine_mapping_export.R\n", + " views: variant.tsv = topLoci (per-variant: pip,\n", + " posterior mean/sd, logBF, cs, region) lbf.tsv = lbf\n", + " (wide per-variant x per-effect log Bayes factor matrix)\n", + " effect.tsv = cs_summary (per credible set: size,\n", + " purity, V, logBF, lead variant) The FineMappingResult\n", + " carries its own region/trait, so `region_list` is\n", + " accepted for CLI compatibility but is no longer used.\n", + " --rds-path paths\n", + "\n", + " sQTL_susie_to_tsv_1:\n", + " Workflow Options:\n", + " --region-list . (as path)\n", + " Migrated: identical to susie_to_tsv but preserves the\n", + " sQTL / leafcutter2 filename sanitization (\"*\" -> \"N\";\n", + " \":\"/\"+\" scrubbed from the task tag), since intron ids\n", + " contain shell-hostile characters. Consumes a\n", + " FineMappingResult RDS and writes the topLoci / lbf /\n", + " cs_summary views.\n", + " --rds-path paths\n", + "\n", + " fsusie_to_tsv_1:\n", + " Workflow Options:\n", + " --region-list . (as path)\n", + " Migrated: consumes an fSuSiE FineMappingResult RDS.\n", + " variant.tsv = topLoci (per-variant: pip, cs,\n", + " cs_95_purity) lbf.tsv = lbf (fSuSiE per-variant\n", + " x per-effect lBF matrix) (Fixes the legacy bug where\n", + " lbf.tsv was written the variant table, not the lbf\n", + " matrix.) is_dummy = cs_95_purity < 0.5; the functional\n", + " effect curves + peak positions are exported by\n", + " fsusie_extract_effect / fsusie_affected_region\n", + " (credible_band / affected_regions views), so they are\n", + " not duplicated here.\n", + " --rds-path paths\n", + "\n", + " *_to_tsv_2:\n", + " Workflow Options:\n", + " --name f'{_input[0]:b}'.split(\".\")[0]\n", + "\n", + " Reduce: concatenate the per-region variant tables (the\n", + " *variant.tsv outputs of the parallel _1 map step) into\n", + " one file, in R via data.table::rbindlist (fill=TRUE\n", + " aligns columns). _input carries all of _1's outputs, so\n", + " keep only the variant tables (not the lbf / effect\n", + " ones).\n", + " susie_tsv_collapse:\n", + " Workflow Options:\n", + " --tsv-path paths\n", + "\n", + " Concatenate the per-region lbf tables (named\n", + " *.chr__...lbf.tsv) by chromosome.\n", + " Chromosome split is plain python (no pandas); the concat\n", + " is R data.table::rbindlist (headers handled by fread;\n", + " fill=TRUE aligns columns).\n", + " susie_pip_landscape_plot:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " Per-region PIP landscape from a FineMappingResult\n", + " (fine_mapping output). Modernized from the legacy multi-\n", + " TSV plot: pecotmr does no plotting, so the ggplot lives\n", + " in fine_mapping_pip_plot.R. (The regulatory/gene\n", + " annotation overlay is a deferred enhancement;\n", + " annot_tibble is kept for CLI compat.)\n", + " susie_upsetR_plot:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " UpSet plot of credible-set variant overlap across the\n", + " FineMappingResult(s)' (study, context, trait, method)\n", + " tuples. pecotmr does no plotting; the UpSet lives in\n", + " fine_mapping_upset.R.\n", + " susie_upsetR_cs_plot:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " Credible-set overlap UpSet plot across the\n", + " FineMappingResult(s), via fine_mapping_upset.R (pecotmr\n", + " does no plotting). trait_to_select is retained for CLI\n", + " compatibility; the single-trait \"CS shared with other\n", + " phenotypes\" sub-view is a deferred wrapper option.\n", + " --trait-to-select 1 (as int)\n", + " tmp_annotatation_of_snps_1:\n", + " Workflow Options:\n", + " --SNP-list VAL (as path, required)\n", + " --annotation-rds VAL (as path, required)\n", + " tmp_annotatation_of_snps_2:\n", + " Workflow Options:\n", + " --SNP-list VAL (as path, required)\n", + " --annotation-rds VAL (as path, required)\n", + " fsusie_extract_effect:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " Fitted effect curve + credible band per fSuSiE credible\n", + " set, via fsusieCredibleBand (fine_mapping_export.R\n", + " `credible_band` view). pecotmr does the wavelet credible\n", + " band; it needs an UNtrimmed fSuSiE fit (fine_mapping\n", + " trim=FALSE). The effect-curve PDF is a deferred plot\n", + " wrapper (pecotmr does no plotting); annot_tibble is kept\n", + " for CLI compatibility.\n", + " fsusie_affected_region:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " GRanges of intervals where the fSuSiE credible band\n", + " excludes 0 (with a direction mcol), via\n", + " fsusieAffectedRegions (fine_mapping_export.R\n", + " `affected_regions` view). Needs an UNtrimmed fSuSiE fit\n", + " (fine_mapping trim=FALSE). The region PDF is a deferred\n", + " plot wrapper.\n", + " mv_susie_2:\n", + " Workflow Options:\n", + " --rds-path paths\n", + "\n", + " Write per-context fine-mapping VCFs (ES / SE / LP / AF +\n", + " PIP / CS / within_cs_pip in the sample column) from a\n", + " FineMappingResult via fine_mapping_vcf.R ->\n", + " pecotmr::writeSumstatsVcf, replacing the inline\n", + " create_vcf. writeSumstatsVcf splits a multi-context\n", + " collection into one .vcf.bgz per context; the runtime\n", + " set is tracked with output: dynamic() (so {cwd} must be\n", + " created up front, since a dynamic output -- unlike a\n", + " concrete target -- does not pre-create its dir).\n", + " cis_results_export_1, gwas_results_export_1, export_top_loci_1: Exporting cis\n", + " susie_twas results\n", + " Workflow Options:\n", + " --per-chunk 200 (as int)\n", + " per chunk we process at most 200 datasets\n", + " --region-file . (as path)\n", + " Region list should have last column being region name.\n", + " --file-path ''\n", + " the path stored original output files\n", + " --prefix (as list)\n", + " assuming orinal files are named as prefix.id.suffix\n", + " prefix of the original files (before id) to identify\n", + " file.\n", + " --suffix VAL (as str, required)\n", + " suffix of the original files (after id) to identify\n", + " file.\n", + " --condition-meta . (as path)\n", + " if need to rename context, please load condition meta\n", + " file\n", + " --pip-thres 0.05 (as float)\n", + " if the pip all variants in a cs < this threshold, then\n", + " remove this cs\n", + " --cs-size 3 (as int)\n", + " only keep top cs_size variants in one cs\n", + " --exported-file . (as path)\n", + " provide exported meta to filter the exported genes\n", + " --region-list . (as path)\n", + " Optional: if a region list is provide the analysis will\n", + " be focused on provided region. The LAST column of this\n", + " list will contain the ID of regions to focus on\n", + " --region-name (as list)\n", + " Optional: if a region name is provided the analysis\n", + " would be focused on the union of provides region list\n", + " and region names\n", + " --geno-ref . (as path)\n", + " the (aligned) geno bim file to check allele flipping.\n", + " Retained for CLI compatibility; allele alignment is now\n", + " done upstream by fine_mapping.R (matchVariants), so it\n", + " is unused here.\n", + " --context-meta . (as path)\n", + " context meta file to map renamed context backs\n", + " --min-corr (as list)\n", + " CS purity (min.abs.corr) cutoff(s); the first value is\n", + " used for conditions_top_loci.\n", + " --[no-]gwas (default to False)\n", + " set this parameter as `True` when exporting gwas data.\n", + " --[no-]fsusie (default to False)\n", + " set this parameter as `True` when exporting fsusie data.\n", + " --[no-]metaQTL (default to False)\n", + " set this parameter as `True` when exporting metaQTL\n", + " data.\n", + " --[no-]mnm (default to False)\n", + " set this parameter as `True` when exporting mnm data.\n", + " cis_results_export_2, gwas_results_export_2:\n", + " Workflow Options:\n", + " --[no-]step1-only (default to False)\n", + " set it as True if you only want run first step (running\n", + " parallel) and combine them manually after all finished\n", + " --exported-file . (as path)\n", + " provide exported meta to filter the exported genes\n", + " --[no-]gwas (default to False)\n", + " optional: qtl or gwas, there is slightly different in\n", + " qtl and gwas rds file\n", + " cis_results_export_3:\n", + " Workflow Options:\n", + " --[no-]step1-only (default to False)\n", + " set it as True if you only want run first step (running\n", + " parallel) and combine them manually after all finished\n", + " gwas_results_export_3: get union of step1 1200 blocks costed ~5mins with in\n", + " one for loop\n", + " Workflow Options:\n", + " --[no-]step1-only (default to False)\n", + " combine_export_meta: simply combine seperate meta files, not works for having\n", + " an exsiting exported file for now.\n", + " Workflow Options:\n", + " --cache-path VAL (as path, required)\n", + " --output-file VAL (as str, required)\n", + " --[no-]remove-cache (default to False)\n", + " export_top_loci_2:\n", + " Workflow Options:\n", + " --export-path cwd\n", + "\n", + " Export the per-region top-loci BED from each\n", + " cis_results_db (an FMR in the modern pipeline) via the\n", + " pecotmr-backed fine_mapping_top_loci_bed.R wrapper.\n", + " getTopLoci does the PIP/CS + independent purity\n", + " filtering; lfsr / conditional_effect are per-(variant,\n", + " context) numeric columns, so the legacy filter_lfsr\n", + " semicolon split/rejoin is gone. `export_suffix`\n", + " deliberately differs from step 1's `--suffix` (input\n", + " rds) to avoid CLI collision.\n", + " --export-prefix ''\n", + " --export-suffix 'cis_results_db.rds'\n", + " --fsusie-prefix ''\n", + " --[no-]preset-top-loci (default to False)\n", + " --signal-cutoff 0.025 (as float)\n", + " PIP cutoff for getTopLoci; optional independent CS\n", + " purity (min.abs.corr) cutoff (<0 => none).\n", + " --min-purity -1.0 (as float)\n", + " --lfsr-thres 0.01 (as float)\n", + " Retained for CLI compatibility; lfsr is now a per-\n", + " variant column (no split/rejoin).\n", + " export_top_loci_3:\n", + " Workflow Options:\n", + " --qtl-type VAL (as str, required)\n", + " Combine per-region .top_loci.bed.gz files into one\n", + " study-level file. Public-facing name:\n", + " {name}.{qtl_type}[.{variant_tag}].top_loci.bed.gz\n", + " --variant-tag ''\n", + " --combine auto\n", + " 'auto' (default): skip step 3 if region_name or\n", + " region_list is set; 'yes': force run; 'no': force skip.\n", + " --region-list . (as path)\n", + " Re-declared so this step can detect step-1 subset\n", + " filters.\n", + " --region-name (as list)\n", + " overlap_qtl_gwas_1:\n", + " Workflow Options:\n", + " --per-chunk 100 (as int)\n", + " --gwas-meta-path . (as path)\n", + " --qtl-meta-path . (as path)\n", + " --gwas-file-path ''\n", + " --qtl-file-path ''\n", + " --region-list . (as path)\n", + " Optional: focus on a region list (last column = region\n", + " id) and/or region names.\n", + " --region-name (as list)\n", + " --signal-cutoff 0.0 (as float)\n", + " PIP cutoff for the top-loci overlap. 0 = intersect all\n", + " top-loci variants (the legacy behaviour, which had its\n", + " CS filter commented out); the coarse block pairing that\n", + " feeds coloc wants breadth, not just the strongest\n", + " signal.\n", + " overlap_qtl_gwas_2:\n", + " Workflow Options:\n", + " --[no-]step1-only (default to False)\n", + " set it as True if you only want run first step (running\n", + " parallel) and combine them manually after all finished\n", + "```" ] }, { "cell_type": "markdown", - "id": "7069f862", + "id": "ba9e5aff", "metadata": { "kernel": "SoS" }, "source": [ - "## Pipeline configuration and the `susie_to_tsv` workflow\n", + "## Workflow implementation\n", "\n", - "The cells below are the global parameters and the `susie_to_tsv` workflow definition, preserved from the original notebook." + "The global parameters and the workflow step definitions." ] }, { diff --git a/code/SoS/mnm_analysis/multivariate_fine_mapping_vignette.ipynb b/code/SoS/mnm_analysis/multivariate_fine_mapping_vignette.ipynb index bcab898b7..acbad2620 100644 --- a/code/SoS/mnm_analysis/multivariate_fine_mapping_vignette.ipynb +++ b/code/SoS/mnm_analysis/multivariate_fine_mapping_vignette.ipynb @@ -2,161 +2,214 @@ "cells": [ { "cell_type": "markdown", - "id": "5839a8ae-e13c-44ba-b06c-8346a0e65655", + "id": "75a5a715", "metadata": {}, "source": [ - "# Multivariate Fine-Mapping with mvSuSiE and mr.mash\n" + "# Multivariate fine-mapping with mvSuSiE\n", + "\n", + "This vignette shows how to jointly fine-map the genetic effects of one molecular trait measured across multiple contexts." ] }, { "cell_type": "markdown", + "id": "e89e3bf6", "metadata": {}, "source": [ - "## Description\n\nThis vignette runs multivariate fine-mapping with mvSuSiE and mr.mash on a single region, jointly modeling multiple molecular phenotypes to identify shared and trait-specific causal variants.\n" + "## Learning goals\n", + "\n", + "After completing this vignette, you will be able to:\n", + "\n", + "- distinguish cross-context mvSuSiE from single-context SuSiE and cross-gene fine-mapping;\n", + "- prepare matched genotype, phenotype and covariate inputs;\n", + "- run the current `qtl_dataset_construct+mnm` workflow; and\n", + "- interpret context-specific posterior effects together with shared variant PIPs." ] }, { "cell_type": "markdown", - "id": "4b860370-77bb-4095-b9b1-1613ed681bf4", + "id": "7148da82", "metadata": {}, "source": [ - "Multivariate fine-mapping using mvSuSiE and mr.mash is also available in our pipeline.\n" + "## Background and method\n", + "\n", + "When the same molecular trait is measured in several tissues, cell types or experimental conditions, analyzing each context separately discards information about shared genetic effects. The `mnm` workflow uses mvSuSiE to model the contexts jointly. It estimates a multivariate effect for each candidate variant and uses patterns learned across contexts to distinguish effects that are shared, context-specific or too weak to resolve.\n", + "\n", + "The workflow first harmonizes genotype, phenotype and covariate data in a `QtlDataset`. It then fine-maps each requested trait across its available contexts. By default, mvSuSiE uses its canonical prior. A previously fitted TWAS-weight object can be supplied with `--prior-twas-weights` to provide a data-driven prior; this is optional and should not be confused with running a separate mr.mash analysis inside this workflow.\n", + "\n", + "Use this route for **one trait across contexts**. Use ordinary `susie_twas` for one trait in one context, and use `mnm_genes` when the scientific unit is multiple genes within the same locus." ] }, { "cell_type": "markdown", - "id": "9a10f540-933d-497c-908f-f868c965007f", + "id": "1b18a8b8", "metadata": {}, "source": [ - "## Input" + "## Worked example\n", + "\n", + "The example fine-maps `ENSG00000130538` jointly in two contexts from the same individuals.\n", + "\n", + "| Role | Example path | What it supplies |\n", + "|---|---|---|\n", + "| Genotype | `input/finemapping/protocol_example.genotype.chr22.bed` | PLINK bed/bim/fam trio |\n", + "| Phenotype manifest | `input/finemapping/protocol_example.pheno_manifest_multicontext.tsv` | One manifest row per context and its phenotype BED file |\n", + "| Covariates | `input/finemapping/protocol_example.covariates.tsv` | Covariates for the shared samples |\n", + "| Association windows | `input/finemapping/protocol_example.association_windows.bed` | Coordinates for the requested trait |\n", + "\n", + "Context rows must refer to the same trait, genome build and sample population. Sample identifiers must agree across all files." ] }, { "cell_type": "markdown", - "id": "5f0bcf9f-55c4-43fa-b846-170c935403b9", + "id": "16e87087", "metadata": {}, "source": [ - "- `--genoFile`: a text file listing the per-chromosome genotype files (PLINK prefixes) to load, one entry per line, as shown below.\n```\n#id #path\n21 $PATH/protocol_example.genotype.chr21_22.21.bed\n22 $PATH/protocol_example.genotype.chr21_22.22.bed\n```\n`--phenoFile`: a tab delimited file containing chr, start, end, ID and path for the regions. For example:\n```\n#chr start end ID path\nchr21 0 14120807 TADB_1297 $PATH/protocol_example.ha.bed.gz\nchr21 10840000 16880069 TADB_1298 $PATH/protocol_example.ha.bed.gz\n```\n\n`--covFile`: path to a gzipped file containing covariates in the rows, and sample ids in the columns. \n`--customized-association-windows`: a tab delimited file containing chr, start, end, and ID regions. For example:\n```\n#chr start end ID\nchr21 0 14120807 TADB_1297\nchr21 10840000 16880069 TADB_1298\n```\n`--region-name`: if you only wish to analyze one region, then include the ID of a region found in the `customized-association-windows` file\n\n`--mixture_prior`: rds file from mr.mash" + "### [Run cross-context fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html#multivariate-fine-mapping)\n", + "\n", + "`qtl_dataset_construct+mnm` constructs the harmonized dataset and performs one joint mvSuSiE fit for the selected trait." ] }, { "cell_type": "markdown", - "id": "58b21adc-571d-483c-b033-0fb2662be3f5", + "id": "bcfe445e", "metadata": {}, "source": [ - "## Output" + "**Timing**: TBD" ] }, { - "cell_type": "markdown", - "id": "25e3b8e3-4434-487c-b8ad-eb34905540dc", + "cell_type": "code", + "execution_count": null, + "id": "fbcf60d2", "metadata": {}, + "outputs": [], "source": [ - "- `{name}.{chr}_{gene_id}.multicontext_data.rds` \u2014 one RDS per gene, the multivariate (mvSuSiE / mr.mash) fine-mapping result that jointly models the effect across all conditions/contexts (e.g. `Ast`, `Exc`, `Inh`, `Mic`).\n\nInspecting the object shows the per-context posterior summaries:\n```\n> str(readRDS(\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/mnm_old/data/test_mnm.chr11_ENSG00000073921.multicontext_data.rds\"))\nList of 8\n $ residual_Y : num [1:150, 1:6] 0.1241 0.2981 -0.6054 0.0435 0.0388 ...\n ..- attr(*, \"dimnames\")=List of 2\n .. ..$ : chr [1:150] \"sample0\" \"sample1\" \"sample10\" \"sample100\" ...\n .. ..$ : chr [1:6] \"Ast\" \"Exc\" \"Inh\" \"Mic\" ...\n $ residual_Y_scalar: num [1:6] 1 1 1 1 1 1\n $ dropped_sample :List of 3\n ..$ X :List of 6\n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n ..$ Y :List of 6\n .. ..$ : chr \"strand\"\n .. ..$ : chr \"strand\"\n .. ..$ : chr \"strand\"\n .. ..$ : chr \"strand\"\n .. ..$ : chr \"strand\"\n .. ..$ : chr \"strand\"\n ..$ covar:List of 6\n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n .. ..$ : chr(0) \n $ X : num [1:150, 1:9970] 0 0 1 1 1 0 0 1 1 1 ...\n ..- attr(*, \"dimnames\")=List of 2\n .. ..$ : chr [1:150] \"sample0\" \"sample1\" \"sample10\" \"sample100\" ...\n .. ..$ : chr [1:9970] \"chr11:84957209:G:C\" \"chr11:84957879:A:G\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" ...\n $ maf : Named num [1:9970] 0.33 0.327 0.103 0.343 0.343 ...\n ..- attr(*, \"names\")= chr [1:9970] \"chr11:84957209:G:C\" \"chr11:84957879:A:G\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" ...\n $ chrom : chr \"chr11\"\n $ grange : chr [1:2] \"85957174\" \"86069881\"\n $ X_variance : Named num [1:9970] 0.441 0.443 0.192 0.458 0.458 ...\n ..- attr(*, \"names\")= chr [1:9970] \"chr11:84957209:G:C\" \"chr11:84957879:A:G\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" ...\n```\n\n* `*.multicontext_bvsr.rds`\n```\n> str(readRDS(\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/mnm_old/multivariate_fine_mapping/test_mnm.chr11_ENSG00000073921.multicontext_bvsr.rds\"),max.level=2)\nList of 1\n $ ENSG00000073921:List of 10\n ..$ mrmash_fitted :List of 14\n .. ..- attr(*, \"class\")= chr [1:2] \"mr.mash\" \"list\"\n ..$ reweighted_mixture_prior :Classes 'MashInitializer', 'R6' \n Public:\n clone: function (deep = FALSE) \n compute_prior_inv: function () \n initialize: function (Ulist, grid, prior_weights = NULL, null_weight = 0, \n n_component: active binding\n n_condition: active binding\n precompute_cov_matrices: function (d, algorithm = c(\"R\", \"cpp\")) \n precomputed: active binding\n prior_variance: active binding\n remove_precomputed: function () \n scale_prior_variance: function (sigma) \n Private:\n inv_mats: NULL\n U: NULL\n xU: list \n ..$ reweighted_mixture_prior_cv:List of 5\n ..$ mvsusie_fitted :List of 28\n .. ..- attr(*, \"class\")= chr \"mvsusie\"\n ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n ..$ analysis_script : chr \"\\nlibrary(pecotmr)\\n\\nphenotype_files = c(\\\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/p\"| __truncated__\n ..$ other_quantities :List of 1\n ..$ context_names : chr [1:6] \"Ast\" \"Exc\" \"Inh\" \"Mic\" ...\n ..$ total_time_elapsed : 'proc_time' Named num [1:5] 104.38 0.653 105.828 0 0\n .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n ..$ region_info :List of 3\n```\n\n* `*.multicontext_twas_weights.rds`\n```\n> str(readRDS(\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/mnm_old/multivariate_twas_weights/test_mnm.chr11_ENSG00000073921.multicontext_twas_weights.rds\"), max.level=3)\nList of 1\n $ ENSG00000073921:List of 6\n ..$ Ast_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n ..$ Exc_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n ..$ Inh_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n ..$ Mic_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n ..$ OPC_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n ..$ Oli_ENSG00000073921:List of 6\n .. ..$ twas_weights :List of 2\n .. ..$ twas_predictions :List of 2\n .. ..$ variant_names : chr [1:6454] \"chr11:84957209:G:C\" \"chr11:84958236:C:A\" \"chr11:84958954:T:C\" \"chr11:84959602:T:C\" ...\n .. ..$ twas_cv_result :List of 4\n .. ..$ total_time_elapsed: 'proc_time' Named num [1:5] 1645.11 3.4 1652.73 0.01 0.02\n .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n .. ..$ region_info :List of 3\n```" + "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+mnm \\\n", + " --name protocol_example \\\n", + " --cwd output_mnm \\\n", + " --genoFile input/finemapping/protocol_example.genotype.chr22.bed \\\n", + " --phenoFile input/finemapping/protocol_example.pheno_manifest_multicontext.tsv \\\n", + " --covFile input/finemapping/protocol_example.covariates.tsv \\\n", + " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", + " --region-name ENSG00000130538 \\\n", + " --transpose-covariates \\\n", + " -j 1" ] }, { "cell_type": "markdown", - "id": "397a4dc3-1e4c-4845-ad8b-beed40f1f408", + "id": "ceb78492", "metadata": {}, "source": [ - "## Steps" + "The command is expected to create:\n", + "\n", + "- `output_mnm/qtl_dataset/protocol_example.qtl_dataset.rds` — harmonized genotype, phenotype and covariate data.\n", + "- `output_mnm/multivariate_fine_mapping/protocol_example.ENSG00000130538.multicontext_bvsr.rds` — the cross-context `QtlFineMappingResult`.\n", + "\n", + "The most useful optional settings are:\n", + "\n", + "| Option | Purpose |\n", + "|---|---|\n", + "| `--contexts` | Restrict the fit to named contexts; empty uses all available contexts |\n", + "| `--mvsusie-max-iter` | Maximum mvSuSiE iterations; default `200` |\n", + "| `--prior-twas-weights` | Optional preceding TWAS-weight RDS used to derive a data-driven prior |\n", + "| `--prior-weights-min` | Lower bound applied to supplied prior weights |\n", + "| `--mvsusie-method-args` | Additional mvSuSiE arguments as JSON |" ] }, { "cell_type": "markdown", - "id": "3bca0962-ae57-422c-a79f-892ef3b7f7ae", + "id": "425d3756", "metadata": {}, "source": [ - "### iv. [Run the Fine-Mapping with mvSuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html#iii-mvsusie-with-twas-weights-from-mr-mash)" + "### Command reference\n", + "\n", + "Check the current interface before adapting the command to a new study." ] }, { "cell_type": "code", "execution_count": null, - "id": "dff2c979-52a1-4ec8-a0be-51b289327d37", + "id": "2a91fa2f", "metadata": {}, "outputs": [], "source": [ - "# Step 1: build the QtlDataset RDS (one per study).\n", - "sos run pipeline/qtl_dataset.ipynb qtl_dataset_construct \\\n", - " --cwd output/qtl_dataset \\\n", - " --study test_mnm \\\n", - " --genotype-prefix output/genotype_by_chrom/wgs.merged.plink_qc.chr1 \\\n", - " --phenotype-manifest data/test_mnm.pheno_manifest.tsv\n", - "\n", - "# Step 2: per-region mvSuSiE joint fine-mapping.\n", - "sos run pipeline/multivariate_fine_mapping.ipynb multivariate_fine_mapping \\\n", - " --cwd output/mnm \\\n", - " --study test_mnm \\\n", - " --qtl-dataset output/qtl_dataset/test_mnm.qtl_dataset.rds \\\n", - " --regions chr1:1000000-2000000\n", - "\n", - "# Step 3 (optional): mr.mash + mvSuSiE TWAS weights on the same regions.\n", - "sos run pipeline/twas_weights.ipynb twas_weights \\\n", - " --cwd output/mnm \\\n", - " --study test_mnm \\\n", - " --qtl-dataset output/qtl_dataset/test_mnm.qtl_dataset.rds \\\n", - " --regions chr1:1000000-2000000 \\\n", - " --methods mrmash,mvsusie" + "sos run pipeline/mnm_regression.ipynb -h" ] }, { "cell_type": "markdown", - "id": "cc7691e6-954c-4dc1-bac3-25d56026ab96", + "id": "f62e81df", + "metadata": {}, + "source": [ + "## Results and interpretation\n", + "\n", + "### Cross-context fine-mapping result\n", + "\n", + "The output is a `QtlFineMappingResult`. The result table identifies the fitted contexts and method; each `entry` contains the mvSuSiE fit and an attached `topLoci` table.\n", + "\n", + "| Component | Interpretation |\n", + "|---|---|\n", + "| Result metadata | Trait, contexts and fitted method |\n", + "| `topLoci` | Variant PIPs, posterior effect summaries and credible-set membership |\n", + "| mvSuSiE fit | Context-specific posterior effects for each single-effect component |\n", + "| Credible-set purity | Whether variants in a credible set are sufficiently correlated to support localization |" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "95ea8a1d", "metadata": {}, + "outputs": [], "source": [ - "## Anticipated Results" + "suppressPackageStartupMessages(library(pecotmr))\n", + "\n", + "result_file <- \"output_mnm/multivariate_fine_mapping/protocol_example.ENSG00000130538.multicontext_bvsr.rds\"\n", + "result <- readRDS(result_file)\n", + "\n", + "cat(\"Class:\", class(result), \"\\n\")\n", + "print(result[, setdiff(names(result), \"entry\"), drop = FALSE])\n", + "\n", + "entry <- result$entry[[1]]\n", + "top_loci <- getTopLoci(entry)\n", + "top_loci <- top_loci[order(top_loci$pip, decreasing = TRUE), ]\n", + "keep <- intersect(c(\"variant_id\", \"pip\", \"cs_95\", \"cs_95_purity\", \"method\"),\n", + " names(top_loci))\n", + "head(top_loci[, keep, drop = FALSE], 8)" ] }, { "cell_type": "markdown", - "id": "5418a39f-f2a6-48ac-8440-38d692cc3c38", + "id": "f8bdbfbd", "metadata": {}, "source": [ - "For each gene, multivariate finemapping will produce a file containing results for the top hits and a file containing twas weights produced by susie." + "Rank variants by PIP, then evaluate credible-set size and purity. The multivariate fit can strengthen evidence when effects are consistent across contexts, but a high joint PIP does not mean that the effect has the same magnitude in every context. Inspect the context-specific posterior effects before labeling a variant as shared or context-specific. Broad, low-purity credible sets indicate insufficient localization rather than a single confirmed causal variant." ] }, { "cell_type": "markdown", - "id": "199a2637-cc0c-4aff-b4ea-a2546936f073", + "id": "2a8a9819", "metadata": {}, "source": [ - "`test_mnm.chr11_ENSG00000073921.multicontext_bvsr.rds`:\n", - "* For each gene of interest, this file contains:\n", - " 1. mrmash_fitted\n", - " 2. reweighted_mixture_prior\n", - " 3. reweighted_mixture_prior_cv\n", - " 4. mvsusie_fitted\n", - " 5. variant_names\n", - " 6. analysis_script\n", - " 7. other_quantities\n", - " 8. context_names\n", - " 9. top_loci\n", - " 10. susie_result_trimmed\n", - " 11. total_time_elapsed\n", - " 12. region_info\n", - "\n", - "`test_mnm.chr11_ENSG00000073921.multicontext_data.rds`: (from the --save-data argument)\n", - "* see [pecotmr code](https://github.com/statfungen/pecotmr/blob/68d87ca1d0a059022bf4e55339621cbddc8993cc/R/file_utils.R#L461) for description \n", - "\n", - "`test_mnm.chr11_ENSG00000073921.multicontext_twas_weights.rds`:\n", - "* For each gene of interest and phenotype, this file contains:\n", - " 1. twas_weights - weights mrmash and mvsusie methods\n", - " 2. twas_predictions - twas predictions for mrmash and mvsusie methods\n", - " 3. variant_names\n", - " 5. twas_cv_result\n", - " 6. total_time_elapsed\n", - " 8. region_info\n" + "## Limitations and common pitfalls\n", + "\n", + "- All context-specific phenotypes must represent the same trait and use compatible genomic coordinates.\n", + "- mvSuSiE does not correct sample mismatches; genotype, phenotype and covariate identifiers must be harmonized first.\n", + "- A missing phenotype in some contexts changes the information available to the joint model and should be documented.\n", + "- A data-driven prior is optional. Do not supply an unrelated TWAS-weight object merely to enable the option.\n", + "- The toy dataset demonstrates the interface but is too small for biological conclusions.\n", + "- Joint evidence does not replace examination of context-specific effect sizes and uncertainty." ] }, { - "cell_type": "code", - "execution_count": null, - "id": "159e580c-e290-4403-a701-d9dfa1043341", + "cell_type": "markdown", + "id": "9dc0bd83", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "## Next steps\n", + "\n", + "For well-localized signals, compare posterior effects across contexts and annotate the highest-PIP variants. Use the cross-gene `mnm_genes` workflow only when the next question concerns several genes in the same locus, and use downstream post-processing to summarize credible sets across analyses." + ] } ], "metadata": { @@ -175,9 +228,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.12.13" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/mnm_analysis/multivariate_multigene_fine_mapping_vignette.ipynb b/code/SoS/mnm_analysis/multivariate_multigene_fine_mapping_vignette.ipynb index 46e0ca3f3..374b454bf 100644 --- a/code/SoS/mnm_analysis/multivariate_multigene_fine_mapping_vignette.ipynb +++ b/code/SoS/mnm_analysis/multivariate_multigene_fine_mapping_vignette.ipynb @@ -2,259 +2,189 @@ "cells": [ { "cell_type": "markdown", - "id": "5839a8ae-e13c-44ba-b06c-8346a0e65655", "metadata": {}, "source": [ - "# Multivariate Fine-Mapping for multiple genes\n" + "# Cross-gene fine-mapping with mvSuSiE\n", + "\n", + "This vignette shows how to jointly fine-map several molecular traits whose coordinates overlap the same genomic region." ] }, { "cell_type": "markdown", - "id": "5161522b-01c0-42f3-b527-5e4e376648c0", "metadata": {}, "source": [ - "## Description" + "## Learning goals\n", + "\n", + "After completing this vignette, you will be able to:\n", + "\n", + "- distinguish cross-gene fine-mapping from cross-context fine-mapping;\n", + "- define a locus containing multiple eligible genes;\n", + "- run the current `qtl_dataset_construct+mnm_genes` workflow; and\n", + "- interpret joint variant evidence without treating correlated genes as independent discoveries." ] }, { "cell_type": "markdown", - "id": "4b860370-77bb-4095-b9b1-1613ed681bf4", "metadata": {}, "source": [ - "Multi gene fine-mapping and TWAS may also be conducted with our pipeline. This considers multiple genes jointly within specific TAD windows.\n", + "## Background and method\n", "\n", - "This step is similar to the multivariate fine-mapping with two main differences. 1) TAD windows with multiple genes need to be defined. The `--pheno_id_map_file` parameter is used for this. 2) To speed things up, the genes are filtered out if they don't have a univariate fine mapped region. Genes may also be filtered out if they do have a univariate fine-mapped signal, but the signal is nowhere close to that of other genes. The `--skip-analysis-pip-cutoff` parameter is used for this.\n", - "\n" + "Nearby genes can share regulatory variants and linkage disequilibrium. Separate fine-mapping analyses may therefore assign the same regional signal to several genes without testing their effects jointly. The `mnm_genes` workflow uses mvSuSiE with `jointSpecification=\"trait\"` to model the genes overlapping each requested locus as a multivariate outcome.\n", + "\n", + "The workflow first constructs one `QtlDataset`. It then creates a region manifest and identifies genes whose coordinates overlap each region. A region must contain at least two joinable genes; otherwise no multivariate fit is produced. The current implementation replaces the older TAD-specific, phenotype-map and univariate-PIP prefilter procedure described by the previous vignette.\n", + "\n", + "Use this route for **multiple genes in one locus**. Use `mnm` for one gene across contexts and `susie_twas` for a single gene-context pair. A TAD is one possible biological definition of a locus, but the workflow accepts any defensible genomic window." ] }, { "cell_type": "markdown", - "id": "e8201581-f9fd-4c8c-8540-8daf0a2dcf76", "metadata": {}, "source": [ - "## Input" + "## Worked example\n", + "\n", + "The bundled chromosome 22 example contains several genes with overlapping association windows.\n", + "\n", + "| Role | Example path | What it supplies |\n", + "|---|---|---|\n", + "| Genotype | `input/finemapping/protocol_example.multigene.genotype.chr22.bed` | PLINK bed/bim/fam trio |\n", + "| Phenotype manifest | `input/finemapping/protocol_example.multigene.pheno_manifest.tsv` | Gene coordinates and phenotype BED path |\n", + "| Covariates | `input/finemapping/protocol_example.multigene.covariates.tsv` | Covariates for matching samples |\n", + "| Region windows | `input/finemapping/protocol_example.multigene.association_windows.bed` | Candidate loci used to group overlapping genes |\n", + "\n", + "The phenotype manifest may contain many genes, but each fitted region must overlap at least two of them. Coordinates, genome build and sample identifiers must agree across inputs." ] }, { "cell_type": "markdown", - "id": "5f0bcf9f-55c4-43fa-b846-170c935403b9", "metadata": {}, "source": [ + "### [Run cross-gene fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html#cross-gene-multivariate-fine-mapping)\n", "\n", - " \n", - "`--genoFile`: path to a plink bed file containin genotypes. Include the `.bed`\n", - "\n", - "`--phenoFile`: a tab delimited file containing chr, start, end, ID and path for the regions. For example:\n", - "```\n", - "#chr start end ID path\n", - "chr12 389319 389320 ENSG00000073614 $PATH/snuc_pseudo_bulk.Mic.mega.normalized.log2cpm.bed.gz\n", - "chr12 752578 752579 ENSG00000060237 $PATH/snuc_pseudo_bulk.Mic.mega.normalized.log2cpm.bed.gz\n", - "```\n", - "\n", - "`--covFile`: path to a gzipped file containing covariates in the rows, and sample ids in the columns. \n", - "\n", - "`--customized-association-windows`: a tab delimited file containing chr, start, end, and ID regions. For example:\n", - "```\n", - "#chr start end TAD_id\n", - "chr1 0 10985501 chr1_0_10985501\n", - "chr1 5101787 11630758 chr1_5101787_11630758\n", - "```\n", - "\n", - "`--phenotype-names`: the names of the phenotypes if multiple are included. There should be one for each phenotype file you include.\n", - "\n", - "`--max-cv-variants`: maximum number of variants for cross-validation.\n", - "\n", - "`--ld_reference_meta_file`: path to file containing chrom, start, end and path for linkage disequilibrium region information. For example:\n", - "```\n", - "#chrom start end path\n", - "chr1 101384274 104443097 chr1/chr1_101384274_104443097.cor.xz,chr1/chr1_101384274_104443097.cor.xz.bim\n", - "chr1 104443097 106225286 chr1/chr1_104443097_106225286.cor.xz,chr1/chr1_104443097_106225286.cor.xz.bim\n", - "```\n", - "\n", - "`--independent_variant_list`: a gzipped file containing variant information. These should be independent from one another in terms of linkage disequilibrium.\n", - "For example:\n", - "```\n", - "chrom pos alt ref variant_id\n", - "chr1 16206 T A chr1:16206:T:A\n", - "chr1 16433 C G chr1:16433:C:G\n", - "```\n", - "\n", - "`--fine_mapping_meta`: A file containg a list of gene and region information and other conditions.\n", - "For example:\n", - "```\n", - "#chr start end region_id TSS original_data combined_data combined_data_sumstats conditions conditions_top_loci\n", - "chr1 0 6480000 ENSG00000008128 1724356 KNIGHT_pQTL.ENSG00000008128.univariate_susie_twas_weights.rds,MiGA_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds,MSBB_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds,ROSMAP_Bennett_Klein_pQTL.ENSG00000008128.univariate_susie_twas_weights.rds,ROSMAP_DeJager_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds,ROSMAP_Kellis_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds,ROSMAP_mega_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds,STARNET_eQTL.ENSG00000008128.univariate_susie_twas_weights.rds $PATH/Fungen_xQTL.ENSG00000008128.cis_results_db.export.rds $PATH/Fungen_xQTL.ENSG00000008128.cis_results_db.export_sumstats.rds Knight_eQTL_brain,MiGA_GFM_eQTL,MiGA_GTS_eQTL,MiGA_SVZ_eQTL,MiGA_THA_eQTL,BM_10_MSBB_eQTL,BM_22_MSBB_eQTL,BM_36_MSBB_eQTL,BM_44_MSBB_eQTL,monocyte_ROSMAP_eQTL,Mic_DeJager_eQTL,Ast_DeJager_eQTL,Oli_DeJager_eQTL,Exc_DeJager_eQTL,Inh_DeJager_eQTL,DLPFC_DeJager_eQTL,PCC_DeJager_eQTL,AC_DeJager_eQTL,Mic_Kellis_eQTL,Ast_Kellis_eQTL,Oli_Kellis_eQTL,OPC_Kellis_eQTL,Exc_Kellis_eQTL,Inh_Kellis_eQTL,Ast_mega_eQTL,Exc_mega_eQTL,Inh_mega_eQTL,Oli_mega_eQTL,STARNET_eQTL_Mac Knight_eQTL_brain,MiGA_GFM_eQTL,MiGA_GTS_eQTL,MiGA_SVZ_eQTL,MiGA_THA_eQTL,BM_10_MSBB_eQTL,BM_22_MSBB_eQTL,BM_36_MSBB_eQTL,BM_44_MSBB_eQTL,monocyte_ROSMAP_eQTL,Mic_DeJager_eQTL,Ast_DeJager_eQTL,Oli_DeJager_eQTL,Exc_DeJager_eQTL,Inh_DeJager_eQTL,DLPFC_DeJager_eQTL,PCC_DeJager_eQTL,AC_DeJager_eQTL,Mic_Kellis_eQTL,Ast_Kellis_eQTL,Oli_Kellis_eQTL,OPC_Kellis_eQTL,Exc_Kellis_eQTL,Inh_Kellis_eQTL,Ast_mega_eQTL,Exc_mega_eQTL,Inh_mega_eQTL,Oli_mega_eQTL,STARNET_eQTL_Mac\n", - "```\n", - "\n", - "`--phenoIDFile`: A bed file containing a list of genes and their LD region.\n", - "For example:\n", - "```\n", - "TAD_id ID\n", - "chr19_0_13957223 ENSG00000172270\n", - "chr19_0_13957223 ENSG00000099864\n", - "chr19_0_13957223 ENSG00000011304\n", - "```\n", - "\n", - "`--skip-analysis-pip-cutoff`: A number of the pip cutoff. \n", - "\n", - "`--coverage`\n", - "\n", - "`--maf`\n", - "\n", - "`--pheno_id_map_file`: A file containing IDs and genes.\n", - "For example:\n", - "```\n", - "ID gene\n", - "chr20:50940933:50941105:clu_44490_-:ENSG00000000419 ENSG00000000419\n", - "chr20:50940933:50941129:clu_44490_-:ENSG00000000419 ENSG00000000419\n", - "chr20:50936262:50942031:clu_44490_-:ENSG00000000419 ENSG00000000419\n", - "```\n", - "\n", - "`--prior-canonical-matrices`\n", - "\n", - "`--save-data`: whether to save intermediate data or not\n", - "\n", - "`--twas-cv-folds`: Perform K folds valiation CV for TWAS. Set this to zero to skip\n", - "\n", - "`--trans-analysis`: Include this if doing trans-analysis (not using phenotypic coordinate information)\n", - "\n", - "`--region-name`: if you only wish to analyze one region, then include the ID of a region found in the `customized-association-windows` file\n", - "\n", - "`--cwd`: output file path" + "`qtl_dataset_construct+mnm_genes` constructs the shared dataset, identifies the genes in each selected locus and fits mvSuSiE jointly." ] }, { "cell_type": "markdown", - "id": "c74904f7", "metadata": {}, "source": [ - "- `--genoFile`: a PLINK `.bed` genotype file (include the `.bed` extension); the `.bim`/`.fam` files must sit alongside it.\n", - "- `--phenoFile`: a tab-delimited region file with columns `chr`, `start`, `end`, `ID`, and `path`, one row per region, where `path` points to that region's molecular-phenotype data.\n", - "- `--region-name`: the region/gene group to fine-map jointly (e.g. `ROSMAP_Ast_mega_eQTL`).\n" + "**Timing**: TBD" ] }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+mnm_genes \\\n", + " --name protocol_example \\\n", + " --cwd output_mnm_genes \\\n", + " --genoFile input/finemapping/protocol_example.multigene.genotype.chr22.bed \\\n", + " --phenoFile input/finemapping/protocol_example.multigene.pheno_manifest.tsv \\\n", + " --covFile input/finemapping/protocol_example.multigene.covariates.tsv \\\n", + " --customized-association-windows input/finemapping/protocol_example.multigene.association_windows.bed \\\n", + " --region-name ENSG00000130538 \\\n", + " --transpose-covariates \\\n", + " -j 1" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", - "id": "c6344399", "metadata": {}, "source": [ - "- `{region_name}.{chr}_{region_id}.multigene_bvsr.rds` \u2014 one RDS per region, the fitted multivariate (mvSuSiE / mr.mash) Bayesian variable-selection model jointly fine-mapping all genes in that region.\n", + "The command is expected to create:\n", "\n", - "Inspecting the object shows the per-region fit (posterior effect estimates, PVE, credible sets and convergence trace):\n", + "- `output_mnm_genes/qtl_dataset/protocol_example.qtl_dataset.rds` \u2014 the harmonized input dataset.\n", + "- `output_mnm_genes/multivariate_fine_mapping/protocol_example.mnm_genes_region_manifest.tsv` \u2014 regions and the genes assigned to each region.\n", + "- `output_mnm_genes/multivariate_fine_mapping/protocol_example.ENSG00000130538.multigene_bvsr.rds` \u2014 the cross-gene `QtlFineMappingResult`; a region with fewer than two joinable genes instead yields no fit.\n", "\n", - "```\n", - "> str(readRDS(\"ROSMAP_Ast_mega_eQTL.chr11_chr11_77324757_82556425.multigene_bvsr.rds\"))\n", - "List of 1\n", - " $ chr11_77324757_82556425:List of 12\n", - " ..$ mrmash_fitted :List of 14\n", - " .. ..$ mu1 : num [1:14830, 1:5] 3.02e-06 3.81e-06 -1.59e-05 -1.59e-05 -1.36e-05 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:14830] \"chr11:77325990:C:T\" \"chr11:77326116:G:A\" \"chr11:77326354:A:G\" \"chr11:77326475:G:C\" ...\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. ..$ S1 : num [1:5, 1:5, 1:14830] 6.07e-07 1.55e-09 1.78e-09 1.62e-09 1.44e-09 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 3\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. .. .. ..$ : chr [1:14830] \"chr11:77325990:C:T\" \"chr11:77326116:G:A\" \"chr11:77326354:A:G\" \"chr11:77326475:G:C\" ...\n", - " .. ..$ w1 : num [1:14830, 1:50] 0.999 0.998 0.997 0.997 0.999 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:14830] \"chr11:77325990:C:T\" \"chr11:77326116:G:A\" \"chr11:77326354:A:G\" \"chr11:77326475:G:C\" ...\n", - " .. .. .. ..$ : chr [1:50] \"null\" \"singleton1_grid1\" \"singleton1_grid2\" \"singleton1_grid3\" ...\n", - " .. ..$ V : num [1:5, 1:5] 0.40797 0.00349 0.016 -0.01287 0.00417 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. ..$ w0 : Named num [1:50] 9.98e-01 7.08e-05 1.12e-04 2.20e-04 4.38e-04 ...\n", - " .. .. ..- attr(*, \"names\")= chr [1:50] \"null\" \"singleton1_grid1\" \"singleton1_grid2\" \"singleton1_grid3\" ...\n", - " .. ..$ S0 : num [1:5, 1:5, 1:50] 1e-08 0e+00 0e+00 0e+00 0e+00 0e+00 1e-08 0e+00 0e+00 0e+00 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 3\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. .. .. ..$ : chr [1:5] \"ENSG00000074201\" \"ENSG00000048649\" \"ENSG00000159063\" \"ENSG00000188997\" ...\n", - " .. .. .. ..$ : chr [1:50] \"null\" \"singleton1_grid1\" \"singleton1_grid2\" \"singleton1_grid3\" ...\n", - " .. ..$ intercept : Named num [1:5] 0.0913 -0.0112 -0.3494 -0.1176 -0.1019\n", - "... (structure truncated; inspect the full object in R) ...\n", - "```" + "Important options are `--contexts`, `--mvsusie-max-iter`, optional `--prior-twas-weights`, and JSON overrides through `--mvsusie-method-args`." ] }, { "cell_type": "markdown", - "id": "00312628", "metadata": {}, "source": [ - "## Step 1: Run the fine-mapping with mvSuSiE\n", + "### Command reference\n", "\n", - "Run the multi-gene fine-mapping with mvSuSiE. See the [mnm_regression documentation](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html) for method details." + "Check the current interface before adapting the example." ] }, { "cell_type": "code", + "metadata": {}, + "source": [ + "sos run pipeline/mnm_regression.ipynb -h" + ], "execution_count": null, - "id": "2b6b5d17-0846-4ed3-ad9a-b8f2c0665dbb", + "outputs": [] + }, + { + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# Step 1: build the QtlDataset RDS for the joint-gene region.\n", - "sos run pipeline/qtl_dataset.ipynb qtl_dataset_construct \\\n", - " --cwd output/qtl_dataset \\\n", - " --study ROSMAP_Ast_mega_eQTL \\\n", - " --genotype-prefix data/mnm_genes/ROSMAP_NIA_WGS.leftnorm.bcftools_qc.plink_qc.11 \\\n", - " --phenotype-manifest data/mnm_genes/snuc_pseudo_bulk.Ast.mega.pheno_manifest.tsv\n", + "## Results and interpretation\n", + "\n", + "### Cross-gene result\n", "\n", - "# Step 2: per-region mvSuSiE joint fine-mapping. Use a region span that\n", - "# covers multiple genes (multi-trait joint mvSuSiE).\n", - "sos run pipeline/multivariate_fine_mapping.ipynb multivariate_fine_mapping \\\n", - " --cwd output/mnm_genes \\\n", - " --study ROSMAP_Ast_mega_eQTL \\\n", - " --qtl-dataset output/qtl_dataset/ROSMAP_Ast_mega_eQTL.qtl_dataset.rds \\\n", - " --regions chr11:65000000-67000000" + "The output is a `QtlFineMappingResult` with one joint entry for the genes assigned to the region.\n", + "\n", + "| Component | Interpretation |\n", + "|---|---|\n", + "| Region metadata | Fitted locus and participating genes |\n", + "| `topLoci` | Variant PIPs and credible-set assignments from the joint model |\n", + "| mvSuSiE fit | Posterior effects across the modeled genes |\n", + "| Credible-set purity | Strength of localization within the regional LD structure |" ] }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "suppressPackageStartupMessages(library(pecotmr))\n", + "\n", + "result_file <- \"output_mnm_genes/multivariate_fine_mapping/protocol_example.ENSG00000130538.multigene_bvsr.rds\"\n", + "result <- readRDS(result_file)\n", + "cat(\"Class:\", class(result), \"\\n\")\n", + "print(result[, setdiff(names(result), \"entry\"), drop = FALSE])\n", + "\n", + "entry <- result$entry[[1]]\n", + "top_loci <- getTopLoci(entry)\n", + "top_loci <- top_loci[order(top_loci$pip, decreasing = TRUE), ]\n", + "keep <- intersect(c(\"variant_id\", \"pip\", \"cs_95\", \"cs_95_purity\", \"method\"), names(top_loci))\n", + "head(top_loci[, keep, drop = FALSE], 8)" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", - "id": "08582666-774d-4620-a3bf-31f35689e7da", "metadata": {}, "source": [ - "For each gene and region, multivariate multigene finemapping will produce a file containing results for the top hits and a file containing twas weights produced by susie." + "A high joint PIP identifies a variant supported by the multivariate regional model; it does not by itself identify which gene mediates the signal. Interpret the variant-level evidence together with posterior effects for each gene. If several genes retain similar effects, the data may not separate shared regulation from correlated phenotypes. A broad or low-purity credible set indicates limited localization." ] }, { "cell_type": "markdown", - "id": "929ceb29-6395-4fd5-8ef9-a198626dffa4", "metadata": {}, "source": [ - "## Output" + "## Limitations and common pitfalls\n", + "\n", + "- Each fitted region needs at least two joinable genes; a single-gene region is not an error but cannot produce a cross-gene fit.\n", + "- Region boundaries determine which genes enter the model and must be scientifically justified.\n", + "- Nearby expression traits can be correlated for technical or biological reasons; joint association does not establish mediation.\n", + "- All phenotype and genotype files must use the same genome build and matched samples.\n", + "- The toy data demonstrate workflow structure rather than realistic power.\n", + "- Do not use the obsolete `--pheno_id_map_file` or `--skip-analysis-pip-cutoff` interface from the earlier implementation." ] }, { "cell_type": "markdown", - "id": "199a2637-cc0c-4aff-b4ea-a2546936f073", "metadata": {}, "source": [ - "`ROSMAP_Ast_DeJager_eQTL.chr11_77324757_86627922.multigene_bvrs.rds`:\n", - "* for each region name, includes:\n", - "1. mrmash_fitted\n", - "2. reweighted_mixture_prior\n", - "3. reweighted_mixture_prior_cv\n", - "4. mvsusie_fitted\n", - "5. variant_names\n", - "6. analysis_script\n", - "7. other_quantitites\n", - "8. analysis_script\n", - "9. top_loci\n", - "10. susie_result_trimmed\n", - "11. total_time_elapsed\n", - "12. region_info\n", - "\n", - "`ROSMAP_Ast_DeJager_eQTL.chr11_77324757_86627922.multigene_data.rds`:(from the --save-data argument)\n", - "* see [pecotmr code](https://github.com/statfungen/pecotmr/blob/68d87ca1d0a059022bf4e55339621cbddc8993cc/R/file_utils.R#L461) for description \n", + "## Next steps\n", "\n", - "`ROSMAP_Ast_DeJager_eQTL.chr11_77324757_86627922.multigene_twas_weights.rds`:\n", - "* for each region name and for each gene within that region, includes:\n", - "1. twas_weights - from mrmash and mvsusie\n", - "2. twas_predictions - from mrmash and mvsusie\n", - "3. variant_names\n", - "4. total_time_elapsed\n", - "5. region_info" + "For a localized signal, compare gene-specific posterior effects, annotate the highest-PIP variants and evaluate independent functional evidence. Use downstream post-processing to compare credible sets with single-gene or cross-context results rather than declaring one target gene from the joint PIP alone." ] } ], diff --git a/code/SoS/mnm_analysis/summary_stats_finemapping_vignette.ipynb b/code/SoS/mnm_analysis/summary_stats_finemapping_vignette.ipynb index c89f2e993..5247749a3 100644 --- a/code/SoS/mnm_analysis/summary_stats_finemapping_vignette.ipynb +++ b/code/SoS/mnm_analysis/summary_stats_finemapping_vignette.ipynb @@ -2,149 +2,181 @@ "cells": [ { "cell_type": "markdown", - "id": "5cf8e54a-dcb4-4fbe-b09e-1b4b30bd2ef9", "metadata": {}, "source": [ - "# Regression with Summary Statistics (RSS) Fine-Mapping and TWAS with SuSiE\n" + "# Fine-mapping GWAS summary statistics with SuSiE RSS\n", + "\n", + "This vignette shows how to combine GWAS summary statistics with an ancestry-matched LD reference to fine-map a genomic region." ] }, { "cell_type": "markdown", - "id": "e675dfd2-63b7-48e1-89cf-182bc281aaf5", "metadata": {}, "source": [ - "## Description" + "## Learning goals\n", + "\n", + "After completing this vignette, you will be able to prepare GWAS and LD metadata, run the RSS workflow, inspect variant PIPs and credible sets, and recognize LD or allele-alignment problems that can invalidate the result." ] }, { "cell_type": "markdown", - "id": "972d6a5b-6bff-4ff8-94b9-ec348116e4c6", "metadata": {}, "source": [ - "Last, we include an option to conduct fine-mapping with SuSiE Regression using Summary Statistics (RSS) model and TWAS.\n" + "## Background and method\n", + "\n", + "SuSiE RSS performs Bayesian fine-mapping from marginal association statistics and an external linkage-disequilibrium matrix. The workflow standardizes each GWAS, aligns its variants and alleles to the selected LD block, optionally performs summary-statistic QC or imputation, and fits SuSiE RSS within each study-region pair.\n", + "\n", + "The LD reference should match the GWAS ancestry and genome build. A mismatch can produce distorted z-score/LD relationships, unstable credible sets or apparently strong signals that are alignment artifacts. This vignette covers fine-mapping; it does not train individual-level TWAS weights." ] }, { "cell_type": "markdown", - "id": "8063eb8c-0969-4a4a-89a1-bea44971eab6", "metadata": {}, "source": [ - "## Input" + "## Worked example\n", + "\n", + "The example analyzes one chromosome 22 LD block from the Bellenguez 2022 Alzheimer disease GWAS.\n", + "\n", + "| Role | Example path | Required contents |\n", + "|---|---|---|\n", + "| GWAS metadata | `input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv` | Study identifier, summary-statistics path and optional column mapping |\n", + "| GWAS summary statistics | `input/rss_analysis/protocol_example.gwas_sumstats.chr22.tsv.gz` | Variant alleles, effect estimate or z score, sample size and frequency fields |\n", + "| Column mapping | `input/rss_analysis/protocol_example.gwas_column_mapping.fixed.yml` | Maps study-specific columns to the protocol schema |\n", + "| LD metadata | `input/ld_reference/protocol_example.ld_meta_file.tsv` | Region coordinates and the corresponding LD-reference prefix |\n", + "\n", + "The requested region is `chr22:49355984-50799822`. GWAS and LD variants must use compatible coordinates, alleles and ancestry." ] }, { "cell_type": "markdown", - "id": "2cd28b57-4189-4106-b4b2-da76573ea22d", "metadata": {}, "source": [ - "- `--gwas-meta` \u2014 TSV with columns `study_id`, `path` (GWAS sumstats, relative or absolute), and optional `column_mapping` (per-study YAML). One row per study:\n", - "\n", - "```\n", - "study_id path column_mapping\n", - "AD_Bellenguez_2022 input/rss_analysis/protocol_example.gwas_sumstats.chr22.tsv.gz input/rss_analysis/protocol_example.gwas_column_mapping.fixed.yml\n", - "```\n", - "\n", - "- `--ld-meta` \u2014 LD-reference meta TSV with columns `#chr`, `start`, `end`, `path` (genotype prefix pointing to PLINK2/PLINK1 files; produced by `rss_ld_sketch.ipynb`):\n", - "\n", - "```\n", - "#chr start end path\n", - "chr22 49355984 50799822 input/ld_reference/chr22_49355984_50799822\n", - "```\n", - "\n", - "- `--regions` \u2014 one or more regions in `chr:start-end` format (e.g. `chr22:49355984-50799822`)\n", - "- `--cwd` \u2014 output root directory\n", - "- `--modular-script-dir` \u2014 path to `code/script/` directory\n", - "\n", - "Optional QC parameters (forwarded to `summaryStatsQc()`):\n", - "\n", - "| Parameter | Default | Description |\n", - "|-----------|---------|-------------|\n", - "| `--qc-method` | `none` | QC method: `none`, `slalom`, or `dentist` |\n", - "| `--impute` | off | Enable RAISS sumstat imputation for missing variants |\n", - "| `--qc-args` | `''` | JSON object of extra `summaryStatsQc()` arguments, e.g. `'{\"mafCutoff\":0.01}'` |\n", - "| `--min-abs-corr` | `0.8` | Minimum absolute pairwise LD r\u00b2 for credible set purity filter |\n", - "| `--L` | `20` | Maximum number of causal signals SuSiE-RSS searches for |\n", - "| `--method-args` | `''` | Nested per-method JSON, e.g. `'{\"susie\":{\"L\":10}}'` |\n" + "### [Run summary-statistics fine-mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/rss_analysis.html#minimal-working-example)\n", + "\n", + "The four chained workflows generate the analysis manifest, harmonize GWAS statistics, fit SuSiE RSS and draw the PIP plot." ] }, { "cell_type": "markdown", - "id": "2eec8386-d780-463d-8d3e-6f62505c55a3", "metadata": {}, "source": [ - "## Output" + "**Timing**: TBD" ] }, { - "cell_type": "markdown", - "id": "6991377f-a6ef-45fe-ae78-20feb19fba9d", + "cell_type": "code", "metadata": {}, "source": [ - "Two output subdirectories are created under `--cwd`:\n\n**`sumstats/`** \u2014 one `GwasSumStats` S4 RDS per (study \u00d7 LD block):\n- `{study_id}.{chrom}_{start}_{end}.gwas_sumstats.rds`\n\n**`fine_mapping/`** \u2014 one `GwasFineMappingResult` S4 RDS per (study \u00d7 LD block):\n- `{study_id}.{chrom}_{start}_{end}.gwas_finemap.rds`\n\n**`plots/`** \u2014 PIP Manhattan plots:\n- `{study_id}.{chrom}_{start}_{end}.pip_plot.png`" - ] + "sos run pipeline/rss_analysis.ipynb \\\n", + " generate_manifest+generate_gwas_sumstats+gwas_fine_mapping+gwas_rss_plot \\\n", + " --cwd output/rss_analysis \\\n", + " --modular-script-dir code/script \\\n", + " --gwas-meta input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv \\\n", + " --regions chr22:49355984-50799822 \\\n", + " --ld-meta input/ld_reference/protocol_example.ld_meta_file.tsv" + ], + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", - "id": "247014fe-47f8-461b-9fc0-2810ea182668", "metadata": {}, "source": [ - "## Minimal Working Example Steps" + "The command creates:\n", + "\n", + "- `output/rss_analysis/sumstats/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_sumstats.rds` \u2014 the harmonized `GwasSumStats` object.\n", + "- `output/rss_analysis/fine_mapping/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_finemap.rds` \u2014 the `GwasFineMappingResult`.\n", + "- `output/rss_analysis/plots/AD_Bellenguez_2022.chr22_49355984_50799822.pip_plot.png` \u2014 the regional PIP plot.\n", + "\n", + "Optional QC settings include `--qc-method` (`none`, `slalom` or `dentist`), `--impute`, JSON `--qc-args`, and the credible-set purity threshold. Use these settings only after confirming their assumptions for the available GWAS and LD reference." ] }, { "cell_type": "markdown", - "id": "43ffff78-a679-46b0-a63e-31d6274169ba", "metadata": {}, "source": [ - "### v. [Run the Summary Statistics Fine-Mapping](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/rss_analysis.html#minimal-working-example)" + "### Command reference\n", + "\n", + "Check the current interface before adapting the example." ] }, { "cell_type": "code", - "execution_count": null, - "id": "f6ff1d68-1d7c-403f-8674-8c2bb0830f6f", "metadata": {}, - "outputs": [], "source": [ - "sos run pipeline/rss_analysis.ipynb \\\n", - " generate_manifest+generate_gwas_sumstats+gwas_fine_mapping+gwas_rss_plot \\\n", - " --cwd output/rss_analysis --modular-script-dir code/script \\\n", - " --gwas-meta input/rss_analysis/protocol_example.rss_mwe.gwas_meta.tsv \\\n", - " --regions chr22:49355984-50799822 \\\n", - " --ld-meta input/ld_reference/protocol_example.ld_meta_file.tsv\n" - ] + "sos run pipeline/rss_analysis.ipynb -h" + ], + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", - "id": "aa1271d0-a5f9-42fb-8993-4d52150e2131", "metadata": {}, "source": [ - "## Anticipated Results" + "## Results and interpretation\n", + "\n", + "### Fine-mapping result\n", + "\n", + "The `GwasFineMappingResult` records the study, region and method. Its `entry` contains the SuSiE fit and a `topLoci` table with one row per aligned variant.\n", + "\n", + "| Component | Interpretation |\n", + "|---|---|\n", + "| `topLoci$pip` | Posterior probability that a variant contributes to a modeled effect |\n", + "| `cs_95` | 95% credible-set assignment |\n", + "| `cs_95_purity` | LD-based purity of the assigned credible set |\n", + "| Marginal columns | Harmonized GWAS effect, uncertainty, z score and p-value |\n", + "| `susieFit` | Model fit, credible sets and diagnostics |" ] }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "suppressPackageStartupMessages(library(pecotmr))\n", + "\n", + "result_file <- \"output/rss_analysis/fine_mapping/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_finemap.rds\"\n", + "result <- readRDS(result_file)\n", + "ld <- attr(result, \"listData\")\n", + "cat(\"Class:\", class(result), \"\\n\")\n", + "print(ld[c(\"study\", \"method\", \"region_id\")])\n", + "\n", + "entry <- ld$entry[[1]]\n", + "top_loci <- attr(entry, \"topLoci\")\n", + "top_loci <- top_loci[order(top_loci$pip, decreasing = TRUE), ]\n", + "head(top_loci[, c(\"variant_id\", \"af\", \"marginal_z\", \"pip\", \"cs_95\", \"cs_95_purity\")], 8)" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", - "id": "96d4ec65-30b4-43c1-be5a-966070ba49b1", "metadata": {}, "source": [ - "Summary statistics fine-mapping produces a results file for each region and gwas of interest." + "The toy result ranks variants by PIP but does not retain a high-purity credible set. That means the example demonstrates the object and workflow without localizing a causal variant. In a substantive analysis, prioritize high-PIP variants only after checking credible-set purity, allele alignment, GWAS/LD ancestry matching and sensitivity to QC. Several variants in one credible set represent unresolved alternatives, not multiple confirmed causal variants." ] }, { "cell_type": "markdown", - "id": "7c4d9fe8-f897-4b36-b804-74d4c7ce784d", "metadata": {}, "source": [ - "### `GwasFineMappingResult` S4 object\n\n```r\nsuppressPackageStartupMessages(library(pecotmr))\nrds <- readRDS(\"output/rss_analysis/fine_mapping/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_finemap.rds\")\nclass(rds) # \"GwasFineMappingResult\"\n\nld <- attr(rds, \"listData\")\nnames(ld) # \"study\" \"method\" \"region_id\" \"entry\"\nld$study # \"AD_Bellenguez_2022\"\nld$method # \"susie\"\n\ne1 <- ld$entry[[1]]\nnames(attributes(e1)) # \"variantIds\" \"susieFit\" \"topLoci\" \"cvResult\" \"class\"\n```\n\n**`topLoci` table** (one row per variant in the region):\n\n```r\ntl <- attr(e1, \"topLoci\")\ndim(tl) # 24 \u00d7 23\nnames(tl)\n# [1] \"variant_id\" \"chrom\" \"pos\" \"A1\" \"A2\"\n# [6] \"N\" \"af\" \"marginal_beta\" \"marginal_se\" \"marginal_z\"\n# [11] \"marginal_p\" \"pip\" \"posterior_mean\" \"posterior_sd\" \"cs_95\"\n# [16] \"cs_70\" \"cs_50\" \"cs_95_purity\" \"method\" \"gene\"\n# [21] \"event\" \"grange_start\" \"grange_end\"\n\n# Top 3 by PIP\ntl_s <- tl[order(tl$pip, decreasing = TRUE), ]\ntl_s[1:3, c(\"variant_id\", \"af\", \"marginal_z\", \"pip\", \"cs_95\", \"cs_95_purity\")]\n# variant_id af marginal_z pip cs_95 cs_95_purity\n# chr22:49363017:G:A 0.317 2.753 0.382 susie_rss_0 0\n# chr22:49784794:G:A 0.073 -2.280 0.292 susie_rss_0 0\n# chr22:49514095:A:G 0.937 2.053 0.268 susie_rss_0 0\n```\n\n> **Toy data note**: All variants fall in one large credible set (`cs_95_purity = 0`), indicating insufficient LD contrast to localize the signal. In real large-sample GWAS the top CS typically contains 1\u201310 variants with purity \u2265 0.5.\n\n### `GwasSumStats` S4 object\n\n```r\nss <- readRDS(\"output/rss_analysis/sumstats/AD_Bellenguez_2022.chr22_49355984_50799822.gwas_sumstats.rds\")\nclass(ss) # \"GwasSumStats\"\n\n# main data \u2014 GRanges with GWAS columns\nld_ss <- attr(ss, \"listData\")\nld_ss$study # \"AD_Bellenguez_2022\"\ne_ss <- ld_ss$entry[[1]] # GRanges\nnames(mcols(e_ss)) # \"SNP\" \"A1\" \"A2\" \"Z\" \"N\" \"MAF\" \"BETA\" \"SE\" \"P\"\nlength(e_ss) # 24 (variants passing QC and matched to LD panel)\n\n# QC audit\nattr(ss, \"qcInfo\")$entryAudit[[1]]\n# $variantsIn: 7609 (raw input variants)\n# $contentFilters$nDropped: 2563\n# $betaSeFromZ$nDerived: 5046 (beta/se imputed from z + N)\n# $matchedAgainstSketch: 24 (variants matched to LD reference)\n# $variantsOut: 24\n```\n\n**`qcInfo$entryAudit` key fields:**\n\n| Field | Description |\n|-------|-------------|\n| `variantsIn` | Raw variants in the GWAS sumstats for this region |\n| `contentFilters$nDropped` | Dropped by QC filters (strand-ambiguous, missing data, etc.) |\n| `betaSeFromZ$nDerived` | Variants where \u03b2/SE were imputed from Z-score and N |\n| `matchedAgainstSketch` | Variants successfully matched to LD reference panel |\n| `variantsOut` | Final variant count used for fine-mapping |" + "## Limitations and common pitfalls\n", + "\n", + "- External LD must match the GWAS ancestry, build and allele coding.\n", + "- Summary statistics and the LD panel should cover the same variants; extensive missingness can change the fit.\n", + "- Imputed summary statistics add model-based information and should be labeled as imputed.\n", + "- Credible sets depend on LD quality and the assumed maximum number of effects.\n", + "- Low purity means the set should not be interpreted as localized.\n", + "- The example block is intentionally small and is not a biological benchmark." ] }, { - "cell_type": "code", - "execution_count": null, - "id": "89c126ec-301f-4c54-a342-c3f7088a6de5", + "cell_type": "markdown", "metadata": {}, - "outputs": [], - "source": [] + "source": [ + "## Next steps\n", + "\n", + "Annotate well-supported variants, compare credible sets across relevant populations or studies, and integrate the result with QTL fine-mapping or colocalization. Preserve the GWAS and LD provenance so downstream users can evaluate compatibility." + ] } ], "metadata": { @@ -163,7 +195,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.12" + "version": "3.12.13" } }, "nbformat": 4, diff --git a/code/SoS/mnm_analysis/univariate_fine_mapping_fsusie_vignette.ipynb b/code/SoS/mnm_analysis/univariate_fine_mapping_fsusie_vignette.ipynb index 5a05681e0..311ba4393 100644 --- a/code/SoS/mnm_analysis/univariate_fine_mapping_fsusie_vignette.ipynb +++ b/code/SoS/mnm_analysis/univariate_fine_mapping_fsusie_vignette.ipynb @@ -2,239 +2,204 @@ "cells": [ { "cell_type": "markdown", - "id": "5839a8ae-e13c-44ba-b06c-8346a0e65655", "metadata": {}, "source": [ - "# Univariate Fine-Mapping of Functional (Epigenomic) Data with fSuSiE\n" + "# Functional fine-mapping with fSuSiE\n", + "\n", + "This vignette shows how to jointly fine-map multiple related molecular measurements in one locus with fSuSiE." ] }, { "cell_type": "markdown", - "id": "fe924afb-7f78-4e1e-8b53-2cda19856bc7", "metadata": {}, "source": [ - "## Description" + "## Learning goals\n", + "\n", + "After completing this vignette, you will be able to:\n", + "\n", + "- decide when fSuSiE is appropriate instead of a single-trait SuSiE analysis;\n", + "- organize genotype, phenotype, covariate and region files for a joint fit;\n", + "- run the current `qtl_dataset_construct+fsusie` workflow; and\n", + "- inspect posterior inclusion probabilities and credible-set assignments without printing the entire result object." ] }, { "cell_type": "markdown", - "id": "4b860370-77bb-4095-b9b1-1613ed681bf4", "metadata": {}, "source": [ - "Univariate fine-mapping for functional (epigenomic) data is conducted with fSuSiE. This is similar to the normal univariate fine-mapping, with the main difference being the use of epigonmic data. \n" + "## Background and method\n", + "\n", + "fSuSiE is intended for a locus measured through multiple related functional traits, such as correlated chromatin features or other molecular measurements. It fits those measurements jointly so that shared evidence can help identify variants associated with the multivariate functional signal. A single gene-expression trait should instead use the ordinary `susie_twas` route.\n", + "\n", + "The workflow first builds a `QtlDataset`, then defines the requested region and calls `fineMappingPipeline()` with the `fsusie` method. The main settings control the prior (`--prior`), maximum prior scale (`--max-scale`), credible-set purity threshold (`--min-purity`) and post-processing method (`--post-processing`). Setting `--susie-top-pc` above zero additionally fine-maps selected phenotype principal components with univariate SuSiE; it is optional and is not part of the default fSuSiE fit.\n", + "\n", + "The bundled files below are a small multi-context molecular-trait example used to demonstrate the current interface. They are not a biological epigenomic benchmark, so substantive analyses should replace them with related functional measurements from the same samples and locus." ] }, { "cell_type": "markdown", - "id": "6eef2529-79a1-4af6-9b96-98c10a5e0b5e", "metadata": {}, "source": [ - "## Input" + "## Worked example\n", + "\n", + "The analysis unit is one locus (`ENSG00000130538`) measured in two contexts for the same individuals.\n", + "\n", + "| Role | Example path | Required structure |\n", + "|---|---|---|\n", + "| Genotype | `input/finemapping/protocol_example.genotype.chr22.bed` | PLINK bed/bim/fam trio with samples matching the phenotypes |\n", + "| Phenotype manifest | `input/finemapping/protocol_example.pheno_manifest_multicontext.tsv` | One row per context, with coordinates, trait identifier and phenotype BED path |\n", + "| Covariates | `input/finemapping/protocol_example.covariates.tsv` | Covariates by sample; this example is transposed with `--transpose-covariates` |\n", + "| Association windows | `input/finemapping/protocol_example.association_windows.bed` | Chromosome, start, end and region identifier |\n", + "\n", + "All four inputs must use compatible genome coordinates and sample identifiers. Multiple phenotype rows must represent measurements that are scientifically meaningful to analyze jointly." ] }, { "cell_type": "markdown", - "id": "5f0bcf9f-55c4-43fa-b846-170c935403b9", "metadata": {}, "source": [ - "- `--genoFile`: a text file listing the per-chromosome genotype files (PLINK prefixes) to load, one entry per line, as shown below.\n", - "```\n", - "#id #path\n", - "21 $PATH/protocol_example.genotype.chr21_22.21.bed\n", - "22 $PATH/protocol_example.genotype.chr21_22.22.bed\n", - "```\n", - "`--phenoFile`: a tab delimited file containing chr, start, end, ID and path for the regions. For example:\n", - "```\n", - "#chr start end ID path\n", - "chr21 0 14120807 TADB_1297 $PATH/protocol_example.ha.bed.gz\n", - "chr21 10840000 16880069 TADB_1298 $PATH/protocol_example.ha.bed.gz\n", - "```\n", + "### [Run fSuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html#fsusie)\n", "\n", - "`--covFile`: path to a gzipped file containing covariates in the rows, and sample ids in the columns. \n", - "`--customized-association-windows`: a tab delimited file containing chr, start, end, and ID regions. For example:\n", - "```\n", - "#chr start end ID\n", - "chr21 0 14120807 TADB_1297\n", - "chr21 10840000 16880069 TADB_1298\n", - "```\n", - "`--region-name`: if you only wish to analyze one region, then include the ID of a region found in the `customized-association-windows` file" + "`qtl_dataset_construct+fsusie` builds the regional dataset and then performs the joint fSuSiE fit." ] }, { "cell_type": "markdown", - "id": "f8e1c046-33da-4626-a5fd-8afb29f81e16", "metadata": {}, "source": [ - "## Output" + "**Timing**: TBD" ] }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+fsusie \\\n", + " --name protocol_example \\\n", + " --cwd output_fsusie \\\n", + " --genoFile input/finemapping/protocol_example.genotype.chr22.bed \\\n", + " --phenoFile input/finemapping/protocol_example.pheno_manifest_multicontext.tsv \\\n", + " --covFile input/finemapping/protocol_example.covariates.tsv \\\n", + " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", + " --region-name ENSG00000130538 \\\n", + " --transpose-covariates \\\n", + " -j 1" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", - "id": "436a39bb-b182-49c0-9ec9-c4b899c8b684", "metadata": {}, "source": [ - "- `{name}.chr{N}_{start}_{end}.{n}_marks.dataset.rds` \u2014 the per-region functional dataset (the epigenomic marks, residualized phenotype and genotype matrices) prepared for fSuSiE.\n", - "- `{name}.chr{N}_..._top_pc_weights.rds` \u2014 the fitted fSuSiE result with top-PC TWAS weights, fine-mapping the functional (epigenomic) signal in that region.\n", + "The command is expected to create:\n", "\n", - "Inspecting either object shows its internal structure:\n", - "```\n", - "> str(readRDS(\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/fsusie/fsus/Mic.chr7_139293693_145380632.16_marks.dataset.rds\"))\n", - "List of 1\n", - " $ chr7:139293693-145380632:List of 13\n", - " ..$ residual_Y :List of 1\n", - " .. ..$ ROSMAP_Mic_snATACQTL: num [1:65, 1:166] -0.0444 -0.3137 -0.0634 0.0658 0.8817 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. .. ..$ : NULL\n", - " ..$ residual_X :List of 1\n", - " .. ..$ : num [1:65, 1:15857] -0.4025 -0.8767 -0.2054 -0.0908 0.6848 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. .. ..$ : chr [1:15857] \"chr7:139302775:AACACACACAC:AACACACACACAC\" \"chr7:139302775:AACACACACAC:AACACACACACACAC\" \"chr7:139304706:G:GGT\" \"chr7:139305695:G:T\" ...\n", - " ..$ residual_Y_scalar: num 1\n", - " ..$ residual_X_scalar: num 1\n", - " ..$ covar :List of 1\n", - " .. ..$ : num [1:65, 1:48] 1 1 1 0 0 0 0 0 1 0 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. .. ..$ : NULL\n", - " ..$ Y :List of 1\n", - " .. ..$ : num [1:65, 1:166] 1.99 2.19 2.02 2.48 3.42 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. .. ..$ : NULL\n", - " ..$ X_data :List of 1\n", - " .. ..$ : num [1:65, 1:15857] 0 0 1 1 1 0 2 0 1 1 ...\n", - " .. .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. .. ..$ : chr [1:15857] \"chr7:139302775:AACACACACAC:AACACACACACAC\" \"chr7:139302775:AACACACACAC:AACACACACACACAC\" \"chr7:139304706:G:GGT\" \"chr7:139305695:G:T\" ...\n", - " ..$ maf :List of 1\n", - " .. ..$ : Named num [1:15857] 0.2692 0.1538 0.0692 0.0923 0.4615 ...\n", - " .. .. ..- attr(*, \"names\")= chr [1:15857] \"chr7:139302775:AACACACACAC:AACACACACACAC\" \"chr7:139302775:AACACACACAC:AACACACACACACAC\" \"chr7:139304706:G:GGT\" \"chr7:139305695:G:T\" ...\n", - " ..$ grange : chr [1:2] \"139293693\" \"145380632\"\n", - " ..$ Y_coordinates :List of 1\n", - " .. ..$ :Classes \u2018tbl_df\u2019, \u2018tbl\u2019 and 'data.frame':\t166 obs. of 3 variables:\n", - " .. .. ..$ #chr : chr [1:166] \"chr7\" \"chr7\" \"chr7\" \"chr7\" ...\n", - " .. .. ..$ start: num [1:166] 1.39e+08 1.39e+08 1.39e+08 1.39e+08 1.39e+08 ...\n", - " .. .. ..$ end : num [1:166] 1.39e+08 1.39e+08 1.39e+08 1.39e+08 1.39e+08 ...\n", - " ..$ dropped_sample :List of 3\n", - " .. ..$ X :List of 1\n", - " .. .. ..$ : chr [1:3] \"sample_71\" \"sample_6\" \"sample_46\"\n", - " .. ..$ Y :List of 1\n", - " .. .. ..$ : chr [1:5] \"sample_1\" \"sample_6\" \"sample_7\" \"sample_46\" ...\n", - " .. ..$ covar:List of 1\n", - " .. .. ..$ : chr [1:3] \"sample_1\" \"sample_47\" \"sample_7\"\n", - " ..$ X : num [1:65, 1:15857] 0 0 1 1 1 0 2 0 1 1 ...\n", - " .. ..- attr(*, \"dimnames\")=List of 2\n", - " .. .. ..$ : chr [1:65] \"sample_10\" \"sample_11\" \"sample_12\" \"sample_13\" ...\n", - " .. .. ..$ : chr [1:15857] \"chr7:139302775:AACACACACAC:AACACACACACAC\" \"chr7:139302775:AACACACACAC:AACACACACACACAC\" \"chr7:139304706:G:GGT\" \"chr7:139305695:G:T\" ...\n", - " ..$ chrom : chr \"chr7\"\n", - "```\n", + "- `output_fsusie/qtl_dataset/protocol_example.qtl_dataset.rds` \u2014 harmonized genotype, phenotype and covariate data.\n", + "- `output_fsusie/fsusie/protocol_example.fsusie_region_manifest.tsv` \u2014 the locus selected for the fit.\n", + "- `output_fsusie/fsusie/protocol_example.ENSG00000130538.fsusie.rds` \u2014 the `QtlFineMappingResult` containing the fSuSiE fit and variant-level summaries.\n", "\n", - "* `*_top_pc_weights.rds`\n", - "```\n", - "> str(readRDS(\"/restricted/projectnb/xqtl/xqtl_protocol/toy_xqtl_protocol/output/fsusie/fsus/Mic.chr7_139293693_145380632.fsusie_mixture_normal_none__top_pc_weights.rds\"),max.level = 3)\n", - "List of 1\n", - " $ chr7:139293693-145380632:List of 1\n", - " ..$ ROSMAP_Mic_snATACQTL:List of 10\n", - " .. ..$ susie_on_top_pc :List of 1\n", - " .. ..$ susie_weights_intermediate:List of 6\n", - " .. ..$ twas_weights :List of 6\n", - " .. ..$ twas_predictions :List of 6\n", - " .. ..$ twas_cv_result :List of 4\n", - " .. ..$ total_time_elapsed : 'proc_time' Named num [1:5] 31992.49 40.47 32206.65 304.39 4.65\n", - " .. .. ..- attr(*, \"names\")= chr [1:5] \"user.self\" \"sys.self\" \"elapsed\" \"user.child\" ...\n", - " .. ..$ fsusie_result :List of 34\n", - " .. .. ..- attr(*, \"class\")= chr \"susiF\"\n", - " .. ..$ Y_coordinates :Classes \u2018tbl_df\u2019, \u2018tbl\u2019 and 'data.frame':\t166 obs. of 3 variables:\n", - " .. ..$ fsusie_summary :List of 5\n", - " .. ..$ region_info :List of 3\n", - "```" + "Key optional settings are:\n", + "\n", + "| Option | Purpose |\n", + "|---|---|\n", + "| `--prior` | Prior family used by fSuSiE; default `mixture_normal` |\n", + "| `--max-scale` | Upper scale bound for the effect-size prior |\n", + "| `--min-purity` | Minimum credible-set purity retained in post-processing |\n", + "| `--post-processing` | fSuSiE post-processing rule |\n", + "| `--susie-top-pc` | Number of phenotype PCs to fine-map separately; default `0` |" ] }, { "cell_type": "markdown", - "id": "397a4dc3-1e4c-4845-ad8b-beed40f1f408", "metadata": {}, "source": [ - "## Minimal Working Example Steps" + "### Command reference\n", + "\n", + "Show all current workflows and options before adapting the example to a new dataset." ] }, + { + "cell_type": "code", + "metadata": {}, + "source": [ + "sos run pipeline/mnm_regression.ipynb -h" + ], + "execution_count": null, + "outputs": [] + }, { "cell_type": "markdown", - "id": "3bca0962-ae57-422c-a79f-892ef3b7f7ae", "metadata": {}, "source": [ - "### iii. [Run the Fine-Mapping with fSuSiE](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html#ii-fsusie)" + "## Results and interpretation\n", + "\n", + "### fSuSiE result\n", + "\n", + "The result is a `QtlFineMappingResult`. Its table-level metadata identifies the region and fitted method; each `entry` stores the fit plus a `topLoci` table with one row per variant.\n", + "\n", + "| Level | Contents |\n", + "|---|---|\n", + "| Result table | Context, trait or region identifiers, method and one `entry` per fit |\n", + "| `entry` | Method-specific fSuSiE fit and attached summaries |\n", + "| `topLoci` | Variant identifiers, PIPs, posterior effects and credible-set labels |\n", + "| Credible-set columns | Membership at the requested coverage and the corresponding purity |" ] }, { "cell_type": "code", - "execution_count": null, - "id": "dff2c979-52a1-4ec8-a0be-51b289327d37", "metadata": {}, - "outputs": [], "source": [ - "# Step 1: build the QtlDataset RDS for the functional phenotype.\n", - "sos run pipeline/qtl_dataset.ipynb qtl_dataset_construct \\\n", - " --cwd output/qtl_dataset \\\n", - " --study Mic \\\n", - " --genotype-prefix data/fsusie/mwe.chr7 \\\n", - " --phenotype-manifest data/fsusie/mwe.pheno_manifest.tsv\n", + "suppressPackageStartupMessages(library(pecotmr))\n", "\n", - "# Step 2: per-region fSuSiE joint fine-mapping over the bins in the LD block.\n", - "sos run pipeline/functional_fine_mapping.ipynb functional_fine_mapping \\\n", - " --cwd output/fsusie \\\n", - " --study Mic \\\n", - " --qtl-dataset output/qtl_dataset/Mic.qtl_dataset.rds \\\n", - " --regions chr7:139293693-145380632" - ] + "result_file <- \"output_fsusie/fsusie/protocol_example.ENSG00000130538.fsusie.rds\"\n", + "result <- readRDS(result_file)\n", + "\n", + "cat(\"Class:\", class(result), \"\\n\")\n", + "print(result[, setdiff(names(result), \"entry\"), drop = FALSE])\n", + "\n", + "entry <- result$entry[[1]]\n", + "top_loci <- getTopLoci(entry)\n", + "top_loci <- top_loci[order(top_loci$pip, decreasing = TRUE), ]\n", + "\n", + "keep <- intersect(\n", + " c(\"variant_id\", \"pip\", \"posterior_mean\", \"posterior_sd\",\n", + " \"cs_95\", \"cs_95_purity\", \"method\"),\n", + " names(top_loci)\n", + ")\n", + "head(top_loci[, keep, drop = FALSE], 8)" + ], + "execution_count": null, + "outputs": [] }, { "cell_type": "markdown", - "id": "cc7691e6-954c-4dc1-bac3-25d56026ab96", "metadata": {}, "source": [ - "## Anticipated Results" + "Interpret variants by PIP first, then use credible-set membership and purity to judge localization. A high-PIP variant in a compact, high-purity credible set is more strongly localized than a similarly ranked variant in a large or low-purity set. Lack of a retained credible set in a toy dataset is not evidence that the locus has no functional effect; small sample size, weak signal, phenotype definition and LD can all prevent localization." ] }, { "cell_type": "markdown", - "id": "c698203c-976e-49d6-9056-a17238bf2099", "metadata": {}, "source": [ - "Univariate finemapping for functional data will produce a file containing results for the top hits and a file containing residuals from SuSiE." + "## Limitations and common pitfalls\n", + "\n", + "- fSuSiE requires at least two joinable traits or contexts. Use ordinary SuSiE for a single trait.\n", + "- The traits should describe related measurements in the same locus and samples; combining unrelated outcomes only because they share coordinates is not a valid joint analysis.\n", + "- Sample identifiers must agree across genotype, phenotype and covariate files.\n", + "- Chromosome naming and genome build must match across all inputs.\n", + "- The example data demonstrate file structure and command composition, not realistic epigenomic power.\n", + "- If the regional fit fails before producing the final RDS, inspect the per-region `.stderr` file rather than interpreting the intermediate dataset as a completed analysis." ] }, { "cell_type": "markdown", - "id": "199a2637-cc0c-4aff-b4ea-a2546936f073", "metadata": {}, "source": [ - "`Mic.chr7_139293693_145380632.fsusie_mixture_normal_none__top_pc_weights.rds`:\n", - "* For each region of interest, this file contains: \n", - " 1. susie_on_top_pc \n", - " 2. twas_weights - for each variant (for enet, lasso and mrash methods). \n", - " 3. twas predictions - for each sample (for enet, lasso, mrash methods)\n", - " 4. twas cross validation results - information on the best method. Data is split into five parts\n", - " 6. fsusie results \n", - " 7. Y coordinates \n", - " 8. fsusie summary \n", - " 9. total time elapsed\n", - " 10. region info - information on the region specified\n", + "## Next steps\n", "\n", - "`Mic.chr7_139293693_145380632.16_marks.dataset.rds`:\n", - "* For each gene of interest, contains residuals for each sample and phenotype\n", - "* see [pecotmr code](https://github.com/statfungen/pecotmr/blob/68d87ca1d0a059022bf4e55339621cbddc8993cc/R/file_utils.R#L461) for description at fsusie uses the `load_regional_functional_data` function, an explanation of the arguments can be found at the similar `load_regional_association_data` function" + "For a retained credible set, annotate the highest-PIP variants and compare their effects across the functional measurements represented in the joint fit. The result can then be passed to the appropriate post-processing or biological-validation workflow; do not treat fine-mapping probabilities alone as functional validation." ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "159e580c-e290-4403-a701-d9dfa1043341", - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { @@ -253,7 +218,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.12" + "version": "3.12.13" } }, "nbformat": 4, diff --git a/code/SoS/mnm_analysis/univariate_fine_mapping_twas_vignette.ipynb b/code/SoS/mnm_analysis/univariate_fine_mapping_twas_vignette.ipynb index d1e8ef26f..941d5434b 100644 --- a/code/SoS/mnm_analysis/univariate_fine_mapping_twas_vignette.ipynb +++ b/code/SoS/mnm_analysis/univariate_fine_mapping_twas_vignette.ipynb @@ -4,87 +4,61 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Steps\n" + "# Univariate fine-mapping and TWAS with SuSiE\n", + "Fine-map cis-xQTL signals and estimate cross-validated transcriptome-wide association study (TWAS) weights for one molecular trait in one or more contexts." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "# Univariate Fine-Mapping and TWAS with SuSiE\n", - "\n", - "## Description\n", - "\n", - "This pipeline performs per-region univariate fine-mapping with SuSiE and computes TWAS\n", - "weights, via the `susie_twas` and `mnm` workflows of **`pipeline/mnm_regression.ipynb`**.\n", - "\n", - "- **`qtl_dataset_construct+susie_twas`** \u2014 builds a `QtlDataset` RDS from genotype/phenotype/covariate files, then for each region fits SuSiE fine-mapping and trains TWAS prediction weights with 10 methods (mrash, susie, susie_inf, enet, lasso, mcp, scad, l0learn, bayes_r, bayes_c), plus a CV-based ensemble weight. Produces `*.univariate_bvsr.rds` (fine-mapping) and `*.univariate_twas_weights.rds` (TWAS weights).\n", - "- **`mnm`** \u2014 reads all `susie_twas` outputs (via `--fine-mapping-meta`), pools CV predictions across multiple contexts, solves a constrained QP to find the optimal method/context mixture, and produces `*.multicontext_twas_weights.rds`.\n", - "\n", - "SuSiE searches for up to L=5 independent signals per region. Covariates are regressed out of both phenotype and genotype matrices before fitting (SuSiE itself does not accept covariates).\n", - "\n", - "### What is a \"region\"?\n", - "\n", - "A region is **one row in the phenotype manifest** (`--phenoFile`) plus its association\n", - "window (from `--customized-association-windows`). One `susie_twas` call fits one SuSiE + TWAS model per region.\n", - "\n", - "* **Gene-based phenotypes.** Manifest row = one gene; window = gene's TSS \u00b1 cis window (or from a pre-built TADB BED).\n", - "* **Peak-based phenotypes (caQTL, mQTL).** Manifest row = one peak/CpG; window = the peak's containing extended-TAD.\n" + "## Learning goals\n", + "After completing this vignette, readers should be able to:\n", + "1. define the analysis unit and cis-association window used by `susie_twas`;\n", + "2. distinguish SuSiE fine-mapping outputs from TWAS prediction weights;\n", + "3. compare prediction methods using out-of-fold performance; and\n", + "4. identify credible sets, posterior inclusion probabilities, and common input failures." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Input Files\n\n| File | Description |\n| --- | --- |\n| `/pheno_manifest.tsv` | Phenotype manifest mapping each region to its phenotype/covariate files |\n| `/association_windows.bed` | Association-test windows (one row per region) |\n| `/peaks_split/.bed.gz{,.tbi}` | Per-region phenotype data, bgzipped and tabix-indexed |\n" + "## Background and method\n", + "`qtl_dataset_construct+susie_twas` in [`mnm_regression.ipynb`](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html) builds a `QtlDataset` from genotype, phenotype, and covariate files. For each region, it residualizes genotype and phenotype matrices, fits SuSiE, and trains ten TWAS prediction models (`mrash`, `susie`, `susie_inf`, `enet`, `lasso`, `mcp`, `scad`, `l0learn`, `bayes_r`, and `bayes_c`) plus a cross-validation-based ensemble.\n", + "\n", + "SuSiE represents the regional effect as a sum of single effects and reports posterior inclusion probabilities (PIPs) and credible sets. In this example, the maximum number of effects is `L = 5`. TWAS weights solve a different problem: they predict the molecular trait from regional genotypes. Fine-mapping evidence and predictive performance should therefore be interpreted separately.\n", + "\n", + "The optional `mnm` workflow pools cross-validated predictions across contexts and estimates a constrained method-by-context mixture, producing multi-context TWAS weights." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Step 1 -- Prepare the phenotype manifest and association-windows BED\n", - "\n", - "The pipeline expects two derived files per experiment:\n", + "## Worked example\n", "\n", - "* `pheno_manifest.tsv` \u2014 5 columns (`#chr start end ID path`), one row per region.\n", - " `path` points to a bgzipped+tabixed phenotype BED restricted to that region.\n", - "* `association_windows.bed` \u2014 4 columns (`chr start end ID`), one row per region.\n", - " `start/end` define the cis search window; `ID` must match a row in the manifest.\n", + "The example fine-maps one gene in two molecular-trait contexts and estimates within-context TWAS weights.\n", "\n", - "For gene-based phenotypes these files are produced by the standard phenotype\n", - "preprocessing + [TADB generation](./../reference_data/generalized_TADB.html) steps.\n", + "### Input files\n", "\n", - "For peak-based phenotypes (caQTL, mQTL) you can derive both from the raw peak BED with\n", - "the helper below; it renames the peak-ID header, splits the multi-sample BED into one\n", - "bgz+tbi per peak, writes the manifest, and annotates each peak with its smallest\n", - "containing extended-TAD." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "bash code/misc/preprocess/prepare_peak_inputs.sh \\\n", - " \\\n", - " \\\n", - " \n", - "\n", - "# Produces:\n", - "# /pheno_manifest.tsv\n", - "# /association_windows.bed\n", - "# /peaks_split/.bed.gz{,.tbi}\n" + "| File | Purpose |\n", + "|---|---|\n", + "| `input/finemapping/protocol_example.genotype.chr22.bed` with matching `.bim` and `.fam` | PLINK genotype data |\n", + "| `input/finemapping/protocol_example.pheno_manifest_multicontext.tsv` | Maps each gene and context to its indexed phenotype BED and covariate file |\n", + "| `input/finemapping/protocol_example.gene_expression.context1.bed.gz` with `.tbi` | Context 1 molecular-trait values |\n", + "| `input/finemapping/protocol_example.gene_expression.context2.bed.gz` with `.tbi` | Context 2 molecular-trait values |\n", + "| `input/finemapping/protocol_example.covariates.tsv` | Covariates for the two contexts |\n", + "| `input/finemapping/protocol_example.association_windows.bed` | Cis-association window for each gene |" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "### Step 2 -- Run `susie_twas` + `mnm`\n", + "### [Run univariate fine-mapping and estimate TWAS weights](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", "\n", - "**Gene-based example** (single gene, 2-context toy dataset):\n" + "This command constructs the analysis dataset, fits SuSiE separately in each context, and estimates TWAS weights. `--save-data` retains the residualized matrices for analyses that reuse the fitted dataset." ] }, { @@ -93,31 +67,37 @@ "metadata": {}, "outputs": [], "source": [ - "# Step 1: build QtlDataset + run SuSiE fine-mapping + TWAS weights (all-in-one)\n", "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+susie_twas \\\n", - " --name protocol_example --cwd output_uni \\\n", - " --genoFile input/colocboost/example.chr22.bed \\\n", - " --phenoFile input/colocboost/pheno_manifest_multicontext.tsv \\\n", - " --covFile input/colocboost/example_covariates.tsv \\\n", - " --customized-association-windows input/colocboost/association_windows.bed \\\n", - " --region-name ENSG00000130538 --transpose-covariates --save-data -j1\n", + " --name protocol_example \\\n", + " --cwd output_uni \\\n", + " --genoFile input/finemapping/protocol_example.genotype.chr22.bed \\\n", + " --phenoFile input/finemapping/protocol_example.pheno_manifest_multicontext.tsv \\\n", + " --covFile input/finemapping/protocol_example.covariates.tsv \\\n", + " --customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", + " --region-name ENSG00000130538 \\\n", + " --transpose-covariates \\\n", + " --save-data \\\n", + " -j1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The worked example produces:\n", "\n", - "# Step 2: multi-context ensemble TWAS weights (mnm)\n", - "sos run pipeline/mnm_regression.ipynb mnm \\\n", - " --name protocol_example --cwd output_mnm \\\n", - " --genoFile input/colocboost/example.chr22.bed \\\n", - " --phenoFile input/colocboost/pheno_manifest_multicontext.tsv \\\n", - " --covFile input/colocboost/example_covariates.tsv \\\n", - " --customized-association-windows input/colocboost/association_windows.bed \\\n", - " --fine-mapping-meta input/colocboost/fine_mapping_meta.tsv \\\n", - " --transpose-covariates --save-data -j1\n" + "- `output_uni/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds`: context-specific SuSiE fine-mapping results.\n", + "- `output_uni/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds`: prediction weights and cross-validation results.\n", + "- `output_uni/fine_mapping_meta.tsv`: manifest linking regions to the generated fine-mapping and weight files." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "**Peak-based example** (same pipeline, swap phenotype/covariate inputs):\n" + "### Optional: [adapt the analysis to peak-based traits](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html)\n", + "\n", + "Peak- or CpG-based traits use the same fine-mapping workflow, but first require a phenotype manifest and biologically appropriate association windows. For peak data, the helper below splits a multi-sample BED into indexed region files and assigns each feature to its smallest containing extended TAD. Replace the placeholders with your peak BED, extended-TAD reference, and output directory, then use the generated manifest and windows in the main command." ] }, { @@ -126,45 +106,40 @@ "metadata": {}, "outputs": [], "source": [ - "# Peak/chromatin example (same pipeline, different input)\n", - "# NOTE: this is a peak catalog with one phenotype file per peak; the\n", - "# qtl_dataset_construct manifest schema (ID, path, cond) instead expects a\n", - "# single multi-trait phenotype file per context. protocol_example.peaks_merged.bed.gz\n", - "# (all 10 peaks, built from peaks_split/) and protocol_example.pheno_manifest_context.tsv\n", - "# match that schema; run qtl_dataset_construct before susie_twas (as in Step 1 above).\n", - "sos run pipeline/mnm_regression.ipynb qtl_dataset_construct+susie_twas \\\n", - "--name protocol_example --cwd output/susie_twas_peaks \\\n", - "--genoFile input/genotype/protocol_example.genotype.chr22.bed \\\n", - "--phenoFile input/phenotype/protocol_example.pheno_manifest_context.tsv \\\n", - "--covFile input/covariate/protocol_example.covariates.tsv \\\n", - "--customized-association-windows input/finemapping/protocol_example.association_windows.bed \\\n", - "--region-name C22P107555 -j1\n" + "bash code/misc/preprocess/prepare_peak_inputs.sh \\\n", + " \\\n", + " \\\n", + " \n", + "\n", + "# Produces:\n", + "# /pheno_manifest.tsv\n", + "# /association_windows.bed\n", + "# /peaks_split/.bed.gz{,.tbi}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Expected output files after `susie_twas`:\n", - "\n", - "```\n", - "output_uni/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds\n", - "output_uni/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds\n", - "output_uni/fine_mapping_meta.tsv \u2190 auto-generated, used by mnm as --fine-mapping-meta\n", - "```\n", - "\n", - "After `mnm`:\n", - "\n", - "```\n", - "output_mnm/twas_weights/protocol_example.ENSG00000130538.multicontext_twas_weights.rds\n", - "```\n" + "### Parameters used in the example\n", + "\n", + "| Parameter | Why it matters here |\n", + "|---|---|\n", + "| `--phenoFile` | Supplies the context-specific molecular traits through the phenotype manifest. |\n", + "| `--customized-association-windows` | Defines the variants considered for each gene instead of using a fixed cis window. |\n", + "| `--region-name` | Restricts this demonstration to `ENSG00000130538`. |\n", + "| `--transpose-covariates` | Matches the orientation of the supplied covariate table. |\n", + "| `--save-data` | Saves residualized matrices that can be reused downstream. |\n", + "| `-j1` | Runs one job for a reproducible, easy-to-debug example. |\n", + "\n", + "See the module link or command reference below for all remaining options and defaults." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Command Interface\n" + "### Command reference" ] }, { @@ -180,197 +155,86 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Key parameters for `qtl_dataset_construct+susie_twas`:\n", - "\n", - "| Parameter | Description |\n", - "|-----------|-------------|\n", - "| `--name` | Study name prefix; all output files are named `{name}.{region_id}.*` |\n", - "| `--cwd` | Output root directory; subdirs `qtl_dataset/`, `fine_mapping/`, `twas_weights/` are created automatically |\n", - "| `--genoFile` | PLINK1 `.bed` file path (`.bim`/`.fam` auto-located); FID/IID must match phenotype/covariate sample IDs |\n", - "| `--phenoFile` | Phenotype manifest TSV \u2014 columns `ID`, `path`, `cond` (one row per context); `path` points to a bgzipped+tabix-indexed phenotype BED |\n", - "| `--covFile` | Covariate TSV \u2014 rows = covariates, columns = samples (use `--transpose-covariates` if rows = samples) |\n", - "| `--customized-association-windows` | 4-column `chr start end ID` BED defining the cis search window per region |\n", - "| `--region-name` | Restrict analysis to one or more region IDs (space-separated); omit to run all regions |\n", - "| `--transpose-covariates` | Transpose covariate file before reading (needed when rows = samples) |\n", - "| `--save-data` | Also emit `*.univariate_data.rds` with residualized X/Y matrices; **required** for downstream `mnm` step |\n", - "| `-j1` | Number of parallel jobs (set to 1 for debugging) |\n", - "\n", - "Additional parameter for `mnm`:\n", - "\n", - "| Parameter | Description |\n", - "|-----------|-------------|\n", - "| `--fine-mapping-meta` | TSV auto-generated by `susie_twas` (at `{cwd}/fine_mapping_meta.tsv`); maps each region to its `univariate_bvsr.rds` and `univariate_twas_weights.rds` paths |\n" + "## Results and interpretation" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Output Format\n", - "\n", - "All outputs are written under `--cwd`, one set per region:\n", - "\n", - "**Fine-mapping** (`output_uni/fine_mapping/`):\n", - "- `{name}.{region_id}.univariate_bvsr.rds` \u2014 `QtlFineMappingResult` S4 object, one entry per context\n", - "\n", - "**TWAS weights** (`output_uni/twas_weights/`):\n", - "- `{name}.{region_id}.univariate_twas_weights.rds` \u2014 `TwasWeights` S4 object (per-method + ensemble)\n", - "\n", - "**Ensemble TWAS weights** (after `mnm` step, `output_mnm/twas_weights/`):\n", - "- `{name}.{region_id}.multicontext_twas_weights.rds` \u2014 multi-context ensemble `TwasWeights` S4\n", - "\n", - "### `QtlFineMappingResult` S4 structure\n", - "\n", - "Top-level via `attr(rds, \"listData\")`:\n", - "\n", - "| Field | Description |\n", - "|-------|-------------|\n", - "| `study` | Study name (from `--name`) |\n", - "| `context` | Context label per entry |\n", - "| `trait` | Gene/trait ID |\n", - "| `method` | Fine-mapping method (`\"susie\"`) |\n", - "| `entry` | List of `FineMappingEntry` S4 objects (one per context) |\n", - "\n", - "Each `FineMappingEntry` has these attributes:\n", - "\n", - "| Attribute | Description |\n", - "|-----------|-------------|\n", - "| `variantIds` | SNP IDs (`chr:pos:ref:alt`) for all variants in the region |\n", - "| `susieFit` | Raw `susie()` output \u2014 `sets$cs` (credible sets after purity filter), `lbf` (log Bayes factors per effect component), `alpha` (posterior inclusion per effect) |\n", - "| `topLoci` | Per-variant summary data.frame (see column reference in Anticipated Results) |\n", - "| `cvResult` | Cross-validation result used in TWAS weight computation |\n", - "\n", - "### `TwasWeights` S4 structure\n", - "\n", - "Top-level via `attr(tw, \"listData\")`:\n", - "\n", - "| Field | Description |\n", - "|-------|-------------|\n", - "| `study` | Study name |\n", - "| `context` | Context label per entry (repeated per method) |\n", - "| `trait` | Gene/trait ID |\n", - "| `method` | Method name: `mrash`, `susie`, `susie_inf`, `enet`, `lasso`, `mcp`, `scad`, `l0learn`, `bayes_r`, `bayes_c`, `ensemble` |\n", - "| `entry` | List of `TwasWeightsEntry` S4 objects (N_contexts \u00d7 11 methods total) |\n", + "### Fine-mapping result\n", "\n", - "Each `TwasWeightsEntry` accessed via `attr(entry, \"\")`:\n", + "- `output_uni/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds`\n", "\n", - "| Attribute | Description |\n", - "|-----------|-------------|\n", - "| `variantIds` | SNP IDs in the region |\n", - "| `weights` | Per-SNP TWAS weights (\u03b2 from genotype\u2192expression model) |\n", - "| `fits` | Fitted model object (class-specific) |\n", - "| `cvPerformance` | CV results: `$metrics` (corr, rsq, adj_rsq, pval, RMSE, MAE) for per-method entries; `$methodCoef` + `$methodPerformance` for ensemble |\n", - "| `standardized` | Whether X/Y were standardized (default `FALSE`) |\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n", + "The RDS contains a `QtlFineMappingResult`:\n", "\n", - "Quick sanity check \u2014 inspect cross-validation performance for the first region:" + "| Level | Access | Contents |\n", + "|---|---|---|\n", + "| Result | `attr(result, \"listData\")` | Study, context, trait, method, and context-specific entries |\n", + "| Context entry | `entries$entry[[i]]` | Fine-mapping information for one context |\n", + "| `topLoci` | `attr(entry, \"topLoci\")` | Variant IDs, PIPs, posterior effects, credible-set membership, and purity |\n", + "| `susieFit` | `attr(entry, \"susieFit\")` | Fitted SuSiE model and retained credible sets |\n", + "| `cvResult` | `attr(entry, \"cvResult\")` | Cross-validation information used during weight estimation |" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "Markdown", + "kernel": "R", "tags": [] }, "outputs": [], - "execution_count": null, "source": [ - "### Fine-Mapping Result: `QtlFineMappingResult` S4\n", - "\n", - "The fine-mapping RDS holds **all contexts for one gene** in a single object.\n", - "Access the structured data via `attr(rds, \"listData\")`:\n", - "\n", - "| Field | Description |\n", - "|-------|-------------|\n", - "| `study` | Study name string (from `--study`) |\n", - "| `context` | Context label for each entry (one entry per context) |\n", - "| `trait` | Gene/trait ID (Ensembl) |\n", - "| `method` | Fine-mapping method used (`\"susie\"`) |\n", - "| `entry` | List of `FineMappingEntry` S4 objects, one per context |\n", - "\n", - "Each `FineMappingEntry` has these attributes:\n", - "\n", - "| Attribute | Class | Description |\n", - "|-----------|-------|-------------|\n", - "| `variantIds` | character | SNP IDs in the region (`chr:pos:ref:alt`) |\n", - "| `susieFit` | susie | Raw `susie()` output \u2014 contains `sets$cs` (credible sets), `lbf` (log Bayes factors), `alpha` (posterior inclusion probabilities per effect) |\n", - "| `topLoci` | data.frame | Per-variant summary table (see column reference below) |\n", - "| `cvResult` | list | Cross-validation result used to compute TWAS weights |\n", - "\n", - "**`topLoci` column reference** (1024 rows \u00d7 23 columns for this example):\n", - "\n", - "| Column | Description |\n", - "|--------|-------------|\n", - "| `variant_id` | SNP ID (`chr:pos:ref:alt`) |\n", - "| `chrom`, `pos` | Chromosome and position |\n", - "| `A1`, `A2` | Effect and reference alleles |\n", - "| `N` | Sample size |\n", - "| `af` | Allele frequency of A1 |\n", - "| `marginal_beta`, `marginal_se` | Marginal effect estimate and standard error |\n", - "| `marginal_z`, `marginal_p` | Marginal z-score and p-value |\n", - "| `pip` | **Posterior Inclusion Probability** \u2014 probability this variant is causal (0\u20131) |\n", - "| `posterior_mean`, `posterior_sd` | Posterior effect size estimate and uncertainty |\n", - "| `cs_95`, `cs_70`, `cs_50` | Which credible set the variant belongs to at each coverage level; empty string = not in any CS |\n", - "| `cs_95_purity` | Min pairwise LD r\u00b2 within the 95% CS; **\u2265 0.5 required** for a credible CS |\n", - "| `method` | Fine-mapping method (`\"susie\"`) |\n", - "| `gene`, `event` | Gene ID and molecular event type |\n", - "| `grange_start`, `grange_end` | Association window boundaries |\n" + "suppressPackageStartupMessages(library(pecotmr))\n", + "\n", + "result <- readRDS(\n", + " \"output_uni/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds\"\n", + ")\n", + "entries <- attr(result, \"listData\")\n", + "entry <- entries$entry[[which(entries$context == \"context1\")]]\n", + "\n", + "top_loci <- attr(entry, \"topLoci\")\n", + "head(\n", + " top_loci[order(top_loci$pip, decreasing = TRUE),\n", + " c(\"variant_id\", \"pip\", \"cs_95\", \"cs_95_purity\")],\n", + " 5\n", + ")\n", + "# variant_id pip cs_95 cs_95_purity\n", + "# chr22:16445263:A:T 0.032 susie_0 0\n", + "# chr22:16418860:A:T 0.031 susie_0 0\n", + "# chr22:16214125:A:T 0.027 susie_0 0\n", + "\n", + "fit <- attr(entry, \"susieFit\")\n", + "length(fit$sets$cs)\n", + "# 0 retained credible sets" ] }, { - "cell_type": "code", - "metadata": { - "kernel": "R", - "tags": [] - }, - "outputs": [], - "execution_count": null, - "source": "suppressPackageStartupMessages(library(pecotmr))\n\n# Load QtlFineMappingResult\nrds <- readRDS(\"output_uni/fine_mapping/protocol_example.ENSG00000130538.univariate_bvsr.rds\")\nclass(rds) # \"QtlFineMappingResult\"\n\nld <- attr(rds, \"listData\")\nld$context # \"context1\" \"context2\"\nld$method # \"susie\" \"susie\"\n\n# --- topLoci: dimensions and column names ---\ne1 <- ld$entry[[1]] # context1\ntl <- attr(e1, \"topLoci\")\n\ndim(tl) # 1024 x 23 (one row per variant in the region)\nnames(tl)\n# [1] \"variant_id\" \"chrom\" \"pos\" \"A1\" \"A2\"\n# [6] \"N\" \"af\" \"marginal_beta\" \"marginal_se\" \"marginal_z\"\n# [11] \"marginal_p\" \"pip\" \"posterior_mean\" \"posterior_sd\" \"cs_95\"\n# [16] \"cs_70\" \"cs_50\" \"cs_95_purity\" \"method\" \"gene\"\n# [21] \"event\" \"grange_start\" \"grange_end\"\n\n# --- Step 1: check for valid credible sets ---\nsf <- attr(e1, \"susieFit\")\nsf$sets$cs # NULL -> no credible set passed purity filter (toy data n=49)\nsf$lbf # 0.027 0.027 0.027 0.028 0.028 -> all near zero -> no detectable signal\n\n# --- Step 2: top variants by PIP ---\ntl_s <- tl[order(tl$pip, decreasing = TRUE), ]\nhead(tl_s[, c(\"variant_id\", \"af\", \"marginal_z\", \"marginal_p\",\n \"pip\", \"cs_95\", \"cs_95_purity\")], 5)\n# variant_id af marginal_z marginal_p pip cs_95 cs_95_purity\n# chr22:16445263:A:T 0.837 3.482 4.99e-04 0.032 susie_0 0\n# chr22:16418860:A:T 0.704 -3.436 5.91e-04 0.031 susie_0 0\n# chr22:16214125:A:T 0.612 3.307 9.42e-04 0.027 susie_0 0\n\n# cs_95 = \"susie_0\" but cs_95_purity = 0 on every row:\n# SuSiE found one CS spanning the whole region (all 1024 SNPs),\n# purity = 0 -> not a meaningful credible set.\n# In real data (n >= 500): expect PIP > 0.5 lead variants\n# and cs_95_purity >= 0.5 with 1-10 SNPs per CS." + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The largest PIPs in context 1 are approximately 0.03, every displayed candidate-set label has purity 0, and SuSiE retains no credible set after filtering. This toy example therefore does not support a localized fine-mapped signal. It demonstrates how to inspect PIPs and credible-set diagnostics, not a biological discovery." + ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "Markdown", - "tags": [] - }, - "outputs": [], - "execution_count": null, + "metadata": {}, "source": [ - "### TWAS Weights Result: `TwasWeights` S4\n", - "\n", - "The TWAS weights RDS holds weights from **all methods \u00d7 all contexts** for one gene.\n", - "Top-level structure via `attr(tw, \"listData\")`:\n", + "### TWAS prediction result\n", "\n", - "| Field | Description |\n", - "|-------|-------------|\n", - "| `study` | Study name |\n", - "| `context` | Context label for each entry (repeated per method) |\n", - "| `trait` | Gene/trait ID |\n", - "| `method` | Method name: `mrash`, `susie`, `susie_inf`, `enet`, `lasso`, `mcp`, `scad`, `l0learn`, `bayes_r`, `bayes_c`, `ensemble` |\n", - "| `entry` | List of `TwasWeightsEntry` S4 objects (N_contexts \u00d7 11 methods total) |\n", + "- `output_uni/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds`\n", "\n", - "Each `TwasWeightsEntry` is accessed via `attr(entry, \"\")` \u2014 **not** `$` notation:\n", + "The RDS contains a `TwasWeights` object. `attr(tw, \"listData\")` gives the study, context, trait, method, and one entry per context-method combination.\n", "\n", - "| Attribute | Description |\n", - "|-----------|-------------|\n", - "| `variantIds` | SNP IDs (`chr:pos:ref:alt`) for all variants in the region |\n", - "| `weights` | **Per-SNP TWAS weights** \u2014 the \u03b2 vector used in Z_TWAS = **w**\u1d40**z** / \u221a(**w**\u1d40R**w**) |\n", - "| `fits` | Fitted model object (class-specific: `mr.ash`, `susie`, `glmnet`, etc.) |\n", - "| `cvPerformance` | CV results \u2014 for per-method entries: `$metrics` with `corr`, `rsq`, `adj_rsq`, `pval`, `RMSE`, `MAE`; for ensemble entry: `$methodCoef` (\u03b6 per method) and `$methodPerformance` (CV R\u00b2 per method) |\n", - "| `standardized` | Whether X/Y were z-score standardized before fitting (default: `FALSE`) |\n", - "\n", - "**CV performance metrics** tell you how well each method predicts expression using out-of-fold cross-validation:\n", - "- `rsq` / `adj_rsq`: cross-validated R\u00b2 \u2014 the primary metric for method quality\n", - "- `corr`: Pearson correlation between predicted and observed expression\n", - "- `pval`: p-value of the cross-validated prediction\n", - "\n", - "**Ensemble `methodCoef`** (\u03b6): non-negative weights summing to 1 that determine how much each method contributes to the final ensemble prediction. `w_ensemble = \u03a3 \u03b6_k \u00d7 w_k`.\n" + "| Entry slot | Contents |\n", + "|---|---|\n", + "| `variantIds` | Variants aligned with the weight vector |\n", + "| `weights` | Per-variant prediction weights |\n", + "| `fits` | Fitted method-specific prediction model |\n", + "| `cvResult` | CV metrics for individual methods; `methodCoef` and `methodPerformance` for the ensemble |\n", + "| `standardized` | Whether genotype and phenotype inputs were standardized |\n", + "| `dataType` | Optional molecular-trait type metadata |" ] }, { @@ -379,25 +243,60 @@ "metadata": {}, "outputs": [], "source": [ - "suppressPackageStartupMessages(library(pecotmr))\n\ntw <- readRDS(\"output_uni/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds\")\nclass(tw) # \"TwasWeights\"\n\nld <- attr(tw, \"listData\")\nunique(ld$context) # \"context1\" \"context2\"\nunique(ld$method) # \"mrash\" \"susie\" \"susie_inf\" \"enet\" \"lasso\" \"mcp\" \"scad\" \"l0learn\" \"bayes_r\" \"bayes_c\" \"ensemble\"\nlength(ld$entry) # 22\n\n# Inspect one entry (context1 / susie)\ne_susie <- ld$entry[ld$context == \"context1\" & ld$method == \"susie\"][[1]]\nwt <- attr(e_susie, \"weights\")\ncat(\"non-zero weights:\", sum(wt != 0), \"/\", length(wt), \"\\n\")\n\nm <- attr(e_susie, \"cvPerformance\")$metrics\nround(m[c(\"corr\",\"rsq\",\"adj_rsq\",\"pval\")], 4)\n# corr rsq adj_rsq pval\n# 0.9798 0.9599 0.9591 0.0000\n\n# Method summary for context1\nidx1 <- which(ld$context == \"context1\")\nfor (i in idx1) {\n e <- ld$entry[[i]]\n m <- tryCatch(attr(e,\"cvPerformance\")$metrics, error=function(e) NULL)\n rsq <- if (!is.null(m) && is.numeric(m)) round(m[\"rsq\"], 3) else NA\n cat(sprintf(\"%-12s rsq=%s\\n\", ld$method[i], rsq))\n}\n# mrash rsq=0.466\n# susie rsq=0.960\n# susie_inf rsq=0.305\n# enet rsq=0.060\n# lasso rsq=0.160\n# mcp rsq=NA\n# scad rsq=0.005\n# l0learn rsq=0.031\n# bayes_r rsq=0.520\n# bayes_c rsq=0.577\n# ensemble rsq=NA\n\n# Ensemble coefficients\nens <- ld$entry[ld$context == \"context1\" & ld$method == \"ensemble\"][[1]]\ncv <- attr(ens, \"cvPerformance\")\nround(cv$methodCoef[cv$methodCoef > 0.001], 3) # bayes_r=0.802, bayes_c=0.198\nround(cv$methodPerformance, 3)" + "suppressPackageStartupMessages(library(pecotmr))\n", + "\n", + "tw <- readRDS(\n", + " \"output_uni/twas_weights/protocol_example.ENSG00000130538.univariate_twas_weights.rds\"\n", + ")\n", + "entries <- attr(tw, \"listData\")\n", + "\n", + "# Inspect the SuSiE predictor for context 1.\n", + "i <- which(entries$context == \"context1\" & entries$method == \"susie\")\n", + "susie_entry <- entries$entry[[i]]\n", + "round(attr(susie_entry, \"cvResult\")$metrics[\n", + " c(\"corr\", \"rsq\", \"adj_rsq\", \"pval\")\n", + "], 4)\n", + "# corr = 0.9798; rsq = 0.9599; adj_rsq = 0.9591; pval < 1e-4\n", + "\n", + "# Compare cross-validated R2 where a method returned CV metrics.\n", + "i <- which(entries$context == \"context1\")\n", + "method_rsq <- sapply(entries$entry[i], function(entry) {\n", + " cv <- attr(entry, \"cvResult\")\n", + " if (!is.list(cv) || is.null(cv$metrics) || !is.numeric(cv$metrics)) {\n", + " return(NA_real_)\n", + " }\n", + " cv$metrics[\"rsq\"]\n", + "})\n", + "setNames(round(method_rsq, 3), entries$method[i])\n", + "\n", + "# Inspect nonzero ensemble coefficients.\n", + "ensemble <- entries$entry[[\n", + " which(entries$context == \"context1\" & entries$method == \"ensemble\")\n", + "]]\n", + "coef <- attr(ensemble, \"cvResult\")$methodCoef\n", + "round(coef[coef > 0.001], 3)\n", + "# bayes_r = 0.955; enet = 0.045" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Interpretation:\n", + "For context 1, the SuSiE predictor has cross-validated R2 = 0.960. The ensemble assigns approximately 0.955 of its coefficient weight to `bayes_r` and 0.045 to `enet`. These values show how to assess prediction performance and ensemble composition. Because the example contains only 49 samples, they should not be treated as stable estimates of out-of-sample accuracy.\n", "\n", - "* `twas_weights$` \u2014 use for TWAS (`Z \u2248 weights \u00b7 LD \u00b7 GWAS z-scores`).\n", - "* `twas_cv_result$performance` \u2014 pick the method with highest `adj_rsq` before applying.\n", - "* `top_loci` in `univariate_bvsr.rds` \u2014 lead variants and credible-set coverages.\n", - "* `susie_result_trimmed$sets$cs` \u2014 indices of variants in each 95% credible set.\n", + "Fine-mapping and TWAS answer different questions. Fine-mapping evaluates which variants are supported within the regional model; TWAS evaluates how well cis-genotypes predict the molecular trait. Before downstream TWAS, confirm allele alignment and validate prediction performance in an adequately sized dataset. A TWAS association does not by itself establish mediation or causality." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Limitations and common pitfalls\n", "\n", - "### Common pitfalls\n", "\n", "* **Sample-ID drift.** The phenotype BED's header columns (5+), the bfile FID/IID, and\n", " the covariate TSV header must all be drawn from the same set. Sos does not warn on\n", - " missing samples \u2014 it silently drops them and may report zero overlap.\n", + " missing samples — it silently drops them and may report zero overlap.\n", "* **Empty regions.** If a region has no variants in its association window (e.g. the\n", " manifest points at a window with no bfile coverage) sos marks it completed with an\n", " empty output. Verify the expected file count in the `INFO: susie_twas output:` line.\n", @@ -405,6 +304,16 @@ " passed the customized windows win. Pass `--cis-window -1` to force the customized\n", " path explicitly.\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Next steps\n", + "Use the [fine-mapping and TWAS mini-protocol](https://statfungen.github.io/xqtl-protocol/mnm_miniprotocol.html) to choose among univariate, multivariate, functional, multi-gene, and summary-statistic routes. Refer to [`mnm_regression.ipynb`](https://statfungen.github.io/xqtl-protocol/code/mnm_analysis/mnm_methods/mnm_regression.html) for the complete command interface and parameter defaults.\n", + "\n", + "After validating credible sets and cross-validated prediction performance, the TWAS weights can enter the GWAS-integration workflows. Fine-mapping PIPs and TWAS associations answer different questions and should not be treated as interchangeable evidence." + ] } ], "metadata": { @@ -414,9 +323,12 @@ "name": "bash" }, "language_info": { + "codemirror_mode": "shell", + "file_extension": ".sh", + "mimetype": "text/x-sh", "name": "bash" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/molecular_phenotypes/QC/apa_impute.ipynb b/code/SoS/molecular_phenotypes/QC/apa_impute.ipynb index ed8c18d9e..546ed9e1a 100644 --- a/code/SoS/molecular_phenotypes/QC/apa_impute.ipynb +++ b/code/SoS/molecular_phenotypes/QC/apa_impute.ipynb @@ -7,15 +7,62 @@ }, "source": [ "# Post-APA calling: Imputation and QC\n", - "## Description\n", - "This notebook is designed to impute the missing values in the PDUI matrix, and perform quantile normailization for the impute values.\n", + "\n", + "Fills the missing values in a PDUI matrix and quantile-normalises the result." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", + "\n", + "Alternative polyadenylation is quantified as PDUI, the fraction of transcripts using the distal poly(A) site. DaPars leaves gaps wherever a gene had too little coverage in a sample to call that fraction, and downstream models need a complete matrix.\n", + "\n", + "This step imputes those gaps with the `impute` package and quantile-normalises the filled matrix so samples are on a common scale. A second, optional workflow renames the sample columns from DaPars internal IDs to the names used elsewhere in the study.\n", + "\n", + "**When to run it.** After APA calling, before the association scan." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ "## Input\n", - "* raw PDUI matrix (row as gene, columns as sample id)\n", - "* covariate file \n", "\n", + "- `--cwd`: the DaPars working directory, holding one `apa_{chr}/` subdirectory per chromosome with the raw `Dapars_result_result_temp.{chr}.txt` PDUI matrix in it. Genes are rows, samples are columns. Required.\n", + "- `--chrlist`: the chromosomes to process, one or more values. Required.\n", + "- `--match`, used by `APArename` only: a two-column table mapping the DaPars project IDs to the sample names to use instead. Example `input/covariate/protocol_example.apa_matchtable.txt`:\n", + "\n", + " ```\n", + " ProjID SampleID\n", + " Sample001 SampleA\n", + " ```\n", + "\n", + "- `--modular-script-dir`: the `code/script` directory holding the analysis scripts.\n", + "- `--thread`, `--ncore`, `--job-size`, `--walltime`, `--mem`: job resources.\n", + "- `--container`: the image to run in." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ "## Output\n", - "* PDUI matrix without missingness \n", - " - The missing value is calculated using `impute` package" + "\n", + "- `{cwd}/apa_{chr}/Dapars_result_impute_{chr}.bed` - the imputed, quantile-normalised PDUI matrix for one chromosome, from `APAimpute`.\n", + "- `{cwd}/apa_{chr}/Dapars_result_impute_renamed_{chr}.bed` - the same matrix with sample columns relabelled, from `APArename`.\n", + "- `{cwd}/Dapars_allchrom.bed` and `{cwd}/Dapars_allchrom_renamed.bed` - the per-chromosome results concatenated, the second bgzipped and tabix-indexed as `Dapars_allchrom_renamed.bed.gz` with a `.tbi`. Example `output/apa/Dapars_allchrom_renamed.bed.gz`, 4 columns and 1 rows:\n", + "\n", + " ```\n", + " #chr start end Gene\n", + " ```" ] }, { @@ -24,7 +71,9 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example\n", + "\n", + "Two workflows: `APAimpute` fills and normalises the matrix, and `APArename` optionally relabels its columns. Run the first; run the second only if the DaPars sample IDs need mapping to your own names." ] }, { @@ -33,7 +82,16 @@ "kernel": "SoS" }, "source": [ - "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." + "### Impute and normalise" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -55,9 +113,20 @@ "kernel": "SoS" }, "source": [ + "### Rename the sample columns\n", + "\n", "Optionally, rename the sample columns of the imputed PDUI matrix using a match table (maps the Dapars sample IDs to your desired sample names):" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -78,7 +147,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -98,7 +167,46 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation" + "```\n", + "\u001b[91mERROR\u001b[0m: \u001b[91mNotebook JSON is invalid: %s\u001b[0m\n", + "usage: sos run code/SoS/molecular_phenotypes/QC/apa_impute.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " APAimpute\n", + " APArename\n", + "\n", + "Global Workflow Options:\n", + " --walltime 40h\n", + " --mem 32G\n", + " --ncore 16 (as int)\n", + " --cwd VAL (as path, required)\n", + " --modular-script-dir code/script (as path)\n", + " --thread 8 (as int)\n", + " --job-size 1 (as int)\n", + " --container ''\n", + "\n", + "Sections\n", + " APAimpute:\n", + " Workflow Options:\n", + " --chrlist VAL VAL ... (as type, required)\n", + " APArename_1:\n", + " Workflow Options:\n", + " --match VAL (as path, required)\n", + " --chrlist VAL VAL ... (as type, required)\n", + " APArename_2:\n", + " Workflow Options:\n", + " --match VAL (as path, required)\n", + " --chrlist VAL VAL ... (as type, required)\n", + " APArename_3:\n", + " Workflow Options:\n", + " --match 'input/covariate/protocol_example.apa_matchtable.txt'\n", + " APArename_4:\n", + "```" ] }, { @@ -107,9 +215,7 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "## Workflow implementation" ] }, { @@ -119,7 +225,17 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\nparameter: walltime = '40h'\nparameter: mem = '32G'\nparameter: ncore = 16\nparameter: cwd = path\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\nparameter: thread = 8\nparameter: job_size = 1\nparameter: container = ''" + "source": [ + "[global]\n", + "parameter: walltime = '40h'\n", + "parameter: mem = '32G'\n", + "parameter: ncore = 16\n", + "parameter: cwd = path\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "parameter: thread = 8\n", + "parameter: job_size = 1\n", + "parameter: container = ''" + ] }, { "cell_type": "code", @@ -128,7 +244,17 @@ "kernel": "SoS" }, "outputs": [], - "source": "[APAimpute]\nparameter: chrlist = list\ninput: [f'{cwd}/apa_{x}/Dapars_result_result_temp.{x}.txt' for x in chrlist]\noutput: [f'{cwd}/apa_{x}/Dapars_result_impute_{x}.bed' for x in chrlist]\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = ncore\nbash: expand= \"${ }\"\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step impute \\\n --cwd ${cwd} \\\n --chrlist \"${chrlist}\"" + "source": [ + "[APAimpute]\n", + "parameter: chrlist = list\n", + "input: [f'{cwd}/apa_{x}/Dapars_result_result_temp.{x}.txt' for x in chrlist]\n", + "output: [f'{cwd}/apa_{x}/Dapars_result_impute_{x}.bed' for x in chrlist]\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = ncore\n", + "bash: expand= \"${ }\"\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step impute \\\n", + " --cwd ${cwd} \\\n", + " --chrlist \"${chrlist}\"" + ] }, { "cell_type": "code", @@ -137,7 +263,19 @@ "kernel": "SoS" }, "outputs": [], - "source": "[APArename_1]\nparameter: match = path\nparameter: chrlist = list\ninput: [f'{cwd}/apa_{x}/Dapars_result_impute_{x}.bed' for x in chrlist], group_by = 1\noutput: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed' for x in chrlist], group_by = 1\nbash: expand= \"${ }\"\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step rename \\\n --input \"${_input}\" \\\n --match \"${match}\" \\\n --output \"${_output}\" \\\n --update-end" + "source": [ + "[APArename_1]\n", + "parameter: match = path\n", + "parameter: chrlist = list\n", + "input: [f'{cwd}/apa_{x}/Dapars_result_impute_{x}.bed' for x in chrlist], group_by = 1\n", + "output: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed' for x in chrlist], group_by = 1\n", + "bash: expand= \"${ }\"\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step rename \\\n", + " --input \"${_input}\" \\\n", + " --match \"${match}\" \\\n", + " --output \"${_output}\" \\\n", + " --update-end" + ] }, { "cell_type": "code", @@ -146,7 +284,17 @@ "kernel": "SoS" }, "outputs": [], - "source": "[APArename_2]\nparameter: match = path\nparameter: chrlist = list\ninput: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed' for x in chrlist], group_by = 1\noutput: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed.gz' for x in chrlist], group_by = 1\nbash: expand= \"${ }\"\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step bgzip_index \\\n --input \"${_input}\" \\\n --output \"${_output}\"" + "source": [ + "[APArename_2]\n", + "parameter: match = path\n", + "parameter: chrlist = list\n", + "input: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed' for x in chrlist], group_by = 1\n", + "output: [f'{cwd}/apa_{x}/Dapars_result_impute_renamed_{x}.bed.gz' for x in chrlist], group_by = 1\n", + "bash: expand= \"${ }\"\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step bgzip_index \\\n", + " --input \"${_input}\" \\\n", + " --output \"${_output}\"" + ] }, { "cell_type": "code", @@ -155,7 +303,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[APArename_3]\nparameter: match = \"input/covariate/protocol_example.apa_matchtable.txt\" #path\ninput: f'{cwd}/Dapars_allchrom.bed'\noutput: f'{cwd}/Dapars_allchrom_renamed.bed'\nbash: expand= \"${ }\"\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step rename \\\n --input \"${_input}\" \\\n --match \"${match}\" \\\n --output \"${_output}\"\n\n[APArename_4]\noutput: f'{_input}.gz', f'{_input}.gz.tbi'\nbash: expand = \"${ }\"\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step bgzip_index \\\n --input \"${_input}\" \\\n --output \"${_output[0]}\"" + "source": [ + "[APArename_3]\n", + "parameter: match = \"input/covariate/protocol_example.apa_matchtable.txt\" #path\n", + "input: f'{cwd}/Dapars_allchrom.bed'\n", + "output: f'{cwd}/Dapars_allchrom_renamed.bed'\n", + "bash: expand= \"${ }\"\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step rename \\\n", + " --input \"${_input}\" \\\n", + " --match \"${match}\" \\\n", + " --output \"${_output}\"\n", + "\n", + "[APArename_4]\n", + "output: f'{_input}.gz', f'{_input}.gz.tbi'\n", + "bash: expand = \"${ }\"\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/apa_impute.R --step bgzip_index \\\n", + " --input \"${_input}\" \\\n", + " --output \"${_output[0]}\"" + ] } ], "metadata": { @@ -194,4 +359,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/molecular_phenotypes/QC/bulk_expression_QC.ipynb b/code/SoS/molecular_phenotypes/QC/bulk_expression_QC.ipynb index 5f6b9e62c..1ec99597f 100644 --- a/code/SoS/molecular_phenotypes/QC/bulk_expression_QC.ipynb +++ b/code/SoS/molecular_phenotypes/QC/bulk_expression_QC.ipynb @@ -6,43 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Sample-level RNA-seq quality control" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Sample-level QC of a bulk RNA-seq expression matrix, following the [GTEx V8](https://gtexportal.org/home/aboutGTEx#staticTextAnalysisMethods) approach. It runs in two parts: `qc_1` removes low-expression genes (genes expressed below the TPM threshold in too many samples), and `qc_2` detects and removes outlier samples using three checks (a D-statistic histogram, a Relative Log Expression (RLE) plot, and hierarchical clustering). A raw count matrix, if provided, is filtered to the same genes and samples as the QC'd TPM matrix." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "**Timing:** ~2-5 min on typical compute infrastructure." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Input Files" + "# Sample-level RNA-seq quality control\n", + "\n", + "Sample-level quality control for a bulk expression matrix, applied before normalisation." ] }, { @@ -51,12 +17,20 @@ "kernel": "SoS" }, "source": [ - "| Parameter | Example (toy) | Description |\n", - "|---|---|---|\n", - "| `--tpm-gct` | `input/rnaseq/protocol_example.rnaseq.tpm_matrix.bed` | Gene expression in TPM; gene ID in the first column, one column per sample. Required. |\n", - "| `--counts-gct` | `input/rnaseq/protocol_example.rnaseq.count_matrix.bed` | Raw gene count matrix. Optional; if given it is filtered to match the QC'd TPM genes/samples. |\n", + "## Overview\n", + "\n", + "Before normalisation it is worth asking whether every sample in the matrix belongs there.\n", + "This step applies sample-level quality control to a bulk expression matrix - flagging\n", + "samples whose overall expression profile is inconsistent with the rest of the cohort, which\n", + "usually means a library preparation or labelling problem rather than biology.\n", + "\n", + "Dropping such samples here matters more than it looks: they inflate the residual variance\n", + "in the association scan and can distort the hidden-factor covariates estimated downstream.\n", + "\n", + "Sample-level QC of a bulk RNA-seq expression matrix, following the [GTEx V8](https://gtexportal.org/home/aboutGTEx#staticTextAnalysisMethods) approach. It runs in two parts: `qc_1` removes low-expression genes (genes expressed below the TPM threshold in too many samples), and `qc_2` detects and removes outlier samples using three checks (a D-statistic histogram, a Relative Log Expression (RLE) plot, and hierarchical clustering). A raw count matrix, if provided, is filtered to the same genes and samples as the QC'd TPM matrix.\n", "\n", - "The toy inputs are symlinks under `input/` pointing into the bundled toy dataset." + "**When to run it.** After expression quantification, before normalisation and covariate\n", + "preprocessing." ] }, { @@ -65,7 +39,38 @@ "kernel": "SoS" }, "source": [ - "## Output Files" + "## Input\n", + "- `--tpm-gct` **`input/rnaseq/protocol_example.rnaseq.tpm_matrix.bed`**\n", + "(gene expression in TPM; gene ID in the first column, one column per sample. Required.)\n", + "\n", + "```\n", + "gene_ID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMPLE_007\t...\n", + "ENSG00000284070\t4.46908614068004\t3.6324384389436\t0\t0.926449274182614\t8.44864560635242\t16.3456237133014\t4.07740959667351\t...\n", + "ENSG00000273342\t0\t19.892726241898\t13.6287618206549\t28.5428919916226\t10.1099209273507\t17.0947587639983\t0\t...\n", + "```\n", + "\n", + "- `--counts-gct` **`input/rnaseq/protocol_example.rnaseq.count_matrix.bed`**\n", + "(raw gene count matrix. Optional; if given it is filtered to match the QC'd TPM genes and samples.)\n", + "\n", + "```\n", + "gene_ID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMPLE_007\t...\n", + "ENSG00000284070\t197\t193\t122\t180\t217\t257\t195\t...\n", + "ENSG00000273342\t80\t274\t243\t318\t226\t260\t133\t...\n", + "```\n", + "\n", + "- `--cwd output/rnaseq` (working directory all outputs are written under. Defaults to `output`.)\n", + "- `--container` (an empty string runs the workflow with the locally installed tools instead of a container)\n", + "\n", + "The filtering thresholds all have defaults and only need setting to override them:\n", + "\n", + "- `--low-expr-TPM 0.1` (a gene must exceed this TPM to count as expressed)\n", + "- `--low-expr-TPM-percent 0.2` (a gene is kept only if it is expressed in at least this fraction of samples)\n", + "- `--RLEFilterPercent 0.05` (fraction of samples dropped by the relative log expression filter)\n", + "- `--DSFilterPercent 0.05` (fraction of samples dropped by the D-statistic filter. For a small cohort raise it, e.g. `0.1`, so a single sample is not over-flagged.)\n", + "- `--topk-genes 100` (number of top-expressed genes used for the sample clustering check)\n", + "- `--cluster-percent 0.6` (fraction of the top genes a sample must share to join a cluster)\n", + "- `--pvalue-cutoff 0.05` (significance threshold for the outlier test)\n", + "- `--cluster-level 5` (tree depth at which clusters are cut)" ] }, { @@ -74,18 +79,24 @@ "kernel": "SoS" }, "source": [ - "Written to `--cwd` (`output/rnaseq/`). The output basename is taken from the TPM input name truncated at the first dot, so here it is `protocol_example`:\n", + "## Output\n", + "\n", + "- **`protocol_example.low_expression_filtered.tpm.gct.gz`** (`qc_1`)\n", + "(TPM matrix after low-expression gene filtering. All outputs go to `--cwd`; the basename comes from the TPM input name truncated at the first dot, so here it is `protocol_example`.)\n", + "- **`protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz`** (`qc_2`)\n", + "(TPM matrix after outlier-sample removal)\n", + "- **`protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz`** (`qc_3`)\n", + "(raw count matrix filtered to the same genes and samples)\n", + "\n", + "Two diagnostic plots are also written but are not declared in any step `output:` statement, so SoS does not track them:\n", "\n", - "| File | Description |\n", - "|---|---|\n", - "| `protocol_example.low_expression_filtered.tpm.gct.gz` | TPM matrix after low-expression gene filtering (`qc_1`). |\n", - "| `protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz` | TPM matrix after outlier-sample removal (`qc_2`). |\n", - "| `protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz` | Raw count matrix filtered to the same genes/samples. |\n", - "| `protocol_example.low_expression_filtered.outlier_removed.tpm.gct.D_stat_hist.pdf` | D-statistic histogram diagnostic plot. |\n", - "| `protocol_example.low_expression_filtered.outlier_removed.tpm.gct.RLEplot.pdf` | Relative Log Expression diagnostic plot. |\n", - "| `protocol_example.low_expression_filtered.outlier_removed.tpm.gct.preQC_cluster.pdf` | Sample clustering diagnostic plot. |\n", + "- **`protocol_example.low_expression_filtered.outlier_removed.tpm.gct.RLEplot.pdf`** (relative log expression plot)\n", + "- **`protocol_example.low_expression_filtered.outlier_removed.tpm.gct.D_stat_hist.pdf`** (D-statistic histogram; not present in the example output)\n", "\n", - "The `outlier_removed.tpm.gct.gz` file is the input to multi-sample normalization." + "The `qc_3` step additionally:\n", + "\n", + "1. Filter out the geneCount table based on TPM table.\n", + "2. Adds two comment lines above the header of TPM and geneCount table to mimick the original output from RNASeQC." ] }, { @@ -94,7 +105,7 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example" ] }, { @@ -103,7 +114,7 @@ "kernel": "SoS" }, "source": [ - "**Note:** `DSFilterPercent` defaults to `0.05`; for the small toy cohort it can be raised (e.g. `0.1`) so a single sample is not over-flagged. `--container ''` makes the workflow use the locally installed tools." + "**Timing**: ~2-5 min (on toy dataset)" ] }, { @@ -126,14 +137,14 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ @@ -146,17 +157,62 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation" + "```\n", + "usage: sos run pipeline/bulk_expression_QC.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " qc\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --tpm-gct VAL (as path, required)\n", + " Required input is TPM file\n", + " --counts-gct . (as path)\n", + " Raw counts file is optional and if available, it will be\n", + " filtered to match with the TPM file sample and genes\n", + " --cwd output (as path)\n", + " --container ''\n", + " --entrypoint ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " qc_1:\n", + " Workflow Options:\n", + " --low-expr-TPM 0.1 (as float)\n", + " --low-expr-TPM-percent 0.2 (as float)\n", + " qc_2:\n", + " Workflow Options:\n", + " --RLEFilterPercent 0.05 (as float)\n", + " --DSFilterPercent 0.05 (as float)\n", + " --topk-genes 100 (as int)\n", + " --cluster-percent 0.6 (as float)\n", + " --pvalue-cutoff 0.05 (as float)\n", + " --cluster-level 5 (as int)\n", + " qc_3:\n", + "```" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "outputs": [], - "source": "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# Required input is TPM file\nparameter: tpm_gct = path\n# Raw counts file is optional and if available, it will be filtered to match with the TPM file sample and genes\nparameter: counts_gct = path()\nparameter: cwd = path(\"output\")\nparameter: container = \"\"\nimport re\nparameter: entrypoint= ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\ncwd = path(f'{cwd:a}')\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n\n# Number of threads\nparameter: numThreads = 8" + "source": [ + "## Workflow implementation" + ] }, { "cell_type": "code", @@ -165,16 +221,51 @@ "kernel": "SoS" }, "outputs": [], - "source": "[qc_1 (basic check and low expression filtering)]\nparameter: low_expr_TPM = 0.1\nparameter: low_expr_TPM_percent = 0.2\ninput: tpm_gct\noutput: f'{cwd}/{_input:bnnn}.low_expression_filtered.tpm.gct.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output:nnn}.stderr', stdout = f'{_output:nnn}.log', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n --step qc_1 \\\n --cwd \"${cwd}\" \\\n --tpm-gct \"${_input}\" \\\n --low-expr-TPM ${low_expr_TPM} \\\n --low-expr-TPM-percent ${low_expr_TPM_percent} \\\n --numThreads ${numThreads}\n" + "source": [ + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# Required input is TPM file\n", + "parameter: tpm_gct = path\n", + "# Raw counts file is optional and if available, it will be filtered to match with the TPM file sample and genes\n", + "parameter: counts_gct = path()\n", + "parameter: cwd = path(\"output\")\n", + "parameter: container = \"\"\n", + "import re\n", + "parameter: entrypoint= ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "cwd = path(f'{cwd:a}')\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "\n", + "# Number of threads\n", + "parameter: numThreads = 8" + ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "**CAUTION: I (GW) am not sure what to do with the offset for log-transformation on TPM. GTEx suggests using offset = 1. Here I keep the recommendation from [these authors](https://github.com/stormlovetao/eQTLQC/blob/master/Sample/src/report.Rmd) where both 0.0001 and 1 were used in different steps.**\n", - "\n" + "[qc_1 (basic check and low expression filtering)]\n", + "parameter: low_expr_TPM = 0.1\n", + "parameter: low_expr_TPM_percent = 0.2\n", + "input: tpm_gct\n", + "output: f'{cwd}/{_input:bnnn}.low_expression_filtered.tpm.gct.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output:nnn}.stderr', stdout = f'{_output:nnn}.log', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n", + " --step qc_1 \\\n", + " --cwd \"${cwd}\" \\\n", + " --tpm-gct \"${_input}\" \\\n", + " --low-expr-TPM ${low_expr_TPM} \\\n", + " --low-expr-TPM-percent ${low_expr_TPM_percent} \\\n", + " --numThreads ${numThreads}\n" ] }, { @@ -183,9 +274,7 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "**Caution.** The offset used for the log transformation on TPM is unresolved. GTEx suggests an offset of 1; the recommendation kept here follows [these authors](https://github.com/stormlovetao/eQTLQC/blob/master/Sample/src/report.Rmd), where both 0.0001 and 1 are used at different steps." ] }, { @@ -195,19 +284,59 @@ "kernel": "SoS" }, "outputs": [], - "source": "[qc_2 (remove outliers)]\nparameter: RLEFilterPercent = 0.05\nparameter: DSFilterPercent = 0.05\nparameter: topk_genes = 100\nparameter: cluster_percent = 0.6\nparameter: pvalue_cutoff = 0.05\nparameter: cluster_level = 5\noutput: f'{cwd}/{_input:bnnn}.outlier_removed.tpm.gct.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output:nnn}.stderr', stdout = f'{_output:nnn}.log', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n --step qc_2 \\\n --cwd \"${cwd}\" \\\n --tpm-gct \"${_input}\" \\\n --RLEFilterPercent ${RLEFilterPercent} \\\n --DSFilterPercent ${DSFilterPercent} \\\n --topk-genes ${topk_genes} \\\n --cluster-percent ${cluster_percent} \\\n --pvalue-cutoff ${pvalue_cutoff} \\\n --cluster-level ${cluster_level} \\\n --numThreads ${numThreads}\n" + "source": [ + "[qc_2 (remove outliers)]\n", + "parameter: RLEFilterPercent = 0.05\n", + "parameter: DSFilterPercent = 0.05\n", + "parameter: topk_genes = 100\n", + "parameter: cluster_percent = 0.6\n", + "parameter: pvalue_cutoff = 0.05\n", + "parameter: cluster_level = 5\n", + "output: f'{cwd}/{_input:bnnn}.outlier_removed.tpm.gct.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output:nnn}.stderr', stdout = f'{_output:nnn}.log', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n", + " --step qc_2 \\\n", + " --cwd \"${cwd}\" \\\n", + " --tpm-gct \"${_input}\" \\\n", + " --RLEFilterPercent ${RLEFilterPercent} \\\n", + " --DSFilterPercent ${DSFilterPercent} \\\n", + " --topk-genes ${topk_genes} \\\n", + " --cluster-percent ${cluster_percent} \\\n", + " --pvalue-cutoff ${pvalue_cutoff} \\\n", + " --cluster-level ${cluster_level} \\\n", + " --numThreads ${numThreads}\n" + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "### **Step (added from upstream):** `qc_3`" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Remove genes and samples from raw counts" + ] }, { "cell_type": "code", - "metadata": {}, - "outputs": [], "execution_count": null, - "source": "[qc_3 (remove gene and samples from raw counts)]\nstop_if(not counts_gct.is_file())\noutput: f'{cwd}/{_input:bnnn}.geneCount.gct.gz'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout', container = container, entrypoint = entrypoint\n Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n --step qc_3 \\\n --cwd \"${cwd}\" \\\n --tpm-gct \"${_input}\" \\\n --counts-gct \"${counts_gct}\" \\\n --numThreads ${numThreads}\n" + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "[qc_3 (remove gene and samples from raw counts)]\n", + "stop_if(not counts_gct.is_file())\n", + "output: f'{cwd}/{_input:bnnn}.geneCount.gct.gz'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout', container = container, entrypoint = entrypoint\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/QC/bulk_expression_QC.R \\\n", + " --step qc_3 \\\n", + " --cwd \"${cwd}\" \\\n", + " --tpm-gct \"${_input}\" \\\n", + " --counts-gct \"${counts_gct}\" \\\n", + " --numThreads ${numThreads}\n" + ] } ], "metadata": { @@ -251,4 +380,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/molecular_phenotypes/QC/bulk_expression_normalization.ipynb b/code/SoS/molecular_phenotypes/QC/bulk_expression_normalization.ipynb index 6d7c5e500..0e8abfbad 100644 --- a/code/SoS/molecular_phenotypes/QC/bulk_expression_normalization.ipynb +++ b/code/SoS/molecular_phenotypes/QC/bulk_expression_normalization.ipynb @@ -8,7 +8,8 @@ }, "source": [ "# Bulk RNA-seq counts normalization\n", - "\n" + "\n", + "Filters out lowly expressed genes and normalizes the RNA-seq count matrix into the molecular phenotype BED file used for QTL analysis." ] }, { @@ -17,7 +18,15 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "The single `normalize` workflow follows the GTEx pipeline. Genes are kept only when they clear both expression thresholds in a minimum fraction of samples: TPM at or above `--tpm-threshold` (0.1 by default) in at least `--sample-frac-threshold` of samples (0.2), and raw read count at or above `--count-threshold` (6) in at least that same fraction. Both conditions must hold, so a gene that is highly expressed in a handful of samples and absent elsewhere is dropped.\n", + "\n", + "What survives is then rescaled. `--normalization-method` selects between TMM followed by CPM through voom (`tmm_cpm_voom`, the default), TMM followed by CPM through edgeR (`tmm_cpm_edger`), and quantile normalization across samples (`qn`). Separately, `--quantile-normalize` is on by default and applies a per-gene inverse-normal transform after rescaling, which is what makes the distribution of each gene comparable across genes rather than across samples. Turning it off adds `no_qnorm` to the output file name, so the two variants never collide.\n", + "\n", + "Sample identifiers are translated on the way out: `--sample-participant-lookup` maps expression sample names to the genotype sample names, so the resulting BED can be matched against genotypes directly. Gene IDs are stripped of their Ensembl version suffix.\n", + "\n", + "**When to run it.** After `bulk_expression_QC`, which produces the filtered and outlier-removed TPM and count matrices this step consumes, and before covariate preprocessing and the association scan." ] }, { @@ -26,12 +35,41 @@ "kernel": "SoS" }, "source": [ + "## Input\n", + "\n", + "* `--tpm-gct` -- the TPM matrix in RNA-SeQC GCT format, from `bulk_expression_QC`, e.g. `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz`. The first two lines are the GCT version and matrix dimensions, the third the sample header:\n", + "\n", + " ```\n", + " #1.2\n", + " # 300 54\n", + " gene_ID\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMPLE_007\tSAM\n", + " ```\n", + "\n", + "* `--counts-gct` -- the raw read-count matrix in the same GCT format and from the same step, e.g. `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz`. It must cover the same genes and samples as the TPM matrix.\n", + "* `--annotation-gtf` -- the collapsed gene model, e.g. `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf`, from `reference_data_preparation`. It supplies the chromosome and position written into the output BED, so its gene names must match the matrices and use the `chr` prefix.\n", + "* `--sample-participant-lookup` -- tab-delimited table with a header and two columns, `sample_id` and `participant_id`, mapping expression sample names to genotype sample names; the two may be identical. Every sample in the matrices has to appear here:\n", + "\n", + " ```\n", + " sample_id\tparticipant_id\n", + " SAMPLE_001\tSAMPLE_001\n", + " SAMPLE_002\tSAMPLE_002\n", + " ```\n", + "\n", + "* `--cwd` -- output directory, default `output`.\n", "\n", + "Filtering and normalization:\n", "\n", + "* `--tpm-threshold` -- minimum TPM, default `0.1`.\n", + "* `--count-threshold` -- minimum read count, default `6`. The example below lowers it to `1` because the toy matrix is small.\n", + "* `--sample-frac-threshold` -- fraction of samples that must clear both thresholds, default `0.2`.\n", + "* `--normalization-method` -- `tmm_cpm_voom` (default), `tmm_cpm_edger`, or `qn`.\n", + "* `--quantile-normalize` / `--no-quantile-normalize` -- per-gene inverse-normal transform after rescaling, on by default.\n", "\n", + "Runtime:\n", "\n", - "The normalization step follows steps used by the GTeX pipeline. Genes are first filtered to keep genes where TPM is greater than 10% in at least 20% of the samples. They are also kept if read counts is greater than 6 in at least 20% of the samples. The filtered data is then normalized using the Trimmed Mean of M-value (TMM) method. \n", - "\n" + "* `--numThreads`, `--job-size`, `--walltime`, `--mem` -- threads (default `20`) and cluster resources.\n", + "* `--container`, `--entrypoint` -- software environment.\n", + "* `--modular-script-dir` -- location of the R driver, default `code/script`." ] }, { @@ -40,7 +78,17 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~1-2 min on typical compute infrastructure." + "## Output\n", + "\n", + "* `..expression.bed.gz` -- the normalized expression matrix in BED layout: `#chr`, `start`, `end` and `gene_id`, then one column per sample, named with the genotype IDs from the look-up table. `no_qnorm` is inserted before `expression` when `--no-quantile-normalize` is used. This file is the molecular phenotype consumed by the QTL and TWAS workflows:\n", + "\n", + " ```\n", + " #chr\tstart\tend\tgene_id\tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\n", + " chr22\t10939387\t10961338\tENSG00000283047\t2.092837798505774\t-1.4557760251170175\t0.16019524\n", + " chr22\t15528191\t15529139\tENSG00000130538\t-1.6022926552158765\t-0.2065470244188349\t0.498428\n", + " ```\n", + "\n", + "The step also writes `.stdout` and `.stderr` beside its output. Example results for the toy data are under `output/rnaseq/`." ] }, { @@ -49,14 +97,7 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", - "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz` | TPM matrix in RNA-SeQC GCT format (output of `bulk_expression_QC`) |\n", - "| `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz` | Read-count matrix in GCT format (output of `bulk_expression_QC`) |\n", - "| `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` | Collapsed gene-model GTF; gene names must match the GCT matrices and use the `chr` prefix |\n", - "| `input/rnaseq/protocol_example.rnaseq.sample_participant_lookup.txt` | Tab-delimited, header, two columns mapping expression sample name to genotype sample name (must cover every sample in the matrices) |" + "## Minimal Working Example" ] }, { @@ -65,9 +106,19 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "### Filter and normalize the QC-ed matrices\n", "\n", - "Filter and TMM-normalize the QC-ed count/TPM matrices into a phenotype `bed.gz`. The inputs here are the outputs of the `bulk_expression_QC` step; `--count-threshold` sets the minimum read count used in the GTeX-style gene filter." + "The TPM and count matrices are the output of `bulk_expression_QC`. `--count-threshold 1` relaxes the default of 6, which few genes would clear in a toy matrix this small." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: ~1-2 min (on toy dataset)" ] }, { @@ -93,53 +144,7 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", - "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tmm_cpm_voom.expression.bed.gz` | TMM/CPM/voom-normalized expression matrix in BED format (`#chr`, `start`, `end`, `gene_id`, then one column per sample); ready as a molecular phenotype for QTL/TWAS analysis |" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Troubleshooting" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "|------|---------|---------|------------------|---------|\n", - "| | | | | |\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Command interface" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "## Command Interface" ] }, { @@ -204,7 +209,76 @@ } ], "source": [ - "!sos run bulk_expression_normalization.ipynb -h" + "sos run pipeline/bulk_expression_normalization.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/bulk_expression_normalization.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " normalize\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " Work directory & output directory\n", + " --counts-gct VAL (as path, required)\n", + " gene count table\n", + " --tpm-gct VAL (as path, required)\n", + " gene TPM table\n", + " --annotation-gtf VAL (as path, required)\n", + " gene gtf annotation table\n", + " --sample-participant-lookup VAL (as path, required)\n", + " A file to map sample ID from expression to genotype,must\n", + " contain two columns, sample_id and participant_id,\n", + " mapping IDs in the expression files to IDs in the\n", + " genotype (these can be the same).\n", + " --tpm-threshold 0.1 (as float)\n", + " --count-threshold 6 (as int)\n", + " --sample-frac-threshold 0.2 (as float)\n", + " --normalization-method 'tmm_cpm_voom'\n", + " Normalization method: TMM + CPM(voom) (tmm_cpm_voom),\n", + " TMM + CPM(edgeR) (tmm_cpm_edger), or quantile\n", + " normalization (qn)\n", + " --[no-]quantile-normalize (default to True)\n", + " Quantile Normalization after rescale\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 20 (as int)\n", + " Number of threads\n", + " --container ''\n", + " --entrypoint ('micromamba run -a \"\" -n' + ' ' + re.sub(r'(_apptainer:latest|_docker:latest|\\.sif)$', '', container.split('/')[-1])) if container else \"\"\n", + "\n", + "\n", + "Sections\n", + " normalize:\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation\n", + "\n", + "The SoS workflow definitions below are unchanged from the original protocol." ] }, { diff --git a/code/SoS/molecular_phenotypes/QC/pseudobulk_preprocessing.ipynb b/code/SoS/molecular_phenotypes/QC/pseudobulk_preprocessing.ipynb index 616a411bf..6a8b8e042 100644 --- a/code/SoS/molecular_phenotypes/QC/pseudobulk_preprocessing.ipynb +++ b/code/SoS/molecular_phenotypes/QC/pseudobulk_preprocessing.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Single-nuclei Pseudobulk Preprocessing (RNA-seq and ATAC-seq)\n" + "# Single-nuclei Pseudobulk Preprocessing (RNA-seq and ATAC-seq)\n", + "\n", + "Aggregates per-nucleus single-cell counts into per-sample pseudobulk matrices, for RNA-seq and ATAC-seq." ] }, { @@ -15,7 +17,7 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", "Single-nuclei pseudobulk preprocessing for RNA-seq and ATAC-seq. Aggregates per-nucleus counts into per-sample pseudobulk matrices, harmonizes sample IDs, and regresses out technical covariates to produce QTL-ready phenotype values.\n", "\n", @@ -24,14 +26,17 @@ "- `sampleid_mapping` -- remap `individualID` headers to standardized `sampleid` across metadata and count matrices.\n", "- `pseudobulk_qc` -- filter, TMM-normalize, fit a technical-covariate model, and write residuals.\n", "\n", - "(`phenotype_formatting` reformats residuals into a BED for snATAC-seq caQTL mapping.)" + "(`phenotype_formatting` reformats residuals into a BED for snATAC-seq caQTL mapping.)\n", + "\n", + "**When to run it.** Run this module after cell-level counts and sample metadata are available and before phenotype formatting or pseudobulk QTL analysis.\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "**Timing:** ~5-10 min on typical compute infrastructure." + "**When to run it.** After single-nuclei data have been clustered and cell types assigned, and before\n", + "any QTL scan -- the association modules read the matrices this module writes." ] }, { @@ -40,64 +45,131 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", - "\n", - "The toy example uses single-nuclei RNA-seq data for the `MIC` (microglia) cell type under `input/snrnaseq/`.\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `protocol_example.snrnaseq.seurat_MIC.rds` | Seurat object (MIC cells) with per-nucleus counts (input to `pseudobulk_counts`) |\n", - "| `protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz` | Pre-aggregated pseudobulk count matrix (genes x samples) |\n", - "| `protocol_example.snrnaseq.metadata_MIC.csv` | Sample-level metadata (sampleid, batch, nuclei counts) |\n", - "| `protocol_example.snrnaseq.tech_vars_MIC.csv` | Technical covariates keyed by `sampleid` |\n", - "| `protocol_example.snrnaseq.id_map.csv` | individualID -> sampleid map (input to `sampleid_mapping`) |\n", - "| `atac_residuals/MIC/protocol_example.snrnaseq.MIC_residuals.txt` | Peak residuals with `chr-start-end` IDs (input to `phenotype_formatting`) |" + "## Input\n", + "\n", + "`pseudobulk_counts` -- aggregate single-nuclei counts into a pseudobulk matrix:\n", + "\n", + "- `--seurat-files input/snrnaseq/protocol_example.snrnaseq.seurat_MIC.rds`: the Seurat objects to aggregate, each carrying `celltype` and `sample` in\n", + " `meta.data`.\n", + "- `--output-dir` (required): where the pseudobulk matrix is written.\n", + "- `--celltype` (default `MIC`): the cell type to subset to. Objects lacking it are skipped.\n", + "- `--min-cells` (default `10`): drop samples contributing fewer nuclei than this.\n", + "\n", + "`sampleid_mapping` -- rename matrix columns to study sample IDs:\n", + "\n", + "- `--map-file input/snrnaseq/protocol_example.snrnaseq.id_map.csv` (required): two-column map from nuclei-level\n", + " IDs to study sample IDs.\n", + "\n", + " ```\n", + " individualID,sampleid\n", + " DONOR_001,SAMPLE_001\n", + " DONOR_002,SAMPLE_002\n", + " ```\n", + "- `--meta-files input/snrnaseq/protocol_example.snrnaseq.metadata_MIC.csv` and\n", + " `--count-files input/snrnaseq/protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz`: the\n", + " metadata and count matrices to relabel. The count matrix is genes by samples:\n", + "\n", + " ```\n", + " ,SAMPLE_001,SAMPLE_002,SAMPLE_003,SAMPLE_004,SAMPLE_005,SAMPLE_006,SAMPLE_007,SAMPLE_008\n", + " ENSG00000000001,299,172,139,269,742,166,696,820,428,811,188,593,131,270,873,49,1244,259,\n", + " ENSG00000000002,533,624,49,2,1911,1822,679,333,147,160,664,92,382,142,160,1323,214,468,1\n", + " ```\n", + "- `--output-dir` (required): where the relabelled files are written.\n", + "\n", + "`pseudobulk_qc` -- filter, optionally batch-correct and normalise:\n", + "\n", + "- `--meta-files` and `--count-files`: the pseudobulk matrices and their metadata.\n", + "- `--output-dir` (required) and `--tech-vars-file input/snrnaseq/protocol_example.snrnaseq.tech_vars_MIC.csv`\n", + " (required): output location, and the technical\n", + " covariates to regress out.\n", + "- `--min-count` (default `5`), `--min-total-count` (default `15`), `--min-prop` (default `0.1`):\n", + " edgeR-style expression filters.\n", + "- `--min-nuclei` (default `20`): drop samples built from fewer nuclei than this.\n", + "- `--batch-correction` (default `FALSE`) and `--batch-method` (default `limma`): whether to correct\n", + " for batch, and with what.\n", + "- `--quant-norm` (default `FALSE`): quantile-normalise the filtered matrix.\n", + "- `--blacklist-file`, `--regions`, `--gene-list` (all empty by default): optional restrictions on the\n", + " features carried forward.\n", + "\n", + "`phenotype_formatting` -- reshape residuals into the phenotype format (snATAC-seq only):\n", + "\n", + "- `--residual-files input/snrnaseq/atac_residuals/MIC/protocol_example.snrnaseq.MIC_residuals.txt`:\n", + " the residualised matrices to reformat.\n", + "- `--gtf-file input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf`\n", + " (required): gene model supplying the coordinates.\n", + "- `--output-dir` (required): where the phenotype files are written.\n", + "\n", + "Shared: `--cwd` (default `output`), `--modular-script-dir` (default `code/script`), and the cluster\n", + "options `--numThreads` (default `8`), `--job-size` (default `1`), `--walltime` (default `5h`),\n", + "`--mem` (default `16G`), `--container`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output\n", + "\n", + "- `pseudobulk_counts_.csv.gz` -- from `pseudobulk_counts`: raw aggregated counts, one\n", + " column per sample. Normalisation is left to `pseudobulk_qc`.\n", + "\n", + " ```\n", + " gene_id,SAMPLE_001,SAMPLE_002,SAMPLE_003,SAMPLE_004,SAMPLE_005,SAMPLE_006,SAMPLE_007,SAM\n", + " NOC2L,29,7,4,16,24,16,7,13,3,3,12,3,9,0,12,0,33,37,30,9\n", + " KLHL17,8,1,0,6,10,16,5,5,0,1,6,0,5,1,3,2,15,14,19,6\n", + " ```\n", + "- relabelled count and metadata files -- from `sampleid_mapping`: the same matrices with columns\n", + " renamed to study sample IDs via `--map-file`.\n", + "- filtered, optionally batch-corrected and normalised matrices plus their residuals -- from\n", + " `pseudobulk_qc`, as GCT:\n", + "\n", + " ```\n", + " ID\tSAMPLE_011\tSAMPLE_012\tSAMPLE_013\tSAMPLE_014\tSAMPLE_015\tSAMPLE_016\tSAMPLE_017\tSAMPLE_0\n", + " 12\t7.218285529299902\t7.765796037583676\t6.875518837530288\t4.3191760256225535\t7.1895314838\n", + " 18\t6.90933528841075\t7.765796037583676\t6.828976251593258\t6.641104120509915\t6.252725310296\n", + " ```\n", + "- phenotype-format files -- from `phenotype_formatting`, for snATAC-seq only.\n", + "- `..residuals.txt` -- from `pseudobulk_qc`: the residualised\n", + " matrix per cell type, which `phenotype_formatting` reads.\n", + "\n", + " ```\n", + " \tSAMPLE_001\tSAMPLE_002\tSAMPLE_003\tSAMPLE_004\tSAMPLE_005\tSAMPLE_006\tSAMPLE_007\tSAMPLE_008\n", + " ENSG00000000001\t10.5316181036712\t10.0782299856604\t9.69847909370219\t10.0321840665649\t11.3\n", + " ENSG00000000002\t9.94704712753556\t10.5923588918617\t8.97464386590436\t4.12683911798198\t12.9\n", + " ```\n", + "- a `.stdout` / `.stderr` log beside each target.\n", + "\n", + "All paths are relative to the `--output-dir` given to each workflow.\n", + "\n", + "Example output for this module lives under `output/snrna_seq/` (counts and residuals) and\n", + "`output/pseudobulk_qc/` (filtered and normalised matrices)." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Step 1: Pseudobulk Count Matrix Generation\n", - "\n", - "Aggregates single-nuclei counts into pseudobulk count matrices per cell type from Seurat objects.\n", - "\n", - "> This step is upstream of `sampleid_mapping` and `pseudobulk_qc`. Output feeds directly into the existing preprocessing pipeline.\n", - "\n", - "### Input\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `celltyped_seuratobj{i}.rds` | Seurat objects with `celltype` and `sample` annotations in `meta.data` |\n", - "\n", - "### Process\n", - "\n", - "1. Load each Seurat object and subset to target cell type — skips objects where cell type is not present\n", - "2. Merge all subsets across objects and join layers\n", - "3. Aggregate raw counts by sample (`AggregateExpression`)\n", - "4. Filter out samples with fewer than `min_cells` cells (default: 10)\n", - "5. Strip Ensembl version suffixes from gene IDs (`ENSG00000000010.1` → `ENSG00000000010`)\n", - "6. Save as `pseudobulk_counts_{celltype}.csv.gz` — raw counts only, normalization handled downstream in `pseudobulk_qc`\n", - "\n", - "> **GLU cell type**: Due to its large size, process in two batches (files 1–6 and 7–11) and pass separately.\n", - "\n", - "### Parameters\n", - "\n", - "| Parameter | Default | Description |\n", - "|-----------|---------|-------------|\n", - "| `seurat_files` | *required* | One or more Seurat `.rds` files |\n", - "| `output_dir` | *required* | Output directory for count matrix |\n", - "| `celltype` | `MIC` | Cell type to extract (must match `celltype` column in `meta.data`) |\n", - "| `min_cells` | `10` | Minimum number of cells per sample to retain |\n", - "\n", - "### Output\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `pseudobulk_counts_{celltype}.csv.gz` | Raw pseudobulk count matrix (genes × samples) |\n", - "\n", + "## Minimal Working Example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Step 1. Pseudobulk count matrix generation\n", "\n", - "**Timing:** 10–30 min per cell type depending on object size" + "Aggregates single-nuclei counts into pseudobulk count matrices per cell type from Seurat objects." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -120,60 +192,18 @@ "kernel": "SoS" }, "source": [ - "## Step 2: Sample ID Mapping\n", - "\n", - "Maps original sample identifiers (`individualID`) to standardized sample IDs (`sampleid`)\n", - "across metadata and count matrix files.\n", - "\n", - "### Input\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `rosmap_sample_mapping_data.csv` | Mapping reference: `individualID → sampleid` |\n", - "| `metadata_{celltype}.csv` | Per-cell-type sample metadata |\n", - "| `pseudobulk_peaks_counts_{celltype}.csv.gz` *(snATAC-seq)* | Per-cell-type peak count matrices |\n", - "| `pseudobulk_counts_{celltype}.csv.gz` *(snRNA-seq)* | Per-cell-type gene count matrices |\n", - "\n", - "### Process\n", - "\n", - "**Part 1 — Metadata files**\n", - "\n", - "For each metadata file:\n", - "1. Look up each `individualID` in the mapping reference\n", - "2. Assign `sampleid` — falls back to `individualID` if no mapping found\n", - "3. Reorder columns: `sampleid` first, then `individualID`, then the rest\n", - "4. Save updated file\n", + "#### Step 2. Sample ID mapping\n", "\n", - "**Part 2 — Count matrix files**\n", - "\n", - "For each count file:\n", - "1. Extract the header row (column names only)\n", - "2. Keep the first column (peak or gene IDs) unchanged\n", - "3. Map remaining column names (`individualID` → `sampleid`) where mapping exists, otherwise keep original\n", - "4. Write new header and stream data rows unchanged\n", - "5. Recompress with gzip\n", - "\n", - "### Parameters\n", - "\n", - "| Parameter | Default | Description |\n", - "|-----------|---------|-------------|\n", - "| `map_file` | *required* | CSV with `individualID` → `sampleid` mapping |\n", - "| `meta_files` | *required* | Metadata CSV files to remap |\n", - "| `count_files` | *required* | Count CSV.gz files to remap |\n", - "| `output_dir` | *required* | Parent output directory; writes to `{output_dir}/1_files_with_sampleid/` |\n", - "\n", - "### Output\n", - "\n", - "Output directory: `{output_dir}/1_files_with_sampleid/`\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `metadata_{celltype}.csv` | Metadata with `sampleid` column prepended |\n", - "| `pseudobulk_peaks_counts_{celltype}.csv.gz` *(snATAC-seq)* | Count matrices with mapped column headers |\n", - "| `pseudobulk_counts_{celltype}.csv.gz` *(snRNA-seq)* | Count matrices with mapped column headers |\n", - "\n", - "\n", - "**Timing:** < 1 min" + "Maps original sample identifiers (`individualID`) to standardized sample IDs (`sampleid`) across metadata and count matrix files." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -196,81 +226,18 @@ "kernel": "SoS" }, "source": [ - "## Step 2: Pseudobulk QC\n", - "\n", - "Regresses out technical covariates for downstream QTL analysis. Works for both snATAC-seq and snRNA-seq.\n", - "\n", - "### Input\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `metadata_{celltype}.csv` | Sample-level metadata (nuclei counts, batch info) |\n", - "| `pseudobulk_*counts_{celltype}.csv.gz` | Pseudobulk count matrix |\n", - "| `tech_vars.csv` | Technical covariates (sampleid + tech var columns, pre-processed) |\n", - "| `hg38-blacklist.v2.bed.gz` *(snATAC-seq, optional)* | Blacklisted genomic regions |\n", - "\n", - "### Process\n", - "\n", - "1. Load count matrix and auto-detect modality (snATAC-seq vs snRNA-seq)\n", - "2. ***(Optional)*** Filter to specific genomic regions (snATAC-seq) or gene list (snRNA-seq)\n", - "3. Load metadata; filter samples with fewer than `min_nuclei` nuclei (default: 20)\n", - "4. Align samples between metadata and count matrix\n", - "5. ***(Optional)*** Filter blacklisted genomic regions (snATAC-seq only)\n", - "6. Merge tech vars from `tech_vars_file` by `sampleid` \n", - "7. Drop samples with NA in any tech var\n", - "8. Apply expression filtering (`filterByExpr`):\n", - " - `min_count = 5`: minimum reads in at least one sample\n", - " - `min_total_count = 15`: minimum total reads across all samples\n", - " - `min_prop = 0.1`: feature expressed in ≥10% of samples\n", - "9. TMM normalization\n", - "10. ***(Optional)*** Batch correction on `sequencingBatch`:\n", - " - `limma::removeBatchEffect` (default)\n", - " - `ComBat` (on log-CPM)\n", - "11. Add `sequencingBatch` and `Library` to model if present and multi-level\n", - "12. Fit linear model (`voom` + `lmFit` + `eBayes`) with **tech vars + batch vars only** \n", - "13. Compute `offset + residuals` as final adjusted values:\n", - " - `offset`: intercept + batch effects at reference level\n", - " - `residuals`: variation after removing technical effects; biological signal retained\n", - "14. ***(Optional)*** Quantile normalization of final values\n", - "\n", - "**Model formula:**\n", - "```\n", - "~ {tech_vars} + [sequencingBatch] + [Library]\n", - "```\n", - "> `sequencingBatch` and `Library` included only if present and have more than one level.\n", - "> Biological variables (`pmi`, `study`, `msex`, `age_death` etc.) are **not** included — they should not be regressed out as they may be associated with genotype.\n", - "\n", - "### Parameters\n", - "\n", - "| Parameter | Default | Description |\n", - "|-----------|---------|-------------|\n", - "| `meta_files` | *required* | Metadata CSV files (one per cell type) |\n", - "| `count_files` | *required* | Count CSV.gz files (one per cell type, same order as `meta_files`) |\n", - "| `output_dir` | *required* | Parent output directory; writes to `{output_dir}/2_residuals/{ct}/` |\n", - "| `tech_vars_file` | *required* | CSV with `sampleid` + tech var columns |\n", - "| `blacklist_file` | `''` | Genomic blacklist BED file (snATAC-seq only) |\n", - "| `regions` | `''` | Comma-separated genomic regions e.g. `chr7:28000000-28300000` (snATAC-seq) |\n", - "| `gene_list` | `''` | Comma-separated gene IDs e.g. `ENSG00000000010` (snRNA-seq) |\n", - "| `batch_correction` | `FALSE` | Apply batch correction (`TRUE`/`FALSE`) |\n", - "| `batch_method` | `limma` | Batch correction method (`limma` or `combat`) |\n", - "| `quant_norm` | `FALSE` | Apply quantile normalization after residuals |\n", - "| `min_count` | `5` | Min reads in at least one sample |\n", - "| `min_total_count` | `15` | Min total reads across all samples |\n", - "| `min_prop` | `0.1` | Min proportion of samples with expression |\n", - "| `min_nuclei` | `20` | Min nuclei per sample |\n", - "\n", - "### Output\n", - "\n", - "Output directory: `{output_dir}/2_residuals/{celltype}/`\n", + "#### Step 3. Pseudobulk QC\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `{celltype}_residuals.txt` | Tech-covariate-adjusted values (log2-CPM) |\n", - "| `{celltype}_residuals_qn.txt` | Quantile-normalized adjusted values *(if `quant_norm=TRUE`)* |\n", - "| `{celltype}_results.rds` | Full results: DGEList, fit, offset, residuals, design, parameters |\n", - "| `{celltype}_filtered_raw_counts.txt` | Filtered raw counts before normalization |\n", - "\n", - "**Timing:** < 5 min per cell type" + "Regresses out technical covariates for downstream QTL analysis. Works for both snATAC-seq and snRNA-seq." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -294,50 +261,18 @@ "kernel": "SoS" }, "source": [ - "## Step 3: Phenotype Reformatting (snATAC-seq only)\n", - "\n", - "Converts residuals into a QTL-ready BED format for genome-wide caQTL mapping.\n", - "\n", - "> For snRNA-seq, please follow this [pipeline](https://github.com/StatFunGen/xqtl-protocol/blob/main/code/data_preprocessing/phenotype/phenotype_formatting.ipynb).\n", - "\n", - "### Input\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `{celltype}_residuals.txt` | Residuals from `pseudobulk_qc` |\n", - "\n", - "### Process\n", - "\n", - "1. Read residuals file with proper handling of feature IDs and sample columns\n", - "2. Parse peak coordinates from peak IDs (`chr-start-end` format)\n", - "3. Convert to midpoint coordinates (standard for QTLtools):\n", - "```\n", - "start = floor((peak_start + peak_end) / 2)\n", - "end = start + 1\n", - "```\n", - "4. Build BED format: `#chr`, `start`, `end`, `ID` followed by per-sample values\n", - "5. Sort by chromosome and position\n", - "6. Compress with `bgzip` and index with `tabix`\n", - "\n", - "### Parameters\n", - "\n", - "| Parameter | Default | Description |\n", - "|-----------|---------|-------------|\n", - "| `residual_files` | *required* | Residual txt files from `pseudobulk_qc` |\n", - "| `output_dir` | *required* | Parent output directory; writes to `{output_dir}/3_pheno_reformat/` |\n", - "\n", - "### Output\n", - "\n", - "Output directory: `{output_dir}/3_pheno_reformat/`\n", + "#### Step 4. Phenotype reformatting (snATAC-seq only)\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `{celltype}_phenotype.bed.gz` | bgzip-compressed BED with midpoint coordinates |\n", - "| `{celltype}_phenotype.bed.gz.tbi` | tabix index for random-access queries |\n", - "\n", - "Compatible with FastQTL, TensorQTL, and QTLtools.\n", - "\n", - "**Timing:** < 1 min per cell type" + "Converts residuals into a QTL-ready BED format for genome-wide caQTL mapping." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -360,46 +295,80 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", - "\n", - "Written to `{output_dir}/2_residuals/{celltype}/` (e.g. `output/snrna_seq/2_residuals/MIC/`).\n", - "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `{celltype}_residuals.txt` | Tech-covariate-adjusted values (log2-CPM) |\n", - "| `{celltype}_results.rds` | Full results: DGEList, fit, offset, residuals, design |\n", - "| `{celltype}_filtered_raw_counts.txt` | Filtered raw counts before normalization |\n", - "\n", - "Stage 1 (`pseudobulk_counts`) writes `0_pseudobulk_counts/pseudobulk_counts_{celltype}.csv.gz`; `sampleid_mapping` writes `1_files_with_sampleid/`." + "## Command Interface" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "sos run pipeline/pseudobulk_preprocessing.ipynb -h" ] }, { "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Command interface" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "Bash" - }, - "outputs": [], + "metadata": {}, "source": [ - "sos run pipeline/pseudobulk_preprocessing.ipynb -h" + "```\n", + "usage: sos run pipeline/pseudobulk_preprocessing.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " pseudobulk_counts\n", + " sampleid_mapping\n", + " pseudobulk_qc\n", + " phenotype_formatting\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " --job-size 1 (as int)\n", + " --walltime 5h\n", + " --mem 16G\n", + " --numThreads 8 (as int)\n", + " --container ''\n", + "\n", + "Sections\n", + " pseudobulk_counts:\n", + " Workflow Options:\n", + " --seurat-files (as list)\n", + " --output-dir VAL (as str, required)\n", + " --celltype MIC\n", + " --min-cells 10 (as int)\n", + " sampleid_mapping:\n", + " Workflow Options:\n", + " --map-file VAL (as str, required)\n", + " --output-dir VAL (as str, required)\n", + " --meta-files (as list)\n", + " --count-files (as list)\n", + " pseudobulk_qc:\n", + " Workflow Options:\n", + " --meta-files (as list)\n", + " --count-files (as list)\n", + " --output-dir VAL (as str, required)\n", + " --tech-vars-file VAL (as str, required)\n", + " --blacklist-file ''\n", + " --batch-correction FALSE\n", + " --batch-method limma\n", + " --quant-norm FALSE\n", + " --min-count 5 (as int)\n", + " --min-total-count 15 (as int)\n", + " --min-prop 0.1 (as float)\n", + " --min-nuclei 20 (as int)\n", + " --regions ''\n", + " --gene-list ''\n", + " phenotype_formatting:\n", + " Workflow Options:\n", + " --residual-files (as list)\n", + " --output-dir VAL (as str, required)\n", + " --gtf-file VAL (as path, required)\n", + "```" ] }, { @@ -407,8 +376,7 @@ "metadata": {}, "source": [ "## Workflow implementation\n", - "\n", - "The cells below define the SoS workflow steps invoked by the commands above. They are not meant to be edited for routine analysis.\n" + "\n" ] }, { @@ -417,7 +385,7 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "### Default Parameters" ] }, { @@ -431,6 +399,7 @@ "[global]\n", "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", "parameter: cwd = path(\"output\")\n", + "parameter: name = \"protocol_example\"\n", "parameter: job_size = 1\n", "parameter: walltime = \"5h\"\n", "parameter: mem = \"16G\"\n", @@ -498,7 +467,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## `pseudobulk_counts`" + "### `pseudobulk_counts`" ] }, { @@ -518,12 +487,13 @@ "import os\n", "\n", "input: seurat_files\n", - "output: f'{output_dir}/0_pseudobulk_counts/pseudobulk_counts_{celltype}.csv.gz'\n", + "output: f'{output_dir}/{name}.pseudobulk_counts_{celltype}.csv.gz'\n", "\n", "task: trunk_workers = 1, trunk_size = 1, walltime = '4:00:00', mem = '64G', cores = 4\n", "\n", "bash: expand = \"${ }\", stdout = f'{_output:n}.stdout', stderr = f'{_output:n}.stderr'\n", " Rscript ${modular_script_dir}/molecular_phenotypes/QC/pseudobulk_preprocessing.R \\\n", + " --name \"${name}\" \\\n", " --step pseudobulk_counts \\\n", " --seurat-files ${' '.join([f'\"{f}\"' for f in seurat_files])} \\\n", " --celltype \"${celltype}\" \\\n", @@ -537,7 +507,7 @@ "kernel": "SoS" }, "source": [ - "## `sampleid_mapping`" + "### `sampleid_mapping`" ] }, { @@ -557,10 +527,11 @@ "import os\n", "\n", "input: meta_files + count_files\n", - "output: [f'{output_dir}/1_files_with_sampleid/{os.path.basename(f)}' for f in meta_files + count_files]\n", + "output: [f'{output_dir}/{os.path.basename(f)}' for f in meta_files + count_files]\n", " \n", "bash: expand = \"${ }\"\n", " Rscript ${modular_script_dir}/molecular_phenotypes/QC/pseudobulk_preprocessing.R \\\n", + " --name \"${name}\" \\\n", " --step sampleid_mapping \\\n", " --map-file \"${map_file}\" \\\n", " ${('--meta-files ' + ' '.join([f'\"{f}\"' for f in meta_files])) if meta_files else ''} \\\n", @@ -574,7 +545,7 @@ "kernel": "SoS" }, "source": [ - "## `pseudobulk_qc`" + "### `pseudobulk_qc`" ] }, { @@ -606,12 +577,13 @@ "_cts = [os.path.basename(f).split('metadata_')[-1].replace('.csv','') for f in meta_files]\n", "\n", "input: meta_files + count_files\n", - "output: [f'{output_dir}/2_residuals/{ct}/{ct}_residuals.txt' for ct in _cts]\n", + "output: [f'{output_dir}/{name}.{ct}.residuals.txt' for ct in _cts]\n", "\n", "task: trunk_workers = 1, trunk_size = 1, walltime = '6:00:00', mem = '64G', cores = 4\n", "\n", "bash: expand = \"${ }\", stdout = f'{_output[0]:n}.stdout', stderr = f'{_output[0]:n}.stderr'\n", " Rscript ${modular_script_dir}/molecular_phenotypes/QC/pseudobulk_preprocessing.R \\\n", + " --name \"${name}\" \\\n", " --step pseudobulk_qc \\\n", " --meta-files ${' '.join([f'\"{f}\"' for f in meta_files])} \\\n", " --count-files ${' '.join([f'\"{f}\"' for f in count_files])} \\\n", @@ -635,7 +607,7 @@ "kernel": "SoS" }, "source": [ - "## `phenotype_reformatting`" + "### `phenotype_reformatting`" ] }, { @@ -653,15 +625,16 @@ "\n", "import os\n", "\n", - "_cts = [os.path.basename(os.path.dirname(f)) for f in residual_files]\n", + "_cts = [os.path.basename(f).replace(f'{name}.','').replace('.residuals.txt','').replace('.residuals_qn.txt','') for f in residual_files]\n", "\n", "input: residual_files\n", - "output: [f'{output_dir}/3_pheno_reformat/{ct}_phenotype.bed.gz' for ct in _cts]\n", + "output: [f'{output_dir}/{name}.{ct}.phenotype.bed.gz' for ct in _cts]\n", "\n", "task: trunk_workers = 1, trunk_size = 1, walltime = '2:00:00', mem = '16G', cores = 2\n", "\n", "bash: expand = \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", " Rscript ${modular_script_dir}/molecular_phenotypes/QC/pseudobulk_preprocessing.R \\\n", + " --name \"${name}\" \\\n", " --step phenotype_formatting \\\n", " --residual-files ${' '.join([f'\"{f}\"' for f in residual_files])} \\\n", " --gtf-file \"${gtf_file}\" \\\n", @@ -681,7 +654,7 @@ "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", - "version": "4.4.3" + "version": "4.5.3" }, "sos": { "kernels": [ @@ -698,4 +671,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/molecular_phenotypes/QC/splicing_normalization.ipynb b/code/SoS/molecular_phenotypes/QC/splicing_normalization.ipynb index e265aa229..3acdc172d 100644 --- a/code/SoS/molecular_phenotypes/QC/splicing_normalization.ipynb +++ b/code/SoS/molecular_phenotypes/QC/splicing_normalization.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Splicing QC and Normalization" + "# Splicing QC and Normalization\n", + "\n", + "Quality control and normalisation of alternative-splicing quantifications from `leafcutter` and `psichomics`." ] }, { @@ -15,9 +17,23 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", + "\n", + "Quality control and normalization of alternative-splicing quantifications produced by the `leafcutter` and `psichomics` tools. Raw outputs are converted to BED format, features with high per-sample missingness (default 40%) are dropped, low-variance introns/events (default min variance 0.001) are removed, values are quantile-normalized, and remaining missing values are mean-imputed. The normalized tables are ready to use as molecular phenotypes for tensorQTL.\n", + "\n", + "Intron excision ratios are not comparable across samples as they come out of the caller.\n", + "They are compositional - each intron is a fraction of its cluster - and sparse, because an\n", + "intron unused in a sample has no reads rather than a zero. Left alone, both properties show\n", + "up in association testing as signal that tracks sequencing depth and sample handling rather\n", + "than genotype. The steps here filter clusters, impute the missing entries and quantile\n", + "normalise, which is what makes the phenotype usable downstream.\n", "\n", - "Quality control and normalization of alternative-splicing quantifications produced by the `leafcutter` and `psichomics` tools. Raw outputs are converted to BED format, features with high per-sample missingness (default 40%) are dropped, low-variance introns/events (default min variance 0.001) are removed, values are quantile-normalized, and remaining missing values are mean-imputed. The normalized tables are ready to use as molecular phenotypes for tensorQTL." + "Two quantification tools are supported and they need different handling, hence the separate\n", + "workflows: `leafcutter_norm` and `leafcutter_qqnorm` for LeafCutter output, `psichomics_norm`\n", + "for PSI values from psichomics.\n", + "\n", + "**When to run it.** After splicing calling, before phenotype preprocessing and association\n", + "testing." ] }, { @@ -26,7 +42,32 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~2-5 min on typical compute infrastructure." + "## Input\n", + "\n", + "- `--ratios`: the splicing ratio matrix to normalise, and the main input to all three workflows. Which form it takes depends on the workflow: `leafcutter_norm` expects the leafcutter per-cluster intron usage counts, `leafcutter_qqnorm` an already-QCed numeric intron-ratio table, and `psichomics_norm` a psichomics PSI matrix keyed by splicing-event ID. Example `input/rnaseq/protocol_example.psichomics.psi_raw_data.tsv`:\n", + "\n", + " ```\n", + " ID SAMPLE_001 SAMPLE_002 SAMPLE_003\n", + " SE_22_+_42438332_42438832_42439332_42439832_ENSG... NA 0.3414 0.1858\n", + " SE_22_-_42440332_42440832_42441332_42441832_ENSG... 0.7942 0.1614 0.2509\n", + " ```\n", + "\n", + " The leafcutter equivalents are `protocol_example.leafcutter.intron_usage_perind.counts.gz` (counts, `count/total` per sample) and `..._raw_data.txt` (the QC-ready numeric table).\n", + "\n", + "- `--qced-data`: where step 3 looks for its input. A directory, the default `.`, is scanned for files ending `_raw_data.txt`. A single file is used directly, and that case also forces `--mean_impute` on to fill any remaining NAs.\n", + "- `--no_norm`: stop `leafcutter_norm` before step 3, leaving the QCed table un-normalised. This is how the three-step route gets a QC-only result to hand to the imputer.\n", + "- `--mean_impute`: off by default. Fills missing ratios by the mean; step 3 turns it on by itself when `--qced-data` names a file.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--container`: the Apptainer or Docker image to run in, for example `oras://ghcr.io/cumc/leafcutter_apptainer:latest`.\n", + "- `--numThreads`, `--mem` and `--walltime`: job resources.\n", + "- `--junc-path`: the directory `Junc_list` globs for per-sample `*.junc` files. Required; it has no default.\n", + "- `--file-suffix`: the extension `Junc_list` looks for, `junc` by default.\n", + "- `--dataset`: names the junction list `Junc_list` writes, `ROSMAP_DLPFC` by default.\n", + "- `--sample-table`: the sample lookup table `Jointcall_samples` reads, previewed above.\n", + "- `--junc-list`: the junction list `Jointcall_samples` reads, normally the file `Junc_list` wrote.\n", + "- `--leafcutter-version`: the subdirectory both steps write into, `leafcutter2` by default.\n", + "\n", + "Route B step 2 calls `phenotype_imputation.ipynb`, not this notebook, so the flags in that command (`--phenoFile` for the QCed table from step 1, and `--prior` and `--varType` for the EBMF model) are that module's options and are documented there. They are not parameters of this notebook." ] }, { @@ -35,53 +76,158 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Output\n", + "\n", + "- `{cwd}/{leafcutter_version}/{dataset}_intron_usage_perind.junc` - the per-cluster junction file assembled by `Junc_list`.\n", + "- `{cwd}/{leafcutter_version}/{sample_table}.rnaseq` - the joint-called sample table from `Jointcall_samples`.\n", + "- `{ratios}_phenotype_file_list.txt` - the phenotype file list written by the first `leafcutter_norm` step. Example `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_phenotype_file_list.stdout` sits beside it.\n", + "- `{input}_raw_data.txt` - the QC'd numeric intron-ratio table from the second `leafcutter_norm` step, which is also what `leafcutter_qqnorm` takes as its starting point.\n", + "- `{input}.qqnorm.txt` - the quantile-normalised phenotype table, from either `leafcutter_norm` or the standalone `leafcutter_qqnorm`. Example `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.txt`, with a bgzipped and tabix-indexed `.qqnorm.bed.gz` beside it. Example `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.txt`, 24 columns and 112 rows, first 5 columns:\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `protocol_example.leafcutter.intron_usage_perind.counts.gz` | leafcutter per-cluster intron usage counts (`count/total` per sample); input to `leafcutter_norm`. |\n", - "| `protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.txt` | A numeric, QC-ready leafcutter intron-ratio BED table; input to the standalone `leafcutter_qqnorm`. |\n", - "| `protocol_example.psichomics.psi_raw_data.tsv` | psichomics PSI matrix keyed by splicing-event IDs; input to `psichomics_norm`. |" + " ```\n", + " #Chr start end ID SAMPLE_001\n", + " chr22 16671178 16671518 chr22:16671178:1667151 -0.25101591868327155\n", + " chr22 16671588 16673600 chr22:16671588:1667360 -1.261282157758418\n", + " ```\n", + "- `{cwd}/psichomics_raw_data_bedded.txt` and `{input}.qqnorm.txt` - the psichomics PSI matrix parsed into BED format and then quantile-normalised.\n", + "\n", + " Example `output/splicing/psichomics_raw_data_bedded.txt`, 24 columns and 31 rows:\n", + "\n", + " ```\n", + " #Chr start end ID\n", + " chr22 42438332 42439832 SE_22_+_42438332_424\n", + " chr22 42440332 42441832 SE_22_-_42440332_424\n", + " ```\n", + "\n", + " and `output/splicing/psichomics_raw_data_bedded.qqnorm.txt`, 24 columns and 31 rows:\n", + "\n", + " ```\n", + " #Chr start end ID\n", + " chr22 42438332 42439832 SE_22_+_42438332_424\n", + " chr22 42440332 42441832 SE_22_-_42440332_424\n", + " ```\n", + "\n", + "Example `output/splicing/leafcutter2/protocol_example_intron_usage_perind.junc` from `Junc_list`, 2 lines, one path per sample:\n", + "\n", + " ```\n", + " output/splicing/junc/SAMPLE_001.junc\n", + " output/splicing/junc/SAMPLE_002.junc\n", + " ```\n", + "\n", + "Example `output/splicing/leafcutter2/protocol_example.rnaseq.sample_participant_lookup.txt.rnaseq` from `Jointcall_samples`, 3 lines:\n", + "\n", + " ```\n", + " sample_id\tparticipant_id\n", + " SAMPLE_001\tSAMPLE_001\n", + " SAMPLE_002\tSAMPLE_002\n", + " ```\n", + "\n", + "Each workflow ends in a quantile-normalised phenotype table in BED-like form, `#Chr start end ID` plus one column per sample, ready to use directly as a molecular phenotype input to TensorQTL.\n", + "" ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## Output Files\n\n| File | Description |\n|------|-------------|\n| `*_raw_data.qqnorm.txt` | Quantile-normalized leafcutter intron-ratio phenotype table. |\n| `psichomics_raw_data_bedded.txt` | psichomics PSI matrix parsed into BED format. |\n| `psichomics_raw_data_bedded.qqnorm.txt` | Quantile-normalized psichomics PSI phenotype table. |\n\nEach workflow produces a quantile-normalized phenotype table in BED-like format (`#Chr start end ID` plus one column per sample), ready to use directly as a molecular phenotype input to TensorQTL.\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example" + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## Steps\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Build the junction list\n", + "RNA-seq sample IDs differ from the WGS sample IDs, so the joint-call sample lookup table is first subset to the RNA-seq samples used in the sQTL analysis, matching the sample set used elsewhere in the protocol. The table pairs each sample ID with its participant ID. Example `input/rnaseq/protocol_example.rnaseq.sample_participant_lookup.txt`, 2 columns and 61 rows:\n", + "\n", + "\n", + "`Junc_list` globs `--junc-path` for per-sample `*.junc` files, resolves them to absolute paths and drops the `all` entry, leaving one list file. No directory of `.junc` files ships here, so `--junc-path` is a placeholder." + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## 0. Generate sample list\n\nRNA-seq sample IDs differ from the WGS sample IDs, so the joint-call sample lookup table is first subset to the RNA-seq samples used in the sQTL analysis, matching the sample set used elsewhere in the protocol.\n\n**Step input:** `ROSMAP_JointCall_sample_participant_lookup_fixed` \u2014 a sample comparison table for ROSMAP datasets.\n\n**Step output:** `ROSMAP_JointCall_sample_participant_lookup_fixed.rnaseq` \u2014 the same lookup table restricted to the RNA-seq sample set.\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/splicing_normalization.ipynb Junc_list \\\n", + " --cwd output/splicing \\\n", + " --junc-path \\\n", + " --dataset protocol_example \\\n", + " --leafcutter-version leafcutter2" + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## `leafcutter_norm`: QC, impute, and normalize leafcutter intron ratios\n\nThis workflow runs the full leafcutter chain in one command: it builds the phenotype table, applies an autosome filter and QC, and quantile-normalizes the intron-usage ratios. The `--mean_impute` option fills missing ratios with the per-intron (row) mean. See the [leafcutter documentation](https://davidaknowles.github.io/leafcutter/index.html); the choice of regtool parameters is [discussed here](https://github.com/davidaknowles/leafcutter/issues/127).\n\n**Parameters.** `chr_blacklist` is a file of blacklisted chromosomes to exclude from analysis, one per line; if none is provided, no chromosomes are excluded.\n\n**Note.** `leafcutter_norm_1` typically requires about 10\u202fGB of memory (more for large inputs); insufficient memory can cause a segmentation fault.\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Joint-call the samples\n", + "\n", + "`Jointcall_samples` takes the junction list from the previous step together with the sample lookup table and writes the `.rnaseq` table that the leafcutter routes consume. The two chain by hand: `--junc-list` is the file `Junc_list` wrote." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n", + "sos run pipeline/splicing_normalization.ipynb Jointcall_samples \\\n", " --cwd output/splicing \\\n", - " --ratios input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz \\\n", - " --mean_impute \n" + " --sample-table input/rnaseq/protocol_example.rnaseq.sample_participant_lookup.txt \\\n", + " --junc-list output/splicing/leafcutter2/protocol_example_intron_usage_perind.junc \\\n", + " --leafcutter-version leafcutter2" ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## `leafcutter_qqnorm`: quantile-normalize an already-QCed leafcutter table\n\nUse this standalone workflow when the intron-ratio table has already been QCed and imputed and only quantile normalization is needed.\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Leafcutter\n", + "\n", + "This workflow runs the full leafcutter chain in one command: it builds the phenotype table, applies an autosome filter and QC, and quantile-normalizes the intron-usage ratios. The `--mean_impute` option fills missing ratios with the per-intron (row) mean. See the [leafcutter documentation](https://davidaknowles.github.io/leafcutter/index.html); the choice of regtool parameters is [discussed here](https://github.com/davidaknowles/leafcutter/issues/127).\n", + "\n", + "**Parameters.** `chr_blacklist` is a file of blacklisted chromosomes to exclude from analysis, one per line; if none is provided, no chromosomes are excluded.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] }, { "cell_type": "code", @@ -91,15 +237,31 @@ }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_qqnorm \\\n", + "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n", " --cwd output/splicing \\\n", - " --qced-data input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.txt \n" + " --ratios input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz \\\n", + " --mean_impute \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Psichomics PSI values\n", + "\n", + "This workflow parses psichomics splicing-event IDs into BED coordinates, applies NA and variance filters, and then quantile-normalizes each event. See the [psichomics documentation](http://bioconductor.org/packages/release/bioc/html/psichomics.html). The only QC applied to PSI values here is NA removal and a minimal variance filter; the psichomics maintainers suggest some further QC, [discussed here](https://github.com/nuno-agostinho/psichomics/issues/450). For reference, the default minimal variance used in leafcutter QC is 0.001. Because the alternative-splicing event types in psichomics outputs differ, normalization is performed per event (rows) rather than per sample (columns).\n" ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## `psichomics_norm`: parse, QC, and normalize psichomics PSI values\n\nThis workflow parses psichomics splicing-event IDs into BED coordinates, applies NA and variance filters, and then quantile-normalizes each event. See the [psichomics documentation](http://bioconductor.org/packages/release/bioc/html/psichomics.html).\n\n**QC.** The only QC applied to PSI values here is NA removal and a minimal variance filter; the psichomics maintainers suggest some further QC, [discussed here](https://github.com/nuno-agostinho/psichomics/issues/450). For reference, the default minimal variance used in leafcutter QC is 0.001.\n\nBecause the alternative-splicing event types in psichomics outputs differ, normalization is performed per event (rows) rather than per sample (columns).\n" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] }, { "cell_type": "code", @@ -120,106 +282,156 @@ "kernel": "SoS" }, "source": [ - "## Complete worked example" + "### Leafcutter with EBMF imputation\n", + "\n", + "This is the leafcutter route split into three commands so that EBMF imputation can be used instead of the default mean imputation. Run it *instead of*, not after, the single `leafcutter_norm` command above.\n", + "\n", + "The steps are chained by hand rather than by SoS, so the placeholders in the commands below must be filled in with real paths:\n", + "\n", + "1. **QC** - `leafcutter_norm --no_norm` stops after the raw-data table, writing `{ratios}_raw_data.txt`.\n", + "2. **Imputation** - `phenotype_imputation.ipynb EBMF` takes that table through `--phenoFile` (``). This step runs a different module.\n", + "3. **Normalization** - `leafcutter_qqnorm` takes the imputed matrix through `--qced-data` (``). Because that argument names a file rather than a directory, this step also switches on mean imputation for any NAs EBMF left behind." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ "To perform leafcutter analysis with QC (setting cluster counts of 0 as NA), imputation (flashR), and normalization, use the following commands (RECOMMENDED):" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "### Step 1: QC" + "#### Step 1. QC" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Input:** intron usage count matrix from LeafCutter clustering (`*_intron_usage_perind.counts.gz`), produced upstream by the splicing calling step.\n\n**Output:** a QC'd count matrix in which cluster counts equal to 0 are set to `NA`; normalization is skipped at this stage via `--no_norm`." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n --cwd ../../output_test/leafcutter/normalize \\\n --ratios ../../output_test/leafcutter/PCC_sample_list_subset_leafcutter_intron_usage_perind.counts.gz \\\n --container oras://ghcr.io/cumc/leafcutter_apptainer:latest \\\n --no_norm # add no norm to skip last step (qqnorm) in leafcutter_norm\n" + "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n", + " --cwd ../../output_test/leafcutter/normalize \\\n", + " --ratios ../../output_test/leafcutter/PCC_sample_list_subset_leafcutter_intron_usage_perind.counts.gz \\\n", + " --container oras://ghcr.io/cumc/leafcutter_apptainer:latest \\\n", + " --no_norm # add no norm to skip last step (qqnorm) in leafcutter_norm\n" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "### Step 2: Imputation" + "#### Step 2. Imputation" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Input:** the QC'd count matrix from Step 1, supplied through `--phenoFile`.\n\n**Output:** an imputed phenotype matrix with missing values filled by the EBMF (flashR) model." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "outputs": [], "source": [ - "sos run pipeline/phenotype_imputation.ipynb EBMF \\\n --phenoFile \\\n --cwd ../../output_test/leafcutter/imputation \\\n --prior ebnm_point_laplace --varType 1 \\\n --container oras://ghcr.io/cumc/factor_analysis_apptainer:latest \\\n --mem 40G --numThreads 20 --walltime 100h \n" + "sos run pipeline/phenotype_imputation.ipynb EBMF \\\n", + " --phenoFile \\\n", + " --cwd ../../output_test/leafcutter/imputation \\\n", + " --prior ebnm_point_laplace --varType 1 \\\n", + " --container oras://ghcr.io/cumc/factor_analysis_apptainer:latest \\\n", + " --mem 40G --numThreads 20 --walltime 100h \n" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "### Step 3: Normalization" + "#### Step 3. Normalization" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Input:** the imputed phenotype matrix from Step 2, supplied through `--qced-data`.\n\n**Output:** a quantile-normalized, BED-ready table (`*.qqnorm.txt`) ready for downstream QTL analysis." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_qqnorm \\\n --qced-data \\\n --container oras://ghcr.io/cumc/leafcutter_apptainer:latest\n" + "sos run pipeline/splicing_normalization.ipynb leafcutter_qqnorm \\\n", + " --cwd output/splicing \\\n", + " --qced-data input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.txt \\\n", + " --container oras://ghcr.io/cumc/leafcutter_apptainer:latest\n" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ "Or if you are going to use the default mean imputation method, you can run it with one-step command (remove --no_norm in the first step):" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Input:** the raw intron usage count matrix (`*_intron_usage_perind.counts.gz`).\n\n**Output:** a quantile-normalized table (`*.qqnorm.txt`) produced in a single pass; missing values are filled by simple mean imputation (`--mean_impute`)." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n --cwd ../../output_test/leafcutter/normalize \\\n --ratios ../../output_test/leafcutter/PCC_sample_list_subset_leafcutter_intron_usage_perind.counts.gz \\\n --container oras://ghcr.io/cumc/leafcutter_apptainer:latest \\\n --mean_impute\n" + "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n", + " --cwd ../../output_test/leafcutter/normalize \\\n", + " --ratios ../../output_test/leafcutter/PCC_sample_list_subset_leafcutter_intron_usage_perind.counts.gz \\\n", + " --container oras://ghcr.io/cumc/leafcutter_apptainer:latest \\\n", + " --mean_impute\n" ] }, { @@ -228,18 +440,103 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run splicing_normalization.ipynb -h" + "sos run pipeline/splicing_normalization.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/splicing_normalization.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " Junc_list\n", + " Jointcall_samples\n", + " leafcutter_norm\n", + " leafcutter_qqnorm\n", + " psichomics_norm\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --chr-blacklist . (as path)\n", + " intron usage ratio file wiht samples after QC optional\n", + " parameter black list if user want to blacklist some\n", + " chromosomes and not to analyze\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", + "\n", + "Sections\n", + " Junc_list:\n", + " Workflow Options:\n", + " --junc-path VAL (as path, required)\n", + " --file-suffix junc\n", + " --leafcutter-version leafcutter2\n", + " --dataset 'ROSMAP_DLPFC'\n", + " Jointcall_samples:\n", + " Workflow Options:\n", + " --sample-table VAL (as path, required)\n", + " --junc-list VAL (as path, required)\n", + " --leafcutter-version leafcutter2\n", + " leafcutter_norm_1:\n", + " Workflow Options:\n", + " --ratios VAL (as path, required)\n", + " --[no-]pseudo-ratio (default to False)\n", + " leafcutter_norm_2:\n", + " Workflow Options:\n", + " --[no-]autosomes (default to True)\n", + " leafcutter_norm_3, leafcutter_qqnorm:\n", + " Workflow Options:\n", + " --[no-]no-norm (default to False)\n", + " --[no-]mean-impute (default to False)\n", + " --na-rate 0.4 (as float)\n", + " minimal NA rate within sample values for an event to be\n", + " kept (default 0.4, leafcutter default)\n", + " --min-variance 0.001 (as float)\n", + " minimal variance across samples for an event to be kept\n", + " (default 0.001, psichomics suggested)\n", + " --qced-data . (as path)\n", + " --[no-]bgzip (default to False)\n", + " psichomics_norm_1:\n", + " Workflow Options:\n", + " --ratios VAL (as path, required)\n", + " psichomics_norm_2:\n", + " Workflow Options:\n", + " --na-rate 0.4 (as float)\n", + " minimal NA rate within sample values for an event to be\n", + " kept (default 0.4, leafcutter default)\n", + " --min-variance 0.001 (as float)\n", + " minimal variance across samples for an event to be kept\n", + " (default 0.001, psichomics suggested)\n", + "```" ] }, { diff --git a/code/SoS/molecular_phenotypes/apa.ipynb b/code/SoS/molecular_phenotypes/apa.ipynb index a20e455d5..160353bf8 100644 --- a/code/SoS/molecular_phenotypes/apa.ipynb +++ b/code/SoS/molecular_phenotypes/apa.ipynb @@ -2,25 +2,58 @@ "cells": [ { "cell_type": "markdown", - "metadata": {}, - "source": "# Alternative polyadenylation\n\n## Description\n\nThis mini-protocol turns aligned RNA-seq reads into an analysis-ready alternative-polyadenylation (APA) phenotype matrix for apaQTL analysis. It chains two pipeline modules through their `pipeline/` symlinks. First, [APA calling](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html) builds a 3'UTR reference, converts transcriptome BAM files to per-base coverage, and runs DaPars2 to quantify a percentage-of-distal-polyA-site-usage (PDUI) matrix per chromosome. Second, [post-APA imputation and QC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/apa_impute.html) fills missing PDUI values, applies quantile normalization, and optionally renames sample columns so that downstream covariate, association, and fine-mapping steps receive a complete matrix. Follow the steps in order; each is a single command on the toy data." + "metadata": { + "kernel": "SoS" + }, + "source": [ + "# Alternative polyadenylation\n", + "\n", + "This mini-protocol converts aligned RNA-seq reads into an analysis-ready alternative-polyadenylation (APA) phenotype matrix for apaQTL analysis." + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## Input\n\n| File | Description |\n| --- | --- |\n| Transcriptome BAM files | Per-sample RNA-seq alignments to the transcriptome, collected under `output/rnaseq/bam`. |\n| Reference GTF (`--hg-gtf`) | Gene annotation used to derive the 3\u2019UTR reference regions (e.g. `chr22.gtf` on the toy data). |\n| Sample match table | Optional tab-delimited table mapping internal IDs to final sample names, used by the rename step. |" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Miniprotocol Timing\n", + "\n", + "Timing: TBD" + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## Steps" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", + "\n", + "[APA calling](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html) derives 3′UTR regions, converts transcriptome BAM files to per-base coverage, and runs DaPars2 to estimate percentage of distal polyadenylation site usage (PDUI). [APA imputation and QC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/apa_impute.html) imputes missing PDUI values, quantile-normalizes the matrix, and can replace internal sample identifiers with analysis identifiers.\n", + "\n", + "The full calling route requires transcriptome BAM files, which are not included with the example data. A precomputed chromosome-22 DaPars result is provided so that the imputation and renaming routes can be run independently." + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "### i. Generate the 3'UTR reference regions from a GTF annotation:" + "source": [ + "## Steps\n", + "\n", + "Choose the route that matches the available starting data; the six commands are not always one mandatory chain.\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Call and process APA from transcriptome alignments | 1 → 2 → 3 → 4 → 5 | `input/reference_data/protocol_example.apa.chr22.gtf`; transcriptome BAM files under `output/rnaseq/bam/` (not bundled) |\n", + "| Resume from per-sample coverage files | 3 → 4 → 5 | `output/apa/wig/*.wig`; matching depth files; `output/apa/protocol_example.apa.chr22_3UTR.bed` |\n", + "| Impute and normalize an existing chromosome-22 DaPars result | 5 | `output/apa/apa_chr22/Dapars_result_result_temp.chr22.txt` |\n", + "| Impute, normalize and rename samples | 5 → 6 | DaPars result above; `input/covariate/protocol_example.apa_matchtable.txt` |\n", + "\n", + "Within the selected route, run the listed commands in numerical order." + ] }, { "cell_type": "markdown", @@ -28,7 +61,9 @@ "kernel": "SoS" }, "source": [ - "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." + "### [1. Build the 3′UTR reference](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html)\n", + "\n", + "**What it does:** `UTR_reference` extracts transcript-level 3′UTR intervals from the reference GTF for DaPars2." ] }, { @@ -40,8 +75,8 @@ "outputs": [], "source": [ "sos run pipeline/apa_calling.ipynb UTR_reference \\\n", - " --cwd output/apa \\\n", - " --hg-gtf output/apa/chr22.gtf" + " --cwd output/apa \\\n", + " --hg-gtf input/reference_data/protocol_example.apa.chr22.gtf" ] }, { @@ -49,7 +84,11 @@ "metadata": { "kernel": "SoS" }, - "source": "### ii. Convert the transcriptome BAM files into per-base coverage (wig) and read-depth (flagstat) files:" + "source": [ + "### [2. Generate coverage and read-depth files](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html)\n", + "\n", + "**What it does:** `bam2tools` converts each transcriptome BAM into a per-base WIG file and a matching read-depth summary." + ] }, { "cell_type": "code", @@ -69,7 +108,11 @@ "metadata": { "kernel": "SoS" }, - "source": "### iii. Compile the DaPars2 sample configuration and mapping files:" + "source": [ + "### [3. Build the DaPars2 configuration](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html)\n", + "\n", + "**What it does:** `APAconfig` creates the sample mapping and DaPars2 configuration files from the coverage directory and 3′UTR annotation." + ] }, { "cell_type": "code", @@ -80,9 +123,9 @@ "outputs": [], "source": [ "sos run pipeline/apa_calling.ipynb APAconfig \\\n", - " --cwd output/apa \\\n", - " --bfile output/apa/wig \\\n", - " --annotation output/apa/chr22_3UTR.bed" + " --cwd output/apa \\\n", + " --bfile output/apa/wig \\\n", + " --annotation output/apa/protocol_example.apa.chr22_3UTR.bed" ] }, { @@ -90,7 +133,11 @@ "metadata": { "kernel": "SoS" }, - "source": "### iv. Use DaPars2 to quantify APA events (PDUI matrix per chromosome):" + "source": [ + "### [4. Estimate chromosome-level PDUI](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/apa_calling.html)\n", + "\n", + "**What it does:** `APAmain` runs DaPars2 for chromosome 22 and writes the unprocessed PDUI result used by the QC module." + ] }, { "cell_type": "code", @@ -112,7 +159,11 @@ "metadata": { "kernel": "SoS" }, - "source": "### v. Impute missing values and run quality control on the PDUI matrix:" + "source": [ + "### [5. Impute and normalize PDUI](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/apa_impute.html)\n", + "\n", + "**What it does:** `APAimpute` imputes missing chromosome-level PDUI values and applies quantile normalization." + ] }, { "cell_type": "code", @@ -132,12 +183,43 @@ "metadata": { "kernel": "SoS" }, - "source": "### vi. Optionally rename the sample columns of the imputed PDUI matrix using a match table:" + "source": [ + "### [6. Rename samples and assemble the final matrix](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/apa_impute.html)\n", + "\n", + "**What it does:** `APArename` maps sample identifiers, combines requested chromosomes, and bgzip-indexes the final APA phenotype matrix." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/apa_impute.ipynb APArename \\\n", + " --cwd output/apa \\\n", + " --chrlist chr22 \\\n", + " --match input/covariate/protocol_example.apa_matchtable.txt" + ] }, { "cell_type": "markdown", - "metadata": {}, - "source": "## Output\n\n| File | Description |\n| --- | --- |\n| `*_3UTR.bed` | 3\u2019UTR reference regions extracted from the annotation, used by DaPars2. |\n| Coverage (`wig`) and `flagstat` files | Per-base read coverage and read-depth summaries derived from the transcriptome BAMs. |\n| PDUI matrix (per chromosome) | DaPars2 quantification of distal poly-A site usage, samples in columns. |\n| Imputed PDUI matrix | The PDUI matrix after missing-value imputation and quantile normalization \u2014 the APA phenotype table used for apaQTL analysis. |" + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Step | Output filename and relative path | Description |\n", + "| --- | --- | --- |\n", + "| 1 | `output/apa/protocol_example.apa.chr22.bed`; `output/apa/protocol_example.apa.chr22.transcript_to_geneName.txt`; `output/apa/protocol_example.apa.chr22_3UTR.bed` | BED12 annotation, transcript-to-gene map and DaPars2 3′UTR intervals |\n", + "| 2 | `output/apa/*.wig`; `output/apa/*.depth` | Per-sample coverage and read-depth files |\n", + "| 3 | `output/apa/sample_mapping_files.txt`; `output/apa/sample_configuration_file.txt` | DaPars2 sample mapping and configuration |\n", + "| 4 | `output/apa/apa_chr22/Dapars_result_result_temp.chr22.txt` | Raw chromosome-22 DaPars2 PDUI result |\n", + "| 5 | `output/apa/apa_chr22/Dapars_result_impute_chr22.bed` | Imputed and normalized chromosome-22 PDUI matrix |\n", + "| 6 | `output/apa/apa_chr22/Dapars_result_impute_renamed_chr22.bed`; `output/apa/apa_chr22/Dapars_result_impute_renamed_chr22.bed.gz`; `output/apa/apa_chr22/Dapars_result_impute_renamed_chr22.bed.gz.tbi`; `output/apa/Dapars_allchrom_renamed.bed`; `output/apa/Dapars_allchrom_renamed.bed.gz`; `output/apa/Dapars_allchrom_renamed.bed.gz.tbi` | Renamed chromosome-level and combined analysis-ready APA phenotype matrices |" + ] }, { "cell_type": "markdown", @@ -147,21 +229,40 @@ "source": [ "## Anticipated Results\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "The complete calling route produces 3′UTR intervals, per-sample coverage summaries, a DaPars2 configuration and one raw PDUI result per requested chromosome. Step 5 produces an imputed chromosome-level phenotype matrix. Step 6 is optional but recommended when the BAM identifiers differ from the identifiers used by covariates and genotypes; its combined bgzip-compressed BED file is the input for downstream apaQTL association testing.\n", + "\n", + "The bundled example starts at step 5 because transcriptome BAM files are not included." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/apa_impute.ipynb APArename \\\n", - " --cwd output/apa \\\n", - " --chrlist chr22 \\\n", - " --match input/covariate/protocol_example.apa_matchtable.txt" + "sos run pipeline/apa_calling.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/apa_impute.ipynb -h" ] } ], @@ -201,4 +302,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/molecular_phenotypes/bulk_expression.ipynb b/code/SoS/molecular_phenotypes/bulk_expression.ipynb index 64084a5c9..d3415a4c2 100644 --- a/code/SoS/molecular_phenotypes/bulk_expression.ipynb +++ b/code/SoS/molecular_phenotypes/bulk_expression.ipynb @@ -7,77 +7,70 @@ "tags": [] }, "source": [ - "# RNA-seq expression\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Input Files\n\n| File | Description |\n| --- | --- |\n| `input/rnaseq/protocol_example.rnaseq.fastq` | Raw RNA-seq FASTQ files (toy dataset) |\n| `input/rnaseq/protocol_example.rnaseq.fastq.list.txt` | Sample sheet listing one FASTQ (pair) per sample |\n| `reference_data/STAR_Index/` | STAR genome index used for alignment |\n" + "# RNA-seq expression\n", + "\n", + "Process bulk RNA-seq FASTQ files into aligned reads and expression estimates, then perform cohort-level expression quality control and normalization.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ "#### Miniprotocol Timing\n", "\n", - "Timing <3.5 hours" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Description\n" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "This miniprotocol shows the use of various modules to prepare reference data, perform RNA-seq calling, quantify expression, conduct quality control and normalize data. The modules are as follows:\n", - "1. `RNA_calling.ipynb` (steps 1-5): Quantifying expression from RNA-seq data\n", - "2. `bulk_expression_QC.ipynb` (step 6): Sample level RNA-seq quality control\n", - "3. `bulk_expression_normalization.ipynb` (step 7): Bulk RNA-seq counts normalization" + "Timing: TBD\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Toy-data run notes\n", + "## Overview\n", "\n", - "These examples run against the bundled toy dataset. Two adjustments were made versus the original protocol notebook so the examples run out-of-the-box on the toy data: the optional `--varVCFfile` (WASP allele-specific filtering) is omitted, since it is not required for eQTL expression quantification and the toy reference does not ship a sample variants VCF; and the QC/normalization input is the toy `input/rnaseq/protocol_example.rnaseq.tpm_matrix.bed` (the original referenced a `tmp` filename). \n", + "This mini-protocol walks through bulk RNA-seq expression processing. [`RNA_calling.ipynb`](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html) performs read-level quality assessment, optional adapter trimming, STAR alignment, and gene- or transcript-level quantification. [`bulk_expression_QC.ipynb`](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_QC.html) filters low-expression features and detects sample outliers, and [`bulk_expression_normalization.ipynb`](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_normalization.html) produces normalized expression matrices for downstream xQTL analysis.\n", "\n", - "Verified end-to-end on the toy data: steps **1 (fastqc)**, **2 (fastp_trim_adaptor)**, **6 (qc)**, and **7 (normalize)** complete successfully, with step vii producing the final TensorQTL-ready `...tmm_cpm_voom.expression.bed.gz`. Steps **3 (STAR_align)**, **4 (rnaseqc_call)**, and **5 (rsem_call)** require a complete STAR genome index; the bundled `reference_data/STAR_Index` is incomplete (it contains only the suffix-array shards and is missing `genomeParameters.txt`/`Genome`), so STAR exits with a FATAL ERROR. To run those steps, first build a STAR index from the reference fasta+gtf (via the `RNA_calling.ipynb` index workflow) and point `--STAR-index` to it. The RNA-calling FASTQ inputs are toy-sized: each sample (`SAMPLE_001`, `SAMPLE_002`) was downsampled to the first 100,000 read-pairs (~7 MB per gzipped file) so the bundle stays small; they are listed in `input/rnaseq/protocol_example.rnaseq.fastq.list.txt` and resolved from `input/rnaseq/protocol_example.rnaseq.fastq/`. Note that the RNA-calling steps (FASTQ QC, trimming, alignment) are a small 2-sample demo (`SAMPLE_001`, `SAMPLE_002`); the downstream expression matrices used for QC and normalization cover the full 60-sample toy cohort (`SAMPLE_001`-`SAMPLE_060`). The two are independent toy inputs, so there is no need for 60 FASTQ files." + "The commands form selectable routes rather than one mandatory chain. Gene-level RNA-SeQC and transcript-level RSEM quantification are alternatives after alignment. The bundled matrix-QC example starts from existing count and TPM matrices, so steps 6\u20137 can be run independently of the toy FASTQ example in steps 1\u20135.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Steps\n" + "## Steps\n", + "\n", + "Choose a route before running commands.\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Inspect raw-read quality only | 1 | `input/rnaseq/protocol_example.rnaseq.fastq.list.txt`
`input/rnaseq/protocol_example.rnaseq.fastq/` |\n", + "| Align untrimmed reads with STAR | 1 \u2192 3 | FASTQ inputs above
`input/reference_data/STAR_Index/`
`input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf`
`input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta`
`input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat` |\n", + "| Trim adapters before STAR alignment | 1 \u2192 2 \u2192 3 | Same inputs as the STAR route |\n", + "| Estimate gene-level expression | 1 \u2192 3 \u2192 4 | STAR-route inputs
`input/rnaseq/protocol_example.rnaseq.bam/sample_bam_list.txt`
`input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.gtf` |\n", + "| Estimate transcript-level expression | 1 \u2192 3 \u2192 5 | STAR-route inputs
`input/rnaseq/protocol_example.rnaseq.bam/sample_bam_list.txt`
`input/reference_data/RSEM_Index/` |\n", + "| QC and normalize existing expression matrices | 6 \u2192 7 | `input/rnaseq/protocol_example.rnaseq.tpm_matrix.bed`
`input/rnaseq/protocol_example.rnaseq.count_matrix.bed`
`input/rnaseq/protocol_example.rnaseq.sample_participant_lookup.txt`
`input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` |\n", + "\n", + "Run only the row matching the intended analysis goal. Adapter trimming is optional; use it when read-level QC or library preparation indicates adapter contamination.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 1. [Perform data quality summary via `fastqc`](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html#i-perform-data-quality-summary-via-fastqc)" + "### 1. [Assess FASTQ read quality](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html)\n", + "\n", + "**What it does:** Generate per-sample FastQC reports before alignment.\n" ] }, { @@ -101,7 +94,9 @@ "tags": [] }, "source": [ - "### 2. [Cut adaptor (Optional)](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html#ii-cut-adaptor-optional)" + "### 2. [Trim sequencing adapters](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html)\n", + "\n", + "**What it does:** Remove configured adapter sequences and write trimmed FASTQ files for alignment.\n" ] }, { @@ -114,19 +109,22 @@ "source": [ "sos run pipeline/RNA_calling.ipynb fastp_trim_adaptor \\\n", " --cwd output/rnaseq --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/protocol_example.rnaseq.fastq --STAR-index reference_data/STAR_Index/ \\\n", - " --gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \n" + " --data-dir input/rnaseq/protocol_example.rnaseq.fastq --STAR-index input/reference_data/STAR_Index/ \\\n", + " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + " --reference-fasta input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --ref-flat input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 3. [Read alignment via STAR and QC via Picard](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html#iii-read-alignment-via-star-and-qc-via-picard)" + "### 3. [Align reads with STAR and run Picard QC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html)\n", + "\n", + "**What it does:** Map reads to the reference genome and calculate alignment-level RNA-seq quality metrics.\n" ] }, { @@ -139,10 +137,10 @@ "source": [ "sos run pipeline/RNA_calling.ipynb STAR_align \\\n", " --cwd output/rnaseq/bam --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/protocol_example.rnaseq.fastq --STAR-index reference_data/STAR_Index/ \\\n", - " --gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", + " --data-dir input/rnaseq/protocol_example.rnaseq.fastq --STAR-index input/reference_data/STAR_Index/ \\\n", + " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + " --reference-fasta input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --ref-flat input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", " --chimSegmentMin 0 \\\n", " -J 50 --mem 200G --numThreads 8 \n" ] @@ -150,10 +148,13 @@ { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 4. [Call gene-level RNA expression via rnaseqc](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html#iv-call-gene-level-rna-expression-via-rnaseqc)" + "### 4. [Quantify gene-level expression with RNA-SeQC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html)\n", + "\n", + "**What it does:** Summarize aligned reads into gene-level expression measurements.\n" ] }, { @@ -168,18 +169,21 @@ " --cwd output/rnaseq/bam \\\n", " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", " --data-dir input/rnaseq/protocol_example.rnaseq.fastq \\\n", - " --gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.gtf \\\n", + " --reference-fasta input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", " --bam_list input/rnaseq/protocol_example.rnaseq.bam/sample_bam_list.txt \n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 5. [Call transcript level RNA expression via RSEM](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html#v-call-transcript-level-rna-expression-via-rsem)" + "### 5. [Quantify transcript-level expression with RSEM](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/RNA_calling.html)\n", + "\n", + "**What it does:** Estimate transcript- and gene-level abundance using the RSEM reference index.\n" ] }, { @@ -194,21 +198,24 @@ " --cwd output/rnaseq/bam \\\n", " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", " --data-dir input/rnaseq/protocol_example.rnaseq.fastq \\\n", - " --STAR-index reference_data/STAR_Index/ \\\n", - " --gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", + " --STAR-index input/reference_data/STAR_Index/ \\\n", + " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + " --reference-fasta input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + " --ref-flat input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", " --bam_list input/rnaseq/protocol_example.rnaseq.bam/sample_bam_list.txt \\\n", - " --RSEM-index reference_data/RSEM_Index \n" + " --RSEM-index input/reference_data/RSEM_Index \n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 6. [Multi-sample RNA-seq QC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_QC.html#vi-multi-sample-rna-seq-qc)" + "### 6. [Perform cohort-level expression QC](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_QC.html)\n", + "\n", + "**What it does:** Filter low-expression features and identify expression outlier samples across the cohort.\n" ] }, { @@ -228,10 +235,13 @@ { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "### 7. [Multi-sample read count normalization](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_normalization.html#vii-multi-sample-read-count-normalization)" + "### 7. [Normalize the QC-passed expression matrices](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/bulk_expression_normalization.html)\n", + "\n", + "**What it does:** Normalize the retained count and TPM matrices and write association-ready expression phenotypes.\n" ] }, { @@ -246,77 +256,113 @@ " --cwd output/rnaseq \\\n", " --tpm-gct output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz \\\n", " --counts-gct output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz \\\n", - " --annotation-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", + " --annotation-gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", " --count-threshold 1 --sample_participant_lookup input/rnaseq/protocol_example.rnaseq.sample_participant_lookup.txt \n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "## Anticipated Results" + "## Output Files\n", + "\n", + "| Step | Output filename and relative path | Description |\n", + "| --- | --- | --- |\n", + "| 1 | `output/rnaseq/fastqc/*_fastqc.html`
`output/rnaseq/fastqc/*_fastqc.zip` | Per-sample FastQC report and archive |\n", + "| 2 | `output/rnaseq/*.trimmed.fq.gz` | Adapter-trimmed FASTQ files |\n", + "| 3 | `output/rnaseq/bam/*.Aligned.sortedByCoord.out.bam`
`output/rnaseq/bam/*.alignment_summary_metrics`
`output/rnaseq/bam/*.bam_file_list` | STAR alignment, Picard metrics and BAM manifest |\n", + "| 4 | `output/rnaseq/bam/*.rnaseqc.gene_tpm.gct.gz` | Gene-level RNA-SeQC TPM matrix |\n", + "| 5 | `output/rnaseq/bam/*.rsem.isoforms.results`
`output/rnaseq/bam/*.rsem.genes.results`
`output/rnaseq/bam/*.rsem_transcripts_expected_count.txt.gz` | RSEM transcript- and gene-level estimates |\n", + "| 6 | `output/rnaseq/protocol_example.low_expression_filtered.tpm.gct.gz`
`output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.gz`
`output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.geneCount.gct.gz` | Filtered TPM and count matrices after sample QC |\n", + "| 7 | `output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct..expression.bed.gz` | Final normalized BED phenotype; the method name is part of the filename |\n", + "| Example QC figures | `website/nature_protocol/PCC_sample_list_subset.rnaseqc.low_expression_filtered.outlier_removed.tpm.gct.D_stat_hist.png`
`website/nature_protocol/PCC_sample_list_subset.rnaseqc.low_expression_filtered.outlier_removed.tpm.gct.RLEplot.png`
`website/nature_protocol/PCC_sample_list_subset.rnaseqc.low_expression_filtered.outlier_removed.tpm.gct.preQC_cluster.png` | Tracked cohort-level examples shown below; the toy-output directory does not currently contain these plots |\n" ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS", + "tags": [] + }, "source": [ - "## Output Files\n\n| File | Description |\n| --- | --- |\n| `output/rnaseq/fastqc/` | Per-sample FastQC quality reports |\n| `output/rnaseq/bam/` | STAR-aligned, Picard-QC BAM files |\n| `output/rnaseq/*.bed.gz` | Normalized gene/transcript expression matrix |\n" + "## Anticipated Results\n", + "\n", + "The calling routes produce aligned BAM files and either gene-level or transcript-level expression estimates. The cohort-level route produces QC-passed and normalized expression matrices suitable for phenotype annotation and xQTL association testing.\n", + "\n", + "The following QC figures summarize distributional and sample-level checks applied before normalization.\n" ] }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "The final output contained QCed and normalized expression data in a bed.gz file. This file is ready for use in TensorQTL." - ] + "
\n", + "\"Figure\n", + "
\n", + "\n", + "**Figure 1A. Bulk RNA-seq quality-control D-statistic distribution.**\n" + ], + "id": "f92c5520" }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": { - "kernel": "Bash" + "kernel": "SoS", + "tags": [] }, - "outputs": [], "source": [ - "%cd /restricted/projectnb/xqtl/jaempawi/xqtl_protocol/toy_example" - ] + "
\n", + "\"Figure\n", + "
\n", + "\n", + "**Figure 1B. Bulk RNA-seq quality-control relative log-expression residuals.**\n" + ], + "id": "c0636815" }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "%preview output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.D_stat_hist.pdf\n", + "
\n", + "\"Figure\n", + "
\n", "\n", - "**Figure 1A. Bulk RNA-Seq Quality Control D-Statistic Distribution.**" - ] + "**Figure 1C. Bulk RNA-seq quality-control Mahalanobis-distance p-value clustering.**\n" + ], + "id": "39b0865e" }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, "source": [ - "%preview output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.RLEplot.pdf\n", + "## Command interface\n", "\n", - "**Figure 1B. Bulk RNA-Seq Quality Control Relative Log Expression Residuals.**" + "List the workflows and parameters available in each module used by this mini-protocol.\n" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash" }, + "outputs": [], "source": [ - "%preview output/rnaseq/protocol_example.low_expression_filtered.outlier_removed.tpm.gct.preQC_cluster.pdf\n", - "\n", - "**Figure 1C. Bulk RNA-Seq Quality Control Mahalanobis Distance P-Value Clustering.**" + "sos run pipeline/RNA_calling.ipynb -h\n", + "sos run pipeline/bulk_expression_QC.ipynb -h\n", + "sos run pipeline/bulk_expression_normalization.ipynb -h\n" ] } ], @@ -348,5 +394,5 @@ } }, "nbformat": 4, - "nbformat_minor": 4 + "nbformat_minor": 5 } \ No newline at end of file diff --git a/code/SoS/molecular_phenotypes/calling/RNA_calling.ipynb b/code/SoS/molecular_phenotypes/calling/RNA_calling.ipynb index 19955516b..be0f1ce07 100644 --- a/code/SoS/molecular_phenotypes/calling/RNA_calling.ipynb +++ b/code/SoS/molecular_phenotypes/calling/RNA_calling.ipynb @@ -8,7 +8,8 @@ }, "source": [ "# Quantifying expression from RNA-seq data\n", - "\n" + "\n", + "Takes raw FASTQ files through quality control, adaptor trimming, STAR alignment and duplicate marking to gene-level and transcript-level expression estimates." ] }, { @@ -17,7 +18,19 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "This module follows the [GTEx](https://gtexportal.org/home/aboutGTEx#staticTextAnalysisMethods) and [TOPMed](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md) RNA-seq pipeline. Paired-end or single-end `fastq.gz` files go in; per-sample expression tables and a merged cohort matrix come out.\n", + "\n", + "The recommended order is: `fastqc` to inspect read quality, `fastp_trim_adaptor` to remove adaptors if the reports call for it, `STAR_align` to map reads to the genome, then `rnaseqc_call` and `rsem_call` to quantify. Alignment and duplicate marking are combined: `picard_qc` is declared as the second step of `STAR_align`, so running the alignment also marks duplicates and collects Picard metrics. The alignment step reimplements the GTEx `run_STAR.py` wrapper inline rather than calling it, so that read length may differ between samples, and re-sorts the unsorted STAR output with samtools instead of letting STAR sort in memory.\n", + "\n", + "Gene-level expression comes from RNA-SeQC v2.4.2 against a gene model collapsed so that each gene is a single feature rather than a set of transcripts [DeLuca et al. (2012)](https://doi.org/10.1093/bioinformatics/bts196). Its read filters are strict: a read counts only if it is uniquely mapped (mapping quality 255 for STAR BAMs), aligned in a proper pair, carries no more than six non-reference bases, and falls entirely within exon boundaries. Reads overlapping introns are discarded. Exon-level counts are produced as well, and a read spanning several exons contributes to each in proportion to the share of the read it covers. Transcript-level expression comes from RSEM v1.3.0 against a transcript-level GTF.\n", + "\n", + "Strandedness can be given per sample in the manifest as `rf`, `fr`, `unstranded` or `strand_missing`, following the library types of [Signal et al. (2022)](https://doi.org/10.1186/s12859-022-04572-7); see the [strand settings reference](https://rnabio.org/module-09-appendix/0009/12/01/StrandSettings/) for what these mean. When it is not supplied, the `strand_detected` workflow infers it from the gene count table [STAR](https://physiology.med.cornell.edu/faculty/skrabanek/lab/angsd/lecture_notes/STARmanual.pdf) emits. Read length is likewise per sample; a length of zero falls back to 100, which `--sjdbOverhang` can change.\n", + "\n", + "Three workflows sit outside that main path. `bam_to_fastq` recovers FASTQ from aligned BAM when only BAM is available. `trimmomatic_trim_adaptor` is an alternative to `fastp`. `filter_reads` filters the alignments for allele-specific work: WASP correction drops reads carrying WASP flags, which mitigates reference-allele bias, and unique-read filtering keeps only alignments at mapping quality 255, following GTEx practice. Either can be applied alone or both together.\n", + "\n", + "**When to run it.** At the start of the expression branch, on raw sequencing data, and before `bulk_expression_QC` and `bulk_expression_normalization`, which take the merged matrices produced here." ] }, { @@ -26,11 +39,56 @@ "kernel": "SoS" }, "source": [ - "Our pipeline follows the GTEx pipeline from the [GTEx](https://gtexportal.org/home/aboutGTEx#staticTextAnalysisMethods)/[TOPMed](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md) project for the quantification of expression from RNA-seq data. Either paired end or single end fastq.gz files may be used as the initial input. Different read [strandedness options](https://rnabio.org/module-09-appendix/0009/12/01/StrandSettings/) are possible, including rf, fr, unstranded or strand_missing, based on library types from Signal et al [[cf. Signal et al (2022)](https://doi.org/10.1186/s12859-022-04572-7)]. Strand detection steps are included in this pipeline to automaticaly detect the strand of the input fastq file by levradging the gene count table ouptut from [STAR](https://physiology.med.cornell.edu/faculty/skrabanek/lab/angsd/lecture_notes/STARmanual.pdf). Read length data is required and is set to a default value of 100 for reads of zero length. \n", + "## Input\n", + "\n", + "* `--sample-list` -- tab-delimited manifest with one line per sample and a header. `ID` and `fq1` are required, `fq2` is required for paired-end data, and `strand` and `read_length` are optional:\n", + "\n", + " ```\n", + " ID\tfq1\tfq2\tstrand\tread_length\n", + " SAMPLE_001\tSAMPLE_001_R1.fastq.gz\tSAMPLE_001_R2.fastq.gz\trf\t100\n", + " SAMPLE_002\tSAMPLE_002_R1.fastq.gz\tSAMPLE_002_R2.fastq.gz\trf\t100\n", + " ```\n", + "\n", + " `strand` is `rf`, `fr`, `unstranded` or `strand_missing`; leaving it out lets `strand_detected` infer it. `read_length` of `0` means unknown and falls back to 100. If no sample has a known read length, omit the column entirely rather than filling it with zeros.\n", + "* `--data-dir` -- directory holding the FASTQ files named in `fq1` and `fq2`. The manifest carries bare filenames, so this has to point at the directory that actually contains them.\n", + "* `--cwd` -- output directory.\n", + "\n", + "Reference data, built by `reference_data_preparation`:\n", + "\n", + "* `--STAR-index` -- STAR genome index, required by `STAR_align`.\n", + "* `--RSEM-index` -- RSEM reference, required by `rsem_call`.\n", + "* `--gtf` -- gene model. `STAR_align` and `picard_qc` take the transcript-level GTF, while `rnaseqc_call` takes the collapsed gene-level one; passing the wrong one silently changes what is quantified.\n", + "* `--reference-fasta` -- the genome FASTA the STAR index was built from. It has to be exactly that file; a different copy of the same assembly makes Picard fail.\n", + "* `--ref-flat` -- refFlat annotation for Picard `CollectRnaSeqMetrics`, which reports how bases distribute across UTRs, introns, intergenic regions and coding exons. `reference_data_preparation` generates it in its `RefFlat_generation` step.\n", + "* `--bam-list` -- the BAM manifest written by `STAR_align`, required by `rnaseqc_call` and `rsem_call`.\n", + "\n", + "Adaptor trimming, for `fastp_trim_adaptor` and `trimmomatic_trim_adaptor`:\n", + "\n", + "* `--min-len` -- reads shorter than this after trimming are discarded; `15` under fastp, `50` under Trimmomatic.\n", + "* `--window-size` -- sliding window for quality trimming, default `4`.\n", + "* `--required-quality` -- quality floor within the window, default `20`.\n", + "* `--leading` / `--trailing` -- mean quality below which the leading or trailing window is cut. fastp defaults to `20` and Trimmomatic to `3`, so the fastp setting is by far the stricter, and matches cutadapt.\n", + "* `--fasta-with-adapters-etc` -- adaptor reference. fastp infers adaptors from the reads and does not need one; Trimmomatic does, for instance `TruSeq3-PE.fa` from the Trimmomatic repository, chosen on the evidence of the FastQC overrepresented-sequences report.\n", + "* `--seed-mismatches`, `--palindrome-clip-threshold`, `--simple-clip-threshold` -- Trimmomatic Illumina-clip settings.\n", + "\n", + "Frequently adjusted:\n", + "\n", + "* `--sjdbOverhang` -- splice junction overhang, default `100`, i.e. read length minus one.\n", + "* `--chimSegmentMin` -- minimum chimeric segment length, default `15`; `0` disables chimeric detection.\n", + "* `--mapping-quality` -- uniqueness cutoff, default `255`.\n", + "* `--detection-threshold` (`rnaseqc_call`) and `--max-frag-len`, `--estimate-rspd` (`rsem_call`).\n", + "* `--optical-distance` (`picard_qc`) -- default `100`; patterned flowcells such as HiSeq X need `2500`.\n", + "* `--zap-raw-bam` -- delete the raw BAM once duplicates are marked.\n", + "* `--varVCFfile` -- variant VCF used to prepare WASP filtering.\n", + "* `--uncompressed` -- set when the FASTQ files are not gzipped.\n", + "\n", + "The captured help below lists every option, including the fastp and Trimmomatic trimming settings and the full set of STAR arguments.\n", "\n", - "We recommend using fastqc to quality control reads, followed by the removal of adaptors with fastp if necessary. After quality control has been conducted, STAR may be used to align reads to the reference genome. We combine this mapping step with an additionaly quality control step using Picard to mark duplicate reads and collect other metrics. \n", + "Runtime:\n", "\n", - "Gene-level RNA expression is called with RNA-SeQC v2.4.2 using a reference gtf that has been collapsed to contain genes instead of gene transcripts [[cf. DeLuca et al., Bioinformatics, 2012](https://doi.org/10.1093/bioinformatics/bts196)]. Reads are only included if they are uniquely mapped (mapping quality of 255 for STAR BAMs), if they are aligned in proper pairs, if the read alignment distance was less than or equal to six (i.e. alignments must not contain more than six non-reference bases), and if they are fully contained within exon boundaries. Reads overlapping introns are not included. Exon level read counts are also called by RNA-SeQC. If a read overlaps multiple exons, then a fractional value equal to the portion of the read contained within the exon is allotted. We call transcript-level RNA expression using RSEM v1.3.0 with a transcript reference gtf. " + "* `--numThreads`, `--job-size`, `--walltime`, `--mem` -- threads and cluster resources.\n", + "* `--container`, `--entrypoint` -- software environment.\n", + "* `--modular-script-dir` -- location of the drivers, default `code/script`." ] }, { @@ -39,7 +97,30 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~10-30 min on typical compute infrastructure." + "## Output\n", + "\n", + "* `_fastqc.html` and `_fastqc.zip` -- per-sample FastQC reports.\n", + "* `.trimmed.fq.gz` with `.trimmed.fq.html` and `.json` -- trimmed reads and the fastp report; `.trimmed.txt` is the manifest of trimmed files. A read whose mate did not survive trimming is discarded by default. `trimmomatic_trim_adaptor` instead keeps them, writing paired and unpaired FASTQ separately, four files per paired-end sample.\n", + "* `.Aligned.sortedByCoord.out.bam` and `.Aligned.toTranscriptome.out.bam` -- STAR genome and transcriptome alignments. `filter_reads` writes a WASP-filtered `..._wasp_qc...bam` alongside.\n", + "* `.bam_file_list` -- the BAM manifest that `rnaseqc_call` and `rsem_call` consume through `--bam-list`:\n", + "\n", + " ```\n", + " sample_id\tstrand\tcoord_bam_list\tBW_list\tSJ_list\ttrans_bam_list\n", + " SAMPLE_001\trf\tSAMPLE_001.Aligned.sortedByCoord.out_nowasp_noqc.md.bam\tSAMPLE_001.Aligned.sor\n", + " ```\n", + "\n", + "* `.alignment_summary_metrics` and the merged `.picard.aggregated_quality.metrics.tsv` -- Picard duplicate and alignment metrics; the marked BAM flags duplicates with `0x400`, decimal 1024:\n", + "\n", + " ```\n", + " Sample PF_READS PF_READS_ALIGNED PCT_PF_READS_ALIGNED PCT_RIBOSOMAL_BASES PCT_CODING_BASES P\n", + " SAMPLE_002 200000 12498 0.06249 0.001012 0.039564 0.289782 0.270124 0.399518 0.329346 0.0184\n", + " ```\n", + "\n", + "* `.rnaseqc.gene_tpm.gct.gz`, `.gene_readsCount.gct.gz` and `.exon_readsCount.gct.gz` -- RNA-SeQC gene- and exon-level quantifications, merged across samples into `.rnaseqc.*.gct.gz`, next to `.metrics.tsv` and per-transcript coverage statistics.\n", + "* `.rsem.genes.results` and `.rsem.isoforms.results` -- RSEM per-sample estimates, with run statistics in `.rsem.stat/` including the `.cnt` read-assignment counts. These merge into seven files, four from the isoform columns and three from the gene columns, among them `.rsem_transcripts_expected_count.txt.gz` and the matching TPM and gene-level matrices.\n", + "* `.multiqc_report.html` -- MultiQC summary across all of the above.\n", + "\n", + "Each step also writes `.stdout` and `.stderr` beside its output. Example results for the toy data are under `output/rnaseq/`, but the raw FASTQ files that produced them are not distributed in this repository." ] }, { @@ -48,26 +129,9 @@ "kernel": "SoS" }, "source": [ - "## Input\n", - "\n", - "A tab delimited file containing sample read information with one line per sample. This file should include a header for the following columns:\n", - "\n", - "1. `ID` - sample ID (required)\n", - "2. `fq1` - name of the fastq file (required)\n", - "3. `fq2` - name of the second fastq file of the sample if using paired end data (required only if using paired end data)\n", - "4. `strand` - the strandedness of the sample (optional) \n", - "[Options include](https://rnabio.org/module-09-appendix/0009/12/01/StrandSettings/) rf, fr, unstranded or strand_missing, based on library types from Signal et al [[cf. Signal et al. 2022](https://doi.org/10.1186/s12859-022-04572-7)]. Strand detection steps are included in this pipeline to automaticaly detect the strand of the input fastq file by leveraging the gene count table ouptut from STAR. \n", - "5. `read_length` - the read length of the sample's reads (optional) \n", - "If this is unknown, enter 0 and the pipeline will use a default read length of 100. This default can be changed using the `--sjdbOverhang` parameter. If none of the samples have read length information then please leave out the read_length column so that the pipeline uses the default length for each sample. \n", - "## Output\n", - "\n", - "The pipeline runs per sample under `--cwd` and produces, in addition to the intermediate alignment files described in the steps below:\n", + "## Minimal Working Example\n", "\n", - "- `{sample_id}.Aligned.sortedByCoord.out.bam` \u2014 coordinate-sorted STAR alignments (a WASP-filtered `..._wasp_qc...bam` variant is also produced for allele-specific work).\n", - "- `{sample_id}.rsem.genes.results` and `{sample_id}.rsem.isoforms.results` \u2014 per-sample RSEM gene- and transcript-level expression estimates (counts and TPM); `.rsem.stat/` holds the RSEM run statistics.\n", - "- `{sample_id}.rnaseqc.gene_tpm.gct.gz` \u2014 RNA-SeQC gene-level TPM matrix used for QC.\n", - "- `{sample_id}.multiqc_report.html` and `*.alignment_summary_metrics` \u2014 MultiQC and Picard alignment-QC summaries.\n", - "- `{bam_list}.rsem_transcripts_expected_count.txt.gz` and the merged `*.rnaseqc.gene_tpm.gct.gz` \u2014 cohort-level expression matrices that merge all samples, ready for downstream normalization.\n" + "These commands use the two demo samples listed in `input/rnaseq/protocol_example.rnaseq.fastq.list.txt`, with the simplest alignment recipe, no WASP filtering and no unique-read filtering, which is what quantifying expression for eQTL analysis calls for. The main path is `fastqc`, `fastp_trim_adaptor`, `STAR_align`, `rnaseqc_call`, `rsem_call`, run in that order; the remaining blocks are optional or alternatives. The raw FASTQ files are not distributed in this repository, so `--data-dir` is shown as a placeholder and has to point at the directory holding the files the manifest names." ] }, { @@ -76,20 +140,9 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", - "\n", - "The pipeline is driven by a tab-delimited sample list and a directory of paired-end FASTQ files, plus shared reference data.\n", + "### Convert BAM back to FASTQ (optional)\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `input/rnaseq/protocol_example.rnaseq.fastq.list.txt` | Sample manifest (`ID`, `fq1`, `fq2`, `strand`, `read_length`); two demo samples `SAMPLE_001`, `SAMPLE_002` |\n", - "| `input/rnaseq/protocol_example.rnaseq.fastq/` | Paired-end FASTQ files referenced by `fq1`/`fq2` |\n", - "| `reference_data/STAR_Index/` | STAR genome index (chromosome-subset for the demo) |\n", - "| `reference_data/RSEM_Index/` | RSEM reference (matching transcript-level GTF) |\n", - "| `reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta` | Reference genome FASTA |\n", - "| `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf` | Transcript-level annotation (STAR / RSEM) |\n", - "| `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` | Collapsed gene-level annotation (RNA-SeQC) |\n", - "| `reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat` | refFlat annotation (Picard) |" + "Only needed when the starting material is aligned BAM rather than FASTQ." ] }, { @@ -98,9 +151,21 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example\n", - "\n", - "The commands below run each stage of the pipeline on the two demo samples. They use the simplest alignment recipe (no WASP / no unique filtering), which is appropriate for quantifying expression for eQTL analysis. Run them in order; each stage consumes the output of the previous one." + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/RNA_calling.ipynb bam_to_fastq \\\n", + "--cwd output/rnaseq \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/bam" ] }, { @@ -112,6 +177,16 @@ "### Quality control with `fastqc`" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -121,9 +196,9 @@ "outputs": [], "source": [ "sos run pipeline/RNA_calling.ipynb fastqc \\\n", - " --cwd output/rnaseq/fastqc \\\n", - " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/" + "--cwd output/rnaseq/fastqc \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq" ] }, { @@ -137,6 +212,16 @@ "Generates trimmed FASTQ files and a new sample list pointing at them." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -146,13 +231,43 @@ "outputs": [], "source": [ "sos run pipeline/RNA_calling.ipynb fastp_trim_adaptor \\\n", - " --cwd output/rnaseq \\\n", - " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/ \\\n", - " --STAR-index reference_data/STAR_Index \\\n", - " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \n" + "--cwd output/rnaseq \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Trim adaptors with `Trimmomatic` (alternative)\n", + "\n", + "An alternative to the fastp step above. Run one or the other, not both." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/RNA_calling.ipynb trimmomatic_trim_adaptor \\\n", + "--cwd output/rnaseq \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq" ] }, { @@ -166,6 +281,16 @@ "Aligns reads and produces the per-run BAM manifest (`.bam_file_list`) that the downstream RSEM step consumes. The recipe below adds no WASP/unique-filter tags (fastest; suitable for eQTL expression quantification). Other recipes are available by adding `--wasp yes` and/or `--unique yes` together with a `--varVCFfile`." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -175,15 +300,86 @@ "outputs": [], "source": [ "sos run pipeline/RNA_calling.ipynb STAR_align \\\n", - " --cwd output/rnaseq/bam \\\n", - " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/ \\\n", - " --STAR-index input/reference_data/STAR_Index \\\n", - " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", - " --chimSegmentMin 0 \\\n", - " -J 2 --mem 16G --numThreads 2 \n" + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq \\\n", + "--STAR-index reference_data/STAR_Index \\\n", + "--gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + "--reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + "--ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", + "--chimSegmentMin 0 \\\n", + "-J 2 --mem 16G --numThreads 2" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Detect strandedness\n", + "\n", + "Infers the library strand from the STAR gene counts, for samples whose manifest leaves `strand` empty. Run it after `STAR_align`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/RNA_calling.ipynb strand_detected \\\n", + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Mark duplicates and collect Picard metrics\n", + "\n", + "`picard_qc` is also the second step of `STAR_align`, so the alignment above has already run it. This command runs it on its own, for instance on BAMs aligned outside this pipeline." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/RNA_calling.ipynb picard_qc \\\n", + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq \\\n", + "--gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + "--ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", + "--reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta" ] }, { @@ -197,6 +393,16 @@ "Uses the collapsed gene-level GTF. Point `--bam_list` at the manifest produced by `STAR_align` and keep `--cwd` consistent with where the BAMs live." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -206,12 +412,12 @@ "outputs": [], "source": [ "sos run pipeline/RNA_calling.ipynb rnaseqc_call \\\n", - " --cwd output/rnaseq/bam \\\n", - " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/ \\\n", - " --gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", - " --reference-fasta input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --bam_list output/rnaseq/bam/protocol_example.rnaseq.fastq.list.bam_file_list \n" + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq \\\n", + "--gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", + "--reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", + "--bam-list output/rnaseq/bam/protocol_example.rnaseq.fastq.list.bam_file_list" ] }, { @@ -225,6 +431,16 @@ "Uses the transcript-level GTF and the RSEM reference. As above, `--bam_list` is the `STAR_align` manifest and `--cwd` must match the BAM location (the manifest stores bare filenames that are resolved relative to `--cwd`)." ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -234,15 +450,11 @@ "outputs": [], "source": [ "sos run pipeline/RNA_calling.ipynb rsem_call \\\n", - " --cwd output/rnaseq/bam \\\n", - " --sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", - " --data-dir input/rnaseq/ \\\n", - " --STAR-index reference_data/STAR_Index \\\n", - " --gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", - " --reference-fasta reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --ref-flat reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat \\\n", - " --bam_list output/rnaseq/bam/protocol_example.rnaseq.fastq.list.bam_file_list \\\n", - " --RSEM-index reference_data/RSEM_Index \n" + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq \\\n", + "--RSEM-index reference_data/RSEM_Index \\\n", + "--bam-list output/rnaseq/bam/protocol_example.rnaseq.fastq.list.bam_file_list" ] }, { @@ -251,17 +463,9 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "### Filter reads with WASP\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `output/rnaseq/fastqc/*_fastqc.html`, `*_fastqc.zip` | Per-sample FastQC reports |\n", - "| `output/rnaseq/bam/.Aligned.sortedByCoord.out.bam` | STAR genome-coordinate alignments |\n", - "| `output/rnaseq/bam/.Aligned.toTranscriptome.out.bam` | STAR transcriptome alignments (RSEM input) |\n", - "| `output/rnaseq/bam/.bam_file_list` | Per-run BAM manifest consumed by `rnaseqc_call` / `rsem_call` |\n", - "| `output/rnaseq/bam/.rsem.genes.results`, `*.rsem.isoforms.results` | RSEM per-sample quantifications |\n", - "| `output/rnaseq/bam/*rsem_genes_tpm.txt.gz`, `*rsem_transcripts_tpm.txt.gz` | Merged gene/transcript TPM matrices |\n", - "| `output/rnaseq/bam/*multiqc_report.html` | Aggregated QC report |" + "Applies WASP filtering to the alignments, producing the `_wasp_qc` BAMs used for allele-specific analysis." ] }, { @@ -270,11 +474,21 @@ "kernel": "SoS" }, "source": [ - "## Troubleshooting\n", - "\n", - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "| --- | --- | --- | --- | --- |\n", - "| `rsem_call` / `rnaseqc_call` | - | `Target unavailable: .../.Aligned.toTranscriptome.out_*.bam` | `--bam_list` points at a manifest whose bare filenames do not exist under the given `--cwd` (the step prepends `{cwd}/` to each entry) | Use the `STAR_align`-generated `.bam_file_list` and set `--cwd` to the directory that actually holds those BAMs |" + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/RNA_calling.ipynb filter_reads \\\n", + "--cwd output/rnaseq/bam \\\n", + "--sample-list input/rnaseq/protocol_example.rnaseq.fastq.list.txt \\\n", + "--data-dir path/to/fastq" ] }, { @@ -283,7 +497,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -294,7 +508,168 @@ }, "outputs": [], "source": [ - "!sos run RNA_calling.ipynb -h" + "sos run pipeline/RNA_calling.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/RNA_calling.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " bam_to_fastq\n", + " fastqc\n", + " fastp_trim_adaptor\n", + " trimmomatic_trim_adaptor\n", + " STAR_align\n", + " strand_detected\n", + " picard_qc\n", + " rnaseqc_call\n", + " rsem_call\n", + " filter_reads\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --sample-list VAL (as path, required)\n", + " Sample meta data list\n", + " --sample-name (as list)\n", + " Sample names to analyze\n", + " --data-dir path(f\"{sample_list:d}\")\n", + "\n", + " Raw data directory, default to the same directory as\n", + " sample list\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --java-mem 6G\n", + " Memory for Java virtual mechine (`picard`)\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --varVCFfile ''\n", + " VarVCFfile for data preparation for wasp_filtering\n", + " --[no-]uncompressed (default to False)\n", + " Whether the fasta/fastq file is compressed or not.\n", + "\n", + "Sections\n", + " bam_to_fastq:\n", + " fastqc:\n", + " fastp_trim_adaptor_1:\n", + " Workflow Options:\n", + " --window-size 4 (as int)\n", + " sliding window setting\n", + " --required-quality 20 (as int)\n", + " --leading 20 (as int)\n", + " the mean quality requirement option for cut_front\n", + " --trailing 20 (as int)\n", + " the mean quality requirement option for cut_tail\n", + " --min-len 15 (as int)\n", + " reads shorter than length_required will be discarded\n", + " --fasta-with-adapters-etc . (as path)\n", + " Path to the reference adaptors\n", + " fastp_trim_adaptor_2:\n", + " trimmomatic_trim_adaptor:\n", + " Workflow Options:\n", + " --fasta-with-adapters-etc . (as path)\n", + " Illumina clip setting Path to the reference adaptors\n", + " --seed-mismatches 2 (as int)\n", + " --palindrome-clip-threshold 30 (as int)\n", + " --simple-clip-threshold 10 (as int)\n", + " --window-size 4 (as int)\n", + " sliding window setting\n", + " --required-quality 20 (as int)\n", + " --leading 3 (as int)\n", + " Other settings\n", + " --trailing 3 (as int)\n", + " --min-len 50 (as int)\n", + " STAR_align_1:\n", + " Workflow Options:\n", + " --gtf VAL (as path, required)\n", + " Reference gene model\n", + " --STAR-index VAL (as path, required)\n", + " STAR indexing file\n", + " --outFilterMultimapNmax 20 (as int)\n", + " --alignSJoverhangMin 8 (as int)\n", + " --alignSJDBoverhangMin 1 (as int)\n", + " --outFilterMismatchNmax 999 (as int)\n", + " --outFilterMismatchNoverLmax 0.1 (as float)\n", + " --alignIntronMin 20 (as int)\n", + " --alignIntronMax 1000000 (as int)\n", + " --alignMatesGapMax 1000000 (as int)\n", + " --outFilterType BySJout\n", + " --outFilterScoreMinOverLread 0.33 (as float)\n", + " --outFilterMatchNminOverLread 0.33 (as float)\n", + " --limitSjdbInsertNsj 1200000 (as int)\n", + " --outSAMstrandField intronMotif\n", + " --outFilterIntronMotifs None\n", + " --alignSoftClipAtReferenceEnds Yes\n", + " --quantMode TranscriptomeSAM GeneCounts (as list)\n", + " --outSAMattrRGline ID:rg1 SM:sm1 (as list)\n", + " --outSAMattributes NH HI AS nM NM ch (as list)\n", + " --chimSegmentMin 15 (as int)\n", + " --chimJunctionOverhangMin 15 (as int)\n", + " --chimOutType Junctions WithinBAM SoftClip (as list)\n", + " --chimMainSegmentMultNmax 1 (as int)\n", + " --sjdbOverhang 100 (as int)\n", + " --mapping-quality 255 (as int)\n", + " strand_detected_1:\n", + " strand_detected_2:\n", + " Workflow Options:\n", + " --strand ''\n", + " picard_qc, STAR_align_2:\n", + " Workflow Options:\n", + " --gtf VAL (as path, required)\n", + " Reference gene model\n", + " --ref-flat VAL (as path, required)\n", + " Path to flat reference file, for computing QC metric\n", + " --reference-fasta VAL (as path, required)\n", + " The fasta reference file used to generate star index\n", + " --optical-distance 100 (as int)\n", + " For the patterned flowcell models (HiSeq X), change to\n", + " 2500\n", + " --[no-]zap-raw-bam (default to False)\n", + " STAR_align_3:\n", + " rnaseqc_call_1:\n", + " Workflow Options:\n", + " --bam-list VAL (as path, required)\n", + " --gtf VAL (as path, required)\n", + " Reference gene model\n", + " --reference-fasta VAL (as path, required)\n", + " --detection-threshold 5 (as int)\n", + " --mapping-quality 255 (as int)\n", + " rnaseqc_call_2:\n", + " Workflow Options:\n", + " --bam-list VAL (as path, required)\n", + " rsem_call_1:\n", + " Workflow Options:\n", + " --bam-list VAL (as path, required)\n", + " --RSEM-index VAL (as path, required)\n", + " --max-frag-len 1000 (as int)\n", + " --[no-]estimate-rspd (default to True)\n", + " rsem_call_2:\n", + " Workflow Options:\n", + " --bam-list VAL (as path, required)\n", + " rsem_call_3, rnaseqc_call_3:\n", + " rsem_call_4, rnaseqc_call_4:\n", + " filter_reads:\n", + " Workflow Options:\n", + " --unique ''\n", + " --wasp ''\n", + " --mapping-quality 255 (as int)\n", + "```" ] }, { @@ -303,7 +678,7 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation\n" ] }, { @@ -408,7 +783,9 @@ } }, "source": [ - "### **Step 0.** Convert BAM back to fastq if necessary" + "### Step 0. Convert BAM back to FASTQ\n", + "\n", + "Recovers paired FASTQ from an aligned BAM, for datasets that arrive as BAM." ] }, { @@ -441,16 +818,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** QC before alignment\n", - "\n", - "This step utilize `fastqc` and will generate two QC report in `html` format. It should be noted that the [paired_end reads will also be qc separately](https://www.biostars.org/p/190584/)\n", - "\n", - "### Step Inputs\n", + "### Step 1. QC before alignment\n", "\n", - "* `fastq1` and `fastq2`: paths to original `fastq.gz` file.\n", - "\n", - "### Step Outputs\n", - "* Two `html` file for QC report" + "`fastqc` on each FASTQ. Paired-end mates are [assessed separately](https://www.biostars.org/p/190584/), so a paired sample yields two reports." ] }, { @@ -483,32 +853,9 @@ "tags": [] }, "source": [ - "### **Step 2.** Remove adaptor through `fastp`\n", - "\n", - "Documentation: [fastp](https://github.com/OpenGene/fastp)\n", - "\n", - "We use `fastp` in place of the `Trimmomatic` for fastp's ability to detect adapter from the reads. It was a c++ command line tool published in [Sept 2018](https://academic.oup.com/bioinformatics/article/34/17/i884/5093234). It will use the following algorithm to detect the adaptors:\n", - ">The adapter-sequence detection algorithm is based on two assumptions: the first is that only one adapter exists in the data; the second is that adapter sequences exist only in the read tails. These two assumptions are valid for major next-generation sequencers like Illumina HiSeq series, NextSeq series and NovaSeq series. We compute the k-mer (k\u2009=\u200910) of first N reads (N\u2009=\u20091\u2009M). From this k-mer, the sequences with high occurrence frequencies (>0.0001) are considered as adapter seeds. Low-complexity sequences are removed because they are usually caused by sequencing artifacts. The adapter seeds are sorted by its occurrence frequencies. A tree-based algorithm is applied to extend the adapter seeds to find the real complete adapter\n", - "\n", - "It was demostrated that fastp can remove all the adaptor automatically and completely faster than Trimmomatic and cutadapt\n", - "\n", - "### Step Inputs\n", - "\n", - "* `fastq`: 1 set of fq.gz file for each sample. (2 files if paired end, 1 file if single end )\n", - "\n", - "### Step Outputs\n", - "* 1 set of `fastq.gz` file for alignment. (2 files if paired end, 1 file if single end )\n", - "* The unpaired reads (i.e.where a read survived, but the partner read did not.) will be discarded by default as those were not used in the following steps. This feature can be added were it was needed. \n", - "* 1 set of html documenting the quality of input reads(1 html file and 1 json file)\n", - "\n", - "### Step options\n", - "\n", - "A few options were selected to be customizable so that fastp step can have the same level of flexiblity as the Trimmomatic step had. They are:\n", - "- min_len: length_required, reads shorter than this will be discarded, default is 15. (int [=15])\n", - "- window_size: cut_window_size, the window size option shared by cut_front, cut_tail or cut_sliding. Range: 1~1000, default: 4 (int [=4])\n", - "- leading/trailing : cut_front_mean_quality/cut_tail_mean_quality, the mean quality requirement option for cut_front/cut_tail, which move a sliding window from front/tail, drop the bases in the window if its mean quality < threshold. **Notice the choice of quality score in `fastp` (N=20) is a lot higher than that of `trimmomatic` (N=3)**. Default `fastp` setting is in line with that of [`cutadapt`](https://cutadapt.readthedocs.io/en/stable/guide.html).\n", + "### Step 2. Remove adaptors with `fastp`\n", "\n", - "The default value are set to be the same as the default value of the `fastp` software." + "Documentation: [fastp](https://github.com/OpenGene/fastp). fastp infers the adaptor from the reads themselves: assuming a single adaptor confined to read tails, it counts 10-mers over the first million reads, keeps the frequent ones as seeds once low-complexity artefacts are dropped, and extends them by a tree search. No adaptor reference is required." ] }, { @@ -537,7 +884,15 @@ "output: [f'{cwd}/{path(x):bn}.trimmed.fq.gz' for x in _input]\n", "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", - " bash ${modular_script_dir}/molecular_phenotypes/calling/RNA_calling.sh fastp_trim_adaptor \\\n --cwd ${cwd} \\\n --paired-end ${is_paired_end} \\\n --input-fastq1 ${_input[0]} ${f'--input-fastq2 {_input[1]}' if is_paired_end else ''} \\\n --output-fastq1 ${_output[0]} ${f'--output-fastq2 {_output[1]}' if is_paired_end else ''} \\\n --adapter-fasta ${fasta_with_adapters_etc} \\\n --min-len ${min_len} --window-size ${window_size} \\\n --required-quality ${required_quality} --leading ${leading} --trailing ${trailing} \\\n --numThreads ${numThreads}\n" + " bash ${modular_script_dir}/molecular_phenotypes/calling/RNA_calling.sh fastp_trim_adaptor \\\n", + " --cwd ${cwd} \\\n", + " --paired-end ${is_paired_end} \\\n", + " --input-fastq1 ${_input[0]} ${f'--input-fastq2 {_input[1]}' if is_paired_end else ''} \\\n", + " --output-fastq1 ${_output[0]} ${f'--output-fastq2 {_output[1]}' if is_paired_end else ''} \\\n", + " --adapter-fasta ${fasta_with_adapters_etc} \\\n", + " --min-len ${min_len} --window-size ${window_size} \\\n", + " --required-quality ${required_quality} --leading ${leading} --trailing ${trailing} \\\n", + " --numThreads ${numThreads}\n" ] }, { @@ -568,30 +923,9 @@ "toc-hr-collapsed": true }, "source": [ - "## Step 2 Alternative: Remove adaptor through `Trimmomatic`\n", - "\n", - "Documentation: [Trimmomatic](http://www.usadellab.org/cms/?page=trimmomatic)\n", - "\n", - "We have replaced this with `fastp`, see above, which performs better than `Trimmomatic` in terms of removing adaptors that `Trimmomatic` cannot detect. `fastp` can also automatically guess the adapter sequences from data and by default no adapter sequence is required for input to `fastp`.\n", - "\n", - "### Step Inputs\n", - "\n", - "* `software_dir`: directory for the software\n", - "* `fasta_with_adapters_etc`: **filename** for the adapter reference file. According to `Trimmomatic` documention,\n", - "\n", - "> As a rule of thumb newer libraries will use `TruSeq3`, but this really depends on your service provider. If you use FASTQC, the \"Overrepresented Sequences\" report can help indicate which adapter file is best suited for your data. \"Illumina Single End\" or \"Illumina Paired End\" sequences indicate single-end or paired-end `TruSeq2` libraries, and the appropriate adapter files are `TruSeq2-SE.fa` and `TruSeq2-PE.fa` respectively. \"TruSeq Universal Adapter\" or \"TruSeq Adapter, Index \u2026\" indicates `TruSeq-3` libraries, and the appropriate adapter files are `TruSeq3-SE.fa` or `TruSeq3-PE.fa`, for single-end and paired-end data respectively. Adapter sequences for `TruSeq2` multiplexed libraries, indicated by \"Illumina Multiplexing \n", - "\u2026\", and the various RNA library preparations are not currently included.\n", - "\n", - "We have `fastqc` workflow previously defined and executed. Users should decide what fasta adapter reference to use based on `fastqc` results (or their own knowledge).\n", + "### Step 2 alternative: remove adaptors with `Trimmomatic`\n", "\n", - "### Step Outputs\n", - "* Two paired `fastq.gz` file for alignment\n", - "* Two unpaired `fastq.gz` \n", - "\n", - ">For single-ended data, one input and one output file are specified, plus the processing steps. For paired-end data, two input files are specified, and 4 output files, 2 for the 'paired' output where both reads survived the processing, and 2 for corresponding 'unpaired' output where a read survived, but the partner read did not.\n", - "\n", - "\n", - "**You need to figure out from fastqc results what adapter reference sequence to use.**, eg `--fasta_with_adapters_etc TruSeq3-PE.fa`. These files can be downloaded from `Trimmomatic` github repo." + "Documentation: [Trimmomatic](http://www.usadellab.org/cms/?page=trimmomatic). Superseded by `fastp`, which catches adaptors Trimmomatic cannot detect and needs no adaptor reference. Kept for cases where a known reference is preferred." ] }, { @@ -621,7 +955,17 @@ "output: ([ f'{cwd}/{_sample_id}_paired_{_input[0]:bn}.gz', f'{cwd}/{_sample_id}_unpaired_{_input[0]:bn}.gz', f'{cwd}/{_sample_id}_paired_{_input[1]:bn}.gz',f'{cwd}/{_sample_id}_unpaired_{_input[1]:bn}.gz' ] if is_paired_end else f'{cwd}/{_sample_id}_trimmed_{_input:bn}.gz')\n", "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout'\n", - " bash ${modular_script_dir}/molecular_phenotypes/calling/RNA_calling.sh trimmomatic_trim_adaptor \\\n --cwd ${cwd} \\\n --paired-end ${is_paired_end} \\\n --java-mem ${java_mem} \\\n --input-fastq1 ${_input[0]} ${f'--input-fastq2 {_input[1]}' if is_paired_end else ''} \\\n ${f'--output-paired1 {_output[0]} --output-unpaired1 {_output[1]} --output-paired2 {_output[2]} --output-unpaired2 {_output[3]}' if is_paired_end else f'--output-se {_output}'} \\\n --adapter-fasta ${fasta_with_adapters_etc} \\\n --seed-mismatches ${seed_mismatches} --palindrome-clip-threshold ${palindrome_clip_threshold} \\\n --simple-clip-threshold ${simple_clip_threshold} \\\n --leading ${leading} --trailing ${trailing} \\\n --window-size ${window_size} --required-quality ${required_quality} --min-len ${min_len}\n" + " bash ${modular_script_dir}/molecular_phenotypes/calling/RNA_calling.sh trimmomatic_trim_adaptor \\\n", + " --cwd ${cwd} \\\n", + " --paired-end ${is_paired_end} \\\n", + " --java-mem ${java_mem} \\\n", + " --input-fastq1 ${_input[0]} ${f'--input-fastq2 {_input[1]}' if is_paired_end else ''} \\\n", + " ${f'--output-paired1 {_output[0]} --output-unpaired1 {_output[1]} --output-paired2 {_output[2]} --output-unpaired2 {_output[3]}' if is_paired_end else f'--output-se {_output}'} \\\n", + " --adapter-fasta ${fasta_with_adapters_etc} \\\n", + " --seed-mismatches ${seed_mismatches} --palindrome-clip-threshold ${palindrome_clip_threshold} \\\n", + " --simple-clip-threshold ${simple_clip_threshold} \\\n", + " --leading ${leading} --trailing ${trailing} \\\n", + " --window-size ${window_size} --required-quality ${required_quality} --min-len ${min_len}\n" ] }, { @@ -631,27 +975,9 @@ "toc-hr-collapsed": true }, "source": [ - "### **Step 3.** Alignment through `STAR`\n", - "\n", - "Documentation : [STAR](https://github.com/alexdobin/STAR) and [Script in docker](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_STAR.py)\n", - "\n", - "This step is the main step for `STAR` alignment. \n", - "\n", - "Originally, the STAR alignment is implemented using the run_STAR.py command from gtex. However, in order to [accomodate different read length among samples](https://github.com/statfungen/xqtl-protocol/issues/318), We reimplement what was included in the wrapper, including the re-alignment of STAR unsorted bam using samtools to avoid high mem consumption. \n", - "\n", - "\n", + "### Step 3. Alignment with `STAR`\n", "\n", - "### Step Inputs\n", - "\n", - "* paths to trimmed `fastq.gz` file from Step 1 as documented in the new sample list.\n", - "* `STAR_index`: directory for the STAR aligment index\n", - "\n", - "### Step Outputs\n", - "\n", - "* bam file output `${cwd}/{sample_id}.Aligned.sortedByCoord.bam`, will be used in step 3 and 4\n", - "* bam file output `${cwd}/{sample_id}.Aligned.toTranscriptome.bam`, will be used in step 5\n", - "\n", - "**NB:** \"${}\" and \"$[]\" are exchangeable as expension, just to keep them consistent throught the bash block." + "Documentation: [STAR](https://github.com/alexdobin/STAR), and the GTEx [run_STAR.py](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_STAR.py) wrapper this step reimplements inline. Produces both the genome-coordinate and the transcriptome BAM." ] }, { @@ -802,26 +1128,9 @@ "toc-hr-collapsed": true }, "source": [ - "### **Step 4.** Mark duplicates reads & QC through `Picard`\n", - "\n", - "This step is the first QC step after `STAR` alignment. This step will performed QC to collect multipe metrics regarding the RNASeq using Picard. Then it will also generate a new `.bam` file with duplication marked with the hexadecimal value of `0x0400`, which corresponds to a decimal value of 1024\n", - " \n", - "### Step Inputs:\n", - "\n", - "* `STAR_bam`: path to the output in Step 2.\n", - "* `reference_fasta`: The fasta reference file used to generate star index, it is critical that the this fasta is *exactly* the same as those that generate the STAR Index, else this error will occurs: https://github.com/statfungen/xqtl-protocol/issues/357\n", - "\n", - "* `RefFlat file` \n", - "\n", - "This file is needed for picard CollectRnaSeqMetrics module, which in turn\n", - "> produces metrics describing the distribution of the bases within the transcripts. It calculates the total numbers and the fractions of nucleotides within specific genomic regions including untranslated regions (UTRs), introns, intergenic sequences (between discrete genes), and peptide-coding sequences (exons). This tool also determines the numbers of bases that pass quality filters that are specific to Illumina data (PF_BASES).\n", - "\n", - "The refFlat file can be generated by the reference_data module, RefFlat_generation step.\n", + "### Step 4. Mark duplicates and collect metrics with `Picard`\n", "\n", - "### Step Outputs:\n", - "\n", - "* A collection of metrics file for each of the samples\n", - "* A new `.bam` file with duplication marked with the hexadecimal value of `0x0400`, which corresponds to a decimal value of 1024\n" + "The first QC pass after alignment: collects Picard RNA-seq metrics and rewrites the BAM with duplicates flagged." ] }, { @@ -906,40 +1215,9 @@ "toc-hr-collapsed": true }, "source": [ - "### **Step 5.** Post aligment QC through `RNA-SeQC`" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Documentation : [RNA-SeQC](https://github.com/getzlab/rnaseqc) and [Script in docker](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_rnaseqc.py)\n", - "\n", - "This step is second QC step after `STAR` alignment. It will perform RNA-seq quantification as well. \n", - "\n", - "### Step Inputs\n", - "\n", - "* `bam_list`: path to the output of STAR_output, which outlined the strands and bam file used for each samples.\n", - "* `gtf`: reference genome `.gtf` file, this gtf file need to have the same chr name format as the index used to generate the bam file and must be on collapsed gene gtf \n", - "\n", - "### Step Outputs\n", - "\n", - "\n", - "The following output files are generated in the output directory you provide:\n", - "\n", - "* {sample}.metrics.tsv : A tab-delimited list of (Statistic, Value) pairs of all statistics and metrics recorded.\n", - "\n", - "* {sample}.exon_reads.gct : A tab-delimited GCT file with (Exon ID, Gene Name, coverage) tuples for all exons which had at least part of one read mapped.\n", + "### Step 5. Post-alignment QC and quantification with `RNA-SeQC`\n", "\n", - "* {sample}.gene_reads.gct : A tab-delimited GCT file with (Gene ID, Gene Name, coverage) tuples for all genes which had at least one read map to at least one of its exons\n", - "\n", - "* {sample}.gene_tpm.gct : A tab-delimited GCT file with (Gene ID, Gene Name, TPM) tuples for all genes reported in the gene_reads.gct file. Note: this file is renamed to .gene_rpkm.gct if the --rpkm flag is present.\n", - "\n", - "* {sample}.fragmentSizes.txt : A list of fragment sizes recorded, if a BED file was provided\n", - "\n", - "* {sample}.coverage.tsv : A tab-delimited list of (Gene ID, Transcript ID, Mean Coverage, Coverage Std, Coverage CV) tuples for all transcripts encountered in the GTF.\n" + "Documentation: [RNA-SeQC](https://github.com/getzlab/rnaseqc), and the GTEx [run_rnaseqc.py](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_rnaseqc.py). The second QC pass, which also produces the gene- and exon-level quantifications." ] }, { @@ -1002,7 +1280,7 @@ "kernel": "SoS" }, "source": [ - "The RNASEQC results were merged in the following step," + "The per-sample RNA-SeQC results are merged in the step below." ] }, { @@ -1036,20 +1314,9 @@ "toc-hr-collapsed": true }, "source": [ - "### **Step 6.** Quantify expression through `RSEM`\n", - "\n", - "Documentation : [RSEM](https://deweylab.github.io/RSEM/rsem-calculate-expression.html) and [Script in docker](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_RSEM.py)\n", - "\n", - "This step generate the expression matrix from STAR output. Estimate gene and isoform expression from RNA-Seq data are generated.\n", + "### Step 6. Quantify expression with `RSEM`\n", "\n", - "### Step Input\n", - "\n", - "* `bam_list`: path to the output of STAR_output, which outlined the strands and bam file used for each samples.\n", - "* transcript-level BAM file: path to the output of Step 3.\n", - "* `RSEM_index`: path to RSEM index\n", - "\n", - "### Step Outputs\n", - "Please see the output section of https://deweylab.github.io/RSEM/rsem-calculate-expression.html" + "Documentation: [RSEM](https://deweylab.github.io/RSEM/rsem-calculate-expression.html), and the GTEx [run_RSEM.py](https://github.com/broadinstitute/gtex-pipeline/blob/master/rnaseq/src/run_RSEM.py). Estimates gene- and isoform-level expression from the transcriptome BAM." ] }, { @@ -1101,7 +1368,7 @@ "kernel": "SoS" }, "source": [ - "The RSEM results were merged in the following steps, seven files (four for each columns in the isoform output and 3 for each of the genes output) will be generated." + "The per-sample RSEM results are merged in the steps below." ] }, { @@ -1139,16 +1406,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 7.** summarize with MultiQC\n", - "\n", - "[MultiQC](https://multiqc.info/docs/#using-multiqc) \n", - "\n", + "### Step 7. Summarize with MultiQC\n", "\n", - ">MultiQC is a reporting tool that parses summary statistics from results and log files generated by other bioinformatics tools. MultiQC doesn't run other tools for you - it's designed to be placed at the end of analysis pipelines or to be run manually when you've finished running your tools. When you launch MultiQC, it recursively searches through any provided file paths and finds files that it recognises. It parses relevant information from these and generates a single stand-alone HTML report file. It also saves a directory of data files with all parsed data for further downstream use.\n", - "\n", - "MultiQC will automatically generate QC report for anything embedded within the given directory. Therefore providing the directory containing all the output will surfice.\n", - "\n", - "The output of MultiQC is a multi-module report each corresponding to the quality report of each step of analysis previously performed." + "[MultiQC](https://multiqc.info/docs/#using-multiqc) searches the output directory, recognises the logs and summary files the earlier steps left behind, and writes a single HTML report plus a directory of parsed data. Pointing it at the directory holding all outputs is enough." ] }, { @@ -1198,29 +1458,9 @@ "kernel": "SoS" }, "source": [ - "### **Step 8.** Filter Reads with WASP\n", - "\n", - "This optional step in the STAR alignment process offers filtration based on WASP correction and unique read identification. WASP correction mitigates reference allele bias in RNA-seq data by eliminating reads with specific WASP flags. Unique read filtering retains only uniquely mapped reads, identified by a mapping quality (MAPQ) value of 255, as per GTEx Consortium standards. These filters can be applied individually or in combination to enhance alignment quality and prepare BAM files for different analysis.\n", - " \n", - "### Step Inputs:\n", - "\n", - "* No input needed to specify manually. All files are from the output from `STAR_align_1`\n", - "\n", - "### Step Outputs:\n", + "### Step 8. Filter reads with WASP\n", "\n", - "* A collection of filtered(or not) `.bam` files\n", - " " - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "Optional. It reads the `STAR_align_1` output directly, so no input has to be named." ] }, { @@ -1251,6 +1491,19 @@ " --wasp \"${wasp}\" \\\n", " --mapping-quality \"${mapping_quality}\"\n" ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Troubleshooting\n", + "\n", + "| Step | Substep | Problem | Possible Reason | Solution |\n", + "| --- | --- | --- | --- | --- |\n", + "| `rsem_call` / `rnaseqc_call` | - | `Target unavailable: .../.Aligned.toTranscriptome.out_*.bam` | `--bam_list` points at a manifest whose bare filenames do not exist under the given `--cwd` (the step prepends `{cwd}/` to each entry) | Use the `STAR_align`-generated `.bam_file_list` and set `--cwd` to the directory that actually holds those BAMs |" + ] } ], "metadata": { diff --git a/code/SoS/molecular_phenotypes/calling/apa_calling.ipynb b/code/SoS/molecular_phenotypes/calling/apa_calling.ipynb index c76d338b9..2e964fb5a 100644 --- a/code/SoS/molecular_phenotypes/calling/apa_calling.ipynb +++ b/code/SoS/molecular_phenotypes/calling/apa_calling.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# APA Calling" + "# APA Calling\n", + "\n", + "Quantifies alternative polyadenylation from RNA-seq coverage with DaPars2, producing per-sample PDUI values." ] }, { @@ -15,17 +17,32 @@ "kernel": "SoS" }, "source": [ - "## Aim\n", - "The purpose of this notebook is to call APA-based information (PDUI) based on [DAPARS2 method](https://github.com/3UTR/DaPars2)." + "## Overview\n", + "\n", + "Most genes have more than one polyadenylation site, and which one is used shifts the length\n", + "of the 3' UTR - changing which regulatory elements survive in the transcript. Treating a\n", + "gene as a single expression value hides that. This step quantifies alternative\n", + "polyadenylation from RNA-seq coverage with [DaPars2](https://github.com/3UTR/DaPars2), giving a per-sample PDUI (percentage of\n", + "distal polyA site usage) that can be scanned for QTLs like any other molecular phenotype.\n", + "\n", + "The workflows run in order: `UTR_reference` builds the annotation DaPars2 needs,\n", + "`bam2tools` converts alignments to coverage, `APAconfig` writes the configuration file and\n", + "`APAmain` runs the quantification.\n", + "\n", + "**When to run it.** After RNA-seq alignment, as an alternative or complement to expression\n", + "and splicing quantification. The output feeds phenotype preprocessing like any other\n", + "molecular phenotype matrix." ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Methods" + "%preview ../../images/apa_calling.png" ] }, { @@ -34,18 +51,53 @@ "kernel": "SoS" }, "source": [ - "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [ - "%preview ../../images/apa_calling.png" + "## Input\n", + "\n", + "The workflow runs in four stages, and each stage consumes the output of the one before it. Only the first two stages need files you supply yourself.\n", + "\n", + "- `--cwd output/apa` (working directory all outputs are written under. Used by every stage. Defaults to `output`.)\n", + "\n", + "**Step 1, `UTR_reference`.**\n", + "\n", + "- `--hg-gtf` **`output/apa/chr22.gtf`**\n", + "(a gene annotation GTF matching the genome build used for alignment. The step reads transcript records from it and derives the 3'UTR intervals that DaPars2 will test. Built from the transcriptome-level gene feature file [prepared by the reference data module](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/reference_data.html).)\n", + "\n", + "**Step 2, `bam2tools`.**\n", + "\n", + "- `--bam-dir` (a directory of transcriptome-aligned BAM files, one per sample. Sample names are taken from the BAM file stems, so those stems must match the identifiers you expect downstream.)\n", + "- `--bam-list` (an explicit list of BAM paths; use instead of `--bam-dir`)\n", + "\n", + "**Step 3, `APAconfig`.**\n", + "\n", + "- `--bfile output/apa/wig` (the directory of WIG tracks written by `bam2tools`. The tracks must end in `.wig`; renaming a `.bedgraph` is enough. The first line is treated as a header, so add any content there if the file has none. If the first column does not carry the `chr` prefix, set `no_chr_prefix = T`.)\n", + "- `--annotation` **`output/apa/chr22_3UTR.bed`**\n", + "(the 3'UTR BED written by `UTR_reference`)\n", + "- `--coverage-threshold 10` (minimum read depth a sample must reach in a region)\n", + "- `--least-pass-coverage-percentage 0.3` (fraction of samples that must clear that depth)\n", + "\n", + "**Step 4, `APAmain`.**\n", + "\n", + "- `--chrlist chr22` (the chromosomes to process)\n", + "- `--chr-prefix true` (set to `False` if contig names in your BAMs lack the `chr` prefix)\n", + "- `--dapars-path code/SoS/molecular_phenotypes/calling/apa` (location of the bundled DaPars2 scripts; change it only if you have moved them)\n", + "\n", + "From the example data, showing the first rows (including the header where the format has one):\n", + "\n", + "**`output/apa/chr22.gtf`**\n", + "\n", + "```\n", + "chr22\tensembl\tgene\t10736171\t10736283\t.\t-\t.\t...\n", + "chr22\tensembl\ttranscript\t10736171\t10736283\t.\t-\t.\t...\n", + "chr22\tensembl\texon\t10736171\t10736283\t.\t-\t.\t...\n", + "```\n", + "\n", + "**`output/apa/chr22_3UTR.bed`**\n", + "\n", + "```\n", + "chr22\t32037111\t32037995\tENST00000658411|LINC02558|chr22|+\t0\t+\n", + "chr22\t46352525\t46352841\tENST00000463785|TRMU|chr22|+\t0\t+\n", + "chr22\t34175390\t34175780\tENST00000668901|LINC01643|chr22|+\t0\t+\n", + "```" ] }, { @@ -54,28 +106,57 @@ "kernel": "SoS" }, "source": [ - "### 3'UTR Reference\n", + "## Output\n", + "\n", + "- **`output/apa/chr22_3UTR.bed`** (`UTR_reference`)\n", + "(the extracted 3'UTR intervals; the name field packs four values separated by `|`: transcript ID, gene symbol, chromosome and strand)\n", "\n", - "* _gtf2bed12.py_ : Covert gtf to bed format (Source from in-house codes from Li Lab: https://github.com/Xu-Dong/Exon_Intron_Extractor/blob/main/scripts/gtf2bed12.py) \n", + "```\n", + "chr22\t32037111\t32037995\tENST00000658411|LINC02558|chr22|+\t0\t+\n", + "chr22\t46352525\t46352841\tENST00000463785|TRMU|chr22|+\t0\t+\n", + "```\n", "\n", - "* _DaPars_Extract_Anno.py_ : extract the 3UTR regions in bed formats from the whole genome bed (Source from Dapars 2: https://github.com/3UTR/DaPars2/blob/master/src/DaPars_Extract_Anno.py)\n", + "- **`output/apa/wig/SAMPLE_001.wig`** (`bam2tools`)\n", + "(per-base coverage track, one per BAM)\n", "\n", - "### Call WIG data from transcriptome BAM files\n", + "```\n", + "track type=bedGraph\n", + "chr22\t0\t10527919\t0\n", + "chr22\t10527919\t10527927\t1\n", + "```\n", "\n", - "Using bedtools or rsem-bam2wig, for RSEM based alignment\n", + "- **`output/apa/wig/SAMPLE_001.flagstat`** (`bam2tools`)\n", + "(total mapped read count used to normalise that sample. The step declares this output as `.depth`; the example data carries `.flagstat`, so the two disagree and the code is the authority.)\n", "\n", - "### Config files Generation\n", - "* _Python 3_ loops to read line by line the sum of reads coverage of all chromosome.\n", + "```\n", + "202561 + 0 in total (QC-passed reads + QC-failed reads)\n", + "200000 + 0 primary\n", + "```\n", "\n", - "### Dapars2 Main Function\n", + "- **`output/apa/sample_mapping_files.txt`** (`APAconfig`)\n", + "(maps each sample's WIG track to its read count)\n", "\n", - "* _Dapars2_Multi_Sample.py_: use the least sqaures methods to calculate the usage of long isoforms (https://github.com/3UTR/DaPars2/blob/master/src/Dapars2_Multi_Sample.py) \n", - " \n", - " Note: this part of code have been modified from source to deal with some formatting discrepancy in wig file\n", + "```\n", + "output/apa/wig/SAMPLE_001.wig\t202561\n", + "output/apa/wig/SAMPLE_002.wig\t201999\n", + "```\n", "\n", - "### Impute missing values in Dapars result\n", + "- **`output/apa/sample_configuration_file.txt`** (`APAconfig`)\n", + "(the DaPars2 run configuration, carrying the coverage thresholds)\n", "\n", - "KNN using `impute` R package." + "```\n", + "Annotated_3UTR=output/apa/chr22.gencode_3UTR.bed\n", + "Aligned_Wig_files=output/apa/wig/SAMPLE_001.wig,output/apa/wig/SAMPLE_002.wig\n", + "Output_directory=output/apa/apa \n", + "Output_result_file=Dapars_result\n", + "Least_pass_coverage_percentage=0.3\n", + "Coverage_threshold=10\n", + "Num_Threads=1\n", + "sequencing_depth_file=output/apa/sample_mapping_files.txt\n", + "```\n", + "\n", + "- **`apa_/Dapars_result_result_temp..txt`** (`APAmain`)\n", + "(the PDUI (Percentage of Distal polyA site Usage Index) estimates, one row per 3'UTR region and one PDUI column per sample. A PDUI near 1 means the distal polyA site dominates; lower values indicate 3'UTR shortening.)" ] }, { @@ -84,7 +165,12 @@ "kernel": "SoS" }, "source": [ - "## Input" + "## Minimal Working Example\n", + "\n", + "### Quantify alternative polyadenylation with DaPars2\n", + "\n", + "The four workflows chain: each consumes the output of the one before it, so run them in\n", + "order." ] }, { @@ -93,10 +179,12 @@ "kernel": "SoS" }, "source": [ - "- A list of transcriptome level BAM files, eg generated by RSEM\n", - "- The 3'UTR annotation reference file\n", + "#### Step 1. Build the 3'UTR reference\n", "\n", - "If you do not have 3'UTR annotation file, please generate it first. Input to this step is the transcriptome level gene feature file in `GTF` format that [we previously prepared](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/reference_data.html)." + "`UTR_reference` converts the GTF to BED12 with `gtf2bed12.py` (from Li Lab's\n", + "[Exon_Intron_Extractor](https://github.com/Xu-Dong/Exon_Intron_Extractor/blob/main/scripts/gtf2bed12.py)),\n", + "then extracts the 3'UTR intervals from the whole-genome BED with\n", + "[`DaPars_Extract_Anno.py`](https://github.com/3UTR/DaPars2/blob/master/src/DaPars_Extract_Anno.py)." ] }, { @@ -105,18 +193,20 @@ "kernel": "SoS" }, "source": [ - "## Output" + "**Timing**: TBD (on toy dataset)" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash" }, + "outputs": [], "source": [ - "* Dapars config files\n", - "* PUDI (Raw) information saved in txt\n", - "* PDUI (Imputed) information saved in txt. This is recommended for further analysis. " + "sos run pipeline/apa_calling.ipynb UTR_reference \\\n", + " --cwd output/apa \\\n", + " --hg-gtf output/apa/chr22.gtf" ] }, { @@ -124,7 +214,12 @@ "metadata": { "kernel": "SoS" }, - "source": "## Steps" + "source": [ + "#### Step 2. Convert the BAM files to coverage\n", + "\n", + "`bam2tools` turns each transcriptome-aligned BAM into a per-base coverage track and a\n", + "read-depth file, using `bedtools` or `rsem-bam2wig` for RSEM-based alignment." + ] }, { "cell_type": "markdown", @@ -132,7 +227,7 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Generate the 3'UTR reference regions from a GTF annotation:" + "**Timing**: TBD (on toy dataset)" ] }, { @@ -143,9 +238,9 @@ }, "outputs": [], "source": [ - "sos run pipeline/apa_calling.ipynb UTR_reference \\\n", + "sos run pipeline/apa_calling.ipynb bam2tools \\\n", " --cwd output/apa \\\n", - " --hg-gtf output/apa/chr22.gtf" + " --bam-dir output/rnaseq/bam" ] }, { @@ -154,20 +249,11 @@ "kernel": "SoS" }, "source": [ - "**Step 2.** Convert the transcriptome BAM files into per-base coverage (wig) and read-depth (flagstat) files:" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "Bash" - }, - "outputs": [], - "source": [ - "sos run pipeline/apa_calling.ipynb bam2tools \\\n", - " --cwd output/apa \\\n", - " --bam-dir output/rnaseq/bam" + "#### Step 3. Write the DaPars2 configuration\n", + "\n", + "`APAconfig` reads each WIG track line by line to total the read coverage across\n", + "chromosomes, then writes the sample mapping file and the DaPars2 configuration file\n", + "carrying the coverage thresholds." ] }, { @@ -176,7 +262,7 @@ "kernel": "SoS" }, "source": [ - "**Step 3.** Generate the DaPars2 sample configuration and mapping files:" + "**Timing**: TBD (on toy dataset)" ] }, { @@ -199,7 +285,22 @@ "kernel": "SoS" }, "source": [ - "**Step 4.** Run DaPars2 to calculate the PDUI matrix per chromosome:" + "#### Step 4. Calculate the PDUI matrix\n", + "\n", + "`APAmain` runs\n", + "[`Dapars2_Multi_Sample.py`](https://github.com/3UTR/DaPars2/blob/master/src/Dapars2_Multi_Sample.py),\n", + "which uses least squares to estimate long-isoform usage per chromosome. The bundled copy\n", + "is modified from source to handle a formatting discrepancy in the WIG files. Missing\n", + "values in the result are imputed by KNN with the R `impute` package." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -223,20 +324,87 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/apa_calling.ipynb -h" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/apa_calling.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " UTR_reference\n", + " bam2tools\n", + " APAconfig\n", + " APAmain\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --walltime 400h\n", + " --mem 200G\n", + " --ncore 16 (as int)\n", + " --cwd output (as path)\n", + " the output directory for generated files\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --job-size 1 (as int)\n", + " --container ''\n", + "\n", + "Sections\n", + " UTR_reference:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " gtf file\n", + " bam2tools:\n", + " Workflow Options:\n", + " --bam-list paths\n", + "\n", + " Transcriptome/coordinate-sorted BAM files to compute\n", + " per-base coverage for\n", + " --bam-dir . (as path)\n", + " Retained for CLI back-compatibility (unused by the R\n", + " port, which takes --bam-list)\n", + " APAconfig:\n", + " Workflow Options:\n", + " --bfile VAL (as path, required)\n", + " --annotation VAL (as path, required)\n", + " --least-pass-coverage-percentage 0.3 (as float)\n", + " --coverage-threshold 10 (as int)\n", + " APAmain:\n", + " Workflow Options:\n", + " --chrlist VAL VAL ... (as type, required)\n", + " --[no-]chr-prefix (default to True)\n", + " Whether the input wig/BAM chromosomes already carry the\n", + " 'chr' prefix (True, default, matching the chr-prefixed\n", + " reference data). Set False for bare-named BAMs/wigs\n", + " (e.g. '22'): dapars.R then prepends 'chr' to the wig\n", + " chroms to match the annotation.\n", + " --dapars-path code/SoS/molecular_phenotypes/calling/apa (as path)\n", + " Retained for CLI back-compatibility (unused by the R\n", + " port of DaPars2)\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { @@ -273,7 +441,8 @@ "kernel": "SoS" }, "source": [ - "### **Step 0.** Generate 3'UTR regions based on GTF" + "### UTR_reference\n", + "Generate 3'UTR regions based on GTF" ] }, { @@ -304,7 +473,8 @@ "kernel": "SoS" }, "source": [ - "### **Step 1.** Generate WIG coverage and flagstat files from BAM files" + "### bam2tools\n", + "Generate WIG coverage and flagstat files from BAM files" ] }, { @@ -334,7 +504,8 @@ "kernel": "SoS" }, "source": [ - "### **Step 2.** Generate the DaPars2 configuration and sample mapping files" + "### APAconfig\n", + "Generate the DaPars2 configuration and sample mapping files" ] }, { @@ -365,18 +536,8 @@ "kernel": "SoS" }, "source": [ - "### **Step 3.** Run DaPars2 main to calculate PDUIs" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### APAmain\n", + "Run DaPars2 main to calculate PDUIs" ] }, { @@ -441,4 +602,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/molecular_phenotypes/calling/methylation_calling.ipynb b/code/SoS/molecular_phenotypes/calling/methylation_calling.ipynb index a8b4da8a0..b8bc72954 100644 --- a/code/SoS/molecular_phenotypes/calling/methylation_calling.ipynb +++ b/code/SoS/molecular_phenotypes/calling/methylation_calling.ipynb @@ -8,7 +8,9 @@ "tags": [] }, "source": [ - "# Quantification of methylation data" + "# Quantification of methylation data\n", + "\n", + "Quantifies methylation from array data, using `sesame` or `minfi`." ] }, { @@ -19,9 +21,9 @@ "tags": [] }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "This notebook implements two methods to quantify methylation data, using `sesame` and `minfi`. We recommend `sesame` over `minfi`.\n", + "This notebook implements two methods to quantify methylation data, using `sesame` and `minfi`. `sesame` is the recommended choice over `minfi`.\n", "\n", "\n", "|Procedure|`minfi`|`sesame`|\n", @@ -30,7 +32,57 @@ "|sample quality|detectionP + mean |sesameQC_calcStats + \"detection\" + frac_dt |\n", "|Bias correction|preprocessQuantile|D ( dyeBiasNL)|\n", "|Probe quality|detectionP|\"P (pOOBAH\tDetection p-value masking using oob)\" |\n", - "|Background substraction|NA|B (noob)|" + "|Background substraction|NA|B (noob)|\n", + "\n", + "### `Sesame` \n", + "\n", + "Getting the beta value from EPIC450 IDAT for 750 samples from 3000 wells take ~40 mins. Based on [sesame documentation](https://www.bioconductor.org/packages/release/bioc/vignettes/sesame/inst/doc/sesame.html), the processing procedure suitable for human on EPIC 450 and 850 platform is \"QCDPB\"\n", + "\n", + "The code for each processing procedure are as followed:\n", + "\n", + "| Code | Name | Detail |\n", + "| -----|------|--------|\n", + "| Q | qualityMask | Mask probes of poor design | \n", + "| C | inferInfiniumIChannel | Infer channel for Infinium-I probes | \n", + "| D | dyeBiasNL | Dye bias correction (non-linear) | \n", + "| P | pOOBAH | Detection p-value masking using oob | \n", + "| B | noob | Background subtraction using oob | \n", + "\n", + "\n", + "Other potential procedures are \n", + "\n", + "\n", + "| Code | Name | Detail |\n", + "| -----|------|--------|\n", + "|0|resetMask|Reset mask to all FALSE |\n", + "|G|prefixMaskButCG|Mask all but cg- probes |\n", + "|H|prefixMaskButC|Mask all but cg- and ch-probes |\n", + "|E|dyeBiasL|Dye bias correction (linear) |\n", + "|I|detectionIB|Mask detection by intermediate beta values |\n", + " \n", + "\n", + "M value is calculated as M = log2(beta/(1-beta)). Beta values of exactly 0 or 1 are replaced with the next min/max value among the beta matrix, which is based on [here](https://github.com/xuz1/ENmix/blob/master/R/utils.R)\n", + "\n", + "### `minfi`\n", + "\n", + "By default, for Infinium MethylationEPIC the data will be annotated based on hg38 using [this annotation](https://github.com/achilleasNP/IlluminaHumanMethylationEPICanno.ilm10b5.hg38), alternatively user can set the `--hg-build` parameter back to 19 to use the [hg19 annotation](https://bioconductor.org/packages/release/data/annotation/html/IlluminaHumanMethylationEPICanno.ilm10b4.hg19.html).\n", + "\n", + "For 450K data however, only hg19 annotation is availble, which is what minfi requires. Everything is reannotated to hg38 in the next step regardless. \n", + "\n", + "1. All the IDAT file in the specified folder and sub-folder will be loaded for samples in input sample CSV file\n", + "2. The methylation data samples will first be filtered based on [bisulphite conversation rate](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4527772/). This operation is done using the [bscon function from watermelon package](http://www.bioconductor.org/packages/release/bioc/vignettes/wateRmelon/inst/doc/wateRmelon.html#introduction) \n", + "3. samples will then be filtered based on a [detection pvalue](https://www.rdocumentation.org/packages/minfi/versions/1.18.4/topics/detectionP), which indicates the quality of the signal at each genomics position\n", + "4. [Stratified Quantile Normalization](https://rdrr.io/bioc/minfi/man/preprocessQuantile.html) will then be applied.\n", + "5. features will be filtered if they are on sex chr, known to be [cross-reactive,maping to multiple regions in the genome.](https://academic.oup.com/nargab/article/2/4/lqaa105/6040968), overlapping with snps, or having too low a detection P. The list of cross-reactive probe can be found as `/opt/cross_reactive_probe_Hop2020.txt` in the docker image and [here](https://raw.githubusercontent.com/hsun3163/xqtl-protocol/main/data/cross_reactive_probe_Hop2020.txt).\n", + "6. Beta and M value will for all the probes/samples will then each be saved to a indexed bed.gz file.\n", + "\n", + "[As documented here](https://github.com/statfungen/xqtl-protocol/issues/312) when the batch of IDAT data are different, there will be a problem reading the IDAT file without specifing the force = TRUE option in the `read.metharray.exp(targets = targets,force = TRUE)`\n", + "\n", + "### Annotate probes\n", + "\n", + "The probes are annotated via `sesameData` package and formatted as bgzipped bed files, regardless of method used to process the IDAT.\n", + "\n", + "**When to run it.** On raw IDAT files, before methylation QC and normalisation." ] }, { @@ -43,9 +95,11 @@ "source": [ "## Input\n", "\n", - "1. `sample_sheet`: path to csv/tsv file that documenting all the meta-information of the bisulfite sequencing. The user need to manually ensure/rename the column names corresponding to the first and second half of the idat file names are \"Sentrix_ID\" and \"Sentrix_Position\" \n", - "2. [optional] `idat_folder`: path to the folder containing all the IDAT files to generate methylation data matrices from. Default is set to using the same folder where `sample_sheet` locates.\n", - "3. [optional] `cross_reactive_probes`: A list of CpG probes that are reported to [map to multiple regions in the genome.](https://academic.oup.com/nargab/article/2/4/lqaa105/6040968) " + "- `--sample-sheet`: a csv or tsv describing the bisulfite sequencing run, one row per array. Two of its columns must be named `Sentrix_ID` and `Sentrix_Position`, matching the first and second halves of the IDAT file names; renaming them is a manual step. Required. Example `input/methylation/protocol_example.methylation.sample_sheet.csv`, with its IDAT folders `200783410067/` and `200783410070/` alongside it.\n", + "- `--sample_sheet_header_rows`: how many rows precede the header, `0` when the column names are on the first line.\n", + "- `--idat_folder`: optional, the directory holding the IDAT files. Defaults to the sample sheet's location.\n", + "- `--container`: the image the callers run in. The examples name `containers/methylation.sif`, which is not present in this repository.\n", + "- `--cwd`: the directory outputs are written to." ] }, { @@ -55,19 +109,64 @@ "kernel": "SoS" }, "source": [ - "## Output\n\nFor each input array, methylation is called with both SeSAMe and minfi and written under `--cwd`:\n\n- `{sample}.sesame.beta.tsv` and `{sample}.sesame.M.tsv` — SeSAMe beta-values (proportion methylated) and M-values (logit-transformed) per probe; `{sample}.sesame.rds` stores the SeSAMe object and `{sample}.sample_qcs.sesame.tsv` the per-sample QC metrics.\n- `{sample}.minfi.beta.tsv` and `{sample}.minfi.M.tsv` — the equivalent beta- and M-value matrices from minfi (with `{sample}.minfi.rds`).\n- `{name}.bed.gz` (a pair for `beta` and `M`) and `{name}.gene_id.annot.tsv` — the final BED-format methylation matrices and the probe-to-gene annotation used as the molecular phenotype downstream.\n" + "## Output\n", + "\n", + "- `{cwd}/{sample}.sesame.beta.tsv` and `{cwd}/{sample}.sesame.M.tsv` - beta values (proportion methylated) and M values (logit-transformed) per probe, probes in rows and samples in columns. Example `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.beta.tsv`, 757798 rows:\n", + "\n", + " ```\n", + " ID SAMPLE_009 SAMPLE_010 SAMPLE_011 SAMPLE_012\n", + " cg00000029 0.62673719799632 0.605457147191955 0.714696202925875 0.665533118879115\n", + " cg00000109 0.843927338779284 0.861928120992581 0.870715137053388 0.862096588282425\n", + " ```\n", + "\n", + "- `{cwd}/{sample}.sample_qcs.sesame.tsv` - per-sample QC metrics. Example `output/methylation/protocol_example.methylation.sample_sheet_int.sample_qcs.sesame.tsv`, 14 rows:\n", + "\n", + " ```\n", + " id num_dtna frac_dtna num_dt frac_dt num_dt_mk\n", + " 200783410067_R04C0 0 0 852978 0.984334483868846 852976\n", + " 200783410067_R05C0 0 0 852085 0.98330396409683 852082\n", + " ```\n", + "\n", + "- `{cwd}/{sample}.sesame.rds` - the SeSAMe object itself.\n", + "- `{cwd}/{sample}.minfi.beta.tsv`, `.minfi.M.tsv` and `.minfi.rds` - the minfi equivalents.\n", + "- `{cwd}/{sample}.*.beta.bed.gz` with a `.tbi`, and `{cwd}/{sample}.*.gene_id.annot.tsv` - the probe-annotated BED form produced by the shared second step.\n", + "\n", + "Example output is present for the SeSAMe path under `output/methylation/`; the minfi products sit in `output/methylation_minfi/`." + ] + }, + { + "cell_type": "markdown", + "id": "164242f1", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", + "\n", + "Two alternative callers over the same IDAT files: `sesame` and `minfi`. Pick one; they are not run in sequence. The sample sheets and their IDAT folders are under `input/methylation/` and `input/methylation_minfi/`. The container `containers/methylation.sif` is not present, so supply your own image via `--container`." ] }, { "cell_type": "markdown", - "id": "seven-contest", + "id": "a659352f", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps\n", + "### SeSAMe\n", "\n", - "\n" + "`sesame` calls methylation with the SeSAMe package, writing beta and M-value matrices plus per-sample QC metrics. The second command shows a sheet whose header starts on the first line, via `--sample_sheet_header_rows 0`." + ] + }, + { + "cell_type": "markdown", + "id": "ac74accd", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -80,14 +179,37 @@ "outputs": [], "source": [ "sos run pipeline/methylation_calling.ipynb sesame \\\n", - " --sample-sheet data/MWE/MWE_Sample_sheet.csv \\\n", + " --sample-sheet input/methylation/protocol_example.methylation.sample_sheet.csv \\\n", " --container containers/methylation.sif\n", "\n", "sos run pipeline/methylation_calling.ipynb sesame \\\n", - " --sample-sheet data/MWE/MWE_Sample_sheet_int.csv \\\n", + " --sample-sheet input/methylation/protocol_example.methylation.sample_sheet_int.csv \\\n", " --container containers/methylation.sif --sample_sheet_header_rows 0" ] }, + { + "cell_type": "markdown", + "id": "ebbdff66", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### minfi\n", + "\n", + "`minfi` performs the equivalent call with the minfi package, producing the same matrix products under its own naming." + ] + }, + { + "cell_type": "markdown", + "id": "2109d78a", + "metadata": { + "kernel": "SoS", + "tags": [] + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -98,7 +220,7 @@ "outputs": [], "source": [ "sos run pipeline/methylation_calling.ipynb minfi \\\n", - " --sample-sheet data/MWE/MWE_Sample_sheet.csv \\\n", + " --sample-sheet input/methylation_minfi/protocol_example.methylation.sample_sheet.csv \\\n", " --container containers/methylation.sif" ] }, @@ -109,104 +231,101 @@ "kernel": "Bash" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", - "execution_count": 1, - "id": "extensive-nature", + "execution_count": null, + "id": "cli-cmd-methylation_calling", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: sos run methylation_calling.ipynb\n", - " [workflow_name | -t targets] [options] [workflow_options]\n", - " workflow_name: Single or combined workflows defined in this script\n", - " targets: One or more targets to generate\n", - " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", - " workflow_options: Double-hyphen workflow-specific parameters\n", - "\n", - "Workflows:\n", - " sesame\n", - " minfi\n", - "\n", - "Global Workflow Options:\n", - " --cwd output (as path)\n", - " The output directory for generated files.\n", - " --sample-sheet VAL (as path, required)\n", - " The companion sample sheet csv file as outlined in the\n", - " input section.\n", - " --idat-folder path(f\"{sample_sheet:d}\")\n", - "\n", - " Raw data folder\n", - " --[no-]keep-only-cpg-probes (default to False)\n", - " Remove probes that are SNPs\n", - " --job-size 1 (as int)\n", - " For cluster jobs, number commands to run per job\n", - " --walltime 5h\n", - " Wall clock time expected\n", - " --mem 16G\n", - " Memory expected\n", - " --numThreads 8 (as int)\n", - " Number of threads\n", - " --container ''\n", - " Software container option\n", - "\n", - "Sections\n", - " sesame_1:\n", - " Workflow Options:\n", - " --samples-frac-dt-cutoff 0.8 (as float)\n", - " threshold to filter out samples based on frac_dt\n", - " (Percentage of probe Detection Success) percentage\n", - " --sample-sheet-header-rows 7 (as int)\n", - " The header rows in the sample sheet csv\n", - " minfi_1:\n", - " Workflow Options:\n", - " --samples-pval-cutoff 0.05 (as float)\n", - " threshold to filter out samples based on detection P\n", - " value\n", - " --probe-pval-cutoff 0.01 (as float)\n", - " threshold to filter out probes based on detection P\n", - " value\n", - " --cross-reactive-probes data/cross_reactive_probe_Hop2020.txt (as path)\n", - " FIXME: document here where this list is obtained from.\n", - " Also the documentation below doesn't sound right. Please\n", - " fix. Use the default list in our docker, if want to skip\n", - " methylation, specify it as \".\"\n", - " --GRCh-build 38 (as int)\n", - " 38 (hg38) or 37 (hg19) for epic data, by default 38.\n", - " Noted for 450K data only GRCh37 is availble\n", - " *_methylation_2:\n" - ] - } - ], + "outputs": [], "source": [ - "sos run methylation_calling.ipynb -h" + "sos run pipeline/methylation_calling.ipynb -h" ] }, { "cell_type": "markdown", - "id": "apparent-swaziland", + "id": "cli-out-methylation_calling", "metadata": { "kernel": "SoS" }, "source": [ - "## Global parameters\n", + "```\n", + "usage: sos run code/SoS/molecular_phenotypes/calling/methylation_calling.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", "\n", - "`keep_only_cpg_probes` option dictate whether only cpg probes should be kept:\n", + "Workflows:\n", + " sesame\n", + " minfi\n", "\n", - "- On an Illumina methylation bead chip, there are three types of probes,whose nature were indicated by their names.\n", - " - cg: cpg probe;\n", - " - rs: explict snp probe;\n", - " - ch: non-CpG targeting probes; [reported to be more prone to cross-hybirdization](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4909830/)\n", - " \n", - " Following the guideline of [Zhou W 2016](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5389466/), by default we do not remove all the rs and ch probes. However, for research that are focusing on the CpG sites, like mQTL discovery, we should use `keep_only_cpg_probes` parameter to filter out other types of probes.\n", - " " + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --sample-sheet VAL (as path, required)\n", + " The companion sample sheet csv file as outlined in the\n", + " input section.\n", + " --idat-folder path(f\"{sample_sheet:d}\")\n", + "\n", + " Raw data folder\n", + " --modular-script-dir code/script (as path)\n", + " --[no-]keep-only-cpg-probes (default to False)\n", + " Remove probes that are SNPs\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", + "\n", + "Sections\n", + " sesame_1:\n", + " Workflow Options:\n", + " --samples-frac-dt-cutoff 0.8 (as float)\n", + " threshold to filter out samples based on frac_dt\n", + " (Percentage of probe Detection Success) percentage\n", + " --sample-sheet-header-rows VAL (as float, required)\n", + " The header rows in the sample sheet csv. Use 0 for no\n", + " headers. Typically it should be 7.\n", + " --n-cores 1 (as int)\n", + " The number of cores to use. If 0, determined by\n", + " BiocParallel::multicoreWorkers().\n", + " minfi_1:\n", + " Workflow Options:\n", + " --samples-pval-cutoff 0.05 (as float)\n", + " threshold to filter out samples based on detection P\n", + " value\n", + " --probe-pval-cutoff 0.01 (as float)\n", + " threshold to filter out probes based on detection P\n", + " value\n", + " --cross-reactive-probes data/cross_reactive_probe_Hop2020.txt (as path)\n", + " Cross-reactive probe list\n", + " (data/cross_reactive_probe_Hop2020.txt); \".\" to skip\n", + " --hg-build 38 (as int)\n", + " 38 (hg38) or 19 (hg19) for epic data, by default 38.\n", + " Noted for 450K data only GRCh37 is availble\n", + " *_2:\n", + "```" + ] + }, + { + "cell_type": "markdown", + "id": "apparent-swaziland", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation" ] }, { @@ -217,7 +336,30 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\n# The output directory for generated files.\nparameter: cwd = path(\"output\")\n# The companion sample sheet csv file as outlined in the input section.\nparameter: sample_sheet = path\n# Raw data folder\nparameter: idat_folder = path(f\"{sample_sheet:d}\")\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# Remove probes that are SNPs\nparameter: keep_only_cpg_probes = False\n# For cluster jobs, number commands to run per job\nparameter: job_size = 1\n# Wall clock time expected\nparameter: walltime = \"5h\"\n# Memory expected\nparameter: mem = \"16G\"\n\n# Number of threads\nparameter: numThreads = 8\n# Software container option\nparameter: container = \"\"\ncwd = path(f'{cwd:a}')" + "source": [ + "[global]\n", + "# The output directory for generated files.\n", + "parameter: cwd = path(\"output\")\n", + "# The companion sample sheet csv file as outlined in the input section.\n", + "parameter: sample_sheet = path\n", + "# Raw data folder\n", + "parameter: idat_folder = path(f\"{sample_sheet:d}\")\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# Remove probes that are SNPs\n", + "parameter: keep_only_cpg_probes = False\n", + "# For cluster jobs, number commands to run per job\n", + "parameter: job_size = 1\n", + "# Wall clock time expected\n", + "parameter: walltime = \"5h\"\n", + "# Memory expected\n", + "parameter: mem = \"16G\"\n", + "\n", + "# Number of threads\n", + "parameter: numThreads = 8\n", + "# Software container option\n", + "parameter: container = \"\"\n", + "cwd = path(f'{cwd:a}')" + ] }, { "cell_type": "markdown", @@ -227,40 +369,7 @@ "tags": [] }, "source": [ - "## `Sesame` \n", - "\n", - "Getting the beta value from EPIC450 IDAT for 750 samples from 3000 wells take ~40 mins.\n", - "\n", - "Based on [sesame documentation](https://www.bioconductor.org/packages/release/bioc/vignettes/sesame/inst/doc/sesame.html), the processing procedure suitable for human on EPIC 450 and 850 platform is \"QCDPB\"\n", - "\n", - "The code for each processing procedure are as followed:\n", - "_____________\n", - "\n", - "| Code | Name | Detail |\n", - "| -----|------|--------|\n", - "| Q | qualityMask | Mask probes of poor design | \n", - "| C | inferInfiniumIChannel | Infer channel for Infinium-I probes | \n", - "| D | dyeBiasNL | Dye bias correction (non-linear) | \n", - "| P | pOOBAH | Detection p-value masking using oob | \n", - "| B | noob | Background subtraction using oob | \n", - "\n", - "\n", - "\n", - "Other potential procedures are \n", - "\n", - "\n", - "| Code | Name | Detail |\n", - "| -----|------|--------|\n", - "|0|resetMask|Reset mask to all FALSE |\n", - "|G|prefixMaskButCG|Mask all but cg- probes |\n", - "|H|prefixMaskButC|Mask all but cg- and ch-probes |\n", - "|E|dyeBiasL|Dye bias correction (linear) |\n", - "|I|detectionIB|Mask detection by intermediate beta values |\n", - " \n", - "\n", - "M value is calculated as M = log2(beta/(1-beta))\n", - "The way we handle beta == 0 or beta == 1 is by replacing them with the next min/max value among the beta matrix, which is based on [here](https://github.com/xuz1/ENmix/blob/master/R/utils.R) \n", - "\n" + "### `Sesame` " ] }, { @@ -271,7 +380,31 @@ "kernel": "SoS" }, "outputs": [], - "source": "[sesame_1]\n# threshold to filter out samples based on frac_dt (Percentage of probe Detection Success) percentage\nparameter: samples_frac_dt_cutoff = 0.8\n# The header rows in the sample sheet csv. Use 0 for no headers. Typically it should be 7.\nparameter: sample_sheet_header_rows = float\n# The number of cores to use. If 0, determined by BiocParallel::multicoreWorkers().\nparameter: n_cores = 1\n\ninput: sample_sheet\noutput: f'{cwd}/{_input:bn}.sesame.rds',f'{cwd}/{_input:bn}.sesame.beta.tsv',f'{cwd}/{_input:bn}.sesame.M.tsv',f'{cwd}/{_input:bn}.sample_qcs.sesame.tsv'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container=container\n Rscript ${modular_script_dir}/molecular_phenotypes/calling/methylation_calling.R --step sesame \\\n --sample-sheet \"${_input}\" \\\n --idat-folder \"${idat_folder}\" \\\n --sample-sheet-header-rows ${sample_sheet_header_rows} \\\n --samples-frac-dt-cutoff ${samples_frac_dt_cutoff} \\\n --n-cores ${n_cores} \\\n ${'--keep-only-cpg-probes' if keep_only_cpg_probes else ''} \\\n --output-rds \"${_output[0]}\" \\\n --output-beta \"${_output[1]}\" \\\n --output-m \"${_output[2]}\" \\\n --output-qcs \"${_output[3]}\"" + "source": [ + "[sesame_1]\n", + "# threshold to filter out samples based on frac_dt (Percentage of probe Detection Success) percentage\n", + "parameter: samples_frac_dt_cutoff = 0.8\n", + "# The header rows in the sample sheet csv. Use 0 for no headers. Typically it should be 7.\n", + "parameter: sample_sheet_header_rows = float\n", + "# The number of cores to use. If 0, determined by BiocParallel::multicoreWorkers().\n", + "parameter: n_cores = 1\n", + "\n", + "input: sample_sheet\n", + "output: f'{cwd}/{_input:bn}.sesame.rds',f'{cwd}/{_input:bn}.sesame.beta.tsv',f'{cwd}/{_input:bn}.sesame.M.tsv',f'{cwd}/{_input:bn}.sample_qcs.sesame.tsv'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container=container\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/calling/methylation_calling.R --step sesame \\\n", + " --sample-sheet \"${_input}\" \\\n", + " --idat-folder \"${idat_folder}\" \\\n", + " --sample-sheet-header-rows ${sample_sheet_header_rows} \\\n", + " --samples-frac-dt-cutoff ${samples_frac_dt_cutoff} \\\n", + " --n-cores ${n_cores} \\\n", + " ${'--keep-only-cpg-probes' if keep_only_cpg_probes else ''} \\\n", + " --output-rds \"${_output[0]}\" \\\n", + " --output-beta \"${_output[1]}\" \\\n", + " --output-m \"${_output[2]}\" \\\n", + " --output-qcs \"${_output[3]}\"" + ] }, { "cell_type": "markdown", @@ -280,22 +413,7 @@ "kernel": "SoS" }, "source": [ - "## `minfi`\n", - "\n", - "By default, for Infinium MethylationEPIC the data will be annotated based on hg38 using [this annotation](https://github.com/achilleasNP/IlluminaHumanMethylationEPICanno.ilm10b5.hg38), alternatively user can set the `--hg-build` parameter back to 19 to use the [hg19 annotation](https://bioconductor.org/packages/release/data/annotation/html/IlluminaHumanMethylationEPICanno.ilm10b4.hg19.html).\n", - "\n", - "For 450K data however, only hg19 annotation is availble, which is what we would use would use for minfi to work. However, we will reannotate everything to hg38 anyways in the next step. \n", - "\n", - "\n", - "\n", - "1. All the IDAT file in the specified folder and sub-folder will be loaded for samples in input sample CSV file\n", - "2. The methylation data samples will first be filtered based on [bisulphite conversation rate](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4527772/). This operation is done using the [bscon function from watermelon package](http://www.bioconductor.org/packages/release/bioc/vignettes/wateRmelon/inst/doc/wateRmelon.html#introduction) \n", - "3. samples will then be filtered based on a [detection pvalue](https://www.rdocumentation.org/packages/minfi/versions/1.18.4/topics/detectionP), which indicates the quality of the signal at each genomics position\n", - "4. [Stratified Quantile Normalization](https://rdrr.io/bioc/minfi/man/preprocessQuantile.html) will then be applied.\n", - "5. features will be filtered if they are on sex chr, known to be [cross-reactive,maping to multiple regions in the genome.](https://academic.oup.com/nargab/article/2/4/lqaa105/6040968), overlapping with snps, or having too low a detection P. The list of cross-reactive probe can be found as `/opt/cross_reactive_probe_Hop2020.txt` in our docker and [here](https://raw.githubusercontent.com/hsun3163/xqtl-protocol/main/data/cross_reactive_probe_Hop2020.txt).\n", - "6. Beta and M value will for all the probes/samples will then each be saved to a indexed bed.gz file.\n", - "\n", - "[As documented here](https://github.com/statfungen/xqtl-protocol/issues/312) when the batch of IDAT data are different, there will be a problem reading the IDAT file without specifing the force = TRUE option in the `read.metharray.exp(targets = targets,force = TRUE)`" + "### `minfi`" ] }, { @@ -339,9 +457,7 @@ "kernel": "SoS" }, "source": [ - "## Annotate probes\n", - "\n", - "The probes are annotated via `sesameData` package and formatted as bgzipped bed files, regardless of method used to process the IDAT." + "### Annotate probes" ] }, { @@ -352,13 +468,17 @@ "kernel": "SoS" }, "outputs": [], - "source": "[*_2]\noutput: f'{_input[1]:n}.bed.gz', f'{_input[2]:n}.bed.gz', f'{_input[0]:n}.gene_id.annot.tsv'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\nbash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container=container\n Rscript ${modular_script_dir}/molecular_phenotypes/calling/methylation_calling.R --step annotate \\\n --input-beta \"${_input[1]}\" \\\n --input-m \"${_input[2]}\" \\\n --output-beta-bed \"${_output[0]}\" \\\n --output-m-bed \"${_output[1]}\" \\\n --output-annot \"${_output[2]}\"" - }, - { - "cell_type": "markdown", - "metadata": {}, "source": [ - "## Anticipated Results\n\nThe pipeline produces a methylation beta-value matrix (one row per CpG probe, one column per sample) with SNP-overlapping probes removed and missing values imputed, ready for downstream mQTL analysis.\n" + "[*_2]\n", + "output: f'{_input[1]:n}.bed.gz', f'{_input[2]:n}.bed.gz', f'{_input[0]:n}.gene_id.annot.tsv'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand= \"${ }\", stderr = f'{_output[0]:n}.stderr', stdout = f'{_output[0]:n}.stdout', container=container\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/calling/methylation_calling.R --step annotate \\\n", + " --input-beta \"${_input[1]}\" \\\n", + " --input-m \"${_input[2]}\" \\\n", + " --output-beta-bed \"${_output[0]}\" \\\n", + " --output-m-bed \"${_output[1]}\" \\\n", + " --output-annot \"${_output[2]}\"" ] } ], diff --git a/code/SoS/molecular_phenotypes/calling/splicing_calling.ipynb b/code/SoS/molecular_phenotypes/calling/splicing_calling.ipynb index 5e5b931a3..d97d89bcb 100644 --- a/code/SoS/molecular_phenotypes/calling/splicing_calling.ipynb +++ b/code/SoS/molecular_phenotypes/calling/splicing_calling.ipynb @@ -9,7 +9,8 @@ }, "source": [ "# Quantifying alternative splicing from RNA-seq data\n", - "\n" + "\n", + "Quantifies alternative splicing from aligned RNA-seq with LeafCutter and psichomics, producing the intron-usage and PSI tables that become splicing phenotypes." ] }, { @@ -19,19 +20,19 @@ "kernel": "SoS" }, "source": [ - "## Description" - ] - }, - { - "cell_type": "markdown", - "id": "4437a565-908c-4160-a302-e24ab313edba", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Our pipeline calls alternative splicing events from RNA-seq data using leafcutter and psichomics to call the RNA-seq data from `fastq.gz` data which has been mapped to a reference genome using STAR with the wasp option. It implements the GTEx pipeline for GTEx/TOPMed project. Please refer to [this page](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md) for detail. The choice of pipeline modules in this project is supported by internal (unpublished) benchmarks from GTEx group.\n", + "## Overview\n", + "\n", + "This module turns aligned RNA-seq into splicing phenotypes. It expects BAM files already mapped with STAR using the WASP option, following the [GTEx/TOPMed RNA-seq pipeline](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md); the choice of modules is supported by internal, unpublished benchmarks from the GTEx group.\n", + "\n", + "Two tools are provided because they measure different things, in the sense described by [Wang et al. (2008)](https://doi.org/10.1038/nature07509) and [Park et al. (2018)](https://doi.org/10.1016/j.ajhg.2017.11.002). They do not depend on each other and can run in parallel.\n", "\n", - "We use two different tools to quantify the many types of splicing events which are outlined in [[cf. Wang et al (2008)](https://doi.org/10.1038/nature07509)] and [[cf. Park et al (2018)](https://doi.org/10.1016/j.ajhg.2017.11.002)]. The first, leafcutter, quantifies the usage of alternatively excised introns. This collectively captures skipped exons, 5’ and 3’ alternative splice site usage and other complex events [[cf. Li et al 2018](https://doi.org/10.1038/s41588-017-0004-9)]. This method was previously applied to ROSMAP data as part of the Brain xQTL version 2.0. The second, psichomics, quantifies specific splicing events [[cf. Agostinho et al. 2019](https://doi.org/10.1093/nar/gky888)].\n" + "- `leafcutter` quantifies the usage of alternatively excised introns. Junctions are extracted from each BAM with regtools, then clustered across samples: introns sharing a splice site are grouped, and each intron is reported as a fraction of the reads in its cluster. That single measure collectively captures skipped exons, alternative 5-prime and 3-prime splice site usage, and more complex events, without needing to name the event type [Li et al. (2018)](https://doi.org/10.1038/s41588-017-0004-9). The clustering defaults, `--min-clu-ratio 0.001 --max-intron-len 500000 --min-clu-reads 30`, are those of the [GTEx sQTL discovery pipeline](https://www.science.org/action/downloadSupplement?doi=10.1126%2Fscience.aaz1776&file=aaz1776_aguet_sm.pdf), section 3.4.3. This is the approach previously applied to ROSMAP data for Brain xQTL version 2.0.\n", + "- `psichomics` quantifies named event types instead, reporting percent-spliced-in (PSI) for skipped exons, mutually exclusive exons, alternative 5-prime and 3-prime splice sites, and alternative first and last exons [Agostinho et al. (2019)](https://doi.org/10.1093/nar/gky888). It reads the `SJ.out.tab` junction counts STAR emits rather than the BAMs, and needs a splicing annotation to say which junctions constitute which event.\n", + "- `leafcutter_preprocessing` is not a third method but the first half of `leafcutter`. The two share one section, declared as `[leafcutter_1, leafcutter_preprocessing_1]`, and this workflow stops once the list of per-sample `.junc` files is written, which is exactly the file `leafcutter` would go on to cluster. Run it only when the clustering is done elsewhere.\n", + "\n", + "Two psichomics annotations are distributed with the example data. `hg38_suppa.rds` was built with SUPPA from the GTF used throughout this protocol; `modified_psichomics_hg38_splicing_annotation.rds` is the package default Human hg38 (2018-04-30) annotation, described in the [psichomics methods](https://academic.oup.com/nar/article/47/2/e7/5114259), with gene names replaced by Ensembl IDs so that identifiers are consistent across the protocol.\n", + "\n", + "**When to run it.** After STAR alignment, and before `splicing_normalization`, which turns the intron-usage and PSI tables produced here into the splicing phenotype matrices used for sQTL association." ] }, { @@ -43,42 +44,37 @@ "source": [ "## Input\n", "\n", - "**Various reference data needs to be prepared before using this workflow**. [Here we provide a module](https://github.com/statfungen/xqtl-protocol/blob/main/code/reference_data/reference_data_preparation.ipynb) to download and prepare the reference data. \n", - "\n", - "A minimal working example is uploaded in the [google drive](https://drive.google.com/drive/folders/1lpcx3eKG2UpauntLUuJ6bMBjHyIhWW_R). It contains example inputs for leafcutter/psichomics, two spliing annotations for psichomics, the meta-data file list, and a example of blacklist chromosome file for leafcutter.\n", + "* `--samples` -- the sample manifest, white-space delimited with a header and four columns: sample ID, RNA strandness, the BAM path used by `leafcutter`, and the `SJ.out.tab` path used by `psichomics`. Strandness is `rf`, `fr`, or `strand_missing`:\n", "\n", - "The leafcutter and psichomics tools may be run in parallel and are not dependent on one another.\n", + " ```\n", + " sample_id strand bam_list SJ_list\n", + " sample_1 rf sample_1.Aligned.sortedByCoord.out.bam sample_1.SJ.out.tab\n", + " sample_2 fr sample_2.Aligned.sortedByCoord.out.bam sample_2.SJ.out.tab\n", + " sample_3 strand_missing sample_3.Aligned.sortedByCoord.out.bam sample_3.SJ.out.tab\n", + " ```\n", "\n", - "The product of this workflow can be used in generating phenotype tables using /molecular_phenotyles/QC/splicing_normalization.ipynb.\n", + "* `--data-dir` -- directory holding the files named in the manifest; defaults to the directory containing `--samples`. Every file listed must be found there. If `.bam.bai` indexes already sit beside the BAMs, LeafCutter reuses them rather than re-indexing.\n", + "* `--splicing-annotation` -- required by `psichomics`: the annotation R object naming which junction combinations form which event, e.g. `Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds`.\n", + "* `--cwd` -- output directory, default `output`.\n", + "* `--container` -- the tool images, `oras://ghcr.io/statfungen/leafcutter_apptainer:latest` and `oras://ghcr.io/statfungen/psichomics_apptainer:latest`. The two workflows need different containers, so they are run as separate commands.\n", "\n", - "Both leafcutter and psichomics section, a meta-data file, white space delimited, containing 4 columns: sample ID, RNA strandness and path to the BAM files input for leafcutter section and to SJ.out.tab files for psichomics section:\n", - "\n", - "```\n", - "sample_id strand bam_list SJ_list\n", - "sample_1 rf sample_1.Aligned.sortedByCoord.out.bam sample_1.SJ.out.tab\n", - "sample_2 fr sample_2.Aligned.sortedByCoord.out.bam sample_2.SJ.out.tab\n", - "sample_3 strand_missing sample_3.Aligned.sortedByCoord.out.bam sample_3.SJ.out.tab\n", - "```\n", + "Junction extraction (`leafcutter`, `leafcutter_preprocessing`):\n", "\n", - "All files listed in this meta-data file should be available in the path provided to the `--data-dir` argument when running either leafcutter or psichomics. \n", + "* `--anchor-len` -- minimum anchor length on each side of a junction, default `8`.\n", + "* `--min-intron-len` -- shortest intron considered, default `50`.\n", + "* `--max-intron-len` -- longest intron considered, default `500000`.\n", "\n", - "If only one type of input files is prepared, one of the bam_list column and SJ_list column can be left empty.\n", + "Intron clustering (`leafcutter`):\n", "\n", - "### `leafcutter`\n", + "* `--min-clu-reads` -- minimum reads in a cluster, default `30`.\n", + "* `--min-clu-ratio` -- minimum fraction of cluster reads supporting a junction, default `0.001`.\n", "\n", - "The bam files can be generated by `the STAR_align` workflow from our RNA_calling.ipynb module. \n", + "Reference data and example input for this module are not in the repository. The reference data is built by [`reference_data_preparation`](https://github.com/statfungen/xqtl-protocol/blob/main/code/reference_data/reference_data_preparation.ipynb), and the example inputs, both psichomics annotations, a manifest and a LeafCutter blacklist-chromosome file, are on [Google Drive](https://drive.google.com/drive/folders/1lpcx3eKG2UpauntLUuJ6bMBjHyIhWW_R).\n", "\n", - "All the BAM files should be available under specified folder (default assumes the same folder as where the meta-data file is).\n", + "Runtime:\n", "\n", - "If intend to blacklist some chromosomes and not analyze it, add one text file named black_list.txt with one chromosome name per line in the same directory of the meta-data file.\n", - "\n", - "\n", - "### `psichomics`\n", - "\n", - "The SJ.out.tab files can be generated by `the STAR_align` workflow from our RNA_calling.ipynb module. \n", - "\n", - "All the SJ.out.tab files should be available under specified folder (default assumes the same folder as where the meta-data file is).\n", - "\n" + "* `--numThreads`, `--job-size`, `--walltime`, `--mem` -- threads (default `8`) and cluster resources.\n", + "* `--modular-script-dir` -- location of the shell and R drivers, default `code/script`." ] }, { @@ -89,7 +85,19 @@ "tags": [] }, "source": [ - "## Output\n\nAll outputs are written under `--cwd`. LeafCutter and psichomics are independent, so a run produces the files for whichever tool was invoked:\n\n- `{sample}.junc` — per-sample LeafCutter junction files extracted from the BAMs.\n- `{group}_intron_usage_perind.counts.gz` and `{group}_intron_usage_perind.junc` — LeafCutter clustered intron-excision counts (the per-intron splicing phenotype) and the matching junction list.\n- `psichomics_junctions.txt` and `psichomics_junctions_{chr}.txt` — psichomics junction tables, genome-wide and split per chromosome.\n- `psi_raw_data.tsv` — raw percent-spliced-in (PSI) values from psichomics, the splicing phenotype used downstream.\n\nThese intron-usage and PSI tables feed `splicing_normalization.ipynb` to build the final splicing phenotype matrices.\n" + "## Output\n", + "\n", + "* `.junc` -- per-sample junction files extracted from the BAMs by regtools, written by both LeafCutter workflows.\n", + "* `_intron_usage_perind.counts.gz` -- the LeafCutter splicing phenotype: one row per intron, keyed `chrom:start:end:clu_N`, giving the fraction of that cluster reads supporting the intron in each sample.\n", + "* `_intron_usage_perind_numers.counts.gz` -- the same rows as raw supporting-read counts rather than ratios.\n", + "* `_pooled` and `_refined` -- intermediate cluster definitions written during clustering.\n", + "* `_intron_usage_perind.junc` -- the list of per-sample `.junc` files. It is the final output of `leafcutter_preprocessing`, and `leafcutter` writes the same file on its way to clustering, although it declares only the counts file as its output, so SoS does not track this one.\n", + "* `psichomics_junctions.txt` -- the junction quantification table. When the manifest spans several input directories, one `psichomics_junctions_.txt` is written per directory and then merged into this file.\n", + "* `psi_raw_data.tsv` -- percent-spliced-in values per event and sample, the psichomics splicing phenotype. Mitochondrial, unplaced and random-contig junctions are dropped before quantification.\n", + "\n", + "Each step also writes `.stdout` and `.stderr` beside its output. There is no example output for this module in the repository, because its inputs are aligned BAM files that are not distributed here.\n", + "\n", + "Both the intron-usage and the PSI table feed `splicing_normalization`, which builds the final splicing phenotype matrices." ] }, { @@ -99,7 +107,7 @@ "kernel": "SoS" }, "source": [ - "## Minimal Working Example Steps\n" + "## Minimal Working Example\n" ] }, { @@ -110,275 +118,203 @@ "tags": [] }, "source": [ - "### i. Splicing Quantification\n", - "#### a. Leafcutter" - ] - }, - { - "cell_type": "markdown", - "id": "1fdeac4b-e9ee-4bc9-9db7-511b01437c20", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "Timing: <30min" + "### LeafCutter intron usage\n", + "\n", + "Extract junctions from every BAM and cluster them into intron-excision ratios. Around 30 minutes on a full sample set." ] }, { "cell_type": "markdown", - "id": "07c88d9b-26ef-40b3-87f6-429f9e4e61fa", + "id": "04874542", "metadata": { "kernel": "SoS" }, "source": [ - "Quantify the usage of alternatively excised introns. " + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", - "execution_count": 14, - "id": "e5e7cbff-a17f-42dd-b854-1eed7ae94213", + "execution_count": null, + "id": "6750fc3a-0683-4145-97eb-304908a62c74", "metadata": { "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INFO: Running \u001b[32mleafcutter_1\u001b[0m: \n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=0) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=1) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=2) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=3) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=4) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=5) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=6) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=7) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=8) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m (index=9) is \u001b[32mignored\u001b[0m due to saved signature\n", - "INFO: \u001b[32mleafcutter_1\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/xqtl_protocol/output_test/leafcutter/1000-PCC.bam.Aligned.sortedByCoord.out_wasp_qc.md.junc /restricted/projectnb/xqtl/xqtl_protocol/output_test/leafcutter/1001-PCC.bam.Aligned.sortedByCoord.out_wasp_qc.md.junc... (10 items in 10 groups)\u001b[0m\n", - "INFO: Running \u001b[32mleafcutter_2\u001b[0m: \n", - "INFO: t53ce7f911566d133 \u001b[32msubmitted\u001b[0m to neurology with job id Your job 2489088 (\"job_t53ce7f911566d133\") has been submitted\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: \u001b[32mleafcutter_2\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/xqtl_protocol/output_test/leafcutter/PCC_sample_list_subset_leafcutter_intron_usage_perind.counts.gz\u001b[0m\n", - "INFO: Workflow leafcutter (ID=w2d4888af18ce85b3) is executed successfully with 1 completed step, 1 ignored step, 10 ignored substeps and 1 completed task.\n" - ] - } - ], + "outputs": [], "source": [ - "!sos run splicing_calling.ipynb leafcutter \\\n", - " --cwd ../../output_test/leafcutter \\\n", - " --samples ../../PCC_sample_list_subset_leafcutter \\\n", - " --data-dir ../../output_test/star_output_wasp \\\n", - " --container oras://ghcr.io/statfungen/leafcutter_apptainer:latest \\\n", - " -c ../csg.yml -q neurology" + "sos run pipeline/splicing_calling.ipynb leafcutter \\\n", + " --cwd output/leafcutter \\\n", + " --samples path/to/sample_list.txt \\\n", + " --data-dir path/to/star_output_wasp \\\n", + " --container oras://ghcr.io/statfungen/leafcutter_apptainer:latest\n" ] }, { "cell_type": "markdown", - "id": "empty-tuition", + "id": "5a2f0523", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "source": [ - "#### b. Psichomics" + "### LeafCutter junction extraction only\n", + "\n", + "The first half of the `leafcutter` command above, stopping once the list of `.junc` files is written. `leafcutter` writes that same list itself, so this workflow is worth running on its own only when the clustering happens elsewhere." ] }, { "cell_type": "markdown", - "id": "58b6326a-5052-47bc-bda9-ab9f9c99c2be", + "id": "13638bb9", "metadata": { "kernel": "SoS" }, "source": [ - "Timing: ~30min" + "**Timing**: TBD (on toy dataset)" ] }, { - "cell_type": "markdown", - "id": "20e797b8-1b27-4e69-83d3-943e4546e58c", + "cell_type": "code", + "execution_count": null, + "id": "8399868d", "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "Quantify specific splicing events. " + "sos run pipeline/splicing_calling.ipynb leafcutter_preprocessing \\\n", + " --cwd output/leafcutter \\\n", + " --samples path/to/sample_list.txt \\\n", + " --data-dir path/to/star_output_wasp \\\n", + " --container oras://ghcr.io/statfungen/leafcutter_apptainer:latest" ] }, { - "cell_type": "code", - "execution_count": 1, - "id": "57fe7020-382e-48a9-b571-8c0ea8e7d8e3", + "cell_type": "markdown", + "id": "empty-tuition", "metadata": { - "kernel": "SoS" + "kernel": "Bash" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "INFO: Running \u001b[32mpsichomics_1\u001b[0m: \n", - "INFO: t9842e29b618d1fad \u001b[32mrestart\u001b[0m from status \u001b[32mfailed\u001b[0m\n", - "INFO: t9842e29b618d1fad \u001b[32msubmitted\u001b[0m to neurology with job id Your job 2490344 (\"job_t9842e29b618d1fad\") has been submitted\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: \u001b[32mpsichomics_1\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/xqtl_protocol/output_test/psichomics/psichomics_junctions.txt\u001b[0m\n", - "INFO: Running \u001b[32mpsichomics_2\u001b[0m: \n", - "INFO: t4908c2bee8ddf317 \u001b[32msubmitted\u001b[0m to neurology with job id Your job 2490387 (\"job_t4908c2bee8ddf317\") has been submitted\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: Waiting for the completion of \u001b[32m1\u001b[0m task.\n", - "INFO: \u001b[32mpsichomics_2\u001b[0m output: \u001b[32m/restricted/projectnb/xqtl/xqtl_protocol/output_test/psichomics/psi_raw_data.tsv\u001b[0m\n", - "INFO: Workflow psichomics (ID=w2c5d88bef5022bf9) is executed successfully with 2 completed steps and 2 completed tasks.\n" - ] - } - ], "source": [ - "!sos run splicing_calling.ipynb psichomics \\\n", - " --cwd ../../output_test/psichomics/ \\\n", - " --samples ../../PCC_sample_list_subset_leafcutter \\\n", - " --data-dir ../../output_test/star_output_wasp \\\n", - " --splicing_annotation ../../reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds \\\n", - " --container oras://ghcr.io/statfungen/psichomics_apptainer:latest \\\n", - " -c ../csg.yml -q neurology" + "### psichomics PSI quantification\n", + "\n", + "Convert the STAR junction counts into a psichomics junction table and quantify percent-spliced-in against the splicing annotation. Around 30 minutes on a full sample set." ] }, { "cell_type": "markdown", - "id": "3c9567a5-64b1-494e-b10f-2db715097851", + "id": "ca640132", "metadata": { "kernel": "SoS" }, "source": [ - "## Troubleshooting" + "**Timing**: TBD (on toy dataset)" ] }, { - "cell_type": "markdown", - "id": "d54e94de-7f4a-4f09-87a9-8a9d4a23934e", + "cell_type": "code", + "execution_count": null, + "id": "bb778e2e-6479-429b-a4fb-c1e7812cbd07", "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "|------|---------|---------|------------------|---------|\n", - "| | | | | |\n", - "\n", - "\n" + "sos run pipeline/splicing_calling.ipynb psichomics \\\n", + " --cwd output/psichomics \\\n", + " --samples path/to/sample_list.txt \\\n", + " --data-dir path/to/star_output_wasp \\\n", + " --splicing-annotation path/to/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds \\\n", + " --container oras://ghcr.io/statfungen/psichomics_apptainer:latest" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "victorian-photography", + "metadata": { + "kernel": "Bash" + }, "source": [ - "## Anticipated Results\n", - "\n", - "The workflow yields per-sample, genome-wide quantifications of alternative splicing in two complementary forms. The leafcutter branch produces `{sample_list}_intron_usage_perind.counts.gz` (intron-excision usage ratios, with rows keyed as `chromosome:intron_start:intron_end:cluster_id`) together with the matching raw-count file `{sample_list}_intron_usage_perind_numers.counts.gz`. The psichomics branch produces `psi_raw_data.tsv`, a table of Percent-Spliced-In (PSI) values for individual splicing events (skipped exon, mutually exclusive exon, alternative 5′/3′ splice sites, alternative first/last exon). These matrices are the phenotype tables that feed the splicing normalization step and, from there, splicing-QTL association." + "## Command Interface" ] }, { - "cell_type": "markdown", - "id": "victorian-photography", + "cell_type": "code", + "execution_count": null, + "id": "8105feec-bee7-429b-9bf7-f840e45bb7ef", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, + "outputs": [], "source": [ - "## Command interface" + "sos run pipeline/splicing_calling.ipynb -h" ] }, { - "cell_type": "code", - "execution_count": 40, - "id": "forbidden-harassment", + "cell_type": "markdown", + "id": "57665062", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "usage: sos run splicing_calling.ipynb\n", - " [workflow_name | -t targets] [options] [workflow_options]\n", - " workflow_name: Single or combined workflows defined in this script\n", - " targets: One or more targets to generate\n", - " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", - " workflow_options: Double-hyphen workflow-specific parameters\n", - "\n", - "Workflows:\n", - " leafcutter\n", - " psichomics\n", - "\n", - "Global Workflow Options:\n", - " --cwd output (as path)\n", - " The output directory for generated files.\n", - " --samples VAL (as path, required)\n", - " Sample meta data list\n", - " --data-dir path(f\"{samples:d}\")\n", - "\n", - " Raw data directory, default to the same directory as\n", - " sample list\n", - " --job-size 1 (as int)\n", - " For cluster jobs, number commands to run per job\n", - " --walltime 5h\n", - " Wall clock time expected\n", - " --mem 16G\n", - " Memory expected\n", - " --numThreads 8 (as int)\n", - " Number of threads\n", - " --container ''\n", - " Software container option\n", - "\n", - "Sections\n", - " leafcutter_1:\n", - " Workflow Options:\n", - " --anchor-len 8 (as int)\n", - " anchor length (default 8)\n", - " --min-intron-len 50 (as int)\n", - " minimum intron length to be analyzed (default 50)\n", - " --max-intron-len 500000 (as int)\n", - " maximum intron length to be analyzed (default 500000)\n", - " leafcutter_2:\n", - " Workflow Options:\n", - " --min-clu-reads 50 (as int)\n", - " minimum reads in a cluster (default 50 reads)\n", - " --max-intron-len 500000 (as int)\n", - " maximum intron length to be analyzed (default 500000)\n", - " psichomics_1:\n", - " psichomics_2:\n" - ] - } - ], "source": [ - "sos run splicing_calling.ipynb -h" + "```\n", + "usage: sos run pipeline/splicing_calling.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " leafcutter\n", + " leafcutter_preprocessing\n", + " psichomics\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --samples VAL (as path, required)\n", + " Sample meta data list\n", + " --data-dir path(f\"{samples:d}\")\n", + "\n", + " Raw data directory, default to the same directory as\n", + " sample list\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", + "\n", + "Sections\n", + " leafcutter_1, leafcutter_preprocessing_1:\n", + " Workflow Options:\n", + " --anchor-len 8 (as int)\n", + " anchor length (default 8)\n", + " --min-intron-len 50 (as int)\n", + " minimum intron length to be analyzed (default 50)\n", + " --max-intron-len 500000 (as int)\n", + " maximum intron length to be analyzed (default 500000)\n", + " leafcutter_2:\n", + " Workflow Options:\n", + " --min-clu-reads 30 (as int)\n", + " minimum reads in a cluster (default 50 reads)\n", + " --max-intron-len 500000 (as int)\n", + " maximum intron length to be analyzed (default 500000)\n", + " --min-clu-ratio 0.001 (as float)\n", + " minimum fraction of reads in a cluster that support a\n", + " junction (default 0.001)\n", + " leafcutter_preprocessing_2:\n", + " psichomics_1:\n", + " psichomics_2:\n", + " Workflow Options:\n", + " --splicing-annotation VAL (as path, required)\n", + " splicing annotation for psichomics (raw psichomics\n", + " annotation, e.g. loadAnnotation output)\n", + "```" ] }, { @@ -388,7 +324,7 @@ "kernel": "SoS" }, "source": [ - "## Setup and global parameters" + "## Workflow implementation" ] }, { @@ -443,31 +379,9 @@ "kernel": "SoS" }, "source": [ - "## `leafcutter`\n", - "\n", - "Documentation: [`leafcutter`](https://davidaknowles.github.io/leafcutter/index.html). The choices of regtool parameters are [discussed here](https://github.com/davidaknowles/leafcutter/issues/127).\n", - "\n", - "### Other clustering options:\n", - "\n", - "* \"-q\", \"--quiet\" : don't print status messages to stdout, default=True.\n", - "\n", - "* \"-p\", \"--mincluratio\" : minimum fraction of reads in a cluster that support a junction, default 0.001. \n", - "\n", - "* \"-c\", \"--cluster\" : refined cluster file when clusters are already made, default = None.\n", - "\n", - "* \"-k\", \"--nochromcheck\" : Don't check that the chromosomes are well formated e.g. chr1, chr2, ..., or 1, 2, ..., default = False.\n", - "\n", - "* \"-C\", \"--includeconst\" : also include constitutive introns, default = False.\n", + "### LeafCutter: junction extraction and clustering\n", "\n", - "The default parameter we used are:\n", - "\n", - "`--min_clu_ratio 0.001 --max_intron_len 500000 --min_clu_reads 30`\n", - "\n", - "These parameter is based on [GTEX's sQTL discovery pipeline (Section 3.4.3) ](https://www.science.org/action/downloadSupplement?doi=10.1126%2Fscience.aaz1776&file=aaz1776_aguet_sm.pdf)\n", - "\n", - "### Things to keep in mind:\n", - "\n", - "* If .bam.bai index files of the .bam input are ready before using leafCutter, it can be placed in the same directory with input .bam files and the \"samtools index ${_input}\" line can be skipped.\n" + "Documentation: [LeafCutter](https://davidaknowles.github.io/leafcutter/index.html); the regtools parameter choices are [discussed here](https://github.com/davidaknowles/leafcutter/issues/127). `leafcutter_1` extracts junctions from each BAM, `leafcutter_2` clusters them into intron-usage ratios, and `leafcutter_preprocessing_2` writes the junction list instead of clustering. The underlying clustering script has further options this module does not expose, among them reusing an existing cluster file, skipping the chromosome-name check, and including constitutive introns." ] }, { @@ -557,28 +471,9 @@ "kernel": "SoS" }, "source": [ - "## `psichomics`\n", - "\n", - "Documentation: [`psichomics`](http://bioconductor.org/packages/release/bioc/html/psichomics.html)\n", - "\n", - "### Other options\n", - "\n", - "quantifySplicing( annotation,\n", - " junctionQuant,\n", - " eventType = c(\"SE\", \"MXE\", \"ALE\", \"AFE\", \"A3SS\", \"A5SS\"),\n", - " minReads = 10,\n", - " genes = NULL\n", - ")\n", - "\n", - "In function quantifySplicing, arguments eventType (Character: splicing event types to quantify), minReads (Integer: values whose number of total supporting read counts is below minReads are returned as NA) and genes (Character: gene symbols for which to quantify splicing events. If NULL, events from all genes are quantified.) can be specified. Usage and default values are shown above.\n", - "\n", - "### Alternative Splicing Annotation Information\n", - "\n", - "Two alternative splicing annotations will be provided in this pipeline which can be download [here](https://drive.google.com/drive/folders/1lpcx3eKG2UpauntLUuJ6bMBjHyIhWW_R). The hg38_suppa.rds is created Via SUPPA using the gtf file of the xqtl-protocol, and the modified_psichomics_hg38_splicing_annotation.rds is modified from the default Human hg38 (2018-04-30) annotation provided by psichomics package. Description of the database can be found in the Alternative splicing annotation section in the [MATERIALS AND METHODS](https://academic.oup.com/nar/article/47/2/e7/5114259?login=true#130023625) part. Gene names of the original annotation are replaced by Ensembl ids for format unifying. The Ensembl IDs used in modifiction are matched from the gtf file, HGNC database, SUPPA and VASTTOOL records within the original annotation.\n", - "\n", - "Theoretically the annotation created using the gtf file only will give results more consistent with other part of the pipeline. The annotation modified from psichomics original hg38 annotation can identify more events since it was build based on information maximizing principle, however there will be risk of containing outdated information too. \n", + "### psichomics: junction quantification and PSI\n", "\n", - "For details of generation method of the gtf file and the two splicing annotations, please check the GFF3 to GTF formatting, Generation of SUPPA annotation for psichomics, and Modification of psichomics default Hg38 splicing annotation sections in [reference_data.ipynb](https://github.com/statfungen/xqtl-protocol/blob/main/code/data_preprocessing/reference_data.ipynb)." + "Documentation: [psichomics](http://bioconductor.org/packages/release/bioc/html/psichomics.html). `psichomics_1` turns the STAR junction counts into a psichomics junction table and `psichomics_2` quantifies PSI against the annotation. The underlying `quantifySplicing` call also accepts a restriction to particular event types, a `minReads` floor below which a value is returned as NA (default 10), and a gene subset; this module quantifies every event type across all genes." ] }, { diff --git a/code/SoS/molecular_phenotypes/methylation.ipynb b/code/SoS/molecular_phenotypes/methylation.ipynb index e42e4cfd6..7140d5227 100644 --- a/code/SoS/molecular_phenotypes/methylation.ipynb +++ b/code/SoS/molecular_phenotypes/methylation.ipynb @@ -2,100 +2,170 @@ "cells": [ { "cell_type": "markdown", + "id": "35948603", "metadata": {}, "source": [ - "# Methylation Data Preprocessing" + "# DNA methylation preprocessing\n", + "\n", + "This mini-protocol converts Illumina methylation-array IDAT files into an analysis-ready probe-by-sample phenotype matrix for mQTL analysis." ] }, { "cell_type": "markdown", + "id": "2be90c3d", "metadata": {}, "source": [ - "## Description\n", + "#### Miniprotocol Timing\n", "\n", - "This mini-protocol turns raw DNA-methylation array data into an analysis-ready methylation phenotype matrix for methylation-QTL (mQTL) analysis. It chains two pipeline modules. First, [methylation calling](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/methylation_calling.html) reads the raw Illumina IDAT intensity files with the SeSAMe package and computes a normalized methylation level (M-value) for every probe in every sample. Second, because array data inevitably contain probes that fail in some samples, a [missing-value imputation](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_imputation.html) step fills the resulting gaps so that downstream tools receive a complete matrix. Follow the two steps in order; each is a single command on the toy data." + "Timing: TBD" ] }, { "cell_type": "markdown", + "id": "85f4a6c2", "metadata": {}, "source": [ - "## Input\n", + "## Overview\n", + "\n", + "Choose either [SeSAMe](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/methylation_calling.html) or [minfi](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/methylation_calling.html) to preprocess paired red/green IDAT intensities. Both workflows produce beta-value and M-value matrices, convert probe coordinates to BED phenotype files, and annotate probes with nearby genes. M values are generally used as the quantitative phenotype for association testing, whereas beta values remain useful for interpretation.\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| IDAT files | Raw Illumina methylation-array intensity files, one pair (Grn/Red) per sample, collected under a single directory. |\n", - "| Sample sheet (`*_arrayMethylation_covariates.tsv`) | Tab-delimited sheet describing each sample and pointing to its IDAT files. The `--sample_sheet_header_rows` parameter sets how many header rows precede the table (default 7; set to 0 when the sheet has no extra header). |\n", - "| Container (`methylation.sif`) | Singularity image providing SeSAMe and its dependencies. |" + "After calling, [phenotype imputation](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_imputation.html) removes probes above the missingness threshold and imputes the remaining missing values. Steps 1 and 2 are alternative starting routes; run only one, then run step 3 on its M-value BED output." ] }, { "cell_type": "markdown", + "id": "d2e10126", "metadata": {}, "source": [ "## Steps\n", "\n", - "### i. Methylation calling\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Process IDAT files with SeSAMe | 1 → 3 | `input/methylation/protocol_example.methylation.sample_sheet_int.csv`; paired `input/methylation/*/*_Grn.idat` and `*_Red.idat` files |\n", + "| Process IDAT files with minfi | 2 → 3 | `input/methylation_minfi/protocol_example.methylation.sample_sheet.csv`; paired `input/methylation_minfi/*/*_Grn.idat` and `*_Red.idat` files |\n", + "\n", + "Run the commands for the selected route in numerical order." + ] + }, + { + "cell_type": "markdown", + "id": "e82bf49d", + "metadata": {}, + "source": [ + "### [1. Call methylation levels with SeSAMe](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/methylation_calling.html)\n", "\n", - "Call methylation levels from the collection of IDAT files with SeSAMe. The `sesame` workflow reads the sample sheet, locates each sample’s IDAT pair, and writes a per-probe methylation (M-value) matrix as a `bed.gz` phenotype file. The first command runs locally; the second submits the same job to an HPC queue (`-q csg -c csg2.yml`). On the toy dataset this step takes roughly 26 minutes and up to ~15 GB of memory." + "**What it does:** `sesame` performs probe- and sample-level detection filtering, calculates beta and M values, and formats both matrices as coordinate-sorted BED files." ] }, { "cell_type": "code", "execution_count": null, - "id": "7686db50-6e00-406b-923f-6e7a3fe1c7ae", + "id": "421aca59", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/methylation_calling.ipynb sesame \\\n", - " --sample-sheet input_data/Methylation/xqtl_protocol_data_arrayMethylation_covariates.tsv \\\n", - " --container containers/methylation.sif --sample_sheet_header_rows 0 --cwd output_rerun/methylation/\n", - " \n", - "sos run pipeline/methylation_calling.ipynb sesame \\\n", - " --sample-sheet input_data/Methylation/xqtl_protocol_data_arrayMethylation_covariates.tsv \\\n", - " --container containers/methylation.sif --sample_sheet_header_rows 0 --cwd output_rerun/methylation/ -q csg -c csg2.yml -J 1 &" + "sos run pipeline/methylation_calling.ipynb sesame --sample-sheet input/methylation/protocol_example.methylation.sample_sheet_int.csv --sample-sheet-header-rows 0 --cwd output/methylation" ] }, { "cell_type": "markdown", + "id": "f3f67af0", "metadata": {}, "source": [ - "### ii. Missing-value imputation\n", + "### [2. Call methylation levels with minfi](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/methylation_calling.html)\n", "\n", - "Array methylation matrices typically contain probes with missing (`NA`) values in some samples. The `bed_filter_na` workflow applies soft-impute to fill these gaps, producing a complete matrix that downstream covariate, association, and fine-mapping steps can consume. On the toy dataset this step takes about 2.5 minutes and up to ~8 GB of memory." + "**What it does:** `minfi` applies detection-p-value filtering and functional normalization, then writes beta and M values in the same downstream-compatible BED format." ] }, { "cell_type": "code", "execution_count": null, - "id": "9314734b-ce46-453a-9e36-413a19400768", + "id": "ff6eb936", "metadata": {}, "outputs": [], "source": [ - "sos run pipeline/phenotype_imputation.ipynb bed_filter_na \\\n", - " --phenoFile output/methylation/xqtl_protocol_data_arrayMethylation_covariates.sesame.M.bed.gz \\\n", - " --cwd ./output/methylation/" + "sos run pipeline/methylation_calling.ipynb minfi --sample-sheet input/methylation_minfi/protocol_example.methylation.sample_sheet.csv --cwd output/methylation_minfi" ] }, { "cell_type": "markdown", + "id": "d3517c97", "metadata": {}, "source": [ - "## Output\n", + "### [3. Filter and impute the M-value matrix](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/phenotype_imputation.html)\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `*.sesame.M.bed.gz` | Per-probe methylation (M-value) matrix produced by the calling step, samples in columns and probes in rows. |\n", - "| Imputed `bed.gz` matrix | The same matrix after soft-impute, with no remaining missing values — the methylation phenotype table used for mQTL analysis. |" + "**What it does:** `bed_filter_na` removes probes exceeding the missingness threshold and uses soft-impute for the remaining missing entries." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "15daf701", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_imputation.ipynb bed_filter_na --phenoFile output/methylation/protocol_example.methylation.sample_sheet_int.sesame.M.bed.gz --cwd ." ] }, { "cell_type": "markdown", + "id": "27ad363f", + "metadata": {}, + "source": [ + "## Output Files\n", + "\n", + "| Route/step | Output filename and relative path | Description |\n", + "| --- | --- | --- |\n", + "| SeSAMe | `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.rds` | Serialized SeSAMe result object |\n", + "| SeSAMe | `output/methylation/protocol_example.methylation.sample_sheet_int.sample_qcs.sesame.tsv` | Per-sample quality-control summary |\n", + "| SeSAMe | `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.beta.tsv`; `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.M.tsv` | Probe-by-sample beta- and M-value tables |\n", + "| SeSAMe | `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.beta.bed.gz`; `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.M.bed.gz` | Indexed BED phenotype matrices |\n", + "| SeSAMe | `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.gene_id.annot.tsv` | Probe-to-gene annotation |\n", + "| minfi | `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.rds` | Serialized minfi result object |\n", + "| minfi | `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.beta.tsv`; `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.M.tsv` | Probe-by-sample beta- and M-value tables |\n", + "| minfi | `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.beta.bed.gz`; `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.M.bed.gz` | Indexed BED phenotype matrices |\n", + "| minfi | `output/methylation_minfi/protocol_example.methylation.sample_sheet.minfi.gene_id.annot.tsv` | Probe-to-gene annotation |\n", + "| Step 3 | `output/methylation/protocol_example.methylation.sample_sheet_int.sesame.M.filter_na.soft.bed.gz` | Filtered and imputed M-value phenotype matrix |\n", + "\n", + "For the minfi route, give step 3 the minfi M-value BED path instead; the output keeps the minfi filename prefix." + ] + }, + { + "cell_type": "markdown", + "id": "5dc0998f", "metadata": {}, "source": [ "## Anticipated Results\n", "\n", - "The pipeline produces a complete, normalized DNA-methylation phenotype matrix (`*.sesame.M.bed.gz`, after imputation) covering all probes across all samples in the sample sheet. This matrix is the methylation equivalent of the expression `bed.gz` files and serves as the phenotype input to the covariate-preprocessing and QTL-association sections of the protocol." + "The selected calling route produces beta- and M-value matrices with probes in rows and samples in columns, together with sample QC and probe annotation files. After step 3, the M-value BED contains only retained probes and has no missing phenotype values, making it suitable for covariate preprocessing and methylation-QTL association testing." + ] + }, + { + "cell_type": "markdown", + "id": "b5b1817f", + "metadata": {}, + "source": [ + "## Command interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e7a7c6ad", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/methylation_calling.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96515df4", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/phenotype_imputation.ipynb -h" ] } ], @@ -133,4 +203,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/molecular_phenotypes/single_cell.ipynb b/code/SoS/molecular_phenotypes/single_cell.ipynb new file mode 100644 index 000000000..899f3c400 --- /dev/null +++ b/code/SoS/molecular_phenotypes/single_cell.ipynb @@ -0,0 +1,238 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Single-cell and single-nucleus molecular phenotype preprocessing\n", + "\n", + "This mini-protocol performs cell-level snRNA-seq quality control and annotation, then prepares cell-type pseudobulk molecular phenotypes for QTL analysis." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Miniprotocol Timing\n", + "\n", + "This is the total duration for one selected route; module-specific timings appear on their respective pages.\n", + "\n", + "Timing: TBD" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Overview\n", + "\n", + "Single-cell and single-nucleus data require two distinct levels of processing. Cell-level processing filters low-quality cells, removes ambient RNA and doublets, and transfers cell-type labels. Pseudobulk processing then aggregates cells within each donor and cell type, harmonizes donor identifiers, adjusts technical covariates, and formats residualized traits for QTL analysis.\n", + "\n", + "The first two steps use [`snRNAseq_preprocessing.ipynb`](snRNAseq_preprocessing.ipynb). The remaining steps use [`pseudobulk_preprocessing.ipynb`](QC/pseudobulk_preprocessing.ipynb). Choose a route from the table rather than running every command automatically." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Steps\n", + "\n", + "| Analysis goal | Commands to run, in order | Inputs |\n", + "|---|---:|---|\n", + "| Cell-level QC and reference-based annotation | 1 \u2192 2 | `input/snrnaseq/protocol_example.snrnaseq.cellranger/`
`input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv`
`input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds` |\n", + "| Generate pseudobulk counts for a selected cell type from the annotated object | 1 \u2192 2 \u2192 3 | Inputs above |\n", + "| Prepare existing RNA pseudobulk counts for QTL analysis | 4 \u2192 5 \u2192 6 | `input/snrnaseq/protocol_example.snrnaseq.id_map.csv`
`input/snrnaseq/protocol_example.snrnaseq.metadata_MIC.csv`
`input/snrnaseq/protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz`
`input/snrnaseq/protocol_example.snrnaseq.tech_vars_MIC.csv`
`input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` |\n", + "| Format existing cell-type residuals for QTL analysis | 6 only | A residual matrix under a cell-type directory and the gene-annotation GTF |\n", + "\n", + "The commands use `MIC` as the concrete example cell type. For another cell type, replace `MIC` consistently in the option value and associated input and output filenames.\n", + "\n", + "Step 3 produces pseudobulk counts but not the metadata and technical-variable files required by steps 4 and 5. Continue with 4 \u2192 5 \u2192 6 only after those companion files are available." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 1. [Cell-level quality control](snRNAseq_preprocessing.ipynb)\n", + "\n", + "**What it does:** Filters cells, removes ambient RNA and doublets, and saves the filtered Seurat object plus a QC table." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/snRNAseq_preprocessing.ipynb sctk_qc --input-dir input/snrnaseq/protocol_example.snrnaseq.cellranger --output-dir output/snrna_seq --sample-meta input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv --name protocol_example.snrnaseq" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 2. [Cell-type annotation](snRNAseq_preprocessing.ipynb)\n", + "\n", + "**What it does:** Transfers labels from the reference Seurat object to the filtered cells and writes a cell-typed Seurat object." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/snRNAseq_preprocessing.ipynb cell_annotation --sctk-rds output/snrna_seq/SCTK_results/protocol_example.snrnaseq.filtered_seuratobj.rds --output-dir output/snrna_seq --seurat-ref input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds --name protocol_example.snrnaseq" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 3. [Pseudobulk count aggregation](QC/pseudobulk_preprocessing.ipynb)\n", + "\n", + "**What it does:** Aggregates counts across cells of the selected type within each donor from the annotated Seurat object." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/pseudobulk_preprocessing.ipynb pseudobulk_counts --seurat-files output/snrna_seq/protocol_example.snrnaseq.celltyped_seuratobj.rds --celltype MIC --output-dir output/snrna_seq --name protocol_example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 4. [Sample-ID harmonization](QC/pseudobulk_preprocessing.ipynb)\n", + "\n", + "**What it does:** Applies the donor-ID map to existing cell-type metadata and count matrices so their sample identifiers agree." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/pseudobulk_preprocessing.ipynb sampleid_mapping --map-file input/snrnaseq/protocol_example.snrnaseq.id_map.csv --meta-files input/snrnaseq/protocol_example.snrnaseq.metadata_MIC.csv --count-files input/snrnaseq/protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz --output-dir output/snrna_seq --name protocol_example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 5. [Pseudobulk quality control and residualization](QC/pseudobulk_preprocessing.ipynb)\n", + "\n", + "**What it does:** Filters low-information features and samples, adjusts the specified technical variables, and writes cell-type residuals." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/pseudobulk_preprocessing.ipynb pseudobulk_qc --meta-files output/snrna_seq/protocol_example.snrnaseq.metadata_MIC.csv --count-files output/snrna_seq/protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz --tech-vars-file input/snrnaseq/protocol_example.snrnaseq.tech_vars_MIC.csv --output-dir output/snrna_seq --name protocol_example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### 6. [QTL phenotype formatting](QC/pseudobulk_preprocessing.ipynb)\n", + "\n", + "**What it does:** Adds genomic coordinates to the residualized cell-type traits and writes a bgzipped phenotype BED for association testing." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/pseudobulk_preprocessing.ipynb phenotype_formatting --residual-files output/snrna_seq/protocol_example.MIC.residuals.txt --output-dir output/snrna_seq --gtf-file input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf --name protocol_example" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Output Files\n", + "\n", + "| Step | Relative path | Contents |\n", + "|---:|---|---|\n", + "| 1 | `output/snrna_seq/SCTK_results/protocol_example.snrnaseq.filtered_seuratobj.rds` | Filtered and corrected Seurat object |\n", + "| 1 | `output/snrna_seq/QC_table/protocol_example.snrnaseq.SCTK_QC_table.csv` | Per-cell QC measurements and calls |\n", + "| 2 | `output/snrna_seq/protocol_example.snrnaseq.celltyped_seuratobj.rds` | Seurat object with transferred cell-type labels |\n", + "| 3 | `output/snrna_seq/protocol_example.pseudobulk_counts_MIC.csv.gz` | Donor-by-feature cell-type pseudobulk counts |\n", + "| 4 | `output/snrna_seq/protocol_example.snrnaseq.metadata_MIC.csv` | Metadata with harmonized donor IDs |\n", + "| 4 | `output/snrna_seq/protocol_example.snrnaseq.pseudobulk_counts_MIC.csv.gz` | Counts with harmonized donor IDs |\n", + "| 5 | `output/snrna_seq/protocol_example.MIC.residuals.txt` | QC-filtered and residualized cell-type traits |\n", + "| 6 | `output/snrna_seq/protocol_example.MIC.phenotype.bed.gz` | Genomically positioned cell-type molecular phenotypes for QTL testing |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Anticipated Results\n", + "\n", + "The cell-level route produces a filtered, cell-typed Seurat object suitable for downstream aggregation. The pseudobulk route produces one donor-level molecular phenotype matrix per cell type and, after residualization and coordinate formatting, a bgzipped BED suitable for the phenotype-preprocessing and QTL-association workflows.\n", + "\n", + "Review cell counts, donor representation, QC exclusions, and residual distributions before association testing; pseudobulk estimates can be unstable when a donor contributes too few cells to a cell type." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Command interface\n", + "\n", + "Inspect all workflows, options, and defaults for the two modules:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/snRNAseq_preprocessing.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/pseudobulk_preprocessing.ipynb -h" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.13" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file diff --git a/code/SoS/molecular_phenotypes/snRNAseq_preprocessing.ipynb b/code/SoS/molecular_phenotypes/snRNAseq_preprocessing.ipynb index 423b02797..85b3f6b2a 100644 --- a/code/SoS/molecular_phenotypes/snRNAseq_preprocessing.ipynb +++ b/code/SoS/molecular_phenotypes/snRNAseq_preprocessing.ipynb @@ -8,8 +8,7 @@ "source": [ "# snRNA-seq Preprocessing\n", "\n", - "## Description\n", - "This pipeline preprocesses single-nuclei RNA-seq data in two stages. First it performs quality control with SCTK and Seurat: removing low-quality cells by mitochondrial content, total counts (nUMI) and detected genes (nFeature), filtering ambient RNA contamination with decontX, and removing doublets with a user-selected method (scds, scrublet, doubletFinder, or doubletCells). It then annotates cell types on the QC-filtered data using SingleR against a reference, transferring cluster-majority labels to the full Seurat object so the result is ready for pseudobulk aggregation." + "Takes CellRanger counts through quality control and cell-type annotation to a Seurat object ready for downstream analysis." ] }, { @@ -18,13 +17,67 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Overview\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/snrnaseq/protocol_example.snrnaseq.cellranger/` | CellRanger output directory (contains the per-sample counts folder with `filtered_feature_bc_matrix`) |\n", - "| `input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv` | Sample barcode-to-patient ID mapping (columns: `libraryBatch`, `cellBarcode`, `individualID`) |\n", - "| `input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds` | SingleR reference SummarizedExperiment object (used in Step 2) |" + "Single-nuclei RNA-seq counts arrive with artefacts that would otherwise be read as biology: dying cells with high mitochondrial content, ambient RNA carried over from the suspension, and droplets holding two nuclei rather than one. Filtering those out, and then deciding what cell type each surviving nucleus is, has to happen before any per-cell-type analysis can start.\n", + "\n", + "Quality control runs through SCTK and Seurat: cells are dropped on mitochondrial percent, total counts (nUMI) and detected genes (nFeature), ambient RNA is removed with decontX, and doublets are removed with a user-selected method, `scds` by default. Cell types are then assigned by transferring labels from an annotated reference dataset onto the filtered object.\n", + "\n", + "**When to run it.** On CellRanger output, before pseudobulk aggregation or any per-cell-type phenotype work." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Input\n", + "\n", + "- `--input-dir`: the CellRanger output directory, holding the per-sample counts folder with `filtered_feature_bc_matrix`. Example `input/snrnaseq/protocol_example.snrnaseq.cellranger/`.\n", + "- `--sample-meta`: a CSV mapping cell barcodes to individuals, with columns `libraryBatch`, `cellBarcode` and `individualID`. Example `input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv`:\n", + "\n", + " ```\n", + " libraryBatch,cellBarcode,individualID\n", + " 190403-B4-A,ATTATCCCAGGACATG-1,R2670295\n", + " 190403-B4-A,GAGCTGCCACACGGAA-1,R1743384\n", + " ```\n", + "\n", + "- `--sctk-rds`: for `cell_annotation`, the QC-filtered Seurat object written by `sctk_qc`.\n", + "- `--seurat-ref`: the annotated reference dataset the cell types are transferred from. Example `input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds`.\n", + "- `--output-dir`: the directory outputs are written to.\n", + "- `--name`: the prefix given to every output filename, `protocol_example.snrnaseq` by default, so results stay traceable to the dataset." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output\n", + "\n", + "- `{output_dir}/SCTK_results/{name}.filtered_seuratobj.rds` - the QC-filtered, clustered Seurat object from `sctk_qc`, and the input to `cell_annotation`. No example ships: `output/snrna_seq/` has no `SCTK_results/` directory.\n", + "- `{output_dir}/QC_table/{name}.SCTK_QC_table.csv` - per-sample SCTK QC metrics. Example `output/snrna_seq/QC_table/protocol_example.snrnaseq.SCTK_QC_table.csv`, 10 columns and 10 rows:\n", + "\n", + " ```\n", + " \"\",\"R6249698\",\"R7840275\",\"R9818080\",\"R8054504\"\n", + " \"Number of Cells,361,269,246,151\n", + " \"Mean counts\",10237,10117,10514,8989.2\n", + " ```\n", + "- `{output_dir}/SCTK_results/{name}.QC_summary.csv` - cell and gene counts at each QC step. No example ships.\n", + "- `{output_dir}/{name}.celltyped_seuratobj.rds` - the cell-type annotated Seurat object from `cell_annotation`. Example `output/snrna_seq/protocol_example.snrnaseq.celltyped_seuratobj.rds`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", + "\n", + "Two workflows run in order: `sctk_qc` filters the CellRanger counts, then `cell_annotation` labels the surviving cells. They are chained by hand - `--sctk-rds` in the second command is the object the first one wrote." ] }, { @@ -33,10 +86,18 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "### QC filtering\n", "\n", - "### Step 1. QC filtering (sctk_qc)\n", - "Runs SCTK/Seurat QC on the CellRanger counts: it drops cells failing the mitochondrial-percent, minimum-count (nUMI) and minimum-gene (nFeature) thresholds, removes ambient RNA with decontX, and removes doublets with the chosen method (default `scds`). The sample-meta CSV maps cell barcodes to individual IDs. The result is a QC-filtered, clustered Seurat object." + "`sctk_qc` drops cells on the mitochondrial-percent, minimum-count and minimum-gene thresholds, removes ambient RNA with decontX, and removes doublets with the method `--doublet-method` selects." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -50,7 +111,8 @@ "sos run pipeline/snRNAseq_preprocessing.ipynb sctk_qc \\\n", " --input-dir input/snrnaseq/protocol_example.snrnaseq.cellranger \\\n", " --output-dir output/snrna_seq \\\n", - " --sample-meta input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv" + " --sample-meta input/snrnaseq/protocol_example.snrnaseq.id_mapping.csv \\\n", + " --name protocol_example.snrnaseq" ] }, { @@ -59,8 +121,16 @@ "kernel": "SoS" }, "source": [ - "### Step 2. Cell type annotation (cell_annotation)\n", - "Annotates cell types on the QC-filtered object using SingleR against the reference SummarizedExperiment. Cells are downsampled per cluster (default 1000) for the SingleR call, then a cluster-majority label is assigned when at least `cluster_threshold` (default 0.90) of the cluster agrees, and transferred back to the full Seurat object." + "### Cell type annotation" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -72,9 +142,30 @@ "outputs": [], "source": [ "sos run pipeline/snRNAseq_preprocessing.ipynb cell_annotation \\\n", - " --sctk-rds output/snrna_seq/SCTK_results/filtered_seuratobj.rds \\\n", + " --sctk-rds output/snrna_seq/SCTK_results/protocol_example.snrnaseq.filtered_seuratobj.rds \\\n", " --output-dir output/snrna_seq \\\n", - " --seurat-ref input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds" + " --seurat-ref input/snrnaseq/protocol_example.snrnaseq.seurat_ref_SE.rds \\\n", + " --name protocol_example.snrnaseq" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/snRNAseq_preprocessing.ipynb -h" ] }, { @@ -83,15 +174,52 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "```\n", + "usage: sos run code/SoS/molecular_phenotypes/snRNAseq_preprocessing.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " sctk_qc\n", + " cell_annotation\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " --name 'protocol_example.snrnaseq'\n", + " Prefix for all output filenames; keeps results traceable\n", + " to the dataset\n", + " --job-size 1 (as int)\n", + " --walltime 5h\n", + " --mem 16G\n", + " --numThreads 8 (as int)\n", + " --container ''\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/snrna_seq/SCTK_results/filtered_seuratobj.rds` | QC-filtered, clustered Seurat object (from Step 1) |\n", - "| `output/snrna_seq/QC_table/SCTK_QC_table.csv` | Per-sample SCTK QC metrics |\n", - "| `output/snrna_seq/SCTK_results/QC_summary.csv` | Cell/gene counts at each QC step |\n", - "| `output/snrna_seq/annotated_seuratobj.rds` | Downsampled Seurat object with per-cell SingleR labels (from Step 2) |\n", - "| `output/snrna_seq/celltyped_seuratobj.rds` | Full Seurat object with cluster-majority cell type labels (from Step 2) |" + "Sections\n", + " sctk_qc:\n", + " Workflow Options:\n", + " --input-dir VAL (as str, required)\n", + " --output-dir VAL (as str, required)\n", + " --sample-meta VAL (as str, required)\n", + " --max-mito-percent 5 (as int)\n", + " --min-ncounts 250 (as int)\n", + " --min-ngenes 500 (as int)\n", + " --doublet-method scds\n", + " --scds-call Singlet\n", + " --scrublet-threshold 0.25 (as float)\n", + " --ambient-method decontX\n", + " --max-decontXsc 0.5 (as float)\n", + " cell_annotation:\n", + " Workflow Options:\n", + " --sctk-rds VAL (as str, required)\n", + " --output-dir VAL (as str, required)\n", + " --seurat-ref VAL (as str, required)\n", + " --downsample-n 1000 (as int)\n", + " --cluster-threshold 0.9 (as float)\n", + "```" ] }, { @@ -100,37 +228,103 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "Step 1 yields a QC-filtered Seurat object plus QC tables summarizing how many cells and genes survive each filtering step. Step 2 adds cell type labels, producing a celltype-labeled Seurat object ready for downstream pseudobulk aggregation." + "## Workflow implementation" ] }, { "cell_type": "code", "execution_count": null, - "id": "5ce144fc-0699-42c5-afec-a31aae5824dc", "metadata": { "kernel": "SoS" }, "outputs": [], - "source": "[global]\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\nparameter: cwd = path(\"output\")\nparameter: job_size = 1\nparameter: walltime = \"5h\"\nparameter: mem = \"16G\"\nparameter: numThreads = 8\nparameter: container = \"\"\n\ncwd = path(f'{cwd:a}')\n" + "source": [ + "[global]\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "parameter: cwd = path(\"output\")\n", + "# Prefix for all output filenames; keeps results traceable to the dataset\n", + "parameter: name = \"protocol_example.snrnaseq\"\n", + "parameter: job_size = 1\n", + "parameter: walltime = \"5h\"\n", + "parameter: mem = \"16G\"\n", + "parameter: numThreads = 8\n", + "parameter: container = \"\"\n", + "\n", + "cwd = path(f'{cwd:a}')\n" + ] }, { "cell_type": "code", "execution_count": null, - "id": "d9a333d1-b118-406e-993a-2d35c78d97f0", "metadata": { "kernel": "SoS" }, "outputs": [], - "source": "[sctk_qc]\nparameter: input_dir = str\nparameter: output_dir = str\nparameter: sample_meta = str\nparameter: max_mito_percent = 5\nparameter: min_ncounts = 250\nparameter: min_ngenes = 500\nparameter: doublet_method = 'scds' # options: 'scds', 'scrublet', 'doubletFinder', 'doubletCells', 'none'\nparameter: scds_call = 'Singlet'\nparameter: scrublet_threshold = 0.25\nparameter: ambient_method = 'decontX' # options: 'decontX', 'none'\nparameter: max_decontXsc = 0.5\n\ninput: []\noutput: f'{output_dir}/SCTK_results/filtered_seuratobj.rds',\n f'{output_dir}/QC_table/SCTK_QC_table.csv'\ntask: trunk_workers = 1, trunk_size = 1, walltime = '36:00:00', mem = '256G', cores = 16\nbash: expand = \"${ }\", stdout = f'{_output[0]:n}.stdout', stderr = f'{_output[0]:n}.stderr'\n Rscript ${modular_script_dir}/molecular_phenotypes/snRNAseq_preprocessing.R \\\n --step sctk_qc \\\n --input-dir \"${input_dir}\" \\\n --output-dir \"${output_dir}\" \\\n --sample-meta \"${sample_meta}\" \\\n --max-mito-percent ${max_mito_percent} \\\n --min-ncounts ${min_ncounts} \\\n --min-ngenes ${min_ngenes} \\\n --doublet-method \"${doublet_method}\" \\\n --scds-call \"${scds_call}\" \\\n --scrublet-threshold ${scrublet_threshold} \\\n --ambient-method \"${ambient_method}\" \\\n --max-decontxsc ${max_decontXsc} \\\n --num-threads ${numThreads}\n" + "source": [ + "[sctk_qc]\n", + "parameter: input_dir = str\n", + "parameter: output_dir = str\n", + "parameter: sample_meta = str\n", + "parameter: max_mito_percent = 5\n", + "parameter: min_ncounts = 250\n", + "parameter: min_ngenes = 500\n", + "parameter: doublet_method = 'scds' # options: 'scds', 'scrublet', 'doubletFinder', 'doubletCells', 'none'\n", + "parameter: scds_call = 'Singlet'\n", + "parameter: scrublet_threshold = 0.25\n", + "parameter: ambient_method = 'decontX' # options: 'decontX', 'none'\n", + "parameter: max_decontXsc = 0.5\n", + "\n", + "input: []\n", + "output: f'{output_dir}/SCTK_results/{name}.filtered_seuratobj.rds',\n", + " f'{output_dir}/QC_table/{name}.SCTK_QC_table.csv'\n", + "task: trunk_workers = 1, trunk_size = 1, walltime = '36:00:00', mem = '256G', cores = 16\n", + "bash: expand = \"${ }\", stdout = f'{_output[0]:n}.stdout', stderr = f'{_output[0]:n}.stderr'\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/snRNAseq_preprocessing.R \\\n", + " --step sctk_qc \\\n", + " --input-dir \"${input_dir}\" \\\n", + " --output-dir \"${output_dir}\" \\\n", + " --name \"${name}\" \\\n", + " --sample-meta \"${sample_meta}\" \\\n", + " --max-mito-percent ${max_mito_percent} \\\n", + " --min-ncounts ${min_ncounts} \\\n", + " --min-ngenes ${min_ngenes} \\\n", + " --doublet-method \"${doublet_method}\" \\\n", + " --scds-call \"${scds_call}\" \\\n", + " --scrublet-threshold ${scrublet_threshold} \\\n", + " --ambient-method \"${ambient_method}\" \\\n", + " --max-decontxsc ${max_decontXsc} \\\n", + " --num-threads ${numThreads}\n" + ] }, { "cell_type": "code", "execution_count": null, - "id": "5bdfae1e-23e1-4d74-8449-5a87a900ce1d", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "outputs": [], - "source": "[cell_annotation]\nparameter: sctk_rds = str\nparameter: output_dir = str\nparameter: seurat_ref = str\nparameter: downsample_n = 1000\nparameter: cluster_threshold = 0.90\n\ninput: []\noutput: f'{output_dir}/celltyped_seuratobj.rds'\ntask: trunk_workers = 1, trunk_size = 1, walltime = '36:00:00', mem = '256G', cores = 16\nbash: expand = \"${ }\", stdout = f'{_output:n}.stdout', stderr = f'{_output:n}.stderr'\n Rscript ${modular_script_dir}/molecular_phenotypes/snRNAseq_preprocessing.R \\\n --step cell_annotation \\\n --sctk-rds \"${sctk_rds}\" \\\n --output-dir \"${output_dir}\" \\\n --seurat-ref \"${seurat_ref}\" \\\n --downsample-n ${downsample_n} \\\n --cluster-threshold ${cluster_threshold} \\\n --num-threads ${numThreads}\n" + "source": [ + "[cell_annotation]\n", + "parameter: sctk_rds = str\n", + "parameter: output_dir = str\n", + "parameter: seurat_ref = str\n", + "parameter: downsample_n = 1000\n", + "parameter: cluster_threshold = 0.90\n", + "\n", + "input: []\n", + "output: f'{output_dir}/{name}.celltyped_seuratobj.rds'\n", + "task: trunk_workers = 1, trunk_size = 1, walltime = '36:00:00', mem = '256G', cores = 16\n", + "bash: expand = \"${ }\", stdout = f'{_output:n}.stdout', stderr = f'{_output:n}.stderr'\n", + " Rscript ${modular_script_dir}/molecular_phenotypes/snRNAseq_preprocessing.R \\\n", + " --step cell_annotation \\\n", + " --sctk-rds \"${sctk_rds}\" \\\n", + " --output-dir \"${output_dir}\" \\\n", + " --name \"${name}\" \\\n", + " --seurat-ref \"${seurat_ref}\" \\\n", + " --downsample-n ${downsample_n} \\\n", + " --cluster-threshold ${cluster_threshold} \\\n", + " --num-threads ${numThreads}\n" + ] } ], "metadata": { diff --git a/code/SoS/molecular_phenotypes/splicing.ipynb b/code/SoS/molecular_phenotypes/splicing.ipynb index cbceb43b3..8b78f367c 100644 --- a/code/SoS/molecular_phenotypes/splicing.ipynb +++ b/code/SoS/molecular_phenotypes/splicing.ipynb @@ -2,201 +2,281 @@ "cells": [ { "cell_type": "markdown", - "id": "binding-ottawa", + "id": "3563f714", "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, "source": [ "# Alternative splicing from RNA-seq data\n", - "\n" + "\n", + "This mini-protocol produces normalized, gene-annotated splicing phenotypes for splicing-QTL analysis using either LeafCutter or psichomics." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "5a84503d", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Input Files\n\n| File | Description |\n| --- | --- |\n| `output/rnaseq/xqtl_protocol_data_bam_list` | List of RNA-seq BAM files produced by RNA calling |\n| `output/leaf_cutter/` | Working directory for leafcutter intron-usage quantification |\n| `output/psichomics/` | Working directory for psichomics PSI quantification |\n" + "#### Miniprotocol Timing\n", + "\n", + "Timing: TBD" ] }, { "cell_type": "markdown", - "id": "fe558690-5e2a-4d42-8ca3-ae0227741716", + "id": "f2785329", "metadata": { "kernel": "SoS" }, "source": [ - "#### Miniprotocol Timing\n", + "## Overview\n", + "\n", + "The [splicing-calling module](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html) provides two alternative quantification routes. LeafCutter derives intron excision ratios from STAR splice-junction files without relying on a transcript annotation. psichomics calculates percent-spliced-in (PSI) values for annotated alternative-splicing events and therefore also requires the SUPPA annotation object.\n", "\n", - "Timing <2 hours" + "The [normalization module](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/splicing_normalization.html) performs missingness and variability filtering followed by quantile normalization. The [gene-annotation module](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html) then assigns coordinates and phenotype groups required by TensorQTL. LeafCutter and psichomics are alternative routes, not one combined chain." ] }, { "cell_type": "markdown", - "id": "5f48cddc-f1ec-42c5-80cc-35e4048fdf27", + "id": "4f19c2ca", "metadata": { "kernel": "SoS" }, "source": [ - "## Description" + "## Steps\n", + "\n", + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| LeafCutter from aligned RNA-seq data | 1 → 2 → 3 | `output/rnaseq/protocol_example.rnaseq.bam.list.txt`; STAR/WASP alignment directories |\n", + "| LeafCutter from a precomputed ratio matrix | 2 → 3 | `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz`; `input/rnaseq/protocol_example.leafcutter.intron_count.tsv` |\n", + "| psichomics from aligned RNA-seq data | 4 → 5 → 6 | BAM list and alignments above; `input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds` |\n", + "| psichomics from a precomputed PSI matrix | 5 → 6 | `input/rnaseq/protocol_example.psichomics.psi_raw_data.tsv` |\n", + "\n", + "Within the selected route, run the commands in numerical order. The bundled example data support the two precomputed-matrix routes; the calling routes require aligned BAM files." ] }, { "cell_type": "markdown", - "id": "0e4d6a37-3eec-4e48-9978-bbee34068dfa", + "id": "29f8084b", "metadata": { "kernel": "SoS" }, "source": [ - "Several other modules should be run before generating splicing data to prepare the data. These include:\n", - "1. `molecular_phenotypes/calling/RNA_calling.ipynb` (step i): Generate data quality summary with fastqc\n", - "2. `molecular_phenotypes/calling/RNA_calling.ipynb` (step ii): Trim adaptors\n", - "3. `molecular_phenotypes/calling/RNA_calling.ipynb` (step iii): Align RNASeq reads with STAR using the wasp option specifically for splicing data\n", + "### [1. Quantify intron usage with LeafCutter](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html)\n", "\n", - "This miniprotocol shows the use of modules for splicing quantification and normalization. They are as follows:\n", - "1. `molecular_phenotypes/calling/splicing_calling.ipynb` (step i): Quantify splicing with leafcutter or psichomics\n", - "2. `molecular_phenotypes/QC/splicing_normalization.ipynb` (step ii): Quality control and normalization of splicing data\n", - "3. `data_preprocessing/phenotype/gene_annotation.ipynb` (step iii): Process splicing data for use in TensorQTL" + "**What it does:** `leafcutter` extracts splice junctions and clusters introns to calculate per-sample intron excision ratios." ] }, { - "cell_type": "markdown", - "id": "34d14dfc-4045-451b-9071-69b799642c25", + "cell_type": "code", + "execution_count": null, + "id": "7a61d022", "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Steps" + "sos run pipeline/splicing_calling.ipynb leafcutter --cwd output/splicing/leafcutter --samples output/rnaseq/protocol_example.rnaseq.bam.list.txt --data-dir output/rnaseq/star_output_wasp" ] }, { "cell_type": "markdown", - "id": "517cdd3d-4b37-45b5-ba39-18890862e426", + "id": "404cb133", "metadata": { - "kernel": "Markdown", - "tags": [] + "kernel": "SoS" }, "source": [ - "### i. [Splicing Quantification with Leafcutter (intron usage ratio) or Psichomics (percent spliced in events)](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html)" + "### [2. Normalize LeafCutter ratios](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/splicing_normalization.html)\n", + "\n", + "**What it does:** `leafcutter_norm` filters introns and clusters, mean-imputes retained missing values, and quantile-normalizes the ratio matrix." ] }, { "cell_type": "code", "execution_count": null, - "id": "fc36a8fe-0622-4a5a-93e9-5df6f65aa781", + "id": "dc9ca222", "metadata": { "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/splicing_calling.ipynb leafcutter \\\n", - " --cwd output/leaf_cutter/ \\\n", - " --samples output/rnaseq/xqtl_protocol_data_bam_list \n", - "\n", - "sos run pipeline/splicing_calling.ipynb psichomics \\\n", - " --cwd output/psichomics/ \\\n", - " --samples output/rnaseq/xqtl_protocol_data_bam_list \\\n", - " --splicing_annotation hg38_suppa.rds " + "sos run pipeline/splicing_normalization.ipynb leafcutter_norm --cwd output/splicing/leafcutter --ratios input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz --mean-impute" ] }, { "cell_type": "markdown", - "id": "f4e7c8ad-d196-4546-83bd-d9b4a428eeb7", + "id": "0fe96ad5", "metadata": { "kernel": "SoS" }, "source": [ - "### ii. [Splicing QC and Normalization](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/splicing_normalization.html)" + "### [3. Annotate LeafCutter phenotypes](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", + "\n", + "**What it does:** `annotate_leafcutter_isoforms` maps introns to genes and writes the coordinate-sorted phenotype matrix and phenotype-group file used by TensorQTL." ] }, { "cell_type": "code", "execution_count": null, - "id": "18794388-051e-4dca-912f-646d20c460ef", + "id": "b00284d7", "metadata": { - "kernel": "Bash", - "tags": [] + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/splicing_normalization.ipynb leafcutter_norm \\\n", - " --cwd output/leaf_cutter/ \\\n", - " --ratios output/leaf_cutter/xqtl_protocol_data_bam_list_intron_usage_perind.counts.gz\n", + "sos run pipeline/gene_annotation.ipynb annotate_leafcutter_isoforms --cwd output/splicing/leafcutter --phenoFile input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.txt --intron-count input/rnaseq/protocol_example.leafcutter.intron_count.tsv --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf --map-stra site" + ] + }, + { + "cell_type": "markdown", + "id": "52917182", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### [4. Quantify annotated events with psichomics](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html)\n", "\n", - "sos run pipeline/splicing_normalization.ipynb psichomics_norm \\\n", - " --cwd psichomics_output \\\n", - " --ratios psichomics_output/psi_raw_data.tsv " + "**What it does:** `psichomics` uses aligned reads and a SUPPA event annotation to calculate PSI values for alternative-splicing events." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a1e38a71", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/splicing_calling.ipynb psichomics --cwd output/splicing/psichomics --samples output/rnaseq/protocol_example.rnaseq.bam.list.txt --data-dir output/rnaseq/star_output_wasp --splicing-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds" ] }, { "cell_type": "markdown", - "id": "650ab818-25a1-447c-a7cd-7f422e1f56df", + "id": "c7d91821", "metadata": { "kernel": "SoS" }, "source": [ - "### iii. [Post Processing for TensorQTL](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)" + "### [5. Normalize psichomics PSI values](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/QC/splicing_normalization.html)\n", + "\n", + "**What it does:** `psichomics_norm` filters PSI events for missingness and variability and produces a quantile-normalized event matrix." ] }, { "cell_type": "code", "execution_count": null, - "id": "75febff1-0246-4dde-b6bb-71e35c4ce521", + "id": "97b10908", "metadata": { - "kernel": "Bash", - "tags": [] + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/gene_annotation.ipynb annotate_leafcutter_isoforms \\\n", - " --cwd output/leaf_cutter/ \\\n", - " --intron_count output/leaf_cutter/xqtl_protocol_data_bam_list_intron_usage_perind_numers.counts.gz \\\n", - " --phenoFile output/leaf_cutter/xqtl_protocol_data_bam_list_intron_usage_perind.counts.gz_raw_data.qqnorm.txt \\\n", - " --annotation-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.gtf \\\n", - " --sample_participant_lookup reference_data/sample_participant_lookup.rnaseq\n", + "sos run pipeline/splicing_normalization.ipynb psichomics_norm --cwd output/splicing/psichomics --ratios input/rnaseq/protocol_example.psichomics.psi_raw_data.tsv" + ] + }, + { + "cell_type": "markdown", + "id": "5cd28892", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### [6. Annotate psichomics phenotypes](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/phenotype/gene_annotation.html)\n", "\n", - "sos run pipeline/code/data_preprocessing/phenotype/gene_annotation.ipynb annotate_psichomics_isoforms \\\n", - " --cwd psichomics_output \\\n", - " --phenoFile psichomics_output/psichomics_raw_data_bedded.qqnorm.txt \\\n", - " --annotation-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformated.ERCC.gene.gtf " + "**What it does:** `annotate_psichomics_isoforms` assigns genomic coordinates and phenotype groups to normalized psichomics events for TensorQTL." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2bb3a4ca", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb annotate_psichomics_isoforms --cwd output/splicing/psichomics --phenoFile output/splicing/psichomics/psichomics_raw_data_bedded.qqnorm.txt --coordinate-annotation input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf" ] }, { "cell_type": "markdown", - "id": "d57cb038-e7ef-4203-add0-4017e743d258", + "id": "e39d7d6f", "metadata": { "kernel": "SoS" }, "source": [ - "## Anticipated Results" + "## Output Files\n", + "\n", + "| Route/step | Output filename and relative path | Description |\n", + "| --- | --- | --- |\n", + "| LeafCutter calling | `output/splicing/leafcutter/*_intron_usage_perind.counts.gz`; `*_intron_usage_perind_numers.counts.gz` | Intron excision ratios and supporting intron counts |\n", + "| LeafCutter normalization | `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.txt`; `input/rnaseq/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.txt` | QC-filtered and quantile-normalized ratios |\n", + "| LeafCutter annotation | `output/splicing/leafcutter/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.formated.bed.gz`; `output/splicing/leafcutter/protocol_example.leafcutter.intron_usage_perind.counts.gz_raw_data.qqnorm.phenotype_group.txt` | TensorQTL phenotype and grouping files |\n", + "| psichomics calling | `output/splicing/psichomics/psi_raw_data.tsv` | Raw event-level PSI matrix |\n", + "| psichomics normalization | `output/splicing/psichomics/psichomics_raw_data_bedded.qqnorm.txt` | QC-filtered and normalized PSI matrix |\n", + "| psichomics annotation | `output/splicing/psichomics/psichomics_raw_data_bedded.qqnorm.formated.bed.gz`; `output/splicing/psichomics/psichomics_raw_data_bedded.qqnorm.phenotype_group.txt` | TensorQTL phenotype and grouping files |" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "cf2a3cd1", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Output Files\n\n| File | Description |\n| --- | --- |\n| `output/leaf_cutter/*_intron_usage_perind.counts.gz` | Leafcutter intron-usage ratios |\n| `psichomics_output/psi_raw_data.tsv` | psichomics percent-spliced-in (PSI) values |\n| `output/leaf_cutter/*.qqnorm.txt` | Normalized splicing phenotype, ready for QTL mapping |\n" + "## Anticipated Results\n", + "\n", + "Each selected route ends with a coordinate-sorted, bgzip-compressed phenotype matrix and a matching phenotype-group file. Rows represent introns or annotated splicing events, columns represent samples, and the normalized values can be supplied directly to splicing-QTL association testing." ] }, { "cell_type": "markdown", - "id": "806ee486-73f3-4759-9cbe-0cfb89a00b93", + "id": "d31455da", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d012f799", "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "The final output contains the QCed and normalized splicing data from leafcutter and psichomics." + "sos run pipeline/splicing_calling.ipynb -h" ] }, { "cell_type": "code", "execution_count": null, - "id": "4958da63-d8bd-47bd-9c1d-0aee23d4eba0", + "id": "5449667d", "metadata": { "kernel": "SoS" }, "outputs": [], - "source": [] + "source": [ + "sos run pipeline/splicing_normalization.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8344b91", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/gene_annotation.ipynb -h" + ] } ], "metadata": { @@ -235,4 +315,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/multivariate_genome/MASH.ipynb b/code/SoS/multivariate_genome/MASH.ipynb new file mode 100644 index 000000000..400df16b7 --- /dev/null +++ b/code/SoS/multivariate_genome/MASH.ipynb @@ -0,0 +1,268 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "242c9400", + "metadata": {}, + "source": "# Multivariate adaptive shrinkage (MASH) mini-protocol\nPrepare cross-condition summary statistics, fit a multivariate adaptive-shrinkage model, and estimate condition-specific effects and contrasts." + }, + { + "cell_type": "markdown", + "id": "a0485e0e", + "metadata": {}, + "source": "#### Miniprotocol Timing\nThis is the total duration for the selected route; module-specific timings appear on their respective pages.\nTiming: TBD" + }, + { + "cell_type": "markdown", + "id": "b4a06433", + "metadata": {}, + "source": "## Overview\nThis mini-protocol organizes the MASH workflow into preprocessing, model fitting, and posterior analysis. Steps 1\u20132 call [`mash_preprocessing.ipynb`](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_preprocessing.html), step 3 calls [`mash_fit.ipynb`](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_fit.html), and steps 4\u20135 call [`mash_posterior.ipynb`](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_posterior.html). The covariance prior and residual variance used for fitting can be learned with [`mixture_prior.ipynb`](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mixture_prior.html).\nSteps 1 and 2 are alternative preprocessing routes. Step 3 fits a model from prepared inputs, while steps 4\u20135 apply an existing model and summarize posterior contrasts." + }, + { + "cell_type": "markdown", + "id": "615550c9", + "metadata": {}, + "source": "## Steps\nChoose a route before running commands; the commands are not one mandatory chain.\n| Analysis goal | Commands to run, in order | Inputs |\n|---|---|---|\n| Build MASH-ready data from fine-mapping results and fit a model | 1 \u2192 3 | `input/finemapping/protocol_example.fine_mapping_meta.tsv`; prepared covariance prior and residual-variance RDS files |\n| Build random and null sets from tensorQTL results and fit a model | 2 \u2192 3 | `input/finemapping/protocol_example.region`; `input/protocol_example.sumstats_list.txt`; prepared covariance prior and residual-variance RDS files |\n| Apply an existing MASH model | 4 | `input/finemapping/protocol_example.analysis_units.txt`; `input/mash/protocol_example.mash_model.rds`; `input/twas/protocol_example.posterior_vhat.rds` |\n| Plot posterior contrasts | 4 \u2192 5 | Inputs for step 4 |\n\nThe fitting command uses `input/mash/protocol_example.EE.mash.rds`, `input/mash/protocol_example.EE.V_simple.rds`, and `input/mash/protocol_example.EE.prior.rds`. The prior and residual variance can be learned with the [mixture-prior module](https://statfungen.github.io/xqtl-protocol/mixture_prior.html); its covariance-component and variance-estimation workflows are alternatives and should be selected deliberately rather than run as a single chain." + }, + { + "cell_type": "markdown", + "id": "6cf8a734", + "metadata": {}, + "source": "### 1. [Prepare strong effects from fine-mapping results](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_preprocessing.html)\n\n**What it does:** Converts fine-mapping posterior estimates into the strong-effect data used to learn or fit a MASH model." + }, + { + "cell_type": "markdown", + "id": "4d2b0f58", + "metadata": {}, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d72cc9f0", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_preprocessing.ipynb susie_to_mash \\\n", + " --name protocol_example_mash \\\n", + " --fine_mapping_meta input/finemapping/protocol_example.fine_mapping_meta.tsv \\\n", + " --finemapping_column susie_path \\\n", + " --sig_p_cutoff 0.1 \\\n", + " --cwd output/mash_preprocessing" + ] + }, + { + "cell_type": "markdown", + "id": "57319d6e", + "metadata": {}, + "source": "### 2. [Prepare random and null effects from tensorQTL results](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_preprocessing.html)\n\n**What it does:** Samples random regions and extracts null effects from tensorQTL summary statistics to complement the strong-effect set. Use this route instead of step 1 when tensorQTL summary statistics are the starting point." + }, + { + "cell_type": "markdown", + "id": "8005b971", + "metadata": {}, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "901f923a", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_preprocessing.ipynb random_null_tensorqtl \\\n", + " --name protocol_example_mash \\\n", + " --region_file input/finemapping/protocol_example.region \\\n", + " --sum_files input/protocol_example.sumstats_list.txt \\\n", + " --traits bulk_rnaseq \\\n", + " --cwd output/mash_preprocessing" + ] + }, + { + "cell_type": "markdown", + "id": "cb1835c7", + "metadata": {}, + "source": "### 3. [Fit the MASH model](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_fit.html)\n\n**What it does:** Fits the multivariate adaptive-shrinkage model using prepared effects, a residual-variance estimate, and a covariance prior; `--compute-posterior` also stores posterior summaries for the fitted data." + }, + { + "cell_type": "markdown", + "id": "b9db560c", + "metadata": {}, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "35c38335", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_fit.ipynb mash \\\n", + " --output-prefix protocol_example_mash \\\n", + " --data input/mash/protocol_example.EE.mash.rds \\\n", + " --vhat-data input/mash/protocol_example.EE.V_simple.rds \\\n", + " --prior-data input/mash/protocol_example.EE.prior.rds \\\n", + " --effect-model EE \\\n", + " --compute-posterior \\\n", + " --cwd output/mash_fit" + ] + }, + { + "cell_type": "markdown", + "id": "d90d08a4", + "metadata": {}, + "source": "### 4. [Apply the fitted model](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_posterior.html)\n\n**What it does:** Computes posterior effect estimates for each analysis unit using an existing MASH model. Adjust `--exclude-condition` only when specific conditions must be omitted." + }, + { + "cell_type": "markdown", + "id": "f37089e2", + "metadata": {}, + "source": [ + "**Timing**: ~30 sec (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "54803990", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_posterior.ipynb posterior \\\n", + " --cwd output/mash_posterior \\\n", + " --analysis-units input/finemapping/protocol_example.analysis_units.txt \\\n", + " --mash-model input/mash/protocol_example.mash_model.rds \\\n", + " --posterior-vhat-files input/twas/protocol_example.posterior_vhat.rds \\\n", + " --data-table-name strong \\\n", + " --exclude-condition 1 3" + ] + }, + { + "cell_type": "markdown", + "id": "a47d3670", + "metadata": {}, + "source": "### 5. [Plot posterior contrasts](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_posterior.html)\n\n**What it does:** Summarizes and plots the condition contrasts produced by step 4." + }, + { + "cell_type": "markdown", + "id": "6fe4c4f0", + "metadata": {}, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a886f8d", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_posterior.ipynb posterior_contrast_plot \\\n", + " --cwd output/mash_posterior \\\n", + " --analysis-units input/finemapping/protocol_example.analysis_units.txt" + ] + }, + { + "cell_type": "markdown", + "id": "fe54c4fb", + "metadata": {}, + "source": [ + "## Output Files\n", + "\n", + "| Step | Relative path | Contents |\n", + "|---:|---|---|\n", + "| 1 | `output/mash_preprocessing/protocol_example_mash.*.posterior_list` | Fine-mapping posterior lists prepared for MASH |\n", + "| 2 | `output/mash_preprocessing/protocol_example_mash.*` | Random/null effects and assembled preprocessing products |\n", + "| 3 | `output/mash_fit/protocol_example_mash.EE.mash_model.rds` | Fitted MASH model |\n", + "| 3 | `output/mash_fit/protocol_example_mash.EE.mash_model.posterior.rds` | Posterior summaries when `--compute-posterior` is enabled |\n", + "| 4 | `output/mash_posterior/*.posterior.rds` | Per-analysis-unit posterior estimates |\n", + "| 5 | `output/mash_posterior/*.posterior_sum.csv` | Combined posterior contrast summary |\n", + "| 5 | `output/mash_posterior/*.posterior_sum.png` | Posterior contrast plot |\n", + "\n", + "Exact per-unit stems are derived from the analysis-units file. Review the module output sections before scripting downstream file discovery." + ] + }, + { + "cell_type": "markdown", + "id": "5d812e1e", + "metadata": {}, + "source": [ + "## Anticipated Results\n", + "\n", + "The fitted model captures effect-sharing patterns across conditions while allowing condition-specific effects. Posterior outputs report shrunk effect estimates and uncertainty for each analysis unit; contrast summaries identify effects that differ between selected conditions.\n", + "\n", + "Inspect the learned covariance components, mixture weights, model diagnostics, and posterior contrast distributions before downstream interpretation. Continue to feature-score workflows in the MASH posterior module only when the corresponding contrast, fine-mapping, or summary-statistic inputs are available." + ] + }, + { + "cell_type": "markdown", + "id": "6ce34c31", + "metadata": {}, + "source": "## Command interface" + }, + { + "cell_type": "code", + "execution_count": null, + "id": "75a2c1c6", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_preprocessing.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5f07683d", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_fit.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c961baed", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mash_posterior.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d281d545", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/mixture_prior.ipynb -h" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SoS", + "language": "sos", + "name": "sos" + }, + "language_info": { + "codemirror_mode": "sos", + "file_extension": ".sos", + "mimetype": "text/x-sos", + "name": "sos", + "nbconvert_exporter": "sos_notebook.converter.SoS_Exporter", + "pygments_lexer": "sos" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/multivariate_genome/MASH/mash_fit.ipynb b/code/SoS/multivariate_genome/MASH/mash_fit.ipynb index 4b89c0985..4814c891f 100644 --- a/code/SoS/multivariate_genome/MASH/mash_fit.ipynb +++ b/code/SoS/multivariate_genome/MASH/mash_fit.ipynb @@ -8,14 +8,7 @@ "source": [ "# MASH analysis pipeline with data-driven prior matrices\n", "\n", - "In this notebook, we utilize the MASH prior, referred to as the [mixture_prior](https://github.com/statfungen/xqtl-protocol/blob/6c637645ce16aee2aa7dc86bbc334fb6bb66b9d9/code/multivariate/MASH/mixture_prior.ipynb#L4), from a previous step. Our objective is to conduct a multivariate analysis under the MASH model. After fitting the model, we subsequently compute the posteriors for our variables of interest." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n\nRequires `protocol_example.mash_input.rds` from `mash_preprocessing`. See that notebook to generate this file." + "Fits a MASH model using data-driven prior matrices and computes posterior quantities for the effects of interest." ] }, { @@ -24,7 +17,17 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "Effects estimated separately in each condition are noisy, and analysing them one condition at a time ignores that most effects are shared. MASH fits a mixture of multivariate normal distributions to the effect estimates, learning from the data which patterns of sharing actually occur - which conditions move together, and how strongly - so that individual estimates can later be shrunk towards those patterns rather than towards zero.\n", + "\n", + "This notebook fits the model. The data-driven prior matrices come from `mixture_prior`, and applying the fitted model to compute posterior estimates is `mash_posterior`. By this point the input data have already been converted from the original association summary statistics into the MASH-format object written by `mash_preprocessing`.\n", + "\n", + "The implementation uses [`mashr`](https://github.com/stephenslab/mashr), which improves on the original MASH algorithm in four respects: likelihood and posterior quantities are computed faster through matrix algebra tricks and a C++ implementation; the MASH mixture is fitted faster by convex optimization; the prior can be estimated by approaches other than `SFA` (see `mixture_prior.ipynb`); and the estimate of the residual variance $\\hat{V}$ is improved.\n", + "\n", + "The prior matrices come from [mixture_prior](https://github.com/statfungen/xqtl-protocol/blob/6c637645ce16aee2aa7dc86bbc334fb6bb66b9d9/code/multivariate/MASH/mixture_prior.ipynb#L4), fitted in a previous step. After the model is fitted, posteriors are computed for the effects of interest.\n", + "\n", + "**When to run it.** After `mash_preprocessing` has assembled effect estimates across conditions and written the MASH-format input file, and before `mash_posterior`. See `mash_preprocessing` to generate that file ([Urbut et al., 2019](https://doi.org/10.1038/s41588-018-0268-8))." ] }, { @@ -33,17 +36,92 @@ "kernel": "SoS" }, "source": [ - "### Multivariate adaptive shrinkage (MASH) analysis of eQTL data\n", + "## Input\n", "\n", + "- `--data` **`input/mash/protocol_example.EE.mash.rds`**\n", + "(input summary statistics data (MASH-format RDS) produced by `mash_preprocessing`)\n", "\n", - "Since we published Urbut 2019, we have improved implementation of MASH algorithm and made a new R package, [`mashr`](https://github.com/stephenslab/mashr). Major improvements compared to Urbut 2019 are:\n", + "```\n", + "List of 4\n", + " $ random.b: num [1:2000, 1:34] 1.371 -0.565 0.363 0.633 0.404 -0.106 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:2000] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ random.s: num [1:2000, 1:34] 1.112 1.056 0.924 1.11 0.996 0.939 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:2000] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ strong.b: num [1:300, 1:34] 1.36 -1.895 1.656 -0.752 1.361 0.64 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ strong.s: num [1:300, 1:34] 1.033 0.966 0.988 0.943 1.212 0.96 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + "```\n", "\n", - "1. Faster computation of likelihood and posterior quantities via matrix algebra tricks and a C++ implementation.\n", - "2. Faster computation of MASH mixture via convex optimization.\n", - "3. New ways to estimate prior in place of the `SFA` approach, see `mixture_prior.ipynb` for details.\n", - "4. Improve estimate of residual variance $\\hat{V}$.\n", + "- `--vhat-data` **`input/mash/protocol_example.EE.V_simple.rds`**\n", + "(estimated residual correlation matrix across conditions, written by `mixture_prior`)\n", "\n", - "At this point, the input data have already been converted from the original association summary statistics to a format convenient for analysis in MASH." + "```\n", + " num [1:34, 1:34] 1 0.0625 0.196 0.0857 0.1888 0.0861 ...\n", + " - attr(*, \"dimnames\")=List of 2\n", + " ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + "```\n", + "\n", + "- `--prior-data` **`input/mash/protocol_example.EE.prior.rds`**\n", + "(data-driven prior covariance matrices `U` and their weights `w`, written by `mixture_prior`)\n", + "\n", + "```\n", + "List of 3\n", + " $ U :List of 73\n", + " ..$ XtX : num [1:34, 1:34] 37.12 -4.7 16.75 -4.48 18.2 -4.56 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ tFLASH_default : num [1:34, 1:34] 155.052 -0.388 51.932 0.116 56.377 0.443 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_1 : num [1:34, 1:34] 6.06e-03 -7.47e-06 -8.25e-09 -1.81e-05 3.81e-09 -1.02e-05 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_2 : num [1:34, 1:34] 1.06e-02 1.55e-06 3.09e-06 -2.45e-06 8.96e-06 6.54e-07 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_3 : num [1:34, 1:34] 6.06e-03 1.27e-07 3.20e-07 2.81e-07 6.19e-07 2.56e-07 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_4 : num [1:34, 1:34] 6.06e-03 -8.89e-08 -3.04e-08 -1.83e-06 8.94e-09 -2.07e-08 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_5 : num [1:34, 1:34] 5.35e+01 -6.04e-06 1.47e+01 4.66e-01 2.45e+01 4.01e-02 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_6 : num [1:34, 1:34] 6.06e-03 1.16e-09 -8.59e-09 2.99e-08 -1.61e-09 6.04e-10 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_7 : num [1:34, 1:34] 6.06e-03 -5.71e-08 3.58e-08 -7.38e-08 -2.86e-09 2.76e-07 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_8 : num [1:34, 1:34] 0.929 6.251 0.891 2.854 0.858 3.241 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_9 : num [1:34, 1:34] 6.06e-03 1.70e-12 -1.40e-06 1.51e-07 -7.10e-08 1.64e-12 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_10 : num [1:34, 1:34] 6.06e-03 -1.78e-07 3.25e-08 4.60e-08 6.25e-08 -1.30e-06 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_11 : num [1:34, 1:34] 3.69e-02 6.90e-07 -4.80e-02 -3.70e-03 -9.68e-01 1.12e-02 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_12 : num [1:34, 1:34] 5.20e-02 1.35e-04 5.19e-02 4.91e-05 4.40e-02 5.03e-04 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_13 : num [1:34, 1:34] 0.011419 0.000139 0.003632 -0.00019 0.002041 0.000241 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_14 : num [1:34, 1:34] 0.17808 0.00263 0.24694 1.16463 0.09564 2.65106 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_15 : num [1:34, 1:34] 6.06e-03 -4.74e-12 -6.49e-13 1.96e-11 6.18e-11 -1.54e-11 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_16 : num [1:34, 1:34] 0.0413 0.019 0.0209 0.041 0.0178 0.0191 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ FLASH_default_17 : num [1:34, 1:34] 6.08e-03 -6.91e-07 6.60e-06 -7.47e-06 -3.12e-06 1.32e-06 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + "... (truncated)\n", + "```\n", + "\n", + "- `--cwd output/mash_fit` (working directory all outputs are written under. Defaults to `./mashr_workflow_output`.)\n", + "- `--output-prefix protocol_example` (prefix for the fitted model and posterior filenames)\n", + "- `--effect-model EE` (MASH effect model: `EE` for exchangeable effects, `EZ` for exchangeable z-scores)\n", + "- `--compute-posterior True` (compute posteriors after fitting. Set `False` to fit the model only.)" ] }, { @@ -52,13 +130,74 @@ "kernel": "SoS" }, "source": [ - "## Input\n", + "## Output\n", + "\n", + "- **`output/mash_fit/protocol_example_mash.EE.mash_model.rds`**\n", + "(fitted MASH model: mixture weights and the fitted prior)\n", "\n", - "- `--data`: input summary statistics data (MASH-format RDS) produced by `mash_preprocessing`.\n", - "- `--vhat-data`: estimated residual variance $\\hat{V}$ (RDS).\n", - "- `--prior-data`: the data-driven prior matrices RDS generated by `mixture_prior`.\n", + "```\n", + "List of 3\n", + " $ mash_model:List of 9\n", + " ..$ result :List of 5\n", + " .. ..$ PosteriorMean: num [1:2000, 1:34] 0.07633 -0.06986 0.06814 0.04333 0.15277 0.00605 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ PosteriorSD : num [1:2000, 1:34] 0.28 0.437 0.304 0.299 0.42 0.329 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ NegativeProb : num [1:2000, 1:34] 0.415 0.555 0.42 0.412 0.359 0.467 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ lfsr : num [1:2000, 1:34] 0.44 0.445 0.447 0.503 0.374 0.52 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ PosteriorCov : num [1:34, 1:34, 1:2000] 0.078574 0.00178 -0.001302 0.000344 -0.000536 0.010921 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 3\n", + " ..$ loglik : num -98517\n", + " ..$ vloglik : num [1:2000, 1] -48.2 -51.6 -49.4 -44.5 -53.6 -46.2 ...\n", + " ..$ null_loglik : num [1:2000] -49 -53.1 -50 -44 -54.8 -46.1 ...\n", + " ..$ alt_loglik : num [1:2000, 1] -48.2 -51.6 -49.3 -44.6 -53.5 -46.2 ...\n", + " ..$ fitted_g :List of 4\n", + " .. ..$ pi : Named num [1:1169] 0.0508 0 0 0 0 0 ...\n", + " .. .. ..- attr(*, \"names\")= chr [1:1169] \"null\" \"XtX.1\" \"tFLASH_default.1\" \"FLASH_default_1.1\" \"FLASH_default_2.1\" ...\n", + " .. ..$ Ulist :List of 73\n", + " .. ..$ grid : num [1:16] 0.0468 0.0663 0.0937 0.1325 0.1874 0.265 ...\n", + " .. ..$ usepointmass: logi TRUE\n", + " ..$ posterior_weights: num [1:2000, 1:18] 0.025 0.0113 0.0268 0.0908 0.015 0.0531 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..- attr(*, \"names\")= chr [1:36000] \"1\" \"604\" \"650\" \"700\" \"723\" ...\n", + " ..$ alpha : num 0\n", + " ..$ lm :List of 2\n", + " .. ..$ loglik_matrix: num [1:2000, 1:1169] -3.282 -2.661 -6.069 -0.829 -3.036 -1.837 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ lfactors : num [1:2000] -45.7 -50.5 -43.9 -43.1 -51.8 -44.3 ...\n", + " ..- attr(*, \"class\")= chr \"mash\"\n", + " $ vhat_file : chr /xqtl/jaempawi/xqtl-protocol-new/input/mash/protocol_example.EE.V_simple.rds\"\n", + " $ prior_file: chr /xqtl/jaempawi/xqtl-protocol-new/input/mash/protocol_example.EE.prior.rds\"\n", + "```\n", "\n", - "MWE data are available on [synapse.org](https://www.synapse.org/#!Synapse:syn69670658)." + "- **`output/mash_fit/protocol_example_mash.EE.posterior.rds`**\n", + "(optional; posterior quantities such as `lfsr` for the \"strong\" set of gene-SNP pairs)\n", + "\n", + "```\n", + "List of 5\n", + " $ PosteriorMean: num [1:300, 1:34] 0.137 -0.311 0.317 -0.166 0.189 0.117 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ PosteriorSD : num [1:300, 1:34] 0.344 0.45 0.432 0.47 0.418 0.399 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ lfdr : num [1:300, 1:34] 0.07816 0.00282 0.03005 0.0025 0.05141 0.03539 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ NegativeProb : num [1:300, 1:34] 0.337 0.744 0.226 0.636 0.313 0.378 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " $ lfsr : num [1:300, 1:34] 0.415 0.256 0.257 0.364 0.364 0.413 ...\n", + " ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ : chr [1:300] \"snp1\" \"snp2\" \"snp3\" \"snp4\" \"snp5\" ...\n", + " .. ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + "```" ] }, { @@ -66,20 +205,22 @@ "metadata": { "kernel": "SoS" }, - "source": "## Output\n\n- A fitted MASH model file `*.mash_model.rds` containing the mixture weights.\n- (Optional) a posterior file `*.posterior.rds` with posterior quantities (e.g. `lfsr`) for the \"strong\" set of gene-SNP pairs.\n" + "source": [ + "## Minimal Working Example\n", + "\n", + "Using the MASH prior [previously generated](https://github.com/statfungen/xqtl-protocol/blob/main/code/multivariate_genome/MASH/mixture_prior.ipynb), fit the MASH model and compute posteriors.\n", + "\n", + "This example fits the MASH mixture model and computes posteriors for the strong set." + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "## Steps\n\nUsing the MASH prior [previously generated](https://github.com/statfungen/xqtl-protocol/blob/main/code/multivariate_genome/MASH/mixture_prior.ipynb), fit the MASH model and compute posteriors.\n\n**Step 1.** Fit the MASH mixture model and compute posteriors for the strong set:" - }, - { - "cell_type": "markdown", - "metadata": {}, "source": [ - "**Timing** (toy chr22 dataset):\n- `mash_fit`: ~1-2 min\n" + "**Timing**: ~1-2 min (on toy dataset)\n", + "" ] }, { @@ -106,20 +247,78 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/mash_fit.ipynb -h" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/mash_fit.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " mash\n", + "\n", + "Global Workflow Options:\n", + " --cwd mashr_workflow_output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " --data VAL (as path, required)\n", + " Input summary statistics data\n", + " --prior-data VAL (as path, required)\n", + " --vhat-data VAL (as path, required)\n", + " --output-prefix ''\n", + " Prefix of output files. If not specified, it will derive\n", + " it from data. If it is specified, for example,\n", + " `--output-prefix AnalysisResults` It will save output\n", + " files as `{cwd}/AnalysisResults*`.\n", + " --output-suffix all\n", + " --effect-model EE\n", + " Exchangable effect (EE) or exchangable z-scores (EZ)\n", + " --container ''\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " mash_1: Fit MASH mixture model (learns the mixture weights on\n", + " the random subset)\n", + " Workflow Options:\n", + " --output-level 4 (as int)\n", + " mash_2: Compute posterior for the \"strong\" set of data as in\n", + " Urbut et al 2017. This is optional because most of the\n", + " time we want to apply the MASH model learned on much\n", + " larger data-set.\n", + " Workflow Options:\n", + " --[no-]compute-posterior (default to True)\n", + " default to True; use --no-compute-posterior to disable\n", + " this\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { @@ -178,9 +377,9 @@ "kernel": "SoS" }, "source": [ - "## `mashr` mixture model fitting\n", + "### `mashr` mixture model fitting\n", "\n", - "Main reference are our `mashr` vignettes [this for mashr eQTL outline](https://stephenslab.github.io/mashr/articles/eQTL_outline.html) and [this for using FLASH prior](https://github.com/stephenslab/mashr/blob/master/vignettes/flash_mash.Rmd). \n", + "The main references are the `mashr` vignettes [this for mashr eQTL outline](https://stephenslab.github.io/mashr/articles/eQTL_outline.html) and [this for using FLASH prior](https://github.com/stephenslab/mashr/blob/master/vignettes/flash_mash.Rmd). \n", "\n", "The outcome of this workflow should be found under `./mashr_workflow_output` folder (can be configured). File names have pattern `*.mash_model_*.rds`. They can be used to computer posterior for input list of gene-SNP pairs (see next section)." ] @@ -216,18 +415,11 @@ "kernel": "SoS" }, "source": [ - "## Optional posterior computations\n", + "### Optional posterior computations\n", "\n", "Additionally provide posterior for the \"strong\" set in MASH input data." ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nProduces `protocol_example.mash_model.rds` with fitted MASH covariance matrices across 16 conditions. Expect ~10 canonical + data-driven covariance components." - ] - }, { "cell_type": "code", "execution_count": null, @@ -307,4 +499,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/multivariate_genome/MASH/mash_posterior.ipynb b/code/SoS/multivariate_genome/MASH/mash_posterior.ipynb index d09f8c540..0cb619472 100644 --- a/code/SoS/multivariate_genome/MASH/mash_posterior.ipynb +++ b/code/SoS/multivariate_genome/MASH/mash_posterior.ipynb @@ -5,13 +5,10 @@ "metadata": { "kernel": "SoS" }, - "source": "# MASH analysis pipeline with posterior computation\n\nThis notebook applies a fitted MASH model (from `mash_fit`) to compute posterior quantities (posterior mean, sd, lfsr, etc.) for a list of gene-SNP effect-size chunks, and derives downstream contrast and feature-score summaries. It is designed to run posterior computation in parallel over many input chunks." - }, - { - "cell_type": "markdown", - "metadata": {}, "source": [ - "## Prerequisites\n\nRequires the MASH model from `mash_fit` (`protocol_example.mash_model.rds`)." + "# MASH analysis pipeline with posterior computation\n", + "\n", + "Applies a fitted MASH model to compute posterior quantities for gene-SNP effect-size chunks and derives contrast and feature-score summaries." ] }, { @@ -19,49 +16,205 @@ "metadata": { "kernel": "SoS" }, - "source": "## Description\n\nFor each input chunk (a list of matrices `bhat`/`sbhat`/`Z`), the `posterior` workflow loads the MASH model and calls `mash_compute_posterior_matrices`. Additional workflows compute posterior contrasts between conditions and feature-level scores (meta, fine-mapped, n-significant, and p-value pairs) from the contrast results." + "source": [ + "## Overview\n", + "\n", + "For each input chunk (a list of matrices `bhat`/`sbhat`/`Z`), the `posterior` workflow loads the MASH model and calls `mash_compute_posterior_matrices`. Additional workflows compute posterior contrasts between conditions and feature-level scores (meta, fine-mapped, n-significant, and p-value pairs) from the contrast results.\n", + "\n", + "Fitting the mixture model and applying it are separate jobs. `mash_fit` learns which\n", + "patterns of sharing exist across conditions; this notebook applies that fitted model to\n", + "each chunk of effects, shrinking noisy estimates towards the patterns the data support.\n", + "Effects that look condition-specific because of noise get pulled towards the shared\n", + "pattern, and genuinely specific ones do not.\n", + "\n", + "It is designed to run posterior computation in parallel over many input chunks.\n", + "\n", + "**When to run it.** After `mash_fit`, on the same effect estimates. Posterior quantities -\n", + "not the raw per-condition estimates - are what downstream comparisons should use.\n", + "\n", + "Requires the MASH model from `mash_fit` (`protocol_example.mash_model.rds`)." + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "## Input\n\nThis notebook has two workflow targets that are run in sequence.\n\n`posterior` (computes per-region posterior mean/covariance):\n- `--mash-model`: a fitted MASH model RDS (the bare `mash` object), e.g. produced by `mash_fit`.\n- `--analysis-units`: a text file whose first column lists paths to posterior-input RDS chunks (one region per line).\n- `--posterior-vhat-files`: matching residual-variance (vhat) matrix RDS file(s).\n- Produces a manifest file (`mash_output_list_all`, tab-separated `id path` pairs) pointing to the per-region posterior RDS outputs.\n\n`mash_posterior_contrast` (computes contrasts from the posterior output):\n- `--posterior-file`: a tab-separated manifest (`id path`) where each path is a per-region posterior RDS produced by the `posterior` step above.\n- `--sum-file`: a tab-separated manifest (`id path`) where each path is the corresponding raw summary-statistics RDS for that region, containing top-level `bhat`/`sbhat` matrices (the same data used to compute the posterior). The `id` values must match between `--posterior-file` and `--sum-file`." + "source": [ + "## Input\n", + "**`posterior`** - computes per-region posterior mean/covariance:\n", + "\n", + "- `--mash-model` **`input/mash/protocol_example.mash_model.rds`**\n", + "(a fitted MASH model RDS, the bare `mash` object, e.g. produced by `mash_fit`)\n", + "\n", + "```\n", + "List of 9\n", + " $ result :List of 5\n", + " ..$ PosteriorMean: num [1:2000, 1:34] 0.07633 -0.06986 0.06814 0.04333 0.15277 0.00605 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ PosteriorSD : num [1:2000, 1:34] 0.28 0.437 0.304 0.299 0.42 0.329 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ NegativeProb : num [1:2000, 1:34] 0.415 0.555 0.42 0.412 0.359 0.467 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ lfsr : num [1:2000, 1:34] 0.44 0.445 0.447 0.503 0.374 0.52 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 2\n", + " ..$ PosteriorCov : num [1:34, 1:34, 1:2000] 0.078574 0.00178 -0.001302 0.000344 -0.000536 0.010921 ...\n", + " .. ..- attr(*, \"dimnames\")=List of 3\n", + " $ loglik : num -98517\n", + " $ vloglik : num [1:2000, 1] -48.2 -51.6 -49.4 -44.5 -53.6 -46.2 ...\n", + " $ null_loglik : num [1:2000] -49 -53.1 -50 -44 -54.8 -46.1 ...\n", + " $ alt_loglik : num [1:2000, 1] -48.2 -51.6 -49.3 -44.6 -53.5 -46.2 ...\n", + " $ fitted_g :List of 4\n", + " ..$ pi : Named num [1:1169] 0.0508 0 0 0 0 0 ...\n", + " .. ..- attr(*, \"names\")= chr [1:1169] \"null\" \"XtX.1\" \"tFLASH_default.1\" \"FLASH_default_1.1\" \"FLASH_default_2.1\" ...\n", + " ..$ Ulist :List of 73\n", + " .. ..$ XtX : num [1:34, 1:34] 0.1763 -0.0223 0.0796 -0.0213 0.0865 -0.0216 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ tFLASH_default : num [1:34, 1:34] 1 -0.0025 0.33493 0.00075 0.3636 0.00286 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_1 : num [1:34, 1:34] 9.99e-05 -1.23e-07 -1.36e-10 -2.99e-07 6.28e-11 -1.68e-07 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_2 : num [1:34, 1:34] 1.49e-04 2.17e-08 4.35e-08 -3.44e-08 1.26e-07 9.20e-09 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_3 : num [1:34, 1:34] 6.12e-05 1.28e-09 3.24e-09 2.84e-09 6.26e-09 2.59e-09 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_4 : num [1:34, 1:34] 4.96e-05 -7.28e-10 -2.49e-10 -1.50e-08 7.31e-11 -1.70e-10 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_5 : num [1:34, 1:34] 1.00 -1.13e-07 2.75e-01 8.71e-03 4.58e-01 7.49e-04 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_6 : num [1:34, 1:34] 9.52e-05 1.82e-11 -1.35e-10 4.70e-10 -2.54e-11 9.50e-12 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_7 : num [1:34, 1:34] 4.68e-05 -4.41e-10 2.77e-10 -5.70e-10 -2.21e-11 2.13e-09 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_8 : num [1:34, 1:34] 0.022 0.1477 0.0211 0.0674 0.0203 0.0766 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_9 : num [1:34, 1:34] 1.86e-04 5.22e-14 -4.29e-08 4.64e-09 -2.18e-09 5.02e-14 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_10 : num [1:34, 1:34] 2.76e-05 -8.13e-10 1.48e-10 2.10e-10 2.85e-10 -5.92e-09 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_11 : num [1:34, 1:34] 1.21e-03 2.27e-08 -1.58e-03 -1.22e-04 -3.18e-02 3.68e-04 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_12 : num [1:34, 1:34] 1.49e-03 3.86e-06 1.48e-03 1.40e-06 1.26e-03 1.44e-05 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_13 : num [1:34, 1:34] 6.92e-04 8.42e-06 2.20e-04 -1.15e-05 1.24e-04 1.46e-05 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_14 : num [1:34, 1:34] 4.36e-03 6.44e-05 6.04e-03 2.85e-02 2.34e-03 6.49e-02 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_15 : num [1:34, 1:34] 2.73e-01 -2.14e-10 -2.92e-11 8.84e-10 2.79e-09 -6.92e-10 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_16 : num [1:34, 1:34] 0.000401 0.000185 0.000203 0.000398 0.000173 0.000186 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_17 : num [1:34, 1:34] 1.01e-03 -1.15e-07 1.09e-06 -1.24e-06 -5.17e-07 2.19e-07 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + " .. ..$ FLASH_default_18 : num [1:34, 1:34] 6.41e-05 -1.99e-10 4.53e-08 3.19e-06 1.39e-09 4.34e-10 ...\n", + " .. .. ..- attr(*, \"dimnames\")=List of 2\n", + "... (truncated)\n", + "```\n", + "\n", + "- `--analysis-units` **`input/finemapping/protocol_example.analysis_units.txt`**\n", + "(a text file whose first column lists paths to posterior-input RDS chunks, one region per line)\n", + "\n", + "```\n", + "\n", + "The per-chunk files this manifest points at are prepared beforehand, one set per batch:\n", + "\n", + "- `*.batch_*.yaml` - the gene-SNP pairs of interest for that batch, identified elsewhere (for example by fine-mapping analysis).\n", + "- `*.batch_*.rds` - the univariate summary statistics for those gene-SNPs, extracted from the YAML; this is what `posterior` consumes.\n", + "- `*.batch_*.stdout` - records SNPs present in the fine-mapping results but absent from the original `fastqtl` output.\n", + "/protocol_example.posterior_input.rds region1\n", + "```\n", + "\n", + "- `--posterior-vhat-files` **`input/twas/protocol_example.posterior_vhat.rds`**\n", + "(matching residual-variance (vhat) matrix RDS file(s))\n", + "\n", + "```\n", + " num [1:34, 1:34] 1 0 0 0 0 0 0 0 0 0 0 0 ...\n", + " - attr(*, \"dimnames\")=List of 2\n", + " ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + " ..$ : chr [1:34] \"ROSMAP_AC_sQTL_PR\" \"ROSMAP_AC_sQTL_UP\" \"ROSMAP_DLPFC_sQTL_PR\" \"ROSMAP_DLPFC_sQTL_UP\" \"ROSMAP_PCC_sQTL_PR\" ...\n", + "```\n", + "\n", + "Produces a manifest file (`mash_output_list_all`, tab-separated `id path` pairs) pointing to the per-region posterior RDS outputs.\n", + "\n", + "**`mash_posterior_contrast`** - computes contrasts from the posterior output:\n", + "\n", + "- `--posterior-file`: a tab-separated manifest (`id path`) where each path is a per-region posterior RDS produced by the `posterior` step above.\n", + "- `--sum-file`: a tab-separated manifest (`id path`) where each path is the corresponding raw summary-statistics RDS for that region, containing top-level `bhat`/`sbhat` matrices (the same data used to compute the posterior). The `id` values must match between `--posterior-file` and `--sum-file`.\n", + "\n", + "- `--cwd output/mash_posterior` (working directory all outputs are written under. Defaults to `./output`.)\n", + "- `--data-table-name bhat` (name of the effect-size table to read from each input chunk)\n", + "- `--exclude-condition` (conditions to drop before computing posteriors; empty by default)" + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "## Output\n\n- Per-chunk posterior RDS files (`*.posterior.rds`) containing `PosteriorMean`, `PosteriorSD`, `lfsr`, `lfdr`, `NegativeProb`, `PosteriorCov` (effects x conditions).\n- A manifest list (`mash_output_list_all`) of the per-chunk posterior files.\n- Contrast and feature-score summary tables from the downstream workflows." + "source": [ + "## Output\n", + "**`posterior_1`**\n", + "- **`cache/{name}.{chunk}.posterior.rds`** - one serialized posterior object per input chunk, loadable with `readRDS()`. The input is split into chunks so the work can be spread across cluster nodes. Each object holds `PosteriorMean`, `PosteriorSD`, `NegativeProb`, `lfsr` and `PosteriorCov` (effects x conditions).\n", + "\n", + "```\n", + "List of 5\n", + "$ PosteriorMean: matrix [300, 34] 0.137296644006322 -0.311361510169076 0.317082792980895 -0.166211879988538 0.18908057204664 ...\n", + "$ PosteriorSD: matrix [300, 34] 0.344426275519538 0.449586894071048 0.431655774119752 0.469980878283076 0.417647229394468 ...\n", + "$ lfdr: matrix [300, 34] 0.0781635470570518 0.00282142909610905 0.0300484413895379 0.00250476599353006 0.0514063370711267 ...\n", + "$ NegativeProb: matrix [300, 34] 0.337086778060348 0.743597948338302 0.226498052642181 0.635857857046459 0.31287430116626 ...\n", + "$ lfsr: matrix [300, 34] 0.4152503251174 0.256402051661698 0.256546494031719 0.364142142953541 0.364280638237386 ...\n", + "```\n", + "\n", + "**`posterior_2`**\n", + "- `{name}.{output_suffix}.posterior_list` - a manifest of the per-chunk posterior files; the suffix comes from `--output-suffix`.\n", + "\n", + "**`mash_posterior_contrast_1`**\n", + "- **`contrast/{name}.{chunk}.posterior_contrast.rds`** - per-chunk posterior contrasts between conditions.\n", + "\n", + "**`mash_posterior_contrast_2`**\n", + "- **`{name}.posterior_sum.csv`** - the contrast summary table.\n", + "\n", + "**`posterior_cntrast_plot`**\n", + "- **`{name}.posterior_sum.png`** - the contrast plot.\n", + " \n", + "**`feature_score_meta`, `feature_score_finemap`, `feature_score_nsig` and `feature_pval_pair`**\n", + "- **`/cache/{name}.featurescore{N}.rds`** - per-chunck score\n", + "- **`{name}.{step_name}.feature_score_sum.csv`** - a summary table " + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "## Steps\n\nThe `posterior` workflow is the entry point; the remaining workflows derive contrasts and feature scores from its outputs. Toy inputs use the `protocol_example.*` prefix." + "source": [ + "## Minimal Working Example" + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": "**Step 1.** Compute MASH posteriors for each input chunk listed in the analysis-units file:" + "source": [ + "### Step 1. Compute MASH posteriors for each input chunk listed in the analysis-units file" + ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Timing** (toy chr22 dataset):\n- `mash_posterior`: ~30 sec\n" + "**Timing**: ~30 sec (on toy dataset)" ] }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb posterior \\\n", @@ -78,31 +231,18 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 2.** Compute posterior contrasts between conditions for the sliced data:" + "source": [ + "### Step 2. Compute posterior contrasts between conditions for the sliced data" + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ - "# Step 1: compute per-region posterior mean/covariance\n", - "sos run pipeline/mash_posterior.ipynb posterior \\\n", - " --cwd output/mash_posterior \\\n", - " --analysis-units input/finemapping/protocol_example.analysis_units.txt \\\n", - " --mash-model input/mash/protocol_example.mash_model.rds \\\n", - " --posterior-vhat-files input/twas/protocol_example.posterior_vhat.rds \\\n", - " --data-table-name strong --exclude-condition 1 3\n", - "\n", - "# Step 2: --posterior-file and --sum-file are tab-separated \"id path\" manifests\n", - "# whose ids must match. --sum-file must point to the RAW summary-stats RDS for\n", - "# each region with top-level bhat/sbhat (i.e. NOT nested under --data-table-name).\n", - "# For production multi-region runs, --posterior-file is typically\n", - "# output/mash_posterior/mash_output_list_all (auto-generated above). For this\n", - "# single-region toy example we derive --sum-file from the same posterior-input\n", - "# file used above, and build both manifests explicitly:\n", "Rscript -e 'p <- strsplit(readLines(\"input/finemapping/protocol_example.analysis_units.txt\")[1], \"\\\\s+\")[[1]][1]; saveRDS(readRDS(p)$strong, \"output/mash_posterior/protocol_example.region1_sumstats.rds\")'\n", "printf 'region1\\t%s\\n' \"$PWD/output/mash_posterior/cache/protocol_example.posterior_input.posterior.rds\" > output/mash_posterior/posterior_manifest.txt\n", "printf 'region1\\t%s\\n' \"$PWD/output/mash_posterior/protocol_example.region1_sumstats.rds\" > output/mash_posterior/sum_manifest.txt\n", @@ -118,17 +258,29 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 3.** Plot the posterior contrast results:" + "source": [ + "### Step 3. Plot the posterior contrast results" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "381ff5e1" }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ - "sos run pipeline/mash_posterior.ipynb posterior_cntrast_plot \\\n", + "sos run pipeline/mash_posterior.ipynb posterior_contrast_plot \\\n", " --cwd output/mash_posterior \\\n", " --analysis-units input/finemapping/protocol_example.analysis_units.txt" ] @@ -138,14 +290,26 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 4.** Compute meta feature scores from the contrast results:" + "source": [ + "### Step 4. Compute meta feature scores from the contrast results" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "7e8c0637" }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb feature_score_meta \\\n", @@ -160,14 +324,26 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 5.** Compute feature scores from contrast results using fine-mapped eQTL/pQTL:" + "source": [ + "### Step 5. Compute feature scores from contrast results using fine-mapped eQTL/pQTL" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "2573b8e6" }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb feature_score_finemap \\\n", @@ -182,14 +358,26 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 6.** Compute n-significant feature scores from contrast results:" + "source": [ + "### Step 6. Compute n-significant feature scores from contrast results" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "2fd7579b" }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb feature_score_nsig \\\n", @@ -204,14 +392,26 @@ "metadata": { "kernel": "SoS" }, - "source": "**Step 7.** Compute p-value-pair feature scores from contrast results:" + "source": [ + "### Step 7. Compute p-value-pair feature scores from contrast results" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ], + "id": "27251ba3" }, { "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "Bash" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb feature_pval_pair \\\n", @@ -226,14 +426,16 @@ "metadata": { "kernel": "SoS" }, - "source": "## Command interface" + "source": [ + "## Command Interface" + ] }, { "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "execution_count": null, "outputs": [], "source": [ "sos run pipeline/mash_posterior.ipynb -h" @@ -244,7 +446,130 @@ "metadata": { "kernel": "SoS" }, - "source": "## Workflow implementation" + "source": [ + "```\n", + "usage: sos run pipeline/mash_posterior.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " posterior\n", + " mash_posterior_contrast\n", + " posterior_cntrast_plot\n", + " feature_score_meta\n", + " feature_score_finemap\n", + " feature_score_nsig\n", + " feature_pval_pair\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " --name test\n", + " --cells (as list)\n", + " Conditions (contexts); order matters\n", + " --group1 (as list)\n", + " Condition groups: replicate populations of one cell type\n", + " share contrast weight\n", + " --group2 (as list)\n", + " --group3 (as list)\n", + " --job-size 1 (as int)\n", + " --container ''\n", + " --per-chunk 1 (as int)\n", + " Number of analysis units per job\n", + " --output-prefix ''\n", + " --output-suffix all\n", + " --effect-model EE\n", + " Exchangable effect (EE) or exchangable z-scores (EZ)\n", + " --vhat simple\n", + " Vhat estimate identifier (e.g. simple / identity / mle)\n", + " --data fastqtl_to_mash_output/FastQTLSumStats.mash.rds (as path)\n", + " --p-cut 1e-05 (as float)\n", + " Significance cutoff for the contrast summary / n-sig\n", + " feature score\n", + " --walltime 1h\n", + " --mem 16G\n", + " --numThreads 1 (as int)\n", + "\n", + "Sections\n", + " posterior_1: Compute MASH posteriors per analysis unit (one posterior\n", + " RDS per region)\n", + " Workflow Options:\n", + " --analysis-units VAL (as path, required)\n", + " File listing per-region data RDS paths (col 1); each\n", + " carries bhat/sbhat matrices\n", + " --bhat-table-name bhat\n", + " Effect-size / standard-error list elements inside each\n", + " region RDS\n", + " --shat-table-name sbhat\n", + " --exclude-condition (as list)\n", + " Conditions (columns) to exclude; names or 1-based\n", + " indices\n", + " posterior_2: Collect the per-region posterior paths into a single\n", + " list\n", + " mash_posterior_contrast_1: Per-region posterior contrasts (deviation +\n", + " pairwise) via mashPosteriorContrast\n", + " Workflow Options:\n", + " --analysis-units VAL (as path, required)\n", + " File listing per-region data RDS paths (same units as\n", + " posterior_1)\n", + " --orig-key bhat\n", + " Effect-size list element inside each region RDS (aligned\n", + " to the posterior)\n", + " --grouping-recipe ''\n", + " Optional file of comma-separated condition groups (one\n", + " per line)\n", + " mash_posterior_contrast_2: Summarize contrast significance across regions ->\n", + " CSV\n", + " mash_posterior_contrast_3, posterior_cntrast_plot: Plot the contrast\n", + " significance summary as a symmetric heatmap\n", + " feature_score_meta_1: Feature score (meta) from per-region contrast results\n", + " Workflow Options:\n", + " --contrast-units VAL (as path, required)\n", + " File listing per-region posterior-contrast RDS paths\n", + " --meta-method REML\n", + " Random-effects estimator (metafor via pecotmr)\n", + " feature_score_finemap_1: Feature score (finemap) using credible sets from\n", + " fine-mapping\n", + " Workflow Options:\n", + " --contrast-units VAL (as path, required)\n", + " --fine-mapping VAL (as path, required)\n", + " Fine-mapping table RDS with cs_order / pip / variants\n", + " columns\n", + " --conditions ''\n", + " Conditions to score (default: all contexts present in\n", + " the contrast)\n", + " feature_score_finemap_2: Merge per-chunk finemap feature scores into one table\n", + " feature_score_nsig_1: Feature score (nsig) from per-region contrast results\n", + " Workflow Options:\n", + " --contrast-units VAL (as path, required)\n", + " File listing per-region posterior-contrast RDS paths\n", + " --p-cutoff 1e-05 (as float)\n", + " Significance cutoff for the n-significant ratio\n", + " feature_pval_pair_1: Feature score (pval_pair) from per-region contrast\n", + " results\n", + " Workflow Options:\n", + " --contrast-units VAL (as path, required)\n", + " File listing per-region posterior-contrast RDS paths\n", + " --meta-method REML\n", + " --se-cutoff 0.001 (as float)\n", + " SE floor for the pairwise meta-analysis\n", + " feature_pval_pair_2, feature_score_meta_2, feature_score_nsig_2: Merge per-\n", + " chunk feature scores into one table (meta / nsig /\n", + " pval_pair)\n", + "```" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Workflow implementation" + ] }, { "cell_type": "code", @@ -288,15 +613,6 @@ "mash_model = file_target(f\"{cwd:a}/{output_prefix}.{effect_model}.V_{vhat}.mash_model.rds\")" ] }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "### Posterior results" - ] - }, { "cell_type": "markdown", "metadata": { @@ -304,9 +620,9 @@ "tags": [] }, "source": [ - "## Posterior \n", + "### posterior \n", "take all the 13K genes,\n", - "if `slice_method = True` for those with missing conditions we just drop those corresponding rows and cols in the prior model" + "with `slice_method = True`, conditions missing from a unit have their rows and columns dropped from the prior model" ] }, { @@ -365,7 +681,7 @@ "tags": [] }, "source": [ - "## Posterior contrast\n", + "### mash_posterior_contrast\n", "- Add group in this module\n", " \n", " e.g. add MiGA-Microglia-scRNA data to this analysis to supplement the Mic cell count shortage, but the MiGA data comes from four sites with four datasets, and here I handled it in such a way that the different Mic's were always in the same state during the deviation contrast analysis. If Mic is the one be compared, each Mic sample would be set as (n_populations - 1)/n_Mic instead of n_populations" @@ -487,7 +803,7 @@ }, "source": [ "### feature_score_finemap\n", - "feature score with fine mapped QTL (the top 1 in each CS)\n", + "Feature score with fine mapped QTL (the top 1 in each CS)\n", "\n", "Fine-mapped approach(more recommend by Dan). pick the top SNP in each CS from each cell type fine mapped results. Then pick the most significant one from contrast result. Get the z-score from that snp, which should be the score of that cell type." ] @@ -581,19 +897,7 @@ }, "source": [ "### feature_pval_pair\n", - "find the specific different cell type pair\n", - "\n", - "perform meta analysis with pairwise contrasts to get a pvalue to find to understand what the specific differences are.\n", - "\n", - "metaanalysis return a warning as \"Warning message: “Ratio of largest to smallest sampling variance extremely large. May not be able to obtain stable results.”\"\n", - "Which is due to the big difference between max(pairwise_standard_errors^2) and min(pairwise_standard_errors^2) So I have delete the snps with small pairwise_standard_errors as Xuewei suggested" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nProduces `protocol_example.mash_posterior.rds` with posterior effect size estimates across conditions. Expect condition-specific enrichment patterns in the Mic/Ast De_Jager cell types for the toy region." + "Find the specific different cell type pair then perform meta analysis with pairwise contrasts to get a pvalue to find to understand what the specific differences are." ] }, { @@ -684,4 +988,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/multivariate_genome/MASH/mash_preprocessing.ipynb b/code/SoS/multivariate_genome/MASH/mash_preprocessing.ipynb index 82103f5bc..a57ef61b9 100644 --- a/code/SoS/multivariate_genome/MASH/mash_preprocessing.ipynb +++ b/code/SoS/multivariate_genome/MASH/mash_preprocessing.ipynb @@ -8,14 +8,7 @@ "source": [ "# Extract genome-wide data for multivariate analysis\n", "\n", - "This notebook prepares input data for Ultimate Deconvolution (to generate the mixture prior for mvSuSiE) or for MASH analysis. It extracts three sets of effects from genome-wide cis fine-mapping results: strong (`Z_s`), null (`Z_n`), and random (`Z_r`)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Prerequisites\n\nRequires genome-wide SuSiE fine-mapping outputs. See the **Important Note** below for toy-data limitations." + "Extracts strong, random and null sets of effects from genome-wide summary statistics and writes them as a single MASH-format input." ] }, { @@ -24,15 +17,19 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", "The workflow produces three z-score matrices used to fit a multivariate prior:\n", "\n", - "- **Strong effects (`Z_s`)** — extracted from genome-wide cis fine-mapping results. The top locus per condition is taken (credible-set coverage threshold 0.7) and the z-scores are merged into one data frame.\n", - "- **Null effects (`Z_n`)** — up to `M` candidate SNPs per region satisfying |z| ≤ 2 are overlapped with the independent-SNP list to keep only independent variants; the union is taken.\n", - "- **Random effects (`Z_r`)** — variants randomly sampled from the supplied independent-variant list.\n", + "- **Strong effects (`Z_s`)** \u2014 extracted from genome-wide cis fine-mapping results. The top locus per condition is taken (credible-set coverage threshold 0.7) and the z-scores are merged into one data frame.\n", + "- **Null effects (`Z_n`)** \u2014 up to `M` candidate SNPs per region satisfying |z| \u2264 2 are overlapped with the independent-SNP list to keep only independent variants; the union is taken.\n", + "- **Random effects (`Z_r`)** \u2014 variants randomly sampled from the supplied independent-variant list.\n", "\n", - "These matrices feed Ultimate Deconvolution / MASH to learn patterns of effect sharing across conditions (e.g. cell types or tissues)." + "These matrices feed Ultimate Deconvolution / MASH to learn patterns of effect sharing across conditions (e.g. cell types or tissues).\n", + "\n", + "Requires genome-wide SuSiE fine-mapping outputs. See the **Important Note** below for toy-data limitations.\n", + "\n", + "**When to run it.** After per-region fine-mapping or tensorQTL association scans have produced results across conditions, and before `mash_fit`." ] }, { @@ -43,10 +40,44 @@ "source": [ "## Input\n", "\n", - "1. **Marginal summary statistics files** — bgzipped summary statistics for chromosomes 1–22, generated by tensorQTL cis-analysis and indexed by `tabix`.\n", - "2. **Fine-mapping results file index** — path to lists of fine-mapped RDS files from fine-mapping output (e.g. `susie_list.tsv`).\n", - "3. **Genome region partition** (optional) — defines genomic regions per gene as enhanced cis regions from which `Z_n` and `Z_r` are extracted. If the complete list of fine-mapping RDS is already available (#2), this file is not required; otherwise extraction is limited to the regions listed (useful for testing).\n", - "4. **Independent variant list** (optional) — list of LD-pruned independent SNPs used to keep only independent null/random variants." + "**`susie_to_mash`** - builds the MASH input from fine-mapped SuSiE results:\n", + "\n", + "- `--fine_mapping_meta` **`input/finemapping/protocol_example.fine_mapping_meta.tsv`**\n", + "(index of the fine-mapped RDS files, one row per region and context. Columns `chrom`, `start`, `end`, `region_id`, `gene_id`, `context`, `susie_path`, `sumstats_path`, `conditions`.)\n", + "\n", + "```\n", + "chrom\tstart\tend\tregion_id\tgene_id\tcontext\tsusie_path\tsumstats_path\t...\n", + "chr22\t15528191\t15529138\tchr22:15528191-15529138\tENSG00000130538\tDe_Jager\tprotocol_example.susie_fit.rds\tprotocol_example.sumstats_db.rds\t...\n", + "```\n", + "\n", + "- `--finemapping_column susie_path` (which column of the meta table holds the fine-mapping RDS path.)\n", + "- `--sig_p_cutoff 0.1` (p-value threshold for calling a variant strong. The toy signal is weak, so loosen this or every strong variant is filtered out.)\n", + "\n", + "**`random_null_tensorqtl`** - extracts random and null effects directly from tensorQTL summary statistics:\n", + "\n", + "- `--region_file` **`input/finemapping/protocol_example.region`**\n", + "(genome region partition defining the analysis units, columns `chrom`, `start`, `end`, `gene_id`.)\n", + "\n", + "```\n", + "chrom\tstart\tend\tgene_id\n", + "chr11\t187771\t3551668\tENSG00000142089\n", + "```\n", + "\n", + "- `--sum_files` **`input/protocol_example.sumstats_list.txt`**\n", + "(list of the per-trait tensorQTL summary-statistics files. This file does not ship with the repository, so no preview is shown.)\n", + "- `--traits bulk_rnaseq` (trait or context labels matching the summary-statistics files.)\n", + "- `--independent_variant_list` (optional; LD-pruned independent SNPs, used to keep only independent null and random variants.)\n", + "\n", + "### Note on `susie_to_mash` inputs\n", + "\n", + "`susie_to_mash` consumes one **`FineMappingResult` RDS per region** (the S4 output of `fine_mapping.R`), listed in `--fine_mapping_meta` under `--finemapping_column`. For each region it takes the lead variant (max PIP) of every credible set in each condition as the *strong* set, and samples the *random* / *null* background from the region's full variant universe (`pecotmr::mashInput`).\n", + "\n", + "**Toy MWE.** The legacy per-region SuSiE fixtures can be converted once to a `QtlFineMappingResult` \u2014 see `tests/fixtures/mash/build_qtl_fine_mapping_result.R`, which builds `protocol_example.QtlFineMappingResult.rds` from the committed toy fine-mapping tables. Point `--fine_mapping_meta` at that RDS to run the toy demo. The toy signal is weak, so loosen `--sig_p_cutoff` (e.g. `0.1`) or every strong variant is filtered out.\n", + "\n", + "For a genome-wide run, provide a `--fine_mapping_meta` listing every region's `FineMappingResult` RDS.\n", + "\n", + "- `--cwd output/mash_preprocessing` (working directory all outputs are written under. Defaults to `output`.)\n", + "- `--name protocol_example` (tag used in the output filename and in the per-gene cache directory)" ] }, { @@ -57,15 +88,9 @@ "source": [ "## Output\n", "\n", - "A list of 10 elements containing the `strong.b`, `random.b`, and `null.b` data frames (z-scores across all conditions), ready for Ultimate Deconvolution / MASH. Example structure:" - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "R" - }, - "source": [ + "- **`/.mash_input.rds`** (`susie_to_mash`, or `random_null_tensorqtl_2`)\n", + "(a list of 10 elements containing the `strong.b`, `random.b` and `null.b` data frames of z-scores across all conditions, ready for Ultimate Deconvolution or MASH. Both entry points write this same file.)\n", + "\n", "```\n", "List of 10\n", " $ strong.b:'data.frame':\t62 obs. of 16 variables:\n", @@ -225,7 +250,10 @@ " ..- attr(*, \"dimnames\")=List of 2\n", " .. ..$ : chr [1:16] \"Mic_De_Jager_eQTL\" \"Ast_De_Jager_eQTL\" \"Oli_De_Jager_eQTL\" \"OPC_De_Jager_eQTL\" ...\n", " .. ..$ : chr [1:16] \"Mic_De_Jager_eQTL\" \"Ast_De_Jager_eQTL\" \"Oli_De_Jager_eQTL\" \"OPC_De_Jager_eQTL\" ...\n", - " ```" + " ```\n", + "\n", + "- **`/_cache/..qss.rds`** (`random_null_tensorqtl_1`)\n", + "(per-gene intermediate written by the tensorQTL entry point before the effects are pooled; not produced by `susie_to_mash`)" ] }, { @@ -234,9 +262,9 @@ "kernel": "SoS" }, "source": [ - "## Steps\n", + "## Minimal Working Example\n", "\n", - "This pipeline has two entry-point workflows. Run whichever matches your input; both write the strong / null / random z-score matrices for downstream multivariate analysis." + "This pipeline has two entry-point workflows. Run whichever matches your input; both write the strong / null / random z-score matrices for downstream multivariate analysis. Both write `{name}.mash_input.rds`, so run one or the other rather than both in sequence." ] }, { @@ -245,27 +273,18 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** `susie_to_mash` — build the MASH input from fine-mapped SuSiE results. Requires `--name`, `--fine_mapping_meta` (the index of fine-mapped RDS files) and `--independent_variant_list`; credible-set coverage and per-chunk size are tunable." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Note: `susie_to_mash` inputs\n", - "\n", - "`susie_to_mash` consumes one **`FineMappingResult` RDS per region** (the S4 output of `fine_mapping.R`), listed in `--fine_mapping_meta` under `--finemapping_column`. For each region it takes the lead variant (max PIP) of every credible set in each condition as the *strong* set, and samples the *random* / *null* background from the region's full variant universe (`pecotmr::mashInput`).\n", - "\n", - "**Toy MWE.** The legacy per-region SuSiE fixtures can be converted once to a `QtlFineMappingResult` — see `tests/fixtures/mash/build_qtl_fine_mapping_result.R`, which builds `protocol_example.QtlFineMappingResult.rds` from the committed toy fine-mapping tables. Point `--fine_mapping_meta` at that RDS to run the toy demo. The toy signal is weak, so loosen `--sig_p_cutoff` (e.g. `0.1`) or every strong variant is filtered out.\n", + "### Build the MASH input from fine-mapped SuSiE results\n", "\n", - "For a genome-wide run, provide a `--fine_mapping_meta` listing every region's `FineMappingResult` RDS." + "The `susie_to_mash` workflow requires `--name`, `--fine_mapping_meta` (the index of fine-mapped RDS files) and `--independent_variant_list`; credible-set coverage and per-chunk size are tunable." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Timing** (toy chr22 dataset):\n- `susie_to_mash`: see note\n- `random_null_tensorqtl`: ~varies\n" + "**Timing**: ~2 min (on toy dataset)" ] }, { @@ -281,12 +300,7 @@ " --fine_mapping_meta input/finemapping/protocol_example.fine_mapping_meta.tsv \\\n", " --finemapping_column susie_path \\\n", " --sig_p_cutoff 0.1 \\\n", - " --cwd output/mash_preprocessing\n", - "\n", - "# --fine_mapping_meta lists one FineMappingResult RDS per region (fine_mapping.R\n", - "# output) in the --finemapping_column. Strong = each credible set's lead variant\n", - "# per condition; random/null are sampled per region. The production\n", - "# --sig_p_cutoff default is 1E-6; loosen it (e.g. 0.1) on weak-signal toy data." + " --cwd output/mash_preprocessing" ] }, { @@ -295,8 +309,18 @@ "kernel": "Bash" }, "source": [ + "### Extract random and null effects from tensorQTL summary statistics\n", "\n", - "**Step 2.** `random_null_tensorqtl` — extract the random and null effects directly from tensorQTL summary statistics. Requires `--name`, `--region_file`, `--independent_variant_list`, and the list of summary-statistics files / traits." + "The `random_null_tensorqtl` workflow requires `--name`, `--region_file`, `--independent_variant_list`, and the list of summary-statistics files and traits." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -307,9 +331,6 @@ }, "outputs": [], "source": [ - "# random_null_tensorqtl builds a multi-context QtlSumStats per region from the\n", - "# matching tensorqtl files (mash_sumstats_construct.R), then assembles the mash\n", - "# input (mash_preprocessing.R). Requires multi-trait tensorqtl sumstats.\n", "sos run pipeline/mash_preprocessing.ipynb random_null_tensorqtl \\\n", " --name protocol_example_mash \\\n", " --region_file input/finemapping/protocol_example.region \\\n", @@ -324,20 +345,105 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/mash_preprocessing.ipynb -h" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/mash_preprocessing.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " susie_to_mash\n", + " random_null_tensorqtl\n", + "\n", + "Global Workflow Options:\n", + " --name VAL (as str, required)\n", + " --cwd output (as path)\n", + " Path to work directory where output locates\n", + " --modular-script-dir code/script (as path)\n", + " --seed 999 (as int)\n", + " --n-random 10 (as int)\n", + " Random / null background rows sampled per region\n", + " --n-null 10 (as int)\n", + " --exclude-condition (as list)\n", + " Conditions (columns) to drop from every partition\n", + " --coverage 0.95 (as float)\n", + " Credible-set coverage for FineMappingResult strong\n", + " selection (susie_to_mash)\n", + " --sig-p-cutoff 1e-06 (as float)\n", + " Strong-partition significance cutoff. Production default\n", + " 1E-6; loosen (e.g. 0.1) for weak-signal toy data or\n", + " every strong variant is filtered out.\n", + " --[no-]z-only (default to False)\n", + " Emit only the z-score matrices (drop the effect-size .b\n", + " / .s matrices)\n", + " --container ''\n", + " Containers that contains the necessary packages\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 1h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + " --independent-variant-list . (as path)\n", + " LD-pruned independent SNP list (optional). When\n", + " provided, restricts the random/null background to\n", + " matching variants (allele-aware via matchVariants);\n", + " strong is unaffected. Default path(\".\") means not\n", + " provided.\n", + "\n", + "Sections\n", + " susie_to_mash: Build the MASH input from per-region FineMappingResult\n", + " RDS (e.g. fine_mapping.R output). Strong = the lead\n", + " variant (max PIP) of each credible set per condition;\n", + " random / null are sampled from each region's full\n", + " variant universe. mashInput merges across regions,\n", + " cleans via filterInvalidSummaryStat, and appends the\n", + " strong XtX cross-product.\n", + " Workflow Options:\n", + " --fine-mapping-meta VAL (as path, required)\n", + " Index of per-region fine-mapping results (one row per\n", + " region)\n", + " --finemapping-column 'susie_path'\n", + " Column in --fine_mapping_meta holding each region's\n", + " FineMappingResult RDS path\n", + " --region-column 'region_id'\n", + " Column holding the region id (labels rows across\n", + " regions)\n", + " random_null_tensorqtl_1:\n", + " Workflow Options:\n", + " --sum-files paths\n", + "\n", + " --region-file VAL (as path, required)\n", + " --traits paths\n", + "\n", + " random_null_tensorqtl_2:\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { @@ -384,7 +490,11 @@ "# Memory expected\n", "parameter: mem = \"16G\"\n", "# Number of threads\n", - "parameter: numThreads = 1\n# LD-pruned independent SNP list (optional). When provided, restricts the\n# random/null background to matching variants (allele-aware via matchVariants);\n# strong is unaffected. Default path(\".\") means not provided.\nparameter: independent_variant_list = path(\".\")\n" + "parameter: numThreads = 1\n", + "# LD-pruned independent SNP list (optional). When provided, restricts the\n", + "# random/null background to matching variants (allele-aware via matchVariants);\n", + "# strong is unaffected. Default path(\".\") means not provided.\n", + "parameter: independent_variant_list = path(\".\")\n" ] }, { @@ -436,14 +546,7 @@ "kernel": "SoS" }, "source": [ - "## Get the random and null effects per analysis unit" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "### Get the random and null effects per analysis unit" ] }, { @@ -488,8 +591,10 @@ }, { "cell_type": "code", - "metadata": {}, "execution_count": null, + "metadata": { + "kernel": "SoS" + }, "outputs": [], "source": [ "[random_null_tensorqtl_2]\n", @@ -546,4 +651,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} +} \ No newline at end of file diff --git a/code/SoS/multivariate_genome/MASH/mixture_prior.ipynb b/code/SoS/multivariate_genome/MASH/mixture_prior.ipynb index cf7623028..94952233e 100644 --- a/code/SoS/multivariate_genome/MASH/mixture_prior.ipynb +++ b/code/SoS/multivariate_genome/MASH/mixture_prior.ipynb @@ -8,7 +8,7 @@ "source": [ "# Mixture prior estimation for MASH\n", "\n", - "This notebook computes a data-driven prior mixture (a set of covariance matrices) for a MASH model, independent of the downstream analysis method. It applies factor analysis (FLASH, PCA), canonical covariances, residual-variance (Vhat) estimation, and Empirical Bayes matrix methods (Extreme Deconvolution `ed_bovy`, Ultimate Deconvolution `ud`) to build the prior, then plots the resulting covariance patterns." + "Estimates the data-driven mixture of covariance matrices that a MASH model uses as its prior, from factor analyses and canonical patterns through residual-variance estimation to the fitted mixture." ] }, { @@ -17,20 +17,98 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "The pipeline proceeds in four stages: (1) factor analyses (`flash`, `flash_nonneg`, `pca`, `canonical`) to derive candidate covariance structures; (2) residual-variance estimation (`vhat_*` workflows) to estimate the error covariance Vhat; (3) multivariate mixture estimation (`ud`, `ud_unconstrained`, `ed_bovy`) to fit the data-driven prior; and (4) `plot_U` to visualise the estimated covariance matrices.\n", + "MASH borrows strength across conditions by putting a prior on effect-size vectors: a mixture of covariance matrices, each describing one pattern of sharing, such as an effect present in a single condition, shared equally everywhere, or shared with condition-specific magnitudes. This module estimates that mixture from the data before any MASH model is fitted, so one prior can serve several downstream analyses.\n", "\n", + "The work proceeds in four steps, in order.\n", + "\n", + "1. Covariance components. `flash` and `flash_nonneg` derive candidate patterns by empirical Bayes factor analysis, the second constraining the factors to be non-negative; `pca` derives them from the leading principal components of the strong effects; `canonical` writes the fixed patterns that need no fitting, namely an identity matrix, one matrix per condition, equal effects, and a few simple heterogeneity models. All four are produced by default, which is what `--mixture-components` lists.\n", + "2. Residual variance. Correlated noise across conditions would otherwise be read as shared signal, so a residual covariance Vhat is estimated from the null effects. Five estimators are available: `identity` assumes no correlation, `simple` takes the empirical correlation of the null z-scores, `simple_specific` takes their covariance with a nearest-positive-definite correction, `corshrink` applies adaptive shrinkage to that correlation, and `mle` refines an estimate by EM on a random subset of the data.\n", + "3. Mixture prior. One of three engines fits the mixture weights and refines the data-driven components. `ed_bovy` is the extreme deconvolution exported by mashr; `ud` and `ud_unconstrained` are the ED and TED updates from udr, and the code marks both as opt-in, `ud` for known numerical issues and `ud_unconstrained` because it expects independent, identically distributed data on the z-score scale. The engine reads the component files from step 1 together with the Vhat estimate from step 2.\n", + "4. Plotting. `plot_U` draws the estimated covariance matrices as heatmaps ordered by their mixture weight.\n", + "\n", + "Two settings tie the steps together. `--effect-model` decides whether effects are exchangeable on the effect-size scale (`EE`) or the z-score scale (`EZ`), and it appears in every file name from step 2 onwards. `--vhat` names which residual-variance estimate the engine should read, so it has to match the estimator that was actually run; the default is `simple`. `mle` is the exception in both directions: it needs a prior to exist already, and when `--vhat mle` is set the engines fall back to reading the `simple` estimate instead.\n", + "\n", + "**When to run it.** After the per-condition summary statistics have been assembled into a single RDS by the effect-extraction step, and before fitting the MASH model, which consumes the prior produced here." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ "## Input\n", "\n", - "- `--data`: a formatted association summary-statistics RDS (a list with `strong.z`/`strong.b`/`strong.s`, `random.*`, `null.*`, and `XtX`), e.g. produced upstream by `extract_effects`.\n", - "- `--output-prefix`: prefix for output files (derived from `--data` if omitted).\n", - "- `--effect-model`: `EE` (exchangeable effects) or `EZ` (exchangeable z-scores).\n", - "- `--vhat`: residual-variance method (`identity`, `simple`, `mle`, `vhat_corshrink_xcondition`, `vhat_simple_specific`).\n", + "* `--data` -- the assembled summary statistics, an RDS holding effect sizes (`.b`), standard errors (`.s`) and z-scores (`.z`) for the strong, random and null subsets, plus `XtX`, each with one column per condition:\n", + "\n", + " ```\n", + " List of 10\n", + " $ random.z: num [1:68, 1:8] -0.286 0.909 1.362 -0.807 -0.185 ...\n", + " $ strong.z: num [1:17, 1:8] 8.77 1.16 9.16 -4.99 -1.02 ...\n", + " $ null.z : num [1:68, 1:8] -0.508 -1.149 -0.422 -0.206 0.351 ...\n", + " $ random.b: num [1:68, 1:8] -0.00799 0.0248 0.03869 -0.02005 -0.00388 ...\n", + " $ strong.b: num [1:17, 1:8] 0.2491 0.0927 0.3318 -0.1553 -0.1398 ...\n", + " $ null.b : num [1:68, 1:8] -0.03792 -0.02839 -0.03397 -0.00571 0.03438 ...\n", + " $ null.s : num [1:68, 1:8] 0.0746 0.0247 0.0805 0.0278 0.0979 ...\n", + " $ random.s: num [1:68, 1:8] 0.028 0.0273 0.0284 0.0249 0.021 ...\n", + " $ strong.s: num [1:17, 1:8] 0.0284 0.0798 0.0362 0.0311 0.1374 ...\n", + " $ XtX : num [1:8, 1:8] 31.06 6.09 1.02 27.12 9.89 ...\n", + " ```\n", "\n", + "* `--output-prefix` -- prefix for every output file; derived from the `--data` basename when omitted.\n", + "* `--cwd` -- output directory, default `mashr_workflow_output`.\n", + "* `--effect-model` -- `EE` or `EZ`, default `EE`.\n", + "* `--vhat` -- which residual-variance estimate the mixture engines read: `identity`, `simple`, `mle`, `vhat_corshrink_xcondition` or `vhat_simple_specific`. Default `simple`.\n", + "* `--mixture-components` -- which component files the engines combine, default `flash flash_nonneg pca canonical`.\n", + "* `--output-suffix` -- suffix carried on output names, default `all`.\n", + "\n", + "Step-specific:\n", + "\n", + "* `--npc` (`pca`) -- number of principal components, default `2`. The comment beside it in the code says it is set to 3 as in the mash paper, which no longer matches the value.\n", + "* `--n-subset` and `--max-iter` (`vhat_mle`) -- rows sampled for the EM estimate, default `6000`, and the iteration cap, default `6`.\n", + "* `--max-comp`, `--to-cor`, `--tol`, `--remove-label`, `--name` (`plot_U`) -- how many components to draw (`-1` for all), whether to convert covariances to correlations, the tolerance, whether to drop labels, and a suffix added to the plot file name. Note that `plot_U` redefines `--data` to mean the prior RDS rather than the summary statistics.\n", + "\n", + "Runtime:\n", + "\n", + "* `--container`, `--job-size`, `--walltime`, `--mem`, `--numThreads` -- software environment and cluster resources.\n", + "* `--modular-script-dir` -- location of the R drivers, default `code/script`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ "## Output\n", "\n", - "- Residual variance estimate, the MASH data-driven prior (`*..prior.rds`), and prior covariance plots." + "* `.flash.rds`, `.flash_nonneg.rds`, `.pca.rds`, `.canonical.rds` -- the covariance components from step 1, each a named list of condition-by-condition matrices. On the toy data `pca` yields `PCA_1`, `PCA_2` and `tPCA` and `canonical` yields 13 matrices, while both FLASH files are empty (`NULL`), so FLASH contributes nothing to the toy prior.\n", + "* `..V_.rds` -- the residual variance estimate from step 2, one condition-by-condition matrix. The method is part of the name, so estimates from different estimators coexist.\n", + "* `..prior.rds` -- the prior itself: the list of covariance matrices `U`, their mixture weights `w`, and the log-likelihood trace of the fit. Components that received zero weight are kept in the list:\n", + "\n", + " ```\n", + " List of 3\n", + " $ U :List of 17\n", + " $ w : Named num [1:17] 0.4714 0 0 0.0616 0.0949 ...\n", + " $ loglik: num [1:1447] 0.705 3.455 3.719 4.142 5.068 ...\n", + " names(U): XtX, PCA_1, PCA_2, tPCA, identity, ALL, Ast, End, Exc, Inh, Mic, OPC, Oli, equal_effects, simple_het_1, simple_het_2, simple_het_3\n", + " ```\n", + "\n", + "* `..prior_c.log` and `..prior_loglike.log` -- engine diagnostics.\n", + "* `.pdf` -- heatmaps of the covariance matrices, ordered by mixture weight.\n", + "\n", + "Each step also writes `.stdout` and `.stderr` beside its output. Example results for the toy data are under `output/mixture_prior/`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n" ] }, { @@ -39,7 +117,9 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "### Step 1. Covariance components\n", + "\n", + "All four run independently of each other, and all four are expected by the engines in step 3, since `--mixture-components` defaults to the full set." ] }, { @@ -48,14 +128,18 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Perform FLASH factor analysis:" + "#### FLASH factors\n", + "\n", + "Empirical Bayes factor analysis of the strong effects." ] }, { "cell_type": "markdown", - "metadata": {}, + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Timing:** ~5-15 min on typical compute infrastructure." + "**Timing**: ~5-15 min (on toy dataset)" ] }, { @@ -78,7 +162,18 @@ "kernel": "SoS" }, "source": [ - "**Step 2.** Perform FLASH analysis with a non-negative factor constraint:" + "#### FLASH factors, non-negative\n", + "\n", + "The same analysis with the factors constrained to be non-negative." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -101,7 +196,18 @@ "kernel": "SoS" }, "source": [ - "**Step 3.** Derive covariances from principal components:" + "#### Principal components\n", + "\n", + "Covariances built from the leading principal components; `--npc` sets how many." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -124,7 +230,18 @@ "kernel": "SoS" }, "source": [ - "**Step 4.** Build canonical (single-condition and shared) covariances:" + "#### Canonical patterns\n", + "\n", + "The fixed patterns that need no fitting: identity, one matrix per condition, equal effects, and simple heterogeneity models." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -147,7 +264,29 @@ "kernel": "SoS" }, "source": [ - "**Step 5.** Estimate residual variance Vhat using the \"identity\" method:" + "### Step 2. Residual variance\n", + "\n", + "Pick one estimator. Whichever is chosen has to be named to step 3 through `--vhat`, which defaults to `simple`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### identity\n", + "\n", + "Assume the conditions carry uncorrelated noise." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -170,7 +309,18 @@ "kernel": "SoS" }, "source": [ - "**Step 6.** Estimate residual variance Vhat using the \"simple\" method (null z-scores):" + "#### simple\n", + "\n", + "Empirical correlation of the null z-scores. This is the estimate the engines look for by default." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -193,7 +343,18 @@ "kernel": "SoS" }, "source": [ - "**Step 7.** Estimate residual variance Vhat using the \"mle\" method:" + "#### mle\n", + "\n", + "EM refinement on a random subset. It reads an existing prior, so it can only run after a first pass through step 3." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -216,7 +377,18 @@ "kernel": "SoS" }, "source": [ - "**Step 8.** Estimate Vhat per condition via corshrink:" + "#### corshrink per condition\n", + "\n", + "Adaptive shrinkage applied to the null correlation." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -239,7 +411,18 @@ "kernel": "SoS" }, "source": [ - "**Step 9.** Estimate Vhat per condition via the \"simple\" method:" + "#### simple per condition\n", + "\n", + "Covariance of the null z-scores with a nearest-positive-definite correction." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -262,7 +445,29 @@ "kernel": "SoS" }, "source": [ - "**Step 10.** Compute the multivariate mixture prior via Ultimate Deconvolution (udr):" + "### Step 3. Mixture prior\n", + "\n", + "Pick one engine. It reads the four component files from step 1 together with the Vhat estimate from step 2, and writes `..prior.rds`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Ultimate Deconvolution (ud)\n", + "\n", + "The ED update from udr. The code marks it opt-in because of known numerical issues." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -285,7 +490,18 @@ "kernel": "SoS" }, "source": [ - "**Step 11.** Compute the mixture prior via unconstrained Ultimate Deconvolution:" + "#### Ultimate Deconvolution, unconstrained (ud_unconstrained)\n", + "\n", + "The TED update from udr, which expects independent, identically distributed data on the z-score scale." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -308,7 +524,18 @@ "kernel": "SoS" }, "source": [ - "**Step 12.** Compute the mixture prior via Extreme Deconvolution (Bovy et al.):" + "#### Extreme Deconvolution (ed_bovy)\n", + "\n", + "The extreme deconvolution exported by mashr." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -331,7 +558,29 @@ "kernel": "SoS" }, "source": [ - "**Step 13.** Plot the estimated prior covariance patterns:" + "### Step 4. Plot the prior\n", + "\n", + "Draw the fitted covariance matrices as heatmaps, ordered by mixture weight." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Plot the prior\n", + "\n", + "Here `--data` is the prior produced in step 3, not the summary statistics, and `--output-prefix` names the plot." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -354,7 +603,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -368,6 +617,105 @@ "sos run pipeline/mixture_prior.ipynb -h" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/mixture_prior.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " flash\n", + " flash_nonneg\n", + " pca\n", + " canonical\n", + " vhat_identity\n", + " vhat_simple\n", + " vhat_mle\n", + " vhat_corshrink_xcondition\n", + " vhat_simple_specific\n", + " ud\n", + " ud_unconstrained\n", + " ed_bovy\n", + " plot_U\n", + "\n", + "Global Workflow Options:\n", + " --cwd mashr_workflow_output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " --data VAL (as path, required)\n", + " Input summary statistics data\n", + " --output-prefix ''\n", + " Prefix of output files. If not specified, it will derive\n", + " it from data. If it is specified, for example,\n", + " `--output-prefix AnalysisResults` It will save output\n", + " files as `{cwd}/AnalysisResults*`.\n", + " --output-suffix all\n", + " --effect-model EE\n", + " Exchangable effect (EE) or exchangable z-scores (EZ)\n", + " --vhat simple\n", + " Identifier of $\\hat{V}$ estimate file Options are\n", + " \"identity\", \"simple\", \"mle\",\n", + " \"vhat_corshrink_xcondition\", \"vhat_simple_specific\"\n", + " --mixture-components flash flash_nonneg pca canonical (as list)\n", + " --container ''\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + "\n", + "Sections\n", + " flash:\n", + " flash_nonneg:\n", + " pca:\n", + " Workflow Options:\n", + " --npc 2 (as int)\n", + " Number of components in PCA analysis for prior set to 3\n", + " as in mash paper\n", + " canonical:\n", + " vhat_identity: V estimate: \"identity\" method\n", + " vhat_simple: V estimate: \"simple\" method (null z-scores)\n", + " vhat_mle: V estimate: \"mle\" method (mash_estimate_corr_em on a\n", + " random subset; needs the prior U)\n", + " Workflow Options:\n", + " --n-subset 6000 (as int)\n", + " number of samples to use\n", + " --max-iter 6 (as int)\n", + " maximum number of iterations\n", + " vhat_corshrink_xcondition: V estimate: \"corshrink\" adaptive-shrinkage null\n", + " correlation (run globally on the null set; the legacy\n", + " per-gene GTEx SumstatQuery path is not portable)\n", + " vhat_simple_specific: V estimate: \"simple_specific\" nearPD(cov(nullZ)) (run\n", + " globally on the null set; legacy per-gene GTEx path not\n", + " portable)\n", + " ud: Prior engine: udr ED update (opt-in; known numerical\n", + " issues)\n", + " ud_unconstrained: Prior engine: udr TED update (opt-in; needs\n", + " i.i.d./z-scale data)\n", + " ed_bovy: Prior engine: mashr extreme deconvolution (the exported\n", + " bovy ED)\n", + " plot_U:\n", + " Workflow Options:\n", + " --max-comp -1 (as int)\n", + " number of components to show\n", + " --[no-]to-cor (default to False)\n", + " whether or not to convert to correlation\n", + " --tol '1E-6'\n", + " --[no-]remove-label (default to False)\n", + " --name ''\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { @@ -384,7 +732,7 @@ "tags": [] }, "source": [ - "## Global parameters" + "### Global parameters" ] }, { @@ -434,7 +782,7 @@ "kernel": "Bash" }, "source": [ - "## Factor analyses" + "### Factor analyses" ] }, { @@ -527,7 +875,7 @@ "kernel": "SoS" }, "source": [ - "## Estimate residual variance\n" + "### Residual variance estimation" ] }, { @@ -649,7 +997,7 @@ "tags": [] }, "source": [ - "## Compute multivariate mixture" + "### Mixture prior engines" ] }, { @@ -731,16 +1079,9 @@ "tags": [] }, "source": [ - "## Plot patterns of sharing\n", + "### Plotting\n", "\n", - "This is a simple utility function that takes the output from the pipeline above and make some heatmap to show major patterns of multivariate effects. The plots will be ordered by their mixture weights." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "A utility that reads the prior produced above and draws heatmaps of its covariance matrices, ordered by mixture weight." ] }, { diff --git a/code/SoS/multivariate_genome/METAL/METAL.ipynb b/code/SoS/multivariate_genome/METAL/METAL.ipynb index 0ad10675a..5cac047d0 100644 --- a/code/SoS/multivariate_genome/METAL/METAL.ipynb +++ b/code/SoS/multivariate_genome/METAL/METAL.ipynb @@ -11,9 +11,9 @@ "\n", "This notebook runs cross-cohort meta-analysis of summary statistics with **METAL** on the toy `protocol_example` dataset. METAL is a command-line tool that takes a script documenting the input summary-statistic files, the field mapping for each, and the analysis settings. Meta-analysis here is essentially a weighted sum of Z-scores, so the same set of variants must be present across the input cohorts; the input is a list of paths to the per-cohort summary statistics to analyse together.\n", "\n", - "By default the weighting **SCHEME** is set to standard error (`STDERR`); switching to sample-size weighting would require a sample-size column in the upstream input. The `AVERAGEFREQ`, `MINMAXFREQ`, and `GENOMICCONTROL` options are off by default — enabling any of them requires the corresponding additional column.\n", + "By default the weighting **SCHEME** is set to standard error (`STDERR`); switching to sample-size weighting would require a sample-size column in the upstream input. The `AVERAGEFREQ`, `MINMAXFREQ`, and `GENOMICCONTROL` options are off by default \u2014 enabling any of them requires the corresponding additional column.\n", "\n", - "The workflow is split into four numbered steps (`METAL_1` … `METAL_4`); the commands below run them in order on the toy input `protocol_example.sumstat_list.tsv` (a tab-separated list with a `#chr` column and one cohort column `protocol_example`). The referenced sumstats carry `chr, pos, A1, A2, beta, se, z, p`, so effect/SE/p-value/alleles are mapped to `beta`/`se`/`p`/`A1` `A2`; with no frequency or sample-size column the default STDERR scheme is used. Results go to `output/metal`, no container.\n", + "The workflow is split into four numbered steps (`METAL_1` \u2026 `METAL_4`); the commands below run them in order on the toy input `protocol_example.sumstat_list.tsv` (a tab-separated list with a `#chr` column and one cohort column `protocol_example`). The referenced sumstats carry `chr, pos, A1, A2, beta, se, z, p`, so effect/SE/p-value/alleles are mapped to `beta`/`se`/`p`/`A1` `A2`; with no frequency or sample-size column the default STDERR scheme is used. Results go to `output/metal`, no container.\n", "\n", "**Role in the protocol.** METAL is the meta-analysis module: it consumes the per-cohort summary statistics produced by QTL association and combines them. It produces two outputs: (1) a list of meta-analysed summary statistics for downstream MASH and mvSuSiE-RSS analysis, and (2) a list of summary statistics in VCF format that serves as the end product of the analysis." ] @@ -44,7 +44,7 @@ "source": [ "## Run the full workflow\n", "\n", - "Calling the `METAL` target runs all four numbered steps in order (`METAL_1` → `METAL_2` → `METAL_3` → `METAL_4`), since they form a chained numbered pipeline. This single command is the normal entry point; the per-step commands below are provided for running or inspecting each step individually." + "Calling the `METAL` target runs all four numbered steps in order (`METAL_1` \u2192 `METAL_2` \u2192 `METAL_3` \u2192 `METAL_4`), since they form a chained numbered pipeline. This single command is the normal entry point; the per-step commands below are provided for running or inspecting each step individually." ] }, { @@ -52,7 +52,8 @@ "metadata": {}, "source": [ "**Timing:** Runtime varies by dataset size and compute resources. For the toy chr22 MWE dataset, most steps complete in under 10 minutes on a standard HPC node." - ] + ], + "id": "68da14d3" }, { "cell_type": "code", @@ -86,6 +87,24 @@ "| `{name}.METAL_list.txt` | recipe list mapping each chromosome to its meta-analysed output file |" ] }, + { + "cell_type": "markdown", + "id": "figured-dover", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "METAT is a command line tool, takes in a script that documenting the input sumstat files, the field of each of those sumstat input file, and then the end of scipt.\n", + "\n", + "METAL analysis is enssentially a weighted sum of Z score, therefore the input of snps from each chrm can be processed seperately. To make sure the same region was analysis, the input of this workflow shall be a list of path to the sumstat, join by \" \" to be analyzed at once.\n", + "\n", + "Also, The scheme of weighting at the moment is set to be standard error, changing it to sample size would require the upstream input have a columns named sample size, which they dont have it yet.\n", + "\n", + "At the moment, the AVERAGEFREQ, MINMAXFREQ, and GENOMICCONTROL are by default set to off, turning on each of the option require additional input from upstream file.\n", + "\n", + "The output file name of the seconde step will by default contains a 1 linking the desinateted prefix and surfix, which lead to the f'{wd}/{name}1.METAL.txt' file name" + ] + }, { "cell_type": "markdown", "id": "3289773d-0254-4a97-bdcb-0b253a8e45d5", @@ -117,7 +136,7 @@ "source": [ "# Pipeline Implementation\n", "\n", - "The SoS workflow definitions below implement the steps run above: the `[global]` parameter block followed by the four numbered steps `METAL_1`–`METAL_4`." + "The SoS workflow definitions below implement the steps run above: the `[global]` parameter block followed by the four numbered steps `METAL_1`\u2013`METAL_4`." ] }, { @@ -125,7 +144,8 @@ "metadata": {}, "source": [ "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] + ], + "id": "5481599f" }, { "cell_type": "code", diff --git a/code/SoS/multivariate_genome/multivariate_mixture_vignette.ipynb b/code/SoS/multivariate_genome/multivariate_mixture_vignette.ipynb index f20118d82..7f16124e9 100644 --- a/code/SoS/multivariate_genome/multivariate_mixture_vignette.ipynb +++ b/code/SoS/multivariate_genome/multivariate_mixture_vignette.ipynb @@ -2,164 +2,211 @@ "cells": [ { "cell_type": "markdown", - "id": "c4b174d1", + "id": "a99833c1", "metadata": { "kernel": "SoS" }, "source": [ - "# Mixture Multivariate Distribution Estimate\n", + "# Learning multivariate effect patterns for MASH\n", "\n", - "This miniprotocol estimates a **mixture multivariate prior**, fits the **Multivariate Adaptive Shrinkage (MASH)** model, and visualizes the estimated covariance components. It is a thin driver that chains two reusable workflow notebooks:\n", - "\n", - "- `mixture_prior.ipynb` \u2014 computes a prior independent of the specific analysis method chosen for the data. This foundational step enables the application of various techniques such as UDR, ED, TED, and initialization with FLASHier, among others. The goal is to establish a mixture model to extract meaningful signals from the data. An earlier version of the approach is outlined in Urbut et al 2019; this workflow implements a few improvements including additional EBMF methods as well as the new `udr` (Ultimate Deconvolution in R) package to fit the mixture model.\n", - "- `mash_fit.ipynb` \u2014 once priors are calculated, the MASH model is fit and posteriors are calculated for variables of interest, with the objective of conducting a multivariate analysis under the MASH model. MASH has improved upon the Urbut et al 2019 paper.\n", - "\n", - "> **Synthetic data note.** This user-friendly copy is wired to small `protocol_example.*` toy inputs under `input/` (a 34-context `mashr` input RDS and the matching MASH input/prior/V files) so the whole chain runs end-to-end without access-controlled data. Swap in your own RDS files to run on real data." + "This vignette explains how to estimate a mixture-of-covariances prior, fit MASH and interpret the learned sharing patterns." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "c6bec6e5", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Description\n", - "\n", - "This vignette describes the conceptual background and statistical theory behind the mixture prior estimation used in multivariate analysis. Unlike the executable mini-protocol notebooks, this vignette is primarily a reference document \u2014 it explains *why* the mixture prior is structured this way and how it relates to MASH covariance estimation.\n", + "## Learning goals\n", "\n", - "For the runnable MWE, see `mash_fit` and `mash_posterior`. For the mixture prior step itself, see `mixture_prior`." + "After completing this vignette, you will be able to explain what the mixture prior represents, distinguish prior estimation from posterior fitting, run the three-step example, and interpret covariance components without treating them as discrete biological clusters." ] }, { "cell_type": "markdown", - "id": "b8f81aa7", + "id": "3fc1f94b", "metadata": { "kernel": "SoS" }, "source": [ - "## Input\n", + "## Background and method\n", "\n", - "The mixture-prior step takes a single **`mashr` input RDS** (the `--data` argument). For the toy example this is `input/mash/protocol_example.mashr_input.rds`, a list with effect-size (`*.b`), z-score (`*.z`), standard-error (`*.s`) matrices for `random`, `strong`, and `null` SNP sets, plus the `XtX` matrix \u2014 each with rows = SNPs and columns = the conditions/contexts (e.g. cell types).\n", + "MASH models effects across many related conditions using a mixture of multivariate normal distributions. Each covariance component represents a possible pattern of effect sharing: condition-specific, broadly shared, correlated among a subset of conditions or learned from the data. Mixture weights describe how strongly the observed effects support these patterns.\n", "\n", - "The MASH-fit step additionally consumes the prior produced by the first step together with the matching MASH input and `V` matrices.\n", + "Prior estimation and posterior inference are separate operations. `mixture_prior.ipynb` learns data-driven covariance components from strong signals and combines them with canonical components. `mash_fit.ipynb` fits the mixture to the full analysis set and computes posterior effect estimates, uncertainties and measures of sharing. Reusing a prior is appropriate only when its conditions and effect architecture are compatible with the target analysis.\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `input/mash/protocol_example.mashr_input.rds` | Mixture-prior input: list of effect/z/se matrices (`random`, `strong`, `null`) + `XtX`, used by `mixture_prior` |\n", - "| `input/mash/protocol_example.EE.mash.rds` | MASH input data (EE effect model) consumed by `mash_fit` |\n", - "| `input/mash/protocol_example.EE.V_simple.rds` | Estimated residual correlation matrix `V` for `mash_fit` |\n", - "| `input/mash/protocol_example.EE.prior.rds` | Mixture prior RDS (also produced by step 1) consumed by `mash_fit` |\n", - "\n", - "**Workflow options carried by the underlying notebooks:**\n", - "\n", - "- `--vhat`: one of `identity`, `simple`, `mle`, `vhat_corshrink_xcondition`, or `vhat_simple_specific`.\n", - "- `--cwd`: output path.\n", - "- `--vhat-data`: for `mash_fit`, the `vhat` data RDS produced in the `mixture_prior` step.\n", - "- `--prior-data`: for `mash_fit`, the prior data RDS produced in the `mixture_prior` step.\n", - "- `--compute-posterior`: for `mash_fit`, whether posterior probabilities should be calculated." + "The example uses small synthetic 34-context inputs. It demonstrates object flow and interpretation, not a biological reference prior." ] }, { "cell_type": "markdown", - "id": "998fa475", + "id": "fef7df5d", "metadata": { "kernel": "SoS" }, "source": [ - "## Output\n", + "## Worked example\n", + "\n", + "The analysis has three sequential steps: estimate the prior, fit MASH, then visualize the covariance components. The paths below define the intended protocol-example bundle, but the complete bundle is not currently shipped: only the prior-estimation fixture is available. The commands show the required interface until the missing MASH input and residual-correlation files are added.\n", "\n", - "The mixture-prior step writes the estimated data-driven covariance components and the assembled mixture prior; the MASH-fit step writes the fitted MASH model and (optionally) per-unit posteriors; the plotting step writes a PDF visualizing the prior covariance matrices.\n", + "| Role | Example path |\n", + "|---|---|\n", + "| Prior-estimation input | `input/mash/protocol_example.mashr_input.rds` |\n", + "| MASH input | `input/mash/protocol_example.EE.mash.rds` |\n", + "| Residual correlation matrix | `input/mash/protocol_example.EE.V_simple.rds` |\n", "\n", - "| File | Description |\n", - "|------|-------------|\n", - "| `output/mixture_prior/protocol_example.EE.prior.rds` | Assembled mixture prior (data-driven + canonical covariance components) from `ed_bovy` |\n", - "| `output/mash_fit/protocol_example_mash.*.rds` | Fitted MASH model and posterior summaries (loglik, fitted_g, posterior means/SDs) |\n", - "| `output/mixture_prior/protocol_example_plots.EE.prior.pdf` | Heatmap visualization of the estimated prior covariance matrices |" + "The matrices must use the same condition order and compatible units. The prior-estimation object contains random, strong and null subsets plus `XtX`; the MASH input contains the effects and standard errors to which the learned prior is applied." ] }, { "cell_type": "markdown", - "id": "a504dfbb", + "id": "37de6ef0", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps\n", - "\n", - "The miniprotocol runs in three steps. Each step calls a reusable workflow notebook through the `pipeline/` symlinks. Outputs of step 1 feed into steps 2 and 3.\n", - "\n", - "**Step 1.** Compute the MASH mixture prior with the `ed_bovy` workflow of `mixture_prior` (estimates data-driven covariance components and assembles the prior).\n", - "\n", - "**Step 2.** Fit the MASH model with the `mash` workflow of `mash_fit`, supplying the prior and `vhat`/MASH input from step 1, and compute posteriors.\n", + "### Step 1. [Estimate the mixture prior](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mixture_prior.html)\n", "\n", - "**Step 3.** Visualize the estimated prior covariance matrices with the `plot_U` workflow of `mixture_prior`." + "`ed_bovy` estimates data-driven covariance components and assembles them with canonical components." + ] + }, + { + "cell_type": "markdown", + "id": "3a29861f", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" ] }, { "cell_type": "code", "execution_count": null, - "id": "84ed7672", + "id": "08945ea2", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/mixture_prior.ipynb ed_bovy \\\n", - " --output-prefix protocol_example \\\n", - " --data input/mash/protocol_example.mashr_input.rds \\\n", - " --cwd output/mixture_prior" + " --output-prefix protocol_example \\\n", + " --data input/mash/protocol_example.mashr_input.rds \\\n", + " --cwd output/mixture_prior" + ] + }, + { + "cell_type": "markdown", + "id": "9acc31a4", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Step 2. [Fit MASH](https://statfungen.github.io/xqtl-protocol/code/multivariate_genome/MASH/mash_fit.html)\n", + "\n", + "`mash` combines the input effects, residual correlation and estimated prior to compute posterior summaries." + ] + }, + { + "cell_type": "markdown", + "id": "9d65b4e8", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" ] }, { "cell_type": "code", "execution_count": null, - "id": "3ec74aee", + "id": "3078f1f3", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/mash_fit.ipynb mash \\\n", - " --output-prefix protocol_example_mash \\\n", - " --data input/mash/protocol_example.EE.mash.rds \\\n", - " --vhat-data input/mash/protocol_example.EE.V_simple.rds \\\n", - " --prior-data input/mash/protocol_example.EE.prior.rds \\\n", - " --effect-model EE \\\n", - " --compute-posterior \\\n", - " --cwd output/mash_fit" + " --output-prefix protocol_example_mash \\\n", + " --data input/mash/protocol_example.EE.mash.rds \\\n", + " --vhat-data input/mash/protocol_example.EE.V_simple.rds \\\n", + " --prior-data output/mixture_prior/protocol_example.EE.prior.rds \\\n", + " --effect-model EE \\\n", + " --compute-posterior \\\n", + " --cwd output/mash_fit" + ] + }, + { + "cell_type": "markdown", + "id": "31c303f8", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Step 3. Visualize the learned covariance components\n", + "\n", + "`plot_U` draws heatmaps of the covariance matrices in the fitted prior." + ] + }, + { + "cell_type": "markdown", + "id": "d575817b", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" ] }, { "cell_type": "code", "execution_count": null, - "id": "f13fc438", + "id": "65af7259", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/mixture_prior.ipynb plot_U \\\n", - " --output-prefix protocol_example_plots \\\n", - " --data output/mixture_prior/protocol_example.EE.prior.rds \\\n", - " --cwd output/mixture_prior" + " --output-prefix protocol_example_plots \\\n", + " --data output/mixture_prior/protocol_example.EE.prior.rds \\\n", + " --cwd output/mixture_prior" ] }, { "cell_type": "markdown", - "id": "306ba0f6", + "id": "195497ad", "metadata": { "kernel": "SoS" }, "source": [ - "## Command interface\n", + "The chain produces:\n", + "\n", + "- `output/mixture_prior/protocol_example.EE.prior.rds` — data-driven and canonical covariance components with their mixture structure.\n", + "- `output/mash_fit/protocol_example_mash.*.rds` — fitted MASH model and, when requested, posterior summaries.\n", + "- `output/mixture_prior/protocol_example_plots.EE.prior.pdf` — covariance-component heatmaps.\n", "\n", - "Each step is driven by one of two reusable workflow notebooks. List their full option sets with `-h`:" + "Run the steps in order. Step 2 uses the prior from Step 1; Step 3 visualizes that same prior." + ] + }, + { + "cell_type": "markdown", + "id": "aa2c3eb0", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Command reference" ] }, { "cell_type": "code", "execution_count": null, - "id": "ea454b1c", + "id": "3a7afb63", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ @@ -169,43 +216,82 @@ }, { "cell_type": "markdown", - "id": "0614bc51", + "id": "fae86b10", "metadata": { "kernel": "SoS" }, "source": [ - "## Workflow implementation\n", + "## Results and interpretation\n", "\n", - "This notebook is a **driver/miniprotocol**: it does not define its own SoS sections but orchestrates two reusable workflow notebooks via the `pipeline/` symlinks:\n", + "### Mixture-prior result\n", "\n", - "- `pipeline/mixture_prior.ipynb` \u2014 provides the `ed_bovy` (mixture-prior estimation) and `plot_U` (prior visualization) workflows, among other covariance-estimation methods (`flash`, `pca`, `canonical`, `ud`, `vhat_*`, ...).\n", - "- `pipeline/mash_fit.ipynb` \u2014 provides the `mash` workflow (MASH model fit + posterior computation).\n", + "The prior contains covariance matrices and mixture information. Inspect dimensions, names and weights rather than printing every matrix.\n", "\n", - "Refer to those notebooks for the underlying R implementation of each step." + "| Result | Interpretation |\n", + "|---|---|\n", + "| Covariance component | Candidate pattern of effect sharing across conditions |\n", + "| Diagonal values | Relative effect variance within conditions |\n", + "| Off-diagonal values | Direction and strength of shared effects |\n", + "| Mixture weight | Support for a component in the fitted effect distribution |\n", + "| Posterior summaries | Shrunk effects and uncertainty after combining data with the mixture |" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "009a4fcf", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "prior <- readRDS(\"output/mixture_prior/protocol_example.EE.prior.rds\")\n", + "cat(\"Class:\", class(prior), \"\\n\")\n", + "cat(\"Top-level fields:\", paste(names(prior), collapse = \", \"), \"\\n\")\n", + "\n", + "fit_files <- list.files(\"output/mash_fit\", pattern = \"^protocol_example_mash.*\\\\.rds$\", full.names = TRUE)\n", + "fit <- readRDS(fit_files[[1]])\n", + "cat(\"MASH result fields:\", paste(names(fit), collapse = \", \"), \"\\n\")" + ] + }, + { + "cell_type": "markdown", + "id": "86992fdc", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "A covariance heatmap is a pattern used by the mixture model, not a cluster assignment for samples or conditions. Strong positive off-diagonal structure supports effects with similar direction across conditions; near-diagonal structure supports condition-specific effects. Interpret a pattern together with its estimated weight and posterior results. Components can overlap, and several components may approximate the same broad biological pattern." ] }, { "cell_type": "markdown", - "id": "3269bd62", + "id": "27c9c1cf", "metadata": { "kernel": "SoS" }, "source": [ - "## Troubleshooting\n", + "## Limitations and common pitfalls\n", "\n", - "| Issue | Cause | Solution |\n", - "|-------|-------|----------|\n", - "| `cannot open compressed file ... No such file or directory` | `--data` RDS path is wrong or the toy input is not staged | Confirm `input/mash/protocol_example.mashr_input.rds` exists (it is a symlink into `data/`) |\n", - "| Step 2 fails on `--prior-data` / `--vhat-data` | Step 1 has not been run yet, so the prior/vhat RDS do not exist | Run Step 1 first; it writes the prior into `output/mixture_prior/` |\n", - "| `Incorrect workflow name` | The workflow name was omitted from `sos run` | Always pass the explicit workflow (`ed_bovy`, `mash`, or `plot_U`) before the `--` parameters |\n", - "| Empty or tiny plot PDF | `plot_U` was pointed at a prior RDS that has no data-driven components | Use the `*.EE.prior.rds` produced by Step 1 as `--data` |" + "- Condition names and ordering must match across all matrices.\n", + "- Strong-effect subsets used to learn covariances can bias the prior if they are unrepresentative.\n", + "- A prior learned in one study should not be transferred automatically to another tissue set or measurement scale.\n", + "- Residual correlation `V` and biological effect covariance are different quantities.\n", + "- Similar covariance components can be non-identifiable; interpret broad patterns rather than every component literally.\n", + "- The complete protocol-example input bundle is currently missing, so the three-step worked example cannot yet run end to end.\n", + "- Synthetic inputs demonstrate mechanics, not expected biological sharing." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "e6cc098d", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "## Next steps\n", + "\n", + "Use the fitted posterior summaries to identify effects that are shared or condition-specific, then compare those conclusions with sensitivity analyses using alternative covariance sets or residual-correlation estimates. Record the condition order and prior provenance with every downstream result." ] } ], @@ -220,10 +306,22 @@ "file_extension": ".sos", "mimetype": "text/x-sos", "name": "sos", - "nbconvert_exporter": "sos.jupyter.converter.SoS_Exporter", + "nbconvert_exporter": "sos_notebook.converter.SoS_Exporter", "pygments_lexer": "sos" + }, + "sos": { + "kernels": [ + [ + "SoS", + "sos", + "sos", + "", + "" + ] + ], + "version": "" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/pecotmr_integration/SuSiE_enloc.ipynb b/code/SoS/pecotmr_integration/SuSiE_enloc.ipynb index d778593e3..6e11aaef5 100644 --- a/code/SoS/pecotmr_integration/SuSiE_enloc.ipynb +++ b/code/SoS/pecotmr_integration/SuSiE_enloc.ipynb @@ -2,105 +2,228 @@ "cells": [ { "cell_type": "markdown", + "id": "dfec32ea", "metadata": { "kernel": "SoS" }, "source": [ "# xQTL-GWAS pairwise enrichment and colocalization\n", "\n", - "Run pairwise enrichment and colocalization between xQTL and GWAS SuSiE fine-mapping results on the toy dataset. The workflow first estimates a global enrichment between the two sets of signals, then performs colocalization (coloc) on the overlapping regions." + "Estimates a global enrichment between xQTL and GWAS SuSiE fine-mapping signals, then colocalises them on the overlapping regions." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "5b5e036f", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Description\n", + "## Overview\n", + "\n", + "This workflow processes fine-mapping results for xQTL, generated by `susie_twas` in the `mnm_regression.ipynb` notebook for cis xQTL, and GWAS fine-mapping results produced by `susie_rss` in the `rss_analysis.ipynb` notebook. It is designed to perform enrichment and colocalization analysis, particularly when fine-mapping results originate from different regions in the case of cis-xQTL and GWAS. The pipeline is capable to integrate and analyze data across these distinct regions. Originally tailored for cis-xQTL and GWAS integration, this pipeline can be applied to other pairwise integrations. An example of such application is in trans analysis, where the fine-mapped regions might be identical between trans-xQTL and GWAS, representing a special case of this broader implementation.\n", + "\n", + "Fine-mapping gives credible sets per trait; it does not say whether an xQTL signal and a\n", + "GWAS signal are the same signal. This step takes both sets of fine-mapping results and\n", + "asks that question directly, using the full posterior rather than a single lead variant per\n", + "locus, which is what makes it robust when a region contains more than one causal variant.\n", + "\n", + "Enrichment \n", + "\n", + "1. **Identify GWAS Blocks:** Select GWAS blocks with top loci from Bellenguez data and using a single variant regression method. Locate the original filenames (`original_data`) for these blocks and map the analysis regions to identify **overlapping gene analysis regions** and corresponding QTL files with top loci table (`condition_top_loci`).\n", + " \n", + "2. **Contexts in xQTL Meta-data:** Find contexts within the xQTL meta-data that include top loci results for each gene. Retrieve the corresponding original xQTL files (`original_data`) by referencing the context meta-data.\n", "\n", - "This workflow processes fine-mapping results for xQTL, generated by `susie_twas` in the `mnm_regression.ipynb` notebook for cis xQTL, and GWAS fine-mapping results produced by `susie_rss` in the `rss_analysis.ipynb` notebook. It is designed to perform enrichment and colocalization analysis, particularly when fine-mapping results originate from different regions in the case of cis-xQTL and GWAS. The pipeline is capable to integrate and analyze data across these distinct regions. Originally tailored for cis-xQTL and GWAS integration, this pipeline can be applied to other pairwise integrations. An example of such application is in trans analysis, where the fine-mapped regions might be identical between trans-xQTL and GWAS, representing a special case of this broader implementation." + "3. **Execute xQTL GWAS Enrichment:** Perform `xqtl_gwas_enrichment` analysis to generate enrichment parameters (a0, a1) and calculate priors (p1, p2, p12).\n", + "\n", + "Coloc\n", + "1. **xQTL Meta-data Contexts:** Within the xQTL meta-data, identify contexts that include top loci results for each gene, indicated by `condition_top_loci`. Retrieve the corresponding original xQTL files (`original_data`) by referring back to the context meta-data. (Optional) Subset the QTL table with specifies gene list. \n", + "\n", + "2. **Original GWAS Files:** Identify GWAS blocks that contain **overlapping top loci variants** for each gene (`block_top_loci`) in above file. Utilize the GWAS list to locate the original filenames (`original_data`) for the identified GWAS block candidates.\n", + "\n", + "3. **Enrichment and Coloc Analysis:** Automatically execute `xqtl_gwas_enrichment` to enable enrichment analysis, generating priors for subsequent coloc analysis through logic defined in `enrichment`. Then, apply `susie_coloc` for coloc analysis on the selected xQTL and GWAS original files, analyzing each gene under each identified condition.\n", + "\n", + "**When to run it.** After `susie_twas` (in `mnm_regression`) for the xQTL side and\n", + "`susie_rss` (in `rss_analysis`) for the GWAS side. Both must be fine-mapped first - this\n", + "step consumes results, it does not produce them." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "590b220d", + "metadata": { + "kernel": "SoS" + }, "source": [ "## Input\n", "\n", - "Lists of SuSiE fine-mapping output objects, in RDS format, of `class(susie)` in R. \n", - "- For xQTL the list is meta-data of format: `chr`, `start`, `end`, `original_data`, `conditions_top_loci`, `block_top_loci` where `original_data` is an RDS file, `conditions_top_loci` is showing which contexts have top loci table (potential signals) `block_top_loci` is the blocks have overlapped top loci variant with xQTL data. That file could be output from `fine_mapping_post_processing/overlap_qtl_gwas`.\n", - "- For GWAS the list is meta-data of format: `chr`, `start`, `end`, `original_data`, `block_top_loci...` where `original_data` is an RDS file. That file could be output from `fine_mapping_post_processing/gwas_results_export`.\n", - "- Context meta is a metafile that shows the analysis_names and the contained contexts. It can be used to identify the corresponding raw data for each context. \n", + "Both workflows read lists of SuSiE fine-mapping output objects in RDS format, of\n", + "`class(susie)` in R, described by two meta-files.\n", "\n", + "- `--xqtl-meta-data` **`input/susie_enloc_data/protocol_example.enloc.xqtl_meta.tsv`**\n", + "(one row per xQTL analysis region. Columns `chr`, `start`, `end`, `original_data`, `conditions_top_loci`, `block_top_loci`, where `original_data` is an RDS file, `conditions_top_loci` shows which contexts have a top-loci table (potential signals), and `block_top_loci` gives the blocks whose overlapped top-loci variants coincide with xQTL data. For enrichment this comes from `fine_mapping_post_processing/cis_results_export`; for coloc from `fine_mapping_post_processing/overlap_qtl_gwas`. The difference is the last two columns, `block_top_loci` and `final_combined_data`, which document overlapped block information at variant level.)\n", "\n", - "- `--gwas_meta_data` \n", - "output from `fine_mapping_post_processing/gwas_results_export`\n", + "```\n", + "#chr\tstart\tend\tregion_id\tTSS\toriginal_data\tcombined_data\tcombined_data_sumstats\t...\n", + "chr1\t20520000\t24080000\tENSG00000142798\t21937309\tprotocol_example.enloc.MiGA_eQTL.ENSG00000142798.univariate_susie_twas_weights.rds,protocol_example.enloc.KNIGHT_pQTL.ENSG00000142798.univariate_susie_twas_weights.rds\tprotocol_example.enloc.qtl.ENSG00000142798.cis_results_db.export.rds\tprotocol_example.enloc.qtl.ENSG00000142798.cis_results_db.export_sumstats.rds\t...\n", + "```\n", + "\n", + "- `--gwas-meta-data` **`input/susie_enloc_data/protocol_example.enloc.gwas_meta.tsv`**\n", + "(one row per GWAS analysis region. Columns `chr`, `start`, `end`, `original_data`, `block_top_loci` and onwards, where `original_data` is an RDS file. Output of `fine_mapping_post_processing/gwas_results_export`.)\n", "\n", "```\n", - "#chr\tstart\tend\tregion_id\tTSS\toriginal_data\tcombined_data\tcombined_data_sumstats\tconditions\tconditions_top_loci\n", - "chr1\t101384274\t104443097\t1_101384274-104443097\tNA\t1_101384274-104443097.susie_rss.rds\tgwas.1_101384274-104443097.cis_results_db.export.rds\tgwas.1_101384274-104443097.cis_results_db.export_sumstats.rds\tNA\tNA\n", - "chr19\t44935906\t46842901\t19_44935906-46842901\tNA\t19_44935906-46842901.susie_rss.rds\tgwas.19_44935906-46842901.cis_results_db.export.rds\tgwas.19_44935906-46842901.cis_results_db.export_sumstats.rds\tAD_Bellenguez_2022,AD_Jansen_2021,AD_Kunkle_Stage1_2019,AD_Wightman_Full_2021,AD_Wightman_Excluding23andMe_2021,AD_Wightman_ExcludingUKBand23andME_2021\tAD_Wightman_ExcludingUKBand23andME_2021.qc_impute,AD_Wightman_ExcludingUKBand23andME_2021.qc_only\tAD_Wightman_ExcludingUKBand23andME_2021.qc_impute\n", + "#chr\tstart\tend\tregion_id\tTSS\toriginal_data\tcombined_data\tcombined_data_sumstats\t...\n", + "chr1\t17351816\t20110062\tchr1_17351816_20110062\tNA\tprotocol_example.enloc.RSS_QC_RAISS_imputed.chr1_17351816_20110062.univariate_susie_rss.rds\tprotocol_example.enloc.gwas.chr1_17351816_20110062.cis_results_db.export.rds\tprotocol_example.enloc.gwas.chr1_17351816_20110062.cis_results_db.export_sumstats.rds\t...\n", + "chr1\t20110062\t22020160\tchr1_20110062_22020160\tNA\tprotocol_example.enloc.RSS_QC_RAISS_imputed.chr1_20110062_22020160.univariate_susie_rss.rds\tprotocol_example.enloc.gwas.chr1_20110062_22020160.cis_results_db.export.rds\tprotocol_example.enloc.gwas.chr1_20110062_22020160.cis_results_db.export_sumstats.rds\t...\n", "```\n", "\n", + "- `--context-meta` **`input/susie_enloc_data/protocol_example.enloc.context_meta.tsv`**\n", + "(maps each analysis name to its cohort and the contexts it contains, so the raw data for each context can be identified)\n", "\n", - "- `--xqtl_meta_data` \n", + "```\n", + "analysis_name\tcohort\tcontext\n", + "KNIGHT_pQTL\tKNIGHT\tKnight_pQTL_brain,Knight_eQTL_brain\n", + "MSBB_eQTL\tMSBB\tBM_10_MSBB_eQTL,BM_22_MSBB_eQTL,BM_36_MSBB_eQTL,BM_44_MSBB_eQTL\n", + "```\n", + "\n", + "- `--qtl-path input/susie_enloc_data` (directory holding the xQTL RDS objects named in the xQTL meta-file)\n", + "- `--gwas-path input/susie_enloc_data` (directory holding the GWAS RDS objects named in the GWAS meta-file)\n", "\n", + "The `-obj` flags are not paths: each names the nested keys to follow inside the RDS\n", + "object to reach the value the pipeline needs.\n", "\n", + "- `--xqtl-finemapping-obj preset_variants_result susie_result_trimmed` (path within the xQTL object to the SuSiE fit)\n", + "- `--xqtl-varname-obj preset_variants_result variant_names` (path within the xQTL object to the variant names)\n", + "- `--xqtl-region-obj region_info grange` (path within the xQTL object to the region definition)\n", + "- `--gwas-finemapping-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed susie_result_trimmed` (path within the GWAS object to the SuSiE fit)\n", + "- `--gwas-varname-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed variant_names` (path within the GWAS object to the variant names)\n", "\n", - "for enrichment: output from `fine_mapping_post_processing/cis_results_export`; for coloc: output from `fine_mapping_post_processing/overlap_qtl_gwas`, the difference between them is without or with last 2 columns: `block_top_loci`, `final_combined_data` to document overlapped block info at variant level\n", + "`susie_coloc` takes two further options:\n", "\n", + "- `--ld-meta-file-path` **`input/ld_reference/protocol_example.ld_meta_file.tsv`**\n", + "(LD reference index used by coloc postprocessing. Columns `chr`, `start`, `end`, `path`. When supplied, coloc credible sets are also reported.)\n", "\n", "```\n", - "#chr\tstart\tend\tregion_id\tTSS\toriginal_data\tcombined_data\tcombined_data_sumstats\tconditions\tconditions_top_loci\tblock_top_loci\tfinal_combined_data\n", - "chr1\t167600000\t171480000\tENSG00000000457\t169894266\tMSBB_eQTL.ENSG00000000457.univariate_susie_twas_weights.rds, ROSMAP_Kellis_eQTL.ENSG00000000457.univariate_susie_twas_weights.rds\tFungen_xQTL.ENSG00000000457.cis_results_db.export.rds\tFungen_xQTL.ENSG00000000457.cis_results_db.export_sumstats.rds\tBM_10_MSBB_eQTL,BM_22_MSBB_eQTL,BM_36_MSBB_eQTL,BM_44_MSBB_eQTL,Ast_Kellis_eQTL\tBM_22_MSBB_eQTL,BM_44_MSBB_eQTL\t\t\n", - "chr19\t41840000\t47960000\tENSG00000130203\t44905790\tROSMAP_Kellis_eQTL.ENSG00000130203.univariate_susie_twas_weights.rds, ROSMAP_Bennett_Klein_pQTL.ENSG00000130203.univariate_susie_twas_weights.rds\tFungen_xQTL.ENSG00000130203.cis_results_db.export.rds\tFungen_xQTL.ENSG00000130203.cis_results_db.export_sumstats.rds\tMic_Kellis_eQTL,DLPFC_Bennett_pQTL\tMic_Kellis_eQTL\t19_44935906-46842901\tFungen_xQTL.ENSG00000130203.cis_results_db.export.overlapped.gwas.rds\n", - "chr20\t49934867\t53560000\tENSG00000000419\t50958554\tMSBB_eQTL.ENSG00000000419.univariate_susie_twas_weights.rds\tFungen_xQTL.ENSG00000000419.cis_results_db.export.rds\tFungen_xQTL.ENSG00000000419.cis_results_db.export_sumstats.rds\tBM_10_MSBB_eQTL,BM_22_MSBB_eQTL\tBM_22_MSBB_eQTL\tFungen_xQTL.ENSG00000000419.cis_results_db.export.overlapped.gwas.rds\n", + "#chr\tstart\tend\tpath\n", + "chr1\t16103\t2888443\tchr1/protocol_example.LD.chr1\n", + "chr1\t2888443\t4320284\tchr1/protocol_example.LD.chr1\n", "```\n", - "- `--context_meta` \n", "\n", - "should be updated as more analysis is done, we used analysis_name and context in this analysis\n", - "```\n", - "analysis_name\tcohort\tcontext\n", - "KNIGHT_pQTL\tKNIGHT\tKnight_pQTL_brain,Knight_eQTL_brain\n", - "MSBB_eQTL\tMSBB\tBM_10_MSBB_eQTL,BM_22_MSBB_eQTL,BM_36_MSBB_eQTL,BM_44_MSBB_eQTL\n", - "MIGA_eQTL\tMIGA\tMiGA_GTS_eQTL,MiGA_SVZ_eQTL,MiGA_THA_eQTL\n", - "```" + "- `--skip-enrich` (omit the enrichment prior. Without it, coloc reads `/..enrichment.rds` to tune its prior, so `xqtl_gwas_enrichment` must have been run first.)\n", + "- `--cwd output/susie_coloc` (working directory all outputs are written under. Defaults to `output`.)" ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "57f29a41", + "metadata": { + "kernel": "SoS" + }, "source": [ - "## Analytical Logic\n- Enrichment \n\n1. **Identify GWAS Blocks:** Select GWAS blocks with top loci from Bellenguez data and using a single variant regression method. Locate the original filenames (`original_data`) for these blocks and map the analysis regions to identify **overlapping gene analysis regions** and corresponding QTL files with top loci table (`condition_top_loci`).\n \n2. **Contexts in xQTL Meta-data:** Find contexts within the xQTL meta-data that include top loci results for each gene. Retrieve the corresponding original xQTL files (`original_data`) by referencing the context meta-data.\n\n3. **Execute xQTL GWAS Enrichment:** Perform `xqtl_gwas_enrichment` analysis to generate enrichment parameters (a0, a1) and calculate priors (p1, p2, p12).\n\n- Coloc\n1. **xQTL Meta-data Contexts:** Within the xQTL meta-data, identify contexts that include top loci results for each gene, indicated by `condition_top_loci`. Retrieve the corresponding original xQTL files (`original_data`) by referring back to the context meta-data. (Optional) Subset the QTL table with specifies gene list. \n\n2. **Original GWAS Files:** Identify GWAS blocks that contain **overlapping top loci variants** for each gene (`block_top_loci`) in above file. Utilize the GWAS list to locate the original filenames (`original_data`) for the identified GWAS block candidates.\n\n3. **Enrichment and Coloc Analysis:** Automatically execute `xqtl_gwas_enrichment` to enable enrichment analysis, generating priors for subsequent coloc analysis through logic defined in `enrichment`. Then, apply `susie_coloc` for coloc analysis on the selected xQTL and GWAS original files, analyzing each gene under each identified condition." + "## Output\n", + "\n", + "- **`/..enrichment.rds`** (`xqtl_gwas_enrichment`)\n", + "(one global enrichment estimate per GWAS and xQTL-context pair, combining all input data for that context)\n", + "\n", + "```r\n", + "enrich <- readRDS(\"output/xqtl_gwas_enrichment/protocol_example.enloc.protocol_example.enloc.Knight_eQTL_brain.enrichment.rds\")\n", + "\n", + "str(enrich)\n", + "# data.frame: 1 obs. of 6 variables:\n", + "# $ gwasStudy : chr \"AD_Bellenguez_2022\"\n", + "# $ qtlStudy : chr \"protocol_example.enloc.protocol_example.enloc\"\n", + "# $ qtlContext : chr \"Knight_eQTL_brain\"\n", + "# $ enrichment : num NA\n", + "# $ enrichmentSe : num NA\n", + "# $ enrichmentLogOdds : num NA\n", + "```\n", + "\n", + "> **Note on toy data**: one row per gwas/qtl-context pair. Enrichment values are `NA` here because a single gene x single GWAS block does not give the underlying logistic-regression enrichment model enough data to fit; this is expected for the toy MWE, not a pipeline error. Reliable enrichment estimates require many gene x GWAS-region pairs.\n", + "\n", + "- **`/susie_coloc/.@.coloc.rds`** (`susie_coloc`)\n", + "(colocalisation results for the regions of interest, one file per context and gene. When `--ld-meta-file-path` is given, coloc credible sets are reported too.)\n", + "\n", + "```r\n", + "res <- readRDS(\"output/susie_coloc/susie_coloc/protocol_example.enloc.Knight_eQTL_brain@ENSG00000142798.coloc.rds\")\n", + "\n", + "length(res) # 1\n", + "names(res) # [1] \"ENSG00000142798\"\n", + "\n", + "str(res, max.level = 2)\n", + "# List of 1\n", + "# $ ENSG00000142798:List of 2\n", + "# ..$ (unnamed) : chr \"No coloc results due to the absence of a GWAS log Bayes factor matrix filtered by prior tolerance.\"\n", + "# ..$ analysis_region: chr \"chr1_20110062_22020160\"\n", + "\n", + "res$ENSG00000142798$analysis_region # \"chr1_20110062_22020160\"\n", + "```\n", + "\n", + "The output is a named list with one entry per gene. Each gene entry contains:\n", + "\n", + "- **`[[1]]` (unnamed)**: the colocalization result — either a data.frame of PP values (positive result) or a character string explaining why coloc was skipped.\n", + "- **`$analysis_region`**: the genomic block ID (e.g. `\"chr1_20110062_22020160\"`) that was analyzed.\n", + "\n", + "When colocalization runs successfully, `res[[gene]][[1]]` is a data.frame with one row per SuSiE effect pair (xQTL effect × GWAS effect) and columns:\n", + "\n", + "| Column | Description |\n", + "|--------|-------------|\n", + "| `nsnps` | Number of variants in the shared analysis window |\n", + "| `PP.H0.abf` | Posterior probability: neither trait has a causal variant in this region |\n", + "| `PP.H1.abf` | Posterior probability: only xQTL has a causal variant |\n", + "| `PP.H2.abf` | Posterior probability: only GWAS has a causal variant |\n", + "| `PP.H3.abf` | Posterior probability: both have causal variants, but different ones |\n", + "| `PP.H4.abf` | Posterior probability: both traits share the same causal variant (colocalization) |\n", + "| `hit1` | Top variant ID from the xQTL credible set |\n", + "| `hit2` | Top variant ID from the GWAS credible set |\n", + "\n", + "PP.H0 + PP.H1 + PP.H2 + PP.H3 + PP.H4 = 1. **PP.H4.abf > 0.8** is the standard threshold for strong colocalization evidence.\n", + "\n", + "> **Note on toy data**: this example returns a message string instead of a data.frame because the toy GWAS fine-mapping signal in this region is too weak (max PIP ≈ 0.04, no credible set). This is an expected negative result for a toy dataset, not a pipeline error." ] }, { "cell_type": "markdown", + "id": "624e119b", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example\n", + "\n", + "The two workflows are independent as run here. `xqtl_gwas_enrichment` estimates the\n", + "global enrichment and `susie_coloc` colocalises, and the command below passes\n", + "`--skip-enrich` so coloc does not read the enrichment estimate. On real data, dropping\n", + "that flag lets coloc pick up `..enrichment.rds` and use it to tune its\n", + "prior; SoS will not run enrichment for you, so run it first if you want that." ] }, { "cell_type": "markdown", + "id": "d44efa79", "metadata": { "kernel": "SoS" }, "source": [ - "**Step 1. Enrichment.** Estimate the global xQTL-GWAS enrichment. `get_analysis_regions` first collects the overlapped regions per gene/block, then `xqtl_gwas_enrichment` produces the enrichment object used as the prior for coloc." + "### Global xQTL-GWAS enrichment\n", + "\n", + "`xqtl_gwas_enrichment` estimates one enrichment value per GWAS and xQTL-context pair,\n", + "combining all input data for that context." ] }, { "cell_type": "markdown", - "metadata": {}, + "id": "d6c033b9", + "metadata": { + "kernel": "SoS" + }, "source": [ - "**Timing:** ~varies on typical compute infrastructure." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, + "id": "ccf487ea", "metadata": { "kernel": "Bash" }, @@ -122,39 +245,31 @@ }, { "cell_type": "markdown", - "metadata": {}, + "id": "26c1fff4", + "metadata": { + "kernel": "SoS" + }, "source": [ - "### Output\n", - "Output file: `{cwd}/{name}.{context}.enrichment.rds`\n", - "\n", - "```r\n", - "enrich <- readRDS(\"output/xqtl_gwas_enrichment/protocol_example.enloc.protocol_example.enloc.Knight_eQTL_brain.enrichment.rds\")\n", - "\n", - "str(enrich)\n", - "# data.frame: 1 obs. of 6 variables:\n", - "# $ gwasStudy : chr \"AD_Bellenguez_2022\"\n", - "# $ qtlStudy : chr \"protocol_example.enloc.protocol_example.enloc\"\n", - "# $ qtlContext : chr \"Knight_eQTL_brain\"\n", - "# $ enrichment : num NA\n", - "# $ enrichmentSe : num NA\n", - "# $ enrichmentLogOdds : num NA\n", - "```\n", + "### Pairwise colocalisation\n", "\n", - "> **Note on toy data**: one row per gwas/qtl-context pair. Enrichment values are `NA` here because a single gene x single GWAS block does not give the underlying logistic-regression enrichment model enough data to fit; this is expected for the toy MWE, not a pipeline error. Reliable enrichment estimates require many gene x GWAS-region pairs." + "`susie_coloc` runs colocalisation on the overlapping regions, analysing each gene under\n", + "each identified condition." ] }, { "cell_type": "markdown", + "id": "c2f95f20", "metadata": { "kernel": "SoS" }, "source": [ - "**Step 2. Coloc.** Run colocalization on the overlapping regions. `--skip-enrich` reuses the enrichment object produced in Step 1, so the `*enrichment.rds` file from that step must be present in `--cwd`. Otherwise enrichment is triggered automatically. `get_overlapped_analysis_regions` selects the regions with overlapping variants before `susie_coloc` runs." + "**Timing**: TBD (on toy dataset)" ] }, { "cell_type": "code", "execution_count": null, + "id": "7982753d", "metadata": { "kernel": "Bash" }, @@ -178,31 +293,113 @@ }, { "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Output\n\nOutput file: `{cwd}/{step_name}/{name}.{context}@{gene}.coloc.rds`\n\n```r\nres <- readRDS(\"output/output/susie_coloc/susie_coloc/protocol_example.enloc.Knight_eQTL_brain@ENSG00000142798.coloc.rds\")\n\nlength(res) # 1\nnames(res) # [1] \"ENSG00000142798\"\n\nstr(res, max.level = 2)\n# List of 1\n# $ ENSG00000142798:List of 2\n# ..$ (unnamed) : chr \"No coloc results due to the absence of a GWAS log Bayes factor matrix filtered by prior tolerance.\"\n# ..$ analysis_region: chr \"chr1_20110062_22020160\"\n\nres$ENSG00000142798$analysis_region # \"chr1_20110062_22020160\"\n```\n\nThe output is a named list with one entry per gene. Each gene entry contains:\n\n- **`[[1]]` (unnamed)**: the colocalization result — either a data.frame of PP values (positive result) or a character string explaining why coloc was skipped.\n- **`$analysis_region`**: the genomic block ID (e.g. `\"chr1_20110062_22020160\"`) that was analyzed.\n\nWhen colocalization runs successfully, `res[[gene]][[1]]` is a data.frame with one row per SuSiE effect pair (xQTL effect × GWAS effect) and columns:\n\n| Column | Description |\n|--------|-------------|\n| `nsnps` | Number of variants in the shared analysis window |\n| `PP.H0.abf` | Posterior probability: neither trait has a causal variant in this region |\n| `PP.H1.abf` | Posterior probability: only xQTL has a causal variant |\n| `PP.H2.abf` | Posterior probability: only GWAS has a causal variant |\n| `PP.H3.abf` | Posterior probability: both have causal variants, but different ones |\n| `PP.H4.abf` | Posterior probability: both traits share the same causal variant (colocalization) |\n| `hit1` | Top variant ID from the xQTL credible set |\n| `hit2` | Top variant ID from the GWAS credible set |\n\nPP.H0 + PP.H1 + PP.H2 + PP.H3 + PP.H4 = 1. **PP.H4.abf > 0.8** is the standard threshold for strong colocalization evidence.\n\n> **Note on toy data**: this example returns a message string instead of a data.frame because the toy GWAS fine-mapping signal in this region is too weak (max PIP ≈ 0.04, no credible set). This is an expected negative result for a toy dataset, not a pipeline error." - ] - }, - { - "cell_type": "markdown", + "id": "7c94a150", "metadata": { "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, + "id": "cli-cmd-SuSiE_enloc", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/SuSiE_enloc.ipynb -h" ] }, + { + "cell_type": "markdown", + "id": "55048be5", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run /xqtl-protocol/code/pecotmr_integration/SuSiE_enloc.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " get_analysis_regions\n", + " get_overlapped_analysis_regions\n", + " xqtl_gwas_enrichment\n", + " susie_coloc\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Workdir\n", + " --gwas-meta-data VAL (as path, required)\n", + " A list of file paths for fine-mapped GWAS results.\n", + " --xqtl-meta-data VAL (as path, required)\n", + " A list of file paths for fine-mapped xQTL results.\n", + " --region-list . (as path)\n", + " Optional: if a region list is provide the analysis will be focused on provided region. The LAST column of this list\n", + " will contain the ID of regions to focus on Otherwise, all regions with both genotype and phenotype files will be\n", + " analyzed\n", + " --region-name (as list)\n", + " Optional: if a region name is provided the analysis would be focused on the union of provides region list and region\n", + " names\n", + " --name f\"{xqtl_meta_data:bnn}.{gwas_meta_data:bnn}\"\n", + "\n", + " It is required to input the name of the analysis\n", + " --container ''\n", + " --job-size 200 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5m\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected: quite large for enrichment analysis but small for xQTL colocalization\n", + " --numThreads 1 (as int)\n", + " Number of threads\n", + " --xqtl-finemapping-obj (as list)\n", + " Optional table name in xQTL RDS files to get fine mapping results (eg 'susie_result_trimmed ').\n", + " --xqtl-varname-obj (as list)\n", + " Optional table name in xQTL RDS files to get variable names (eg ' variant_names ').\n", + " --gwas-finemapping-obj (as list)\n", + " Optional table name in GWAS RDS files to get fine mapping results (eg 'AD_Bellenguez_2022 single_effect_regression\n", + " susie_result_trimmed ').\n", + " --gwas-varname-obj (as list)\n", + " Optional table name in GWAS RDS files to get variable names(eg 'AD_Bellenguez_2022 single_effect_regression\n", + " variant_names ').\n", + " --xqtl-region-obj (as list)\n", + " Optional table name in xQTL RDS files to get region info (eg 'susie_result_trimmed region_info grange ').\n", + " --gwas-region-obj (as list)\n", + " Optional table name in GWAS RDS files to get region info (eg 'AD_Bellenguez_2022 single_effect_regression region_info\n", + " grange ').\n", + " --gwas-path ''\n", + " Directory path for GWAS orignal finemapping results\n", + " --qtl-path ''\n", + " Directory path for xQTL orignal finemapping results\n", + " --context-meta . (as path)\n", + " a meta file showing the context and corresponding analysis_name\n", + " --[no-]minp (default to False)\n", + " use conditions_top_loci_minp column or not, which can reduce a lot computing resource by pick top 1 isoform\n", + "\n", + "Sections\n", + " get_analysis_regions: get overlapped regions by gene and block region for enrichment analysis\n", + " get_overlapped_analysis_regions: get overlapped regions from flatten table, to get the regions with overlapped variants and select those\n", + " regions for coloc analysis\n", + " xqtl_gwas_enrichment:\n", + " susie_coloc:\n", + " Workflow Options:\n", + " --[no-]skip-enrich (default to False)\n", + " depends: sos_step(\"xqtl_gwas_enrichment\") #changed skip enrichment or not\n", + " --[no-]filter-lbf-cs (default to False)\n", + " filter lbf by cs as default in susie coloc. default is False means filtering by V > prior_tol\n", + " --ld-meta-file-path . (as path)\n", + " ld reference path for postprocessing\n", + "```" + ] + }, { "cell_type": "markdown", "id": "3841a4cd-738c-4882-9863-9688fefbcd23", @@ -409,13 +606,6 @@ " ${('--enrichment '+cwd.absolute().joinpath(name + \".\" + _jobs[\"unit_id\"].split(\"@\")[0] + \".enrichment.rds\").as_posix()) if not skip_enrich else ''} \\\n", " --output ${_output}\n" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nSee the **Output** sections under Step 1 and Step 2 above for actual output structures with real field names and toy dataset values." - ] } ], "metadata": { diff --git a/code/SoS/pecotmr_integration/gwas_integration.ipynb b/code/SoS/pecotmr_integration/gwas_integration.ipynb new file mode 100644 index 000000000..8dd838de0 --- /dev/null +++ b/code/SoS/pecotmr_integration/gwas_integration.ipynb @@ -0,0 +1,456 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "fda26cf0", + "metadata": { + "kernel": "SoS" + }, + "source": "# GWAS and xQTL integration mini-protocol\nIntegrate molecular-QTL results with GWAS using enrichment, colocalization, TWAS, cTWAS, quantile TWAS, or INTACT." + }, + { + "cell_type": "markdown", + "id": "8d1974d1", + "metadata": { + "kernel": "SoS" + }, + "source": "#### Miniprotocol Timing\nThis is the total duration for the selected route; module-specific timings appear on their respective pages.\nTiming: TBD" + }, + { + "cell_type": "markdown", + "id": "6666b5c7", + "metadata": { + "kernel": "SoS" + }, + "source": "## Overview\nThis mini-protocol presents complementary routes for connecting molecular-QTL and GWAS evidence. Steps 1\u20132 call [`SuSiE_enloc.ipynb`](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/SuSiE_enloc.html), steps 3\u20137 call [`twas_ctwas.ipynb`](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html), and step 8 calls [`intact.ipynb`](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/intact.html).\nEnrichment, colocalization, standard TWAS, cTWAS, quantile TWAS, and INTACT answer different questions and are not one mandatory chain. Only cTWAS steps 4\u20136 must be run sequentially." + }, + { + "cell_type": "markdown", + "id": "1a03f7c3", + "metadata": { + "kernel": "SoS" + }, + "source": "## Steps\nChoose a route before running commands; the commands are not one mandatory chain.\n| Analysis goal | Commands to run, in order | Inputs |\n|---|---|---|\n| Estimate global xQTL\u2013GWAS enrichment | 1 | `input/susie_enloc_data/protocol_example.enloc.gwas_meta.tsv`; `input/susie_enloc_data/protocol_example.enloc.xqtl_meta.tsv`; fine-mapping objects referenced by those tables |\n| Test pairwise colocalization | 2 | The same GWAS and xQTL fine-mapping metadata as step 1 |\n| Run standard TWAS and MR | 3 | `input/twas/protocol_example.twas.gwas_meta.tsv`; `input/twas/protocol_example.twas.xqtl_meta.tsv`; `input/ld_reference/protocol_example.ld_meta_file.tsv`; `input/twas/protocol_example.twas.LD_blocks.chr22.bed`; `input/twas/protocol_example.twas.data_type_table.txt` |\n| Fine-map genes and SNPs jointly with cTWAS | 4 \u2192 5 \u2192 6 | GWAS, xQTL, LD-reference, and region metadata used by the TWAS route |\n| Run quantile TWAS | 7 | The TWAS inputs, with quantile-specific molecular-QTL weights |\n| Combine PTWAS and fastenloc evidence | 8 | `input/twas/protocol_example.ptwas.output`; `input/twas/protocol_example.fastenloc.gene.out` |\n\nRun only the commands for the selected route. Steps 4\u20136 are one chained cTWAS analysis; the other numbered steps are independent alternatives." + }, + { + "cell_type": "markdown", + "id": "35c02971", + "metadata": { + "kernel": "SoS" + }, + "source": "### 1. [Estimate global xQTL\u2013GWAS enrichment](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/SuSiE_enloc.html)\n\n**What it does:** Estimates whether fine-mapped xQTL signals are enriched among GWAS signals across many regions and molecular contexts." + }, + { + "cell_type": "markdown", + "id": "f5a324e3", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a14fe1d5", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/SuSiE_enloc.ipynb xqtl_gwas_enrichment \\\n", + " --gwas-meta-data input/susie_enloc_data/protocol_example.enloc.gwas_meta.tsv \\\n", + " --xqtl-meta-data input/susie_enloc_data/protocol_example.enloc.xqtl_meta.tsv \\\n", + " --xqtl-finemapping-obj preset_variants_result susie_result_trimmed \\\n", + " --xqtl-varname-obj preset_variants_result variant_names \\\n", + " --gwas-finemapping-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed susie_result_trimmed \\\n", + " --gwas-varname-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed variant_names \\\n", + " --xqtl-region-obj region_info grange \\\n", + " --qtl-path input/susie_enloc_data \\\n", + " --gwas-path input/susie_enloc_data \\\n", + " --context-meta input/susie_enloc_data/protocol_example.enloc.context_meta.tsv \\\n", + " --cwd output/xqtl_gwas_enrichment" + ] + }, + { + "cell_type": "markdown", + "id": "aa91abf7", + "metadata": { + "kernel": "SoS" + }, + "source": "### 2. [Test pairwise colocalization](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/SuSiE_enloc.html)\n\n**What it does:** Tests whether an xQTL and GWAS association in the same region are consistent with a shared causal variant." + }, + { + "cell_type": "markdown", + "id": "8870f517", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c39af683", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/SuSiE_enloc.ipynb susie_coloc \\\n", + " --gwas-meta-data input/susie_enloc_data/protocol_example.enloc.gwas_meta.tsv \\\n", + " --xqtl-meta-data input/susie_enloc_data/protocol_example.enloc.xqtl_meta.tsv \\\n", + " --xqtl-finemapping-obj preset_variants_result susie_result_trimmed \\\n", + " --xqtl-varname-obj preset_variants_result variant_names \\\n", + " --gwas-finemapping-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed susie_result_trimmed \\\n", + " --gwas-varname-obj AD_Bellenguez_2022 RSS_QC_RAISS_imputed variant_names \\\n", + " --xqtl-region-obj region_info grange \\\n", + " --qtl-path input/susie_enloc_data \\\n", + " --gwas-path input/susie_enloc_data \\\n", + " --context-meta input/susie_enloc_data/protocol_example.enloc.context_meta.tsv \\\n", + " --ld-meta-file-path input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --skip-enrich \\\n", + " --cwd output/susie_coloc" + ] + }, + { + "cell_type": "markdown", + "id": "dd5628b2", + "metadata": { + "kernel": "SoS" + }, + "source": "### 3. [Run standard TWAS and MR](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html)\n\n**What it does:** Tests genetically predicted molecular traits for association with the GWAS trait and reports regional Mendelian-randomization results." + }, + { + "cell_type": "markdown", + "id": "4dd7a318", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce2c93eb", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb twas \\\n", + " --cwd output --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --ld_reference_sample_size 17000 \\\n", + " --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed \\\n", + " --xqtl_type_table input/twas/protocol_example.twas.data_type_table.txt \\\n", + " --rsq_pval_cutoff 0.05 --rsq_cutoff 0.01 \\\n", + " --region-name chr22_10000000_19000000" + ] + }, + { + "cell_type": "markdown", + "id": "8ce845a0", + "metadata": { + "kernel": "SoS" + }, + "source": "### 4. [Assemble cTWAS region data](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html)\n\n**What it does:** Harmonizes GWAS statistics, xQTL weights, and LD for the regions that will enter cTWAS fine-mapping." + }, + { + "cell_type": "markdown", + "id": "27e38f80", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "43a84936", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb ctwas \\\n", + " --cwd output --name protocol_example \\\n", + " --thin 1 --prior_var_structure shared_all \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed \\\n", + " --twas_weight_cutoff 0 \\\n", + " --region-name chr22_10000000_19000000" + ] + }, + { + "cell_type": "markdown", + "id": "4c1dd8ec", + "metadata": { + "kernel": "SoS" + }, + "source": "### 5. [Estimate cTWAS global parameters](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html)\n\n**What it does:** Reuses the assembled inputs from step 4 to estimate the prior parameters required by cTWAS." + }, + { + "cell_type": "markdown", + "id": "912f0d33", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3204beb", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb ctwas \\\n", + " --run_param_est --skip_assembly --thin 1 \\\n", + " --prior_var_structure shared_all \\\n", + " --cwd output --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed" + ] + }, + { + "cell_type": "markdown", + "id": "1ebec301", + "metadata": { + "kernel": "SoS" + }, + "source": "### 6. [Fine-map genes and SNPs with cTWAS](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html)\n\n**What it does:** Uses the assembled inputs and estimated parameters to calculate joint posterior inclusion probabilities for genes and SNPs." + }, + { + "cell_type": "markdown", + "id": "bb946a41", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cdbb7381", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb ctwas \\\n", + " --run_finemapping --skip_assembly \\\n", + " --prior_var_structure shared_all \\\n", + " --cwd output --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed \\\n", + " --region-name chr22_10000000_19000000" + ] + }, + { + "cell_type": "markdown", + "id": "7b65a05c", + "metadata": { + "kernel": "SoS" + }, + "source": "### 7. [Run quantile TWAS](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html)\n\n**What it does:** Runs the quantile-TWAS route for molecular-trait effects that may differ across the phenotype distribution." + }, + { + "cell_type": "markdown", + "id": "012a09d3", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "454b7d13", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb quantile_twas \\\n", + " --cwd output --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --ld_reference_sample_size 17000 \\\n", + " --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed \\\n", + " --xqtl_type_table input/twas/protocol_example.twas.data_type_table.txt \\\n", + " --region-name chr22_10000000_19000000" + ] + }, + { + "cell_type": "markdown", + "id": "37b756f9", + "metadata": { + "kernel": "SoS" + }, + "source": "### 8. [Combine PTWAS and colocalization with INTACT](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/intact.html)\n\n**What it does:** Combines PTWAS z-scores with fastenloc colocalization probabilities to prioritize genes supported by both association and colocalization evidence." + }, + { + "cell_type": "markdown", + "id": "1d22bde4", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb2b8e40", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/intact.ipynb intact \\\n", + " --fastenloc-file input/twas/protocol_example.fastenloc.gene.out \\\n", + " --ptwas-file input/twas/protocol_example.ptwas.output \\\n", + " --tissue DLPFC \\\n", + " --cwd output/intact" + ] + }, + { + "cell_type": "markdown", + "id": "3fa6bdb9", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output Files\n", + "\n", + "| Step | Relative path | Contents |\n", + "|---:|---|---|\n", + "| 1 | `output/xqtl_gwas_enrichment/..enrichment.rds` | Global enrichment estimate for each GWAS\u2013xQTL-context pair |\n", + "| 2 | `output/susie_coloc/susie_coloc/.@.coloc.rds` | Regional SuSiE colocalization probabilities |\n", + "| 3 | `output/twas/twas/...twas.rds` | Per-gene TWAS results |\n", + "| 3 | `output/twas/twas/..twas.tsv.gz` | Regional TWAS summary |\n", + "| 3 | `output/twas/twas/..mr_result.tsv.gz` | Regional Mendelian-randomization summary |\n", + "| 4 | `output/ctwas/.ctwas_inputs.rds` | Assembled cTWAS inputs |\n", + "| 5 | `output/ctwas/.ctwas_est.rds` | Estimated cTWAS prior parameters |\n", + "| 6 | `output/ctwas/.ctwas_finemap.rds` | Joint gene and SNP fine-mapping results |\n", + "| 7 | `output/quantile_twas/.*` | Quantile-TWAS results, with stems determined by the analysis regions |\n", + "| 8 | `output/intact/DLPFC.INTACT.rds` | Gene-level INTACT posterior probabilities |\n", + "\n", + "Some workflows derive context, gene, or region identifiers from metadata, so their output contains one file per analysis unit." + ] + }, + { + "cell_type": "markdown", + "id": "8373ad31", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", + "\n", + "Enrichment evaluates global sharing between molecular-QTL and GWAS signals, whereas colocalization evaluates individual regions. TWAS prioritizes traits whose genetically predicted levels associate with the GWAS outcome; cTWAS jointly fine-maps genes and SNPs; INTACT prioritizes genes supported by both PTWAS and colocalization.\n", + "\n", + "These analyses provide complementary evidence, not interchangeable proof of causality. Interpret prioritized genes together with fine-mapping quality, LD, prediction performance, colocalization support, tissue relevance, and sensitivity analyses." + ] + }, + { + "cell_type": "markdown", + "id": "334b2a49", + "metadata": { + "kernel": "SoS" + }, + "source": "## Command interface" + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cb204a90", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/SuSiE_enloc.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d68fe976", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb -h" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f22b8d94", + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/intact.ipynb -h" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "SoS", + "language": "sos", + "name": "sos" + }, + "language_info": { + "codemirror_mode": "sos", + "file_extension": ".sos", + "mimetype": "text/x-sos", + "name": "sos", + "nbconvert_exporter": "sos_notebook.converter.SoS_Exporter", + "pygments_lexer": "sos" + }, + "sos": { + "kernels": [ + [ + "SoS", + "sos", + "sos", + "", + "" + ] + ], + "version": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file diff --git a/code/SoS/pecotmr_integration/intact.ipynb b/code/SoS/pecotmr_integration/intact.ipynb index fc83629a2..83c14423b 100644 --- a/code/SoS/pecotmr_integration/intact.ipynb +++ b/code/SoS/pecotmr_integration/intact.ipynb @@ -17,13 +17,15 @@ "kernel": "SoS" }, "source": [ - "## Methods\n", + "## Overview\n", "\n", "The posterior probabilities in the INTACT function are calculated through the following steps:\n", "\n", "- **Compute Bayes Factors:** The function converts TWAS z-scores into Bayes factors by computing a grid of Bayes factors using different values of `K` (a vector of values over which Bayesian model averaging is performed, default `c(1,2,4,8,16)`), then performing Bayesian model averaging using the log sum exp trick.\n", "- **Compute Prior Probabilities:** The `prior_fun` function converts `GLCP` into prior probabilities. `prior_fun` is set as linear by default.\n", - "- **Compute Posterior Probabilities.**" + "- **Compute Posterior Probabilities.**\n", + "\n", + "**When to run it.** After PTWAS and fastenloc have both been run on the same gene set, to combine their evidence." ] }, { @@ -39,7 +41,8 @@ "- `--tissue`: tissue / dataset label used to name the output (e.g. `DLPFC`).\n", "- `--alpha`: FDR significance threshold (default `0.05`).\n", "\n", - "The genes are matched between the two inputs by joining on the gene name." + "The genes are matched between the two inputs by joining on the gene name.\n", + "- `--cwd`: the directory outputs are written to." ] }, { @@ -50,16 +53,18 @@ "source": [ "## Output\n", "\n", - "An RDS file `/.INTACT.rds` containing the merged PTWAS + fastenloc table augmented with the INTACT posterior probability (`intact_pip`) and an FDR significance flag (`fdr_sig`), sorted by descending posterior probability." - ] - }, - { - "cell_type": "markdown", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Steps" + "- `{cwd}/{tissue}.INTACT.rds` - the merged PTWAS and fastenloc table with the INTACT posterior probability added, sorted by descending posterior. Example `output/intact/DLPFC.INTACT.rds`, a data frame of 40 genes and 5 columns:\n", + "\n", + " ```\n", + " 'data.frame': 40 obs. of 5 variables:\n", + " $ gene : chr \"GENE021\" \"GENE023\" \"GENE004\" \"GENE034\" ...\n", + " $ zscore : num -6.55 -4.45 4.03 -3.41 -3.61 ...\n", + " $ GLCP : num 0.9975 0.0909 0.2677 0.8608 0.3994 ...\n", + " $ intact_pip: num 1 0.983 0.975 0.963 0.941 ...\n", + " $ fdr_sig : logi TRUE TRUE TRUE TRUE TRUE FALSE ...\n", + " ```\n", + "\n", + " `zscore` comes from the PTWAS input and `GLCP` from fastenloc; `intact_pip` is the posterior this module computes from the two, and `fdr_sig` flags the genes passing `--alpha`." ] }, { @@ -68,7 +73,9 @@ "kernel": "SoS" }, "source": [ - "**Step 1.** Run INTACT on the PTWAS and fastenloc output for one tissue." + "## Minimal Working Example\n", + "\n", + "One workflow, `intact`, run once per tissue. It requires the R package `INTACT` from Bioconductor, provided by the pipeline environment as `bioconductor-intact`." ] }, { @@ -77,7 +84,7 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~1-2 min on typical compute infrastructure." + "**Timing**: ~1-2 min (on toy dataset)" ] }, { @@ -101,7 +108,7 @@ "kernel": "SoS" }, "source": [ - "> **Environment note.** This step requires the R package `INTACT` (Bioconductor), now provided by the pipeline environment (`bioconductor-intact`). The `intact` workflow above runs end-to-end and is covered by `tests/notebooks/pecotmr_integration/test_intact.py` against a small committed PTWAS + fastenloc fixture; supply real PTWAS and fastenloc output files for a production run." + "> **Environment note.** This step requires the R package `INTACT` (Bioconductor), provided by the pipeline environment as `bioconductor-intact`. Supply real PTWAS and fastenloc output files for a production run." ] }, { @@ -110,7 +117,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -130,7 +137,40 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation" + "```\n", + "usage: sos run code/SoS/pecotmr_integration/intact.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " intact\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " Workdir\n", + " --modular-script-dir code/script (as path)\n", + " Directory of the modular analysis scripts (code/script)\n", + " --fastenloc-file ''\n", + " fastenloc output\n", + " --ptwas-file ''\n", + " ptwas output\n", + " --tissue ''\n", + " dataset\n", + " --alpha 0.05 (as float)\n", + " --QTL eQTL\n", + " QTL data type\n", + " --container ''\n", + " --job-size 1 (as int)\n", + " --walltime 5h\n", + " --mem 8G\n", + " --numThreads 1 (as int)\n", + "\n", + "Sections\n", + " intact:\n", + "```" ] }, { @@ -139,9 +179,7 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "## Workflow implementation" ] }, { @@ -151,7 +189,27 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\n# Workdir\nparameter: cwd = path(\"output\")\n# Directory of the modular analysis scripts (code/script)\nparameter: modular_script_dir = path('code/script')\n# fastenloc output\nparameter: fastenloc_file = \"\"\n# ptwas output\nparameter: ptwas_file = \"\"\n# dataset \nparameter: tissue = ''\nparameter: alpha = 0.05\n# QTL data type\nparameter: QTL = 'eQTL'\nparameter: container = ''\nparameter: job_size = 1\nparameter: walltime = \"5h\"\nparameter: mem = \"8G\"\nparameter: numThreads = 1\n" + "source": [ + "[global]\n", + "# Workdir\n", + "parameter: cwd = path(\"output\")\n", + "# Directory of the modular analysis scripts (code/script)\n", + "parameter: modular_script_dir = path('code/script')\n", + "# fastenloc output\n", + "parameter: fastenloc_file = \"\"\n", + "# ptwas output\n", + "parameter: ptwas_file = \"\"\n", + "# dataset \n", + "parameter: tissue = ''\n", + "parameter: alpha = 0.05\n", + "# QTL data type\n", + "parameter: QTL = 'eQTL'\n", + "parameter: container = ''\n", + "parameter: job_size = 1\n", + "parameter: walltime = \"5h\"\n", + "parameter: mem = \"8G\"\n", + "parameter: numThreads = 1\n" + ] }, { "cell_type": "code", @@ -160,7 +218,18 @@ "kernel": "SoS" }, "outputs": [], - "source": "[intact]\ninput: ptwas_file, fastenloc_file\noutput: f'{cwd}/{tissue}.INTACT.rds'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand = \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout', container = container\n Rscript ${modular_script_dir}/pecotmr_integration/intact.R \\\n --ptwas-file ${_input[0]} \\\n --fastenloc-file ${_input[1]} \\\n --alpha ${alpha} \\\n --output ${_output}\n" + "source": [ + "[intact]\n", + "input: ptwas_file, fastenloc_file\n", + "output: f'{cwd}/{tissue}.INTACT.rds'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand = \"${ }\", stderr = f'{_output:nn}.stderr', stdout = f'{_output:nn}.stdout', container = container\n", + " Rscript ${modular_script_dir}/pecotmr_integration/intact.R \\\n", + " --ptwas-file ${_input[0]} \\\n", + " --fastenloc-file ${_input[1]} \\\n", + " --alpha ${alpha} \\\n", + " --output ${_output}\n" + ] } ], "metadata": { @@ -199,4 +268,4 @@ }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/code/SoS/pecotmr_integration/twas_ctwas.ipynb b/code/SoS/pecotmr_integration/twas_ctwas.ipynb index fa95e86e9..46931eebf 100644 --- a/code/SoS/pecotmr_integration/twas_ctwas.ipynb +++ b/code/SoS/pecotmr_integration/twas_ctwas.ipynb @@ -8,7 +8,25 @@ "source": [ "# TWAS, cTWAS and MR\n", "\n", - "## Description\n", + "Runs transcriptome-wide association analysis, quantile TWAS, and cTWAS fine-mapping to identify which gene and SNP signals are likely to be causal." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Overview\n", + "\n", + "A TWAS scan tests each gene's genetically predicted expression against a trait, but a\n", + "significant gene is not necessarily a causal one: nearby variants with direct effects on\n", + "the trait, and the predicted expression of neighbouring genes, are correlated with the\n", + "gene's own eQTLs and act as confounders. cTWAS addresses this by fine-mapping genes and\n", + "variants jointly within a region, so a gene is credited only for signal that its expression\n", + "explains beyond the surrounding variants and genes, and reports a posterior inclusion\n", + "probability rather than a p-value ([Zhao et al., 2024](https://doi.org/10.1038/s41588-023-01648-9)).\n", + "`finemapCtwasRegions`) and offers four workflows:\n", "\n", "This module provides software implementations for transcriptome-wide association analysis (TWAS), Quantile TWAS, and variant selection that yields sparse signals for cTWAS (causal TWAS) analysis following the multi-group cTWAS method of Qian et al. (2024+). It additionally performs Mendelian Randomization using fine-mapping instrumental variables (IV) as described in Zhang et al. (2020) for \"causal\" effect estimation and model validation. The unit of analysis is a single gene-trait pair.\n", "\n", @@ -18,7 +36,12 @@ "\n", "**Prerequisites:** TWAS weights (`protocol_example.twas_weights.rds`) from `mnm_regression`, plus GWAS summary statistics and an LD matrix for the region of interest.\n", "\n", - "**Timing** (toy chr22 dataset): `twas` ~50 sec; `ctwas` ~42 sec." + "**Timing** (toy chr22 dataset): `twas` ~50 sec; `ctwas` ~42 sec.\n", + "\n", + "MR can be run for candidate genes afterwards, limited to genes with cTWAS significance and a strong instrumental variable, using fine-mapped xQTL with GWAS data; multiple IVs aggregate by fixed-effect meta-analysis, and results with severe exclusion-restriction violations are excluded.\n", + "\n", + "**When to run it.** After you have TWAS weights (from `mnm_regression`) and GWAS summary\n", + "statistics. cTWAS consumes weights, it does not produce them." ] }, { @@ -27,124 +50,146 @@ "kernel": "SoS" }, "source": [ - "## Step 1: TWAS\n", + "## Input\n", "\n", - "Extract the GWAS z-scores and the corresponding LD matrix for the region of interest, (optionally) run allele-matching QC, process the SuSiE-TWAS weights, run the association test for each molecular context across multiple sets of weights, and keep the best cross-validated model per gene. A gene-context pair is considered imputable when its cross-validated performance reaches adjusted $r^2$ >=0.01 and p-value <0.05 in at least one method; non-imputable genes are dropped.\n", + "- `--gwas_meta_data` **`input/twas/protocol_example.twas.gwas_meta.tsv`**\n", + "(one row per GWAS study. Columns `study_id`, `chrom`, `file_path`, `sample_size`; `file_path` points at the summary statistics for that chromosome.)\n", "\n", - "*Notes:* specifying a `column_file_path` (YAML) enables `load_rss_data()`, which standardizes column names and can generate missing `z`/`beta` columns via `col_to_flip`; without it, the simpler `tabix_region()` is used. Use `--comment_string \"#\"` to handle comment lines in the summary statistics file (by default no comment symbol is assumed). For LASSO, Elastic Net, and mr.ash the weights are taken as-is for QTL variants overlapping GWAS variants, while SuSiE weights can be adjusted to exactly match GWAS variants.\n", + "```\n", + "study_id\tchrom\tfile_path\tsample_size\n", + "protocol_example_twas_chr22\t22\tprotocol_example.twas.gwas_sumstats.chr22.tsv.gz\t200000\n", + "```\n", + "\n", + "- `--xqtl_meta_data` **`input/twas/protocol_example.twas.xqtl_meta.tsv`**\n", + "(one row per gene or region with its weight file. Columns `#chr`, `start`, `end`, `region_id`, `TSS`, `original_data`, `contexts`.)\n", "\n", - "**Input \u2014 GWAS data interface (similar to `susie_rss`):**\n", - "- GWAS summary statistics files: tab-delimited, tabix-indexed by `chrom`/`pos`; first 4 columns `chrom`, `pos`, `A1`, `A2`. For MR, `effect_allele_frequency` and sample-size columns are required.\n", - "- Optional column-mapping YAML: required `chrom`, `pos`, `A1`, `A2`, `z` (or `betahat`/`sebetahat`); optional `n`, `var_y`.\n", - "- Optional GWAS meta-file (`study_id`, chrom, file path, optional mapping file; chrom `0` = genome-wide):\n", "```\n", - "study_id chrom file_path column_mapping_file\n", - "study1 1 gwas1.tsv.gz column_mapping.yml\n", - "study1 2 gwas2.tsv.gz column_mapping.yml\n", + "#chr\tstart\tend\tregion_id\tTSS\toriginal_data\tcontexts\n", + "chr22\t10000000\t19000000\tENSG00000130538\t15528191\tinput/twas/protocol_example.twas.reshaped_toy.chr22_ENSG00000130538.univariate_twas_weights.rds\tbulk_rnaseq\n", "```\n", - "- LD reference metadata: single TSV with `#chrom`, `start`, `end`, LD-matrix path (comma-separated matrix,bim), genome build. See the [LD reference preparation doc](https://statfungen.github.io/xqtl-protocol/code/reference_data/rss_ld_sketch.html).\n", - "- xQTL weight database (RDS, region -> context -> weight matrix), metadata columns `#chr`, `start`, `end`, `TSS`, `region_id`, `original_data`:\n", + "\n", + "- `--ld_meta_data` **`input/ld_reference/protocol_example.ld_meta_file.tsv`**\n", + "(LD blocks and where the matrices live. Columns `#chr`, `start`, `end`, `path`. Produced by `ld_reference_generation`.)\n", + "\n", "```\n", - "#chr start end region_id TSS original_data\n", - "chr1 0 6480000 ENSG00000008128 1724356 KNIGHT_pQTL.ENSG00000008128.univariate_susie_twas_weights.rds, ... (truncated)\n", + "#chr\tstart\tend\tpath\n", + "chr1\t16103\t2888443\tchr1/protocol_example.LD.chr1\n", + "chr1\t2888443\t4320284\tchr1/protocol_example.LD.chr1\n", "```\n", "\n", - "**Output \u2014 TWAS result table** (imputable genes only): `gwas_study, chrom, start, end, block, gene, TSS, context, is_imputable, method, is_selected_method, rsq_adj_cv, pval_cv, twas_z, twas_pval`. Key columns: `TSS` = transcription start site; `start`/`end` = gene window from the [extended TADB window](https://github.com/cumc/xqtl-analysis/blob/main/resource/TADB_enhanced_cis.coding.bed); `is_imputable` = CV r-square >0.01 and pvalue <0.05 in >=1 method; `is_selected_method` = best model (highest CV r-square, CV pvalue <0.05); `block` = LD region of the gene's TSS based on [predefined LD blocks](https://github.com/cumc/xqtl-data/blob/main/descriptor/reference_data/ld_reference.md).\n", + "- `--regions` **`input/twas/protocol_example.twas.LD_blocks.chr22.bed`**\n", + "(the LD blocks to analyze. Columns `chr`, `start`, `stop`.)\n", + "\n", + "```\n", + "chr\tstart\tstop\n", + "chr22\t10000000\t19000000\n", + "```\n", + "\n", + "- `--xqtl_type_table` **`input/twas/protocol_example.twas.data_type_table.txt`**\n", + "(maps each xQTL context to its modality, used when grouping contexts for cTWAS)\n", + "\n", + "```\n", + "context\ttype\n", + "bulk_rnaseq\teQTL\n", "```\n", - "chr molecular_id TSS start end context gwas_study method is_imputable is_selected_method rsq_cv pval_cv twas_z twas_pval\n", - "1 ENSG00000060718 103108871 101000000 104000000 AC_DeJager_eQTL Bellenguez_EADB_2022 bayes_r TRUE TRUE 0.25 3.39e-39 0.39 0.69\n", - "10 ENSG00000048740 10798396 9320000 12336675 Ast_DeJager_eQTL Bellenguez_EADI_2022 enet TRUE FALSE 0.16 2.72e-17 -0.21 0.83\n", - "```\n" + "\n", + "- `--cwd output/twas` (working directory all outputs are written under)\n", + "- `--name protocol_example` (tag used in every output filename)\n", + "- `--region-name chr22_10000000_19000000` (optional; restrict to named regions)\n", + "\n", + "Model and filtering options:\n", + "\n", + "- `--ld_reference_sample_size` (sample size of the LD reference panel, used to scale the LD matrices)\n", + "- `--prior_var_structure` (how the cTWAS prior variance is shared across groups)\n", + "- `--rsq_cutoff` (minimum cross-validation r-squared for a weight model to be used)\n", + "- `--rsq_pval_cutoff` (maximum cross-validation p-value for a weight model to be used)\n", + "- `--twas_weight_cutoff` (drop weights below this magnitude before assembling cTWAS inputs)\n", + "- `--thin` (fraction of SNPs retained when thinning for parameter estimation)\n", + "- `--run_param_est` (estimate cTWAS group priors)\n", + "- `--run_finemapping` (run cTWAS fine-mapping after the priors are estimated)\n", + "- `--skip_assembly` (reuse an existing `ctwas_inputs.rds` instead of rebuilding it)\n", + "\n", + "File formats:\n", + "\n", + "- GWAS summary statistics are tab-delimited and tabix-indexed by `chrom`/`pos`; the first four columns are `chrom`, `pos`, `A1`, `A2`. For MR, `effect_allele_frequency` and a sample-size column are also required.\n", + "- The GWAS meta-file may carry an optional `column_mapping_file` column pointing at a YAML that renames columns: required `chrom`, `pos`, `A1`, `A2`, `z` (or `betahat`/`sebetahat`); optional `n`, `var_y`. `chrom 0` means genome-wide.\n", + "- The LD reference meta-file gives the LD-matrix path as a comma-separated `matrix,bim` pair, plus the genome build. See [ld_reference_generation](ld_reference_generation).\n", + "- xQTL weights are an RDS database keyed region to context to weight matrix. Weights from LASSO, Elastic Net and mr.ash are taken as-is for QTL variants overlapping GWAS variants; SuSiE weights are adjusted to match GWAS variants exactly.\n", + "- Use `--comment_string \"#\"` if the summary statistics carry comment lines; no comment character is assumed by default.\n", + "- `--cs_min_cor` (minimum correlation for a cTWAS credible set; default 0)\n", + "- `--min_pip_cutoff` (minimum PIP for a variant to be reported; default 0)\n", + "- `--max_num_variants` (cap on variants considered per region; default unlimited)\n", + "- `--multi_group` (use the multi-group cTWAS model instead of a single shared prior)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "metadata": { - "kernel": "SoS" - }, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" + "kernel": "SoS", + "tags": [] }, - "outputs": [], - "source": [] + "source": [ + "## Output\n", + "\n", + "- **`output/twas/twas/...twas.rds`** (`twas`)\n", + "(per-gene TWAS result, one file per gene in the region)\n", + "- **`output/twas/twas/..twas.tsv.gz`** (`twas`, side file)\n", + "(the TWAS table for the whole region. Columns `gwas_study`, `chrom`, `start`, `end`, `block`, `gene`, `TSS`, `context`, `is_imputable`, `method`, `is_selected_method`, `rsq_adj_cv`, `pval_cv`, `twas_z`, `twas_pval`. `is_selected_method` marks the best-performing model per gene-context pair -- the one with the highest cross-validation r-square.)\n", + "\n", + "```\n", + "chr\tmolecular_id\tTSS\tstart\tend\tcontext\tgwas_study\tmethod\tis_imputable\n", + "22\tENSG00000130538\t15528191\t10000000\t19000000\tbulk_rnaseq\tprotocol_example_twas_chr22\tbayes_c\tTRUE\n", + "22\tENSG00000130538\t15528191\t10000000\t19000000\tbulk_rnaseq\tprotocol_example_twas_chr22\tbayes_r\tTRUE\n", + "```\n", + "\n", + "- **`output/twas/twas/..mr_result.tsv.gz`** (`twas`, side file)\n", + "(Mendelian Randomization results for the same region)\n", + "\n", + "```\n", + "gene_name\tnum_CS\tnum_IV\tcpip\tmeta_eff\tse_meta_eff\tmeta_pval\tQ\n", + "ENSG00000130538\t\t\t\t\t\t\t\n", + "```\n", + "\n", + "- **`/ctwas/.ctwas_inputs.rds`** (`ctwas_1`)\n", + "(assembled cTWAS inputs: weights, LD and GWAS z-scores for the regions to be fine-mapped)\n", + "- **`/ctwas/.ctwas_est.rds`** (`ctwas_2`)\n", + "(estimated cTWAS group prior parameters)\n", + "- **`/ctwas/.ctwas_finemap.rds`** (`ctwas_3`)\n", + "(cTWAS fine-mapping result: posterior inclusion probabilities for genes and SNPs in each LD block)\n", + "\n", + "Only the `.twas.rds` files are declared in the `twas` step `output:` statement. The `.twas.tsv.gz`, `.mr_result.tsv.gz`, `.twas_data.rds`, `.gwas_sumstats.rds` and `.twas_weights.rds` files, and the `cor_cache/` directory, are written alongside but not tracked by SoS. " + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": [] + "source": [ + "## Minimal Working Example\n", + "\n", + "The three methods below are independent: run whichever you need. All use the chr22 example data in this repository." + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [] + "source": [ + "### Standard TWAS scan\n", + "\n", + "`twas` extracts the GWAS z-scores and LD matrix for each region, processes the SuSiE-TWAS weights, and runs the association test for each molecular context, keeping the best cross-validated model per gene. Genes that clear neither `--rsq_cutoff` nor `--rsq_pval_cutoff` in any method are dropped as non-imputable." + ] }, { "cell_type": "markdown", "metadata": { "kernel": "SoS" }, - "source": [] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": { - "kernel": "SoS" - }, - "outputs": [], - "source": [] - }, - { - "cell_type": "raw", - "metadata": { - "kernel": "SoS" - }, - "source": [] + "source": [ + "**Timing**: TBD (on toy dataset)" + ] }, { "cell_type": "code", @@ -172,28 +217,13 @@ "kernel": "SoS" }, "source": [ - "## Step 2: cTWAS \u2014 region assembly, global parameters, and fine-mapping\n", + "### cTWAS fine-mapping\n", "\n", - "Combine the selected best-performing TWAS prediction models, TWAS gene z-scores, GWAS SNP z-scores, and LD reference region information into the per-region cTWAS input; estimate the global group prior across all regions; then screen and fine-map regions to obtain posterior inclusion probabilities (PIP) for genes and SNPs. The section is split into three runs: region-data assembly, global-parameter estimation (`--run_param_est`), and causal fine-mapping (`--run_finemapping`).\n", + "`ctwas` combines the selected TWAS models, gene and SNP z-scores and the LD reference into a per-region input, estimates the global group prior across regions, then fine-maps each region for posterior inclusion probabilities over genes and SNPs. It is one workflow run three times, switched by `--run_param_est` and `--run_finemapping`; `--skip_assembly` reuses the assembled inputs rather than rebuilding them.\n", "\n", - "The cTWAS R package is required: `remotes::install_github(\"xinhe-lab/ctwas\", ref = \"multigroup\")`. Variant selection is performed based on the `top_loci` table, SuSiE CS set, or twas-weights effect size when any of `twas_weight_cutoff` (default=0), `cs_min_cor` (default=0), `min_pip_cutoff` (default=0), or `max_num_variants` (default=Inf) is set away from its default. The prior can use a single shared group via `--prior_var_structure shared_all` or the multi-group model via `--multi_group`.\n", + "Requires the cTWAS R package: `remotes::install_github(\"xinhe-lab/ctwas\", ref = \"multigroup\")`.\n", "\n", - "**Input \u2014 TWAS region information** (multiple TWAS and SNP data within each region are combined for joint inference to select variables \u2014 genes or SNPs \u2014 likely to be directly associated with the phenotype rather than via correlation):\n", - "```\n", - "chrom start end block_id\n", - "1 1000 5000 block1\n", - "2 2000 6000 block2\n", - "3 3000 7000 block3\n", - "```\n", - "\n", - "**Output \u2014 cTWAS fine-mapping** (per variable: `id, molecular_id, type, context, susie_pip, group, cs, region_id, z`):\n", - "```\n", - "id molecular_id type context susie_pip cs region_id z\n", - "ENSG00000148429|eQTL_Inh_DeJager_eQTL ENSG00000148429 eQTL Inh_DeJager_eQTL 0.07121779052573 L1 10_10500888_12817813 -6.20856901762341\n", - "10:10504379:T:C 10:10504379:T:C SNP SNP 0.987261359280169 10_10500888_12817813 1.03614457831325\n", - "```\n", - "\n", - "For candidate genes, **MR** can subsequently be run: limit MR to genes with cTWAS significance AND a strong instrumental variable (fine-mapping PIP or CS); use fine-mapped xQTL with GWAS data; for multiple IVs aggregate via fixed-effect meta-analysis; and exclude results with severe exclusion-restriction (ER) violations.\n" + "`-n` cannot preview this chain: `ctwas_1` reads a manifest that `get_analysis_regions` only writes at run time, so a dry run stops at the first step." ] }, { @@ -202,7 +232,16 @@ "kernel": "SoS" }, "source": [ - "#### cTWAS Step 1: Assemble region data" + "#### Step 1.: Assemble region data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -230,7 +269,16 @@ "kernel": "SoS" }, "source": [ - "#### cTWAS Step 2: Estimate global parameters" + "#### Step 2.: Estimate global parameters" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -257,7 +305,16 @@ "kernel": "SoS" }, "source": [ - "#### cTWAS Step 3: Fine-map causal genes and SNPs" + "#### Step 3.: Fine-map causal genes and SNPs" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -285,8 +342,17 @@ "kernel": "SoS" }, "source": [ - "## Step 3: Quantile TWAS\n", - "Use pre-computed TWAS weights for quantile-specific testing: for each quantile level, cluster and integrate by fixed and dynamic region groups, extract the relevant GWAS z-scores and LD matrix for the region, and perform quantile region-specific association tests, identifying variants whose effects vary across different quantile regions of the phenotype distribution. Use `--region-name` (formatted as `chr_start_stop`) to focus on specific blocks, or `--region` to analyze a selected list of regions.\n" + "### Quantile TWAS\n", + "Use pre-computed TWAS weights for quantile-specific testing: for each quantile level, cluster and integrate by fixed and dynamic region groups, extract the relevant GWAS z-scores and LD matrix for the region, and perform quantile region-specific association tests, identifying variants whose effects vary across different quantile regions of the phenotype distribution. Use `--region-name` (formatted as `chr_start_stop`) to focus on specific blocks, or `--region` to analyze a selected list of regions." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -308,6 +374,180 @@ " --region-name chr22_10000000_19000000" ] }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/twas_ctwas.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/twas_ctwas.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " get_analysis_regions\n", + " twas\n", + " ctwas\n", + " quantile_twas\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " --gwas-meta-data . (as path)\n", + " --xqtl-meta-data . (as path)\n", + " --ld-meta-data . (as path)\n", + " --ld-reference-sample-size 17000 (as int)\n", + " --xqtl-type-table ''\n", + " --gwas-name (as list)\n", + " --gwas-data (as list)\n", + " --column-mapping (as list)\n", + " --regions . (as path)\n", + " --region-name (as list)\n", + " Optional: if a region name is provided the analysis\n", + " would be focused on the union of provides region list\n", + " and region names\n", + " --name f\"{xqtl_meta_data:bn}.{gwas_meta_data:bn}\"\n", + "\n", + " --container ''\n", + " --job-size 100 (as int)\n", + " --walltime 5m\n", + " --mem 8G\n", + " --numThreads 1 (as int)\n", + " --name-suffix ''\n", + " name suffix add to end of the name variable for the\n", + " output files\n", + " --gwas-study (as list)\n", + " optional parameter in ctwas to only perform gwas\n", + " specific analysis\n", + "\n", + "Sections\n", + " get_analysis_regions:\n", + " twas:\n", + " Workflow Options:\n", + " --coverage 'cs_coverage_0.95'\n", + " Legacy CLI retained. Wired to the pecotmr selection\n", + " knobs: rsq_cutoff, rsq_pval_cutoff, rsq_option,\n", + " rsq_pval_option (CV weight selection). MR is deferred,\n", + " so mr_pval_cutoff and the remaining legacy params are\n", + " kept declared for CLI stability but are not consumed by\n", + " the S4 path.\n", + " --rsq-cutoff 0.01 (as float)\n", + " Thresholds for rsq and CV p-value for imputability/best-\n", + " model selection\n", + " --rsq-pval-cutoff 0.05 (as float)\n", + " --mr-pval-cutoff 0.05 (as float)\n", + " --[no-]save-ctwas-data (default to True)\n", + " --[no-]save-mr-result (default to True)\n", + " --rsq-option rsq\n", + " --rsq-pval-option adj_rsq_pval pval (as list)\n", + " --batch-load-memory 500 (as int)\n", + " load by batches if memory resource is limited, default\n", + " to load all at once\n", + " --event-filter-rules . (as path)\n", + " --comment-string NULL\n", + " --[no-]rename-column (default to False)\n", + " ctwas_1:\n", + " Workflow Options:\n", + " --chrom ''\n", + " chromosome to assemble (integer or 'chrN'); default: the\n", + " lone gene-bearing chrom\n", + " --twas-weight-cutoff 0.0 (as float)\n", + " weight pre-filters passed to assembleCtwasInputs\n", + " --max-num-variants Inf\n", + " --cs-min-cor 0.0 (as float)\n", + " --min-pip-cutoff 0.0 (as float)\n", + " --thin 1.0 (as float)\n", + " declared for CLI stability; consumed downstream / not by\n", + " assembleCtwasInputs\n", + " --maxSNP 20000 (as int)\n", + " --[no-]multi-group (default to True)\n", + " --[no-]skip-assembly (default to False)\n", + " --twas-weights (as list)\n", + " TwasWeights source (option c): empty -> the upstream\n", + " twas step's per-gene weights\n", + " ({cwd}/twas/{name}.{region}.{gene}.twas_weights.rds);\n", + " override with a list of prebuilt TwasWeights RDS (e.g.\n", + " the blessed ctwas weights extracted by the blessed S4\n", + " ctwas weights) when the toy twas weights carry no\n", + " signal.\n", + " ctwas_2:\n", + " Workflow Options:\n", + " --[no-]run-param-est (default to False)\n", + " cTWAS step 2 (estimate priors): estCtwasParam via\n", + " ctwas_est.R. Reads the assembled inputs from [ctwas_1]\n", + " on disk so it can be run independently. --fallback-to-\n", + " prefit recovers the prefit estimate when the accurate EM\n", + " cannot be estimated (e.g. the single-gene MWE),\n", + " mirroring the legacy ctwas_2 workaround.\n", + " --[no-]skip-assembly (default to False)\n", + " --thin 1.0 (as float)\n", + " --prior-var-structure 'shared_all'\n", + " --niter 50 (as int)\n", + " --[no-]multi-group (default to True)\n", + " declared for CLI stability; not consumed by the S4 path\n", + " ctwas_3:\n", + " Workflow Options:\n", + " --[no-]run-finemapping (default to False)\n", + " cTWAS step 3 (screen + finemap): screenCtwasRegions +\n", + " finemapCtwasRegions via ctwas_finemap.R. Reads the\n", + " estimated params from [ctwas_2] on disk so it can be run\n", + " independently. Emits the per-gene cTWAS fine-mapping\n", + " result.\n", + " --L 5 (as int)\n", + " --min-nonSNP-PIP 0.5 (as float)\n", + " --[no-]merge-regions (default to False)\n", + " Boundary-gene region merging (legacy ctwas_3\n", + " merge_regions, default-off): when True, after fine-\n", + " mapping, each high-PIP boundary gene's adjacent LD\n", + " blocks are merged and re-fine-mapped via\n", + " mergeCtwasBoundaryRegions (require-in-CS, like the\n", + " legacy susie_pip>0.5 & !is.na(cs) selection); maxSNP\n", + " caps SNPs per merged region.\n", + " --maxSNP 20000 (as int)\n", + " --[no-]keep-snps (default to True)\n", + " retain the SNP background as a dedicated\n", + " study=context=\"SNP\" CtwasResult row; default True\n", + " matches the legacy pipeline, which kept SNP rows in the\n", + " finemap output\n", + " --thin 1.0 (as float)\n", + " declared for CLI stability; not consumed by the S4 path\n", + " --max-iter 0 (as int)\n", + " --prior-var-structure 'shared_all'\n", + " --subset-context (as list)\n", + " --[no-]multi-group (default to True)\n", + " --p-diff-thresh 5e-08 (as float)\n", + " --alias NULL\n", + " quantile_twas:\n", + " Workflow Options:\n", + " --[no-]save-ctwas-data (default to True)\n", + " --[no-]save-mr-result (default to False)\n", + "```" + ] + }, { "cell_type": "markdown", "metadata": { diff --git a/code/SoS/pecotmr_integration/twas_vignette.ipynb b/code/SoS/pecotmr_integration/twas_vignette.ipynb index 0e434c277..b68f0584a 100644 --- a/code/SoS/pecotmr_integration/twas_vignette.ipynb +++ b/code/SoS/pecotmr_integration/twas_vignette.ipynb @@ -2,203 +2,238 @@ "cells": [ { "cell_type": "markdown", - "id": "b4db4b05-3a30-4a89-a6b0-dc325fc9804c", + "id": "d54b0106", "metadata": {}, "source": [ - "# Transcriptome Wide Association Study" + "# From genetically predicted expression to trait association\n", + "\n", + "This vignette explains how standard TWAS and cTWAS answer different gene–trait association questions and how to interpret their outputs." ] }, { "cell_type": "markdown", - "id": "c65f1f2f-e7b0-4f45-a78c-237ef31fe274", + "id": "d8d21607", "metadata": {}, "source": [ - "Transcriptome-wide association analysis (TWAS) is included as a continuation of the SuSiE-TWAS workflow. The output from TWAS is used to perform variant selection used in the causal TWAS (cTWAS) analysis. " + "## Learning goals\n", + "\n", + "After completing this vignette, you will be able to choose between standard TWAS and cTWAS, prepare their shared metadata inputs, run either route, and interpret gene-level evidence without equating association with causality." ] }, { "cell_type": "markdown", - "id": "6c417c0d-2d9e-44c6-9673-eae8a85e5e6f", + "id": "72d1e1ac", "metadata": {}, "source": [ - "Input:" + "## Background and method\n", + "\n", + "Standard TWAS tests whether the genetically predicted component of a molecular phenotype is associated with a complex trait. It combines GWAS summary statistics, prediction weights and an LD reference to calculate a gene-level association statistic. A significant result can arise from a causal molecular effect, horizontal pleiotropy or linkage between distinct molecular and trait variants.\n", + "\n", + "cTWAS jointly models genes and nearby variants in LD blocks. By allowing direct variant effects alongside gene-mediated effects, it aims to distinguish candidate gene associations from local genetic confounding. Its three internal stages assemble inputs, estimate model parameters and perform fine-mapping; these stages form one chained `ctwas` workflow.\n", + "\n", + "Standard TWAS and cTWAS are **alternative analysis methods**, not consecutive mandatory steps. Run standard TWAS for a direct gene-level scan. Run cTWAS when the goal is joint gene/variant prioritization under its model and the required cTWAS software is available." ] }, { "cell_type": "markdown", - "id": "70937229-3938-4303-af9d-cc68bcaf4e1c", + "id": "0f2b2b76", "metadata": {}, - "source": "`--gwas_meta_data`: GWAS metadata table, one row per study \u00d7 chromosome.\n\n```\nstudy_id chrom file_path sample_size\nprotocol_example_twas_chr22 22 input/twas/protocol_example.twas.gwas_sumstats.chr22.tsv.gz 200000\n```\n\n| Column | Description |\n|--------|-------------|\n| `study_id` | GWAS study name (used in output file naming) |\n| `chrom` | Chromosome number (integer, no \"chr\" prefix) |\n| `file_path` | Path to GWAS sumstats TSV.gz |\n| `sample_size` | GWAS sample size (used to scale statistics) |\n\n`--xqtl_meta_data`: xQTL TWAS weights metadata, one row per gene.\n\n```\n#chr start end region_id TSS original_data contexts\nchr22 10000000 19000000 ENSG00000130538 15528191 input/twas/protocol_example.twas.univariate_twas_weights.rds bulk_rnaseq\n```\n\n| Column | Description |\n|--------|-------------|\n| `#chr / start / end` | Analysis region (LD block coordinates) |\n| `region_id` | Gene Ensembl ID |\n| `TSS` | Transcription start site coordinate |\n| `original_data` | Path to `*.univariate_twas_weights.rds` (from `mnm_regression.ipynb susie_twas`) |\n| `contexts` | Context names covered by this file (comma-separated if multiple) |\n\n`--ld_meta_data`: LD reference index file (same file used by `rss_analysis.ipynb`, produced by `rss_ld_sketch.ipynb`).\n\n`--regions`: LD block BED file, one block per row.\n\n```\nchr start stop\nchr22 10000000 19000000\n```\n\n`--xqtl_type_table`: mapping from context to xQTL type.\n\n```\ncontext type\nbulk_rnaseq eQTL\n```\n\n`--ld_reference_sample_size`: sample size of the LD reference panel (used to scale the LD matrix).\n\n`--rsq_cutoff` / `--rsq_pval_cutoff`: a gene is imputable (`is_imputable = TRUE`) if at least one method has `rsq_cv \u2265 rsq_cutoff` AND `pval_cv < rsq_pval_cutoff`.\n\n`--region-name`: run only the specified LD block (optional; omit to run all blocks in `--regions`)." + "source": [ + "## Worked example\n", + "\n", + "Both routes use the same chromosome 22 metadata bundle.\n", + "\n", + "| Role | Example path | Contents |\n", + "|---|---|---|\n", + "| GWAS metadata | `input/twas/protocol_example.twas.gwas_meta.tsv` | Study and GWAS summary-statistics paths |\n", + "| xQTL/TWAS metadata | `input/twas/protocol_example.twas.xqtl_meta.tsv` | Molecular traits and prediction-weight locations |\n", + "| LD metadata | `input/ld_reference/protocol_example.ld_meta_file.tsv` | LD-block coordinates and reference files |\n", + "| LD blocks | `input/twas/protocol_example.LD_blocks.chr22.bed` | Genomic regions used by cTWAS |\n", + "| Data-type table | `input/twas/protocol_example.data_type_table.txt` | cTWAS feature-type definitions |\n", + "\n", + "GWAS, weights and LD must use compatible variants, alleles, genome build and ancestry. Choose one route below according to the analysis goal." + ] }, { "cell_type": "markdown", - "id": "b2a093c3-4a00-412d-869a-b315212cfc2f", + "id": "2921ebb4", "metadata": {}, "source": [ - "## Overview" + "### [Standard TWAS](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html#standard-twas-scan)\n", + "\n", + "The `twas` workflow calculates one association result per modeled molecular trait." ] }, { "cell_type": "markdown", - "id": "76a4aafe-183a-49b2-aad1-22dc85a47f5d", + "id": "15f2e21c", "metadata": {}, "source": [ - "1. Run TWAS\n", - "2. Run cTWAS" + "**Timing**: TBD" ] }, { - "cell_type": "markdown", - "id": "c0df529d-b3b3-4b86-a5fa-555abfb3b2a4", + "cell_type": "code", + "execution_count": null, + "id": "0f24cb2f", "metadata": {}, + "outputs": [], "source": [ - "## Steps" + "sos run pipeline/twas_ctwas.ipynb twas \\\n", + " --cwd output \\\n", + " --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv" ] }, { "cell_type": "markdown", - "id": "d9745420-48a2-4896-911a-b4486c07c25b", + "id": "4549847c", "metadata": {}, "source": [ - "### i. Run TWAS" + "Standard TWAS writes one file per gene:\n", + "\n", + "- `output/twas/protocol_example.{region_id}.{gene}.twas.rds` — a `GRanges` result containing the gene-level TWAS statistic and metadata." ] }, { "cell_type": "markdown", - "id": "56c232b4-c403-4b48-8064-37a957b1ddd6", + "id": "aa80f390", "metadata": {}, - "source": "```bash\nsos run pipeline/twas_ctwas.ipynb twas \\\n --cwd output --name protocol_example \\\n --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n --ld_reference_sample_size 17000 \\\n --regions input/twas/protocol_example.twas.LD_blocks.chr22.bed \\\n --xqtl_type_table input/twas/protocol_example.twas.data_type_table.txt \\\n --rsq_pval_cutoff 0.05 --rsq_cutoff 0.01 \\\n --region-name chr22_10000000_19000000\n```" + "source": [ + "### [cTWAS](https://statfungen.github.io/xqtl-protocol/code/pecotmr_integration/twas_ctwas.html#ctwas-fine-mapping)\n", + "\n", + "The `ctwas` workflow runs its three dependent stages in order: input assembly, parameter estimation and joint fine-mapping." + ] }, { "cell_type": "markdown", - "id": "13c59653-8894-4d75-9ae6-d024c9a0a711", + "id": "214dce38", "metadata": {}, "source": [ - "### ii. Run cTWAS" + "**Timing**: TBD" ] }, { - "cell_type": "markdown", - "id": "028b5939-5247-4d16-9a81-6d8b2bd57b82", + "cell_type": "code", + "execution_count": null, + "id": "5a77a991", "metadata": {}, + "outputs": [], "source": [ - "```\n", "sos run pipeline/twas_ctwas.ipynb ctwas \\\n", - " --cwd output/twas --name test \\\n", - " --gwas_meta_data data/twas/gwas_meta_test.tsv \\\n", - " --ld_meta_data data/ld_meta_file_with_bim.tsv \\\n", - " --xqtl_meta_data data/twas/mwe_twas_pipeline_test_small.tsv \\\n", - " --twas_weight_cutoff 0 \\\n", - " --chrom 11 \\\n", - " --regions data/twas/EUR_LD_blocks.bed \\\n", - " --region-name chr10_80126158_82231647 chr11_84267999_86714492\n", - "```" + " --cwd output \\\n", + " --name protocol_example \\\n", + " --gwas_meta_data input/twas/protocol_example.twas.gwas_meta.tsv \\\n", + " --xqtl_meta_data input/twas/protocol_example.twas.xqtl_meta.tsv \\\n", + " --ld_meta_data input/ld_reference/protocol_example.ld_meta_file.tsv \\\n", + " --LD_Blocks input/twas/protocol_example.LD_blocks.chr22.bed \\\n", + " --data_type_table input/twas/protocol_example.data_type_table.txt" ] }, { "cell_type": "markdown", - "id": "14173c00-68e6-49da-8686-78d30c909fff", + "id": "2c5d20b9", "metadata": {}, "source": [ - "## Anticipated Results" + "cTWAS is expected to write:\n", + "\n", + "- `output/ctwas/protocol_example.ctwas_inputs.rds` — assembled GWAS, LD and prediction-weight inputs.\n", + "- `output/ctwas/protocol_example.ctwas_est.rds` — estimated cTWAS model parameters.\n", + "- `output/ctwas/protocol_example.ctwas_finemap.rds` — joint gene/variant fine-mapping results.\n", + "\n", + "The example cTWAS outputs are not currently shipped, so this route documents the current interface but has no result preview yet." ] }, { "cell_type": "markdown", - "id": "8e9e6c04-18f9-4e7f-b6eb-72618c65c751", + "id": "bc5420bb", "metadata": {}, "source": [ - "i. Run TWAS" + "### Command reference" ] }, { - "cell_type": "markdown", - "id": "03c930ed-fc2e-43cb-a4cf-5d513a59e0fb", - "metadata": {}, - "source": "**`{name}.{region_id}.{gene}.twas.rds`** \u2014 `GRanges` S4 object, one file per gene.\n\n```r\nsuppressPackageStartupMessages({ library(pecotmr); library(GenomicRanges) })\n\n# one file per gene \u2014 region_id = LD block, e.g. chr22_10000000_19000000\nres <- readRDS(\"output/twas/protocol_example.chr22_10000000_19000000.ENSG00000130538.twas.rds\")\nclass(res) # \"GRanges\"\n\nnames(mcols(res))\n# [1] \"qtlStudy\" \"context\" \"trait\" \"method\"\n# [5] \"gwasStudy\" \"twasZ\" \"twasPval\" \"waldRatio\"\n# [9] \"waldRatioSe\" \"mrPval\" \"nIV\" \"Q\"\n# [13] \"I2\" \"nCs\"\n```\n\n| Column | Description |\n|--------|-------------|\n| `seqnames`, `start`, `end` | Gene genomic coordinates (LD block range) |\n| `qtlStudy` | xQTL study name (from `--name`) |\n| `context` | Cell type / tissue context |\n| `trait` | Gene Ensembl ID |\n| `method` | TWAS weight method (`mrash`, `susie`, `ensemble`, etc.) |\n| `gwasStudy` | GWAS study name |\n| `twasZ` | **TWAS Z-score**: **w**\u1d40 **z**_GWAS / \u221a(**w**\u1d40 R **w**) |\n| `twasPval` | Two-sided p-value |\n| `waldRatio` / `waldRatioSe` | MR Wald ratio effect and SE (single instrument) |\n| `mrPval` | MR p-value |\n| `nIV` | Number of MR instrument variables |\n| `Q` / `I2` | MR heterogeneity statistics |\n| `nCs` | Number of credible sets contributing to the TWAS signal |\n\n**Example result (toy data, chr22, n=49):**\n\n```r\ndf <- as.data.frame(res)\ndf[!is.na(df$seqnames), c(\"context\", \"trait\", \"method\", \"gwasStudy\", \"twasZ\", \"twasPval\")]\n# context trait method gwasStudy twasZ twasPval\n# bulk_rnaseq ENSG00000130538 mrash protocol_example_twas_chr22 1.867225 0.0618702\n```\n\n> `twasPval = 0.062` is sub-threshold \u2014 toy data (n=49) has insufficient power.\n> Genome-wide significance threshold: p < 5\u00d710\u207b\u2076 (Bonferroni over ~20,000 genes)." - }, - { - "cell_type": "markdown", - "id": "368d3c7e-cf30-45e0-b63f-4efb7b4e0816", + "cell_type": "code", + "execution_count": null, + "id": "f9f82c38", "metadata": {}, + "outputs": [], "source": [ - "ii. Run cTWAS" + "sos run pipeline/twas_ctwas.ipynb -h" ] }, { "cell_type": "markdown", - "id": "48e50e68-a3a1-4c79-951e-0e5f637c3a03", + "id": "31c23b07", "metadata": {}, "source": [ - "`ctwas_region_chr1_z_snp_map.rds`\n", - "* includes:\n", + "## Results and interpretation\n", "\n", - "1. z_snp - snp z-values per study\n", - "2. snp_map\n" + "### Standard TWAS result\n", + "\n", + "Each gene file is a `GRanges` object. Inspect the association statistic, p-value and identifying metadata rather than printing all object slots.\n", + "\n", + "| Field type | Interpretation |\n", + "|---|---|\n", + "| Gene and region | Molecular trait and LD block tested |\n", + "| TWAS statistic | Direction and strength of association for genetically predicted expression |\n", + "| P-value | Evidence against no gene-level association before multiple-testing correction |\n", + "| Weight metadata | Prediction model and context used to construct the test |" ] }, { - "cell_type": "markdown", - "id": "6d13c754-b2b2-4ea2-b165-2bf61582443b", + "cell_type": "code", + "execution_count": null, + "id": "e6cceb37", "metadata": {}, + "outputs": [], "source": [ - "`ctwas_region_chr1_LD_map.rds`\n", - "* includes:\n", + "suppressPackageStartupMessages({\n", + " library(pecotmr)\n", + " library(GenomicRanges)\n", + "})\n", "\n", - "1. region_id\n", - "2. LD_file\n", - "3. SNP_file\n" + "files <- list.files(\"output/twas\", pattern = \"^protocol_example.*\\\\.twas\\\\.rds$\", full.names = TRUE)\n", + "result <- readRDS(files[[1]])\n", + "cat(\"Class:\", class(result), \"\\n\")\n", + "result" ] }, { "cell_type": "markdown", - "id": "ffe63e4f-ee40-4994-8748-dfae52ec3649", + "id": "af6729d5", "metadata": {}, "source": [ - "`ctwas_region_chr1_ctwas_weights.rds`\n", - "* includes ctwas weights for each gene in each study" + "A significant TWAS association identifies a gene whose genetically predicted molecular phenotype tracks trait risk under the fitted weights and LD reference. It does not establish that changing the gene will change the trait. Compare direction across contexts, correct for the number of tested genes, and use fine-mapping, colocalization and functional evidence to assess whether the signal is compatible with mediation rather than LD or pleiotropy.\n", + "\n", + "For cTWAS, interpret posterior probabilities jointly across genes and direct variant effects. A high gene posterior is evidence under the cTWAS model, not proof of a causal transcript. Examine whether nearby variants retain direct effects and whether conclusions are stable to LD and prior choices." ] }, { "cell_type": "markdown", - "id": "dd6f1b06-fbda-4504-a1f6-5fc6f59208ad", + "id": "d3c90ef4", "metadata": {}, "source": [ - "`ctwas_region_chr1_[study_name].ctwas_boundary_genes.thin0.1.rds`\n", - "* one of these files is generated for each study. Includes:\n", - "1. chrom\n", - "2. id\n", - "3. p0\n", - "4. p1\n", - "5. molecular_id\n", - "6. weight_name\n", - "7. region_start\n", - "8. region_stop\n", - "9. region_id\n", - "10. n_regions" + "## Limitations and common pitfalls\n", + "\n", + "- Prediction weights must transfer to the GWAS population; ancestry or tissue mismatch can reduce validity.\n", + "- TWAS significance can reflect LD or horizontal pleiotropy rather than mediation.\n", + "- Weakly predicted molecular traits have limited power and unstable direction.\n", + "- Standard TWAS and cTWAS are alternatives; standard TWAS output is not a required input to the cTWAS workflow.\n", + "- cTWAS conclusions depend on LD quality, model priors and the included gene/variant set.\n", + "- Neither method replaces experimental validation." ] }, { "cell_type": "markdown", - "id": "2b04fd18-964e-40f0-8153-052ee3b0bb43", - "metadata": {}, - "source": [ - "`ctwas_region_chr1_[study_name].ctwas_region_data.thin0.1.rds`\n", - "* one of these files is generated for each study. Include these values for each region:\n", - "1. region_id\n", - "2. chrom\n", - "3. start\n", - "4. stop\n", - "5. minpos\n", - "6. maxpos\n", - "7. thin\n", - "8. gid\n", - "9. sid\n", - "10. z_gene\n", - "11. z_snp\n", - "12. types\n", - "13. contexts\n", - "14. groups" + "id": "0b1d54a5", + "metadata": {}, + "source": [ + "## Next steps\n", + "\n", + "For prioritized genes, compare results across molecular contexts, evaluate colocalization with QTL signals and inspect variant-level fine-mapping evidence. Treat concordance across methods as stronger prioritization evidence while preserving the distinction between statistical association and biological causality." ] } ], @@ -223,4 +258,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/reference_data/generalized_TADB.ipynb b/code/SoS/reference_data/generalized_TADB.ipynb index 9bdd8fabe..7141efc7b 100644 --- a/code/SoS/reference_data/generalized_TADB.ipynb +++ b/code/SoS/reference_data/generalized_TADB.ipynb @@ -6,44 +6,26 @@ "metadata": { "kernel": "SoS" }, - "source": "# Generation of Topologically Associated Domains and their Boundaries\n\n## Description\n\nThis notebook builds **TAD boundaries (TADBs)** and TADB-enhanced cis windows from tissue/brain TAD calls. It runs in two conceptual stages: (i) *manage TAD redundancy* by recursively merging overlapping specific TADs (those whose overlap exceeds a cutoff) into a smaller set of generalized TADs, and (ii) *generate TADB-enhanced cis windows and extended TADBs* by deriving boundaries from the generalized + specific TADs and joining them with gene coordinates to produce per-gene cis windows.\n\nDuring fine mapping we often use a cis window (the gene body extended by 1Mb up- and downstream, i.e. gene start − 1Mb to gene end + 1Mb) as the fine-mapping region. That choice lacks a biological justification, so here we instead extend regions using TAD structure, producing both extended TADBs and TADB-enhanced cis windows since each serves a different goal. Genes within each TADB are extended by their 1Mb cis windows and the outermost boundary is taken, yielding roughly 1,381 TADBs that can serve as functional units for epigenetic analysis.\n\n> **Synthetic-data note.** This minimal working example runs on a small synthetic set of chr22 TAD blocks (`protocol_example.brain_TADs.txt`) and a chr22 gene table (`protocol_example.gene_start_end.tsv`, derived from the protocol gene-model GTF). It is for demonstration only and does not reproduce a full genome-wide TADB build." - }, - { - "cell_type": "markdown", - "id": "90ebc2fb", - "metadata": { - "kernel": "SoS" - }, "source": [ - "## Input\n", + "# Generation of Topologically Associated Domains and their Boundaries\n", "\n", - "- `--tad-input`: tab-separated TAD coordinates with columns `chr`, `start`, `end` (no header). Example: `input/tadb/protocol_example.brain_TADs.txt`.\n", - "- `--gene-coords`: gene coordinate table with columns `index`, `#chr`, `start`, `end`, `gene_id`, `gene_name` (derived from the gene-model GTF). Example: `input/tadb/protocol_example.gene_start_end.tsv`.\n", - "- `--cwd`: output directory (default `output/tadb`).\n", - "- `--overlap-cutoff`: minimum percent overlap to merge two specific TADs into one generalized TAD (default `80`).\n", - "\n", - "For a genome-wide build, the raw inputs are `Cortex_DLPFC_Schmitt2016-raw_TADs.txt` and `Hippocampus_Schmitt2016-raw_TADs.txt` (hg38 cortex/hippocampus TAD regions, [cf. McArthur et al 2021](https://doi.org/10.1016/j.ajhg.2021.01.001) and [Schmitt et al 2017](https://doi.org/10.1016/j.celrep.2016.10.061); available at [3dgenome.fsm.northwestern.edu](http://3dgenome.fsm.northwestern.edu/publications.html)) together with the gene model `Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf`.\n", - "\n", - "## Output\n", - "\n", - "- Generalized TAD: `generalized_TAD.tsv`\n", - "- Generalized TADB: `generalized_TADB.tsv`\n", - "- TADB-enhanced cis window: `TADB_enhanced_cis.bed`\n", - "- Extended TADB: `extended_TADB.bed`\n" + "Merges tissue-specific TAD calls into one generalized set and extends it into per-gene fine-mapping regions." ] }, { "cell_type": "markdown", - "id": "5bcd31fb", - "metadata": { - "kernel": "SoS" - }, + "id": "0d81e978", + "metadata": {}, "source": [ - "## Detailed walkthrough\n", + "## Overview\n", "\n", - "The `default` workflow constructs the generalized TADs and TADB-enhanced cis windows in a single pass: it manages TAD redundancy (recursive merge of overlapping/neighboring TADs), derives generalized TAD boundaries, then builds the TADB-enhanced cis windows and extended TADBs by joining those boundaries with gene coordinates. The cells below document this process step by step for reference and reproducibility.\n", + "Analyses that work locus by locus need a definition of \"locus\". Using a fixed window around\n", + "each gene is simple but arbitrary: regulatory contacts do not respect a fixed distance, and\n", + "two genes in the same regulatory neighbourhood get analysed as if independent. Topologically\n", + "associating domain boundaries give a definition grounded in chromatin architecture instead,\n", + "and this step generates the boundary files that downstream region-based analyses consume.\n", "\n", - "**Timing:** ~varies on typical compute infrastructure.\n" + "**When to run it.** Run this module before region-based association or fine-mapping when TAD-defined regions are preferred to fixed-width cis windows.\n" ] }, { @@ -53,7 +35,7 @@ "kernel": "SoS" }, "source": [ - "## Step 1: Manage TAD Redundancy" + "### Managing TAD redundancy" ] }, { @@ -79,16 +61,6 @@ "The merged TADs are processed in several passes. First, neighboring TABs are merged, including a step that manually corrects the start and end position of each chromosome. Preliminary merges then remove exact duplicates (same chromosome, start, and end). Next, the overlap between TADs is determined — the overlap with the preceding TAD, the overlap with the following TAD, and TADs entirely contained within another TAD — with two overlap values tracked per TAD (preceding and following). Finally, TADs are merged recursively: each TAD is extended to the right boundary of the last TAD and to the left boundary of the next, repeating until no further merging is possible, which yields the set of generalized TADs." ] }, - { - "cell_type": "markdown", - "id": "f149b097-05d1-4cdb-931e-a2c667389f62", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Step 2: Generate TADB-enhanced cis windows and extended TADBs" - ] - }, { "cell_type": "markdown", "id": "617c7efe", @@ -157,7 +129,11 @@ "metadata": { "kernel": "SoS" }, - "source": "#### Compare TADB and cis windows\n\nEach TADB covers many genes. For fine-mapping, each gene is assigned a cis window (the gene body ± 1Mb, i.e. gene start − 1Mb to gene end + 1Mb), so the next step checks whether the TADBs fully cover the cis windows of the genes inside them. Verifying that every gene is covered by a TADB confirms the TADBs are correct, since they should span the whole genome. The only genes in the full gene list not covered by a TADB are on chromosome Y, MT, or are ERCC spike-ins; these are expected to be absent because the TAD data does not include them. A value of 0 marks a cis window not fully covered by the TADB its gene lies in: even after constructing the TADBs, many genes still have a cis window (gene body ± 1Mb) that extends beyond its TADB region." + "source": [ + "#### Compare TADB and cis windows\n", + "\n", + "Each TADB covers many genes. For fine-mapping, each gene is assigned a cis window (the gene body ± 1Mb, i.e. gene start − 1Mb to gene end + 1Mb), so the next step checks whether the TADBs fully cover the cis windows of the genes inside them. Verifying that every gene is covered by a TADB confirms the TADBs are correct, since they should span the whole genome. The only genes in the full gene list not covered by a TADB are on chromosome Y, MT, or are ERCC spike-ins; these are expected to be absent because the TAD data does not include them. A value of 0 marks a cis window not fully covered by the TADB its gene lies in: even after constructing the TADBs, many genes still have a cis window (gene body ± 1Mb) that extends beyond its TADB region." + ] }, { "cell_type": "markdown", @@ -165,43 +141,45 @@ "metadata": { "kernel": "SoS" }, - "source": "#### Construct TADB-enhanced cis windows and extended TADBs\n\nFor each gene, its cis window (the gene body ± 1Mb, i.e. gene start − 1Mb to gene end + 1Mb) and the TADB it falls in are combined, extending the region outward to the smaller start and the larger end of the two. This yields one extended cis window per gene, most with a length close to or larger than the original cis window, so that every gene maps to an extended cis window and none is left uncovered. Compared with the TADB-enhanced cis window, the extended TADB allows a single gene to belong to multiple extended regions." - }, - { - "cell_type": "code", - "execution_count": null, - "id": "01693710", - "metadata": { - "kernel": "Bash" - }, - "outputs": [], "source": [ - "sos run pipeline/generalized_TADB.ipynb default \\\n", - " --tad-input input/tadb/protocol_example.brain_TADs.txt \\\n", - " --gene-coords input/tadb/protocol_example.gene_start_end.tsv \\\n", - " --cwd output/tadb" + "#### Construct TADB-enhanced cis windows and extended TADBs\n", + "\n", + "For each gene, its cis window (the gene body ± 1Mb, i.e. gene start − 1Mb to gene end + 1Mb) and the TADB it falls in are combined, extending the region outward to the smaller start and the larger end of the two. This yields one extended cis window per gene, most with a length close to or larger than the original cis window, so that every gene maps to an extended cis window and none is left uncovered. Compared with the TADB-enhanced cis window, the extended TADB allows a single gene to belong to multiple extended regions." ] }, { "cell_type": "markdown", - "id": "7df69b58", - "metadata": { - "kernel": "SoS" - }, + "id": "7071d295-46af-4ddc-8910-0f278f45faa1", + "metadata": {}, "source": [ - "## Command interface" + "#### Why the regions are extended\n", + "\n", + "Fine mapping conventionally uses a cis window, the gene body extended 1 Mb upstream and downstream, as the region to search. That choice has no biological justification, so this module uses topologically associated domains instead, built by merging TAD calls from hippocampus and cortex brain tissue ([McArthur et al. 2021](https://doi.org/10.1016%2Fj.ajhg.2021.01.001), [Schmitt et al. 2017](https://doi.org/10.1016%2Fj.celrep.2016.10.061)).\n", + "\n", + "Variants sitting within boundaries can affect gene expression too, which is why the regions are extended to the adjacent boundaries rather than stopping at the TAD edge, so that no possible causal variant is left out. The extension is deliberately conservative: the information a 1 Mb cis window provides should not be lost either, so both the TADB and the TADB-enhanced cis window are extended, each serving a different purpose.\n", + "\n", + "An extended TADB starts from the generalized TADB. Every gene inside it is found, each gene's start and end are extended by a 1 Mb cis window, and the outermost boundary of all those windows and of the TADB becomes the boundary of the extended TADB. On the reference data this yields 1,381 TADBs, which can then be used as functional units for epigenetic analysis.\n", + "\n", + "A TADB-enhanced cis window starts instead from the cis window of each gene. The outermost boundary of the generalized TADB the gene sits in and of the gene's own 1 Mb window becomes the boundary of the enhanced window; where a gene falls in two generalized TADBs, the outermost of both the TADB and the cis window is taken. The result is one cis window per gene.\n", + "\n", + "**When to run it.** Once per genome build, as reference data preparation. The output is an input to the analyses that split work by region, rather than something rerun per study." ] }, { - "cell_type": "code", - "execution_count": null, - "id": "ba8f48c4", + "cell_type": "markdown", + "id": "90ebc2fb", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, - "outputs": [], "source": [ - "sos run pipeline/generalized_TADB.ipynb -h" + "## Input\n", + "\n", + "- `--tad-input`: tab-separated TAD coordinates with columns `chr`, `start`, `end` (no header). Example: `input/tadb/protocol_example.brain_TADs.txt`.\n", + "- `--gene-coords`: gene coordinate table with columns `index`, `#chr`, `start`, `end`, `gene_id`, `gene_name` (derived from the gene-model GTF). Example: `input/tadb/protocol_example.gene_start_end.tsv`.\n", + "- `--cwd`: output directory (default `output/tadb`).\n", + "- `--overlap-cutoff`: minimum percent overlap to merge two specific TADs into one generalized TAD (default `80`).\n", + "\n", + "For a genome-wide build, the raw inputs are `Cortex_DLPFC_Schmitt2016-raw_TADs.txt` and `Hippocampus_Schmitt2016-raw_TADs.txt` (hg38 cortex/hippocampus TAD regions, [cf. McArthur et al 2021](https://doi.org/10.1016/j.ajhg.2021.01.001) and [Schmitt et al 2017](https://doi.org/10.1016/j.celrep.2016.10.061); available at [3dgenome.fsm.northwestern.edu](http://3dgenome.fsm.northwestern.edu/publications.html)) together with the gene model `Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf`." ] }, { @@ -213,46 +191,135 @@ "source": [ "## Output\n", "\n", - "- `generalized_TAD.tsv`: redundancy-managed (merged) generalized TADs (`chr`, `start`, `end`).\n", - "- `generalized_TADB.tsv`: generalized TAD boundaries with a `TADB` index.\n", - "- `TADB_enhanced_cis.bed`: per-gene TADB-enhanced cis windows (`#chr`, `start`, `end`, `gene_id`).\n", - "- `extended_TADB.bed`: extended TAD boundaries (`#chr`, `start`, `end`, `index`)." + "- `{cwd}/generalized_TAD.tsv` - the redundancy-managed merged TADs, `chr`, `start`, `end`, no header. 13 rows on the example:\n", + "\n", + " ```\n", + " chr22 10700000 12700000\n", + " chr22 13000000 15000000\n", + " chr22 15200000 17200000\n", + " ```\n", + "\n", + "- `{cwd}/generalized_TADB.tsv` - the generalized TAD boundaries with a `TADB` index. Note the first boundary starts at 0, since a TADB spans the ambiguous region either side of a TAD:\n", + "\n", + " ```\n", + " #chr start end index\n", + " chr22 0 13000000 TADB1\n", + " chr22 12650000 15300000 TADB2\n", + " ```\n", + "\n", + "- `{cwd}/TADB_enhanced_cis.bed` - one TADB-enhanced cis window per gene, 1,387 rows on the example:\n", + "\n", + " ```\n", + " #chr start end gene_id\n", + " chr22 0 13000000 ENSG00000226444\n", + " chr22 0 13000000 ENSG00000276871\n", + " ```\n", + "\n", + "- `{cwd}/extended_TADB.bed` - the extended TAD boundaries, same count as the generalized TADBs but reaching further to take in the cis windows of the genes they contain:\n", + "\n", + " ```\n", + " #chr start end index\n", + " chr22 0 13626642 TADB_1\n", + " chr22 12650000 16304556 TADB_2\n", + " ```" ] }, { "cell_type": "markdown", - "id": "d6df2c4d", - "metadata": { - "kernel": "SoS" - }, + "id": "c2cc23c2", + "metadata": {}, "source": [ - "## Anticipated Results\n", + "## Minimal Working Example\n", "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "One workflow, `default`, which builds the generalized TADs and then the boundary and cis-window products in a single pass." ] }, { "cell_type": "markdown", - "id": "c9caa725-1aa8-4657-91f7-b9a84406f688", + "id": "cc7e645a", "metadata": { "kernel": "SoS" }, "source": [ - "## Troubleshooting" + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "01693710", + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/generalized_TADB.ipynb default \\\n", + " --tad-input input/tadb/protocol_example.brain_TADs.txt \\\n", + " --gene-coords input/tadb/protocol_example.gene_start_end.tsv \\\n", + " --cwd output/tadb" ] }, { "cell_type": "markdown", - "id": "f9fbfa3c-4250-4eb4-b73f-af89190277f0", + "id": "7df69b58", "metadata": { "kernel": "SoS" }, "source": [ - "| Step | Substep | Problem | Possible Reason | Solution |\n", - "|------|---------|---------|------------------|---------|\n", - "| | | | | |\n", + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cli-cmd-generalized_TADB", + "metadata": {}, + "outputs": [], + "source": [ + "sos run pipeline/generalized_TADB.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "id": "cli-out-generalized_TADB", + "metadata": {}, + "source": [ + "```\n", + "usage: sos run pipeline/generalized_TADB.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " default\n", "\n", - "\n" + "Global Workflow Options:\n", + " --tad-input VAL (as path, required)\n", + " Brain/tissue TAD coordinates: a tab-separated file with\n", + " columns chr, start, end (no header)\n", + " --gene-coords VAL (as path, required)\n", + " Gene coordinates table derived from the gene-model GTF\n", + " (columns: index, #chr, start, end, gene_id, gene_name)\n", + " --cwd output/tadb (as path)\n", + " Output directory\n", + " --modular-script-dir code/script (as path)\n", + " --overlap-cutoff 80 (as int)\n", + " Minimum percent overlap for two specific TADs to be\n", + " merged into one generalized TAD\n", + " --container ''\n", + " Container image (kept empty; we no longer use\n", + " containers)\n", + " --job-size 1 (as int)\n", + " Resource options (kept for parity with the protocol)\n", + " --walltime 20h\n", + " --mem 40G\n", + " --numThreads 1 (as int)\n", + "\n", + "Sections\n", + " default:\n", + "```" ] }, { @@ -262,9 +329,7 @@ "kernel": "SoS" }, "source": [ - "## Workflow implementation\n", - "\n", - "The cells below define the SoS workflow steps invoked by the command above. They are not meant to be edited for routine analysis.\n" + "## Workflow implementation\n" ] }, { @@ -275,7 +340,25 @@ "kernel": "SoS" }, "outputs": [], - "source": "[global]\n# Brain/tissue TAD coordinates: a tab-separated file with columns chr, start, end (no header)\nparameter: tad_input = path\n# Gene coordinates table derived from the gene-model GTF (columns: index, #chr, start, end, gene_id, gene_name)\nparameter: gene_coords = path\n# Output directory\nparameter: cwd = path(\"output/tadb\")\nparameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n# Minimum percent overlap for two specific TADs to be merged into one generalized TAD\nparameter: overlap_cutoff = 80\n# Container image (kept empty; we no longer use containers)\nparameter: container = ''\n# Resource options (kept for parity with the protocol)\nparameter: job_size = 1\nparameter: walltime = \"20h\"\nparameter: mem = \"40G\"\nparameter: numThreads = 1" + "source": [ + "[global]\n", + "# Brain/tissue TAD coordinates: a tab-separated file with columns chr, start, end (no header)\n", + "parameter: tad_input = path\n", + "# Gene coordinates table derived from the gene-model GTF (columns: index, #chr, start, end, gene_id, gene_name)\n", + "parameter: gene_coords = path\n", + "# Output directory\n", + "parameter: cwd = path(\"output/tadb\")\n", + "parameter: modular_script_dir = path('code/script') # override with --modular-script-dir\n", + "# Minimum percent overlap for two specific TADs to be merged into one generalized TAD\n", + "parameter: overlap_cutoff = 80\n", + "# Container image (kept empty; we no longer use containers)\n", + "parameter: container = ''\n", + "# Resource options (kept for parity with the protocol)\n", + "parameter: job_size = 1\n", + "parameter: walltime = \"20h\"\n", + "parameter: mem = \"40G\"\n", + "parameter: numThreads = 1" + ] }, { "cell_type": "code", @@ -285,7 +368,24 @@ "kernel": "SoS" }, "outputs": [], - "source": "[default]\ninput: tad = tad_input, gene = gene_coords\noutput: gentad = f'{cwd}/generalized_TAD.tsv',\n gentadb = f'{cwd}/generalized_TADB.tsv',\n cis = f'{cwd}/TADB_enhanced_cis.bed',\n ext = f'{cwd}/extended_TADB.bed'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[\"cis\"]:bn}'\nbash: container=container, expand = \"${ }\", stderr = f'{_output[\"cis\"]:n}.stderr', stdout = f'{_output[\"cis\"]:n}.stdout'\n Rscript ${modular_script_dir}/reference_data/generalized_TADB.R \\\n --tad-input ${_input[\"tad\"]} \\\n --gene-coords ${_input[\"gene\"]} \\\n --overlap-cutoff ${overlap_cutoff} \\\n --output-gentad ${_output[\"gentad\"]} \\\n --output-gentadb ${_output[\"gentadb\"]} \\\n --output-cis ${_output[\"cis\"]} \\\n --output-ext ${_output[\"ext\"]}" + "source": [ + "[default]\n", + "input: tad = tad_input, gene = gene_coords\n", + "output: gentad = f'{cwd}/generalized_TAD.tsv',\n", + " gentadb = f'{cwd}/generalized_TADB.tsv',\n", + " cis = f'{cwd}/TADB_enhanced_cis.bed',\n", + " ext = f'{cwd}/extended_TADB.bed'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output[\"cis\"]:bn}'\n", + "bash: container=container, expand = \"${ }\", stderr = f'{_output[\"cis\"]:n}.stderr', stdout = f'{_output[\"cis\"]:n}.stdout'\n", + " Rscript ${modular_script_dir}/reference_data/generalized_TADB.R \\\n", + " --tad-input ${_input[\"tad\"]} \\\n", + " --gene-coords ${_input[\"gene\"]} \\\n", + " --overlap-cutoff ${overlap_cutoff} \\\n", + " --output-gentad ${_output[\"gentad\"]} \\\n", + " --output-gentadb ${_output[\"gentadb\"]} \\\n", + " --output-cis ${_output[\"cis\"]} \\\n", + " --output-ext ${_output[\"ext\"]}" + ] } ], "metadata": { @@ -304,7 +404,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.12" + "version": "3.12.13" }, "sos": { "kernels": [ @@ -321,4 +421,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/code/SoS/reference_data/ld_prune_reference.ipynb b/code/SoS/reference_data/ld_prune_reference.ipynb index 71d361798..de0aaafb7 100644 --- a/code/SoS/reference_data/ld_prune_reference.ipynb +++ b/code/SoS/reference_data/ld_prune_reference.ipynb @@ -7,7 +7,9 @@ "kernel": "SoS" }, "source": [ - "# Independent list of variants using LD clumping" + "# Independent list of variants using LD clumping\n", + "\n", + "Prunes a reference genotype panel down to a set of approximately independent variants, one LD block at a time." ] }, { @@ -17,11 +19,15 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", + "\n", + "Many downstream methods assume the variants they are handed are approximately independent. A reference genotype panel is not: neighbouring variants are correlated through linkage disequilibrium, so a raw variant list counts the same signal several times over. This step runs PLINK LD clumping (`--indep-pairwise`) within each LD block and then merges the survivors into a single list, which is the form `mashr` and similar analyses expect.\n", + "\n", + "Working one block at a time keeps each clumping job small and lets the blocks run in parallel. The merge step afterwards also rewrites the variant IDs into one consistent format.\n", "\n", - "This notebook builds a list of approximately independent (weakly linked) variants from a reference genotype panel by running PLINK LD clumping (`--indep-pairwise`) within each LD block, then merging the pruned variants into a single list. The resulting variant list is useful for downstream `mashr` analysis where a set of independent variants is required.\n", + "**Synthetic-data note.** The minimal working example runs on a small synthetic chr22 PLINK panel, `protocol_example.ld_genotype.chr22`, of 60 samples and roughly 18k variants, built from the toy genotype VCF. It is for demonstration only and is not real individual-level data.\n", "\n", - "> **Synthetic-data note.** This minimal working example runs on a small synthetic chr22 PLINK panel (`protocol_example.ld_genotype.chr22`, 60 samples / ~18k variants) built from the toy genotype VCF. It is for demonstration only and is not real individual-level data." + "**When to run it.** Once against the reference panel, before any analysis that needs a set of independent variants." ] }, { @@ -33,9 +39,17 @@ "source": [ "## Input\n", "\n", - "- `--genotype-list`: a tab-separated file (no header). Each row is an LD block label in the first column followed by one or more PLINK bfile prefixes (`.bed`, with matching `.bim`/`.fam`). Example: `input/ld_prune/protocol_example.ld_genotype.list`.\n", - "- `--cwd`: output directory (default `output/ld_pruned`).\n", - "- `--window` / `--shift` / `--r2`: PLINK `--indep-pairwise` parameters (defaults `50`, `10`, `0.001`)." + "- `--genotype-list`: a tab-separated file with no header. Each row is an LD block label in the first column followed by one or more PLINK bfile prefixes. Every prefix needs its `.bed`, `.bim` and `.fam` present together, otherwise the run stops with `Error: Failed to open ... .bed`. Example `input/ld_prune/protocol_example.ld_genotype.list`:\n", + "\n", + " ```\n", + " chr22_10516173_17414263 input/ld_prune/protocol_example.ld_genotype.chr22.bed\n", + " chr22_17414263_19608021 input/ld_prune/protocol_example.ld_genotype.chr22.bed\n", + " chr22_19608021_22004675 input/ld_prune/protocol_example.ld_genotype.chr22.bed\n", + " ```\n", + "\n", + "- `--window`, `--shift` and `--r2`: the PLINK `--indep-pairwise` parameters, `50`, `10` and `0.001` by default. An `--r2` this strict is aggressive on a small panel; if a block comes back with an empty `.prune.in`, loosen `--r2` to something like `0.2` or widen `--window`.\n", + "- `--cwd`: the directory outputs are written to.\n", + "- `--modular-script-dir`: the `code/script` directory holding the modular analysis scripts." ] }, { @@ -47,35 +61,47 @@ "source": [ "## Output\n", "\n", - "- Per-block `*.prune.in` files (variants kept by LD clumping) under `/LD_pruning/`.\n", - "- A merged list of independent variants `LD_pruned_variants.txt` under `/LD_pruning/`." + "- `{cwd}/LD_pruning/{block}.prune.in` - one file per LD block, listing the variants clumping kept, one per line. Example `output/ld_pruned/LD_pruning/chr22_19608021_22004675.prune.in`, 273 lines:\n", + "\n", + " ```\n", + " chr22:10761227_G_A\n", + " chr22:11312810_G_A\n", + " chr22:11328856_G_T\n", + " chr22:11334723_T_C\n", + " ```\n", + "\n", + " PLINK writes the discarded variants to `{block}.prune.out` and a run log to `{block}.log` beside it.\n", + "\n", + "- `{cwd}/LD_pruning/LD_pruned_variants.txt` - the merged list across every block, with the variant IDs rewritten from PLINK's underscore separator to colons. Example `output/ld_pruned/LD_pruning/LD_pruned_variants.txt`, 820 lines and 5 columns:\n", + "\n", + " ```\n", + " chrom pos alt ref variant_id\n", + " chr22 10761227 G A chr22:10761227:G:A\n", + " chr22 11312810 G A chr22:11312810:G:A\n", + " chr22 11328856 G T chr22:11328856:G:T\n", + " ```" ] }, { "cell_type": "markdown", - "id": "9a623139", + "id": "82e996ab", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps" + "## Minimal Working Example\n", + "\n", + "`LD_pruning` runs both numbered steps in order: `LD_pruning_1` clumps each block, then `LD_pruning_2` merges the survivors. `LD_pruning_2` runs in R and needs `data.table`, `dplyr` and `stringr` in the active environment." ] }, { "cell_type": "markdown", - "id": "82e996ab", + "id": "f07ff02a", "metadata": { "kernel": "SoS" }, "source": [ - "**Step 1.** Run the full `LD_pruning` workflow. It performs LD clumping per block (`LD_pruning_1`) and then merges the surviving variants into a single list (`LD_pruning_2`)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Timing:** ~5-10 min on typical compute infrastructure." + "**Timing**: ~5-10 min (on toy dataset)" ] }, { @@ -99,7 +125,7 @@ "kernel": "SoS" }, "source": [ - "## Command interface" + "## Command Interface" ] }, { @@ -114,6 +140,45 @@ "sos run pipeline/ld_prune_reference.ipynb -h" ] }, + { + "cell_type": "markdown", + "id": "4213390e", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run code/SoS/reference_data/ld_prune_reference.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " LD_pruning\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " Directory holding the modular analysis scripts\n", + " (code/script)\n", + " --job-size 1 (as int)\n", + " --walltime 1h\n", + " --mem 80G\n", + " --numThreads 10 (as int)\n", + "\n", + "Sections\n", + " LD_pruning_1:\n", + " Workflow Options:\n", + " --genotype-list VAL (as path, required)\n", + " --window 50 (as int)\n", + " --shift 10 (as int)\n", + " --r2 0.001 (as float)\n", + " LD_pruning_2:\n", + "```" + ] + }, { "cell_type": "markdown", "id": "0162dade", @@ -135,7 +200,14 @@ }, "outputs": [], "source": [ - "[global]\nparameter: cwd = path(\"output\")\n# Directory holding the modular analysis scripts (code/script)\nparameter: modular_script_dir = path('code/script')\nparameter: job_size = 1\nparameter: walltime = \"1h\"\nparameter: mem = \"80G\"\nparameter: numThreads = 10\n" + "[global]\n", + "parameter: cwd = path(\"output\")\n", + "# Directory holding the modular analysis scripts (code/script)\n", + "parameter: modular_script_dir = path('code/script')\n", + "parameter: job_size = 1\n", + "parameter: walltime = \"1h\"\n", + "parameter: mem = \"80G\"\n", + "parameter: numThreads = 10\n" ] }, { @@ -147,7 +219,32 @@ }, "outputs": [], "source": [ - "[LD_pruning_1]\nparameter: genotype_list = path\nparameter: window = 50\nparameter: shift = 10\nparameter: r2 = 1e-3\n\nimport csv\n# genotype_list: header row + one row per block (block_id, bfile...); pandas read\n# used header=0, so the first row is treated as a header here too.\nwith open(genotype_list) as _fh:\n _rows = [r for r in csv.reader(_fh, delimiter=\"\\t\") if r]\n_rows = _rows[1:]\ninput_blocks = [r[0] for r in _rows]\ninput_files = [r[1:] for r in _rows]\ndel _rows, _fh\n\ninput: input_files, group_by = 1, group_with = \"input_blocks\"\noutput: prune = f'{cwd}/{step_name[:-2]}/{_input_blocks}.prune.in'\ntask: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n plink2 \\\n --bfile ${_input:anr} \\\n --indep-pairwise ${window} ${shift} ${r2} \\\n --rm-dup force-first \\\n --out ${_output[\"prune\"]:annr} \\\n --threads ${numThreads}\n" + "[LD_pruning_1]\n", + "parameter: genotype_list = path\n", + "parameter: window = 50\n", + "parameter: shift = 10\n", + "parameter: r2 = 1e-3\n", + "\n", + "import csv\n", + "# genotype_list: header row + one row per block (block_id, bfile...); pandas read\n", + "# used header=0, so the first row is treated as a header here too.\n", + "with open(genotype_list) as _fh:\n", + " _rows = [r for r in csv.reader(_fh, delimiter=\"\\t\") if r]\n", + "_rows = _rows[1:]\n", + "input_blocks = [r[0] for r in _rows]\n", + "input_files = [r[1:] for r in _rows]\n", + "del _rows, _fh\n", + "\n", + "input: input_files, group_by = 1, group_with = \"input_blocks\"\n", + "output: prune = f'{cwd}/{step_name[:-2]}/{_input_blocks}.prune.in'\n", + "task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, cores = numThreads, tags = f'{step_name}_{_output:bn}'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " plink2 \\\n", + " --bfile ${_input:anr} \\\n", + " --indep-pairwise ${window} ${shift} ${r2} \\\n", + " --rm-dup force-first \\\n", + " --out ${_output[\"prune\"]:annr} \\\n", + " --threads ${numThreads}\n" ] }, { @@ -159,30 +256,13 @@ }, "outputs": [], "source": [ - "[LD_pruning_2]\ninput: group_by = \"all\"\noutput: f'{cwd}/{step_name[:-2]}/LD_pruned_variants.txt'\nbash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n Rscript ${modular_script_dir}/reference_data/ld_prune_reference.R \\\n --input ${_input:r,} \\\n --output ${_output:r}\n" - ] - }, - { - "cell_type": "markdown", - "id": "4213390e", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Troubleshooting\n", - "\n", - "| Problem | Likely cause | Fix |\n", - "| --- | --- | --- |\n", - "| `Error: Failed to open ... .bed` | bfile prefix in the genotype list is wrong or `.bim`/`.fam` missing | Ensure all three PLINK files exist next to the `.bed` named in the list |\n", - "| Empty `*.prune.in` | `--r2` threshold too strict for the toy data | Loosen `--r2` (e.g. `0.2`) or widen `--window` |\n", - "| `LD_pruning_2` R error about packages | `data.table`/`dplyr`/`stringr` not installed | Install the R packages in the active environment |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Anticipated Results\n\nThe pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." + "[LD_pruning_2]\n", + "input: group_by = \"all\"\n", + "output: f'{cwd}/{step_name[:-2]}/LD_pruned_variants.txt'\n", + "bash: expand= \"${ }\", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'\n", + " Rscript ${modular_script_dir}/reference_data/ld_prune_reference.R \\\n", + " --input ${_input:r,} \\\n", + " --output ${_output:r}\n" ] } ], diff --git a/code/SoS/reference_data/reference_data.ipynb b/code/SoS/reference_data/reference_data.ipynb index 3fc3f2a96..f850dc06e 100644 --- a/code/SoS/reference_data/reference_data.ipynb +++ b/code/SoS/reference_data/reference_data.ipynb @@ -6,18 +6,23 @@ "kernel": "SoS" }, "source": [ - "# Reference Data" + "# Reference data preparation\n", + "\n", + "Prepare the genome, annotation, alignment indices and optional genomic reference products used by downstream xQTL workflows." ] }, { "cell_type": "markdown", "metadata": { + "jp-MarkdownHeadingCollapsed": true, "kernel": "SoS" }, "source": [ - "This miniprotocol walks through how the reference data used throughout the xQTL protocol is downloaded, formatted and indexed. It is an introductory, top-to-bottom guide: each step calls a single workflow from the `reference_data_preparation.ipynb` module (plus `VCF_QC.ipynb` for dbSNP, and two interactive notebooks for the TAD and LD-block references).\n", + "#### Miniprotocol Timing\n", + "\n", + "This is the total duration for all phases; module-specific timings appear on their respective pages.\n", "\n", - "**Miniprotocol timing:** ~4 hours, dominated by the genome download and the STAR/RSEM indexing steps." + "Timing: TBD" ] }, { @@ -26,13 +31,11 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "The miniprotocol chains three modules:\n", + "This mini-protocol walks through how the reference data used throughout the xQTL Protocol are downloaded, formatted, and indexed. It is an introductory, top-to-bottom guide: each step calls a single workflow from [`reference_data_preparation.ipynb`](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html), with additional workflows from [`VCF_QC.ipynb`](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/VCF_QC.html), [`generalized_TADB.ipynb`](https://statfungen.github.io/xqtl-protocol/code/reference_data/generalized_TADB.html), and [`rss_ld_sketch.ipynb`](https://statfungen.github.io/xqtl-protocol/code/reference_data/rss_ld_sketch.html).\n", "\n", - "1. `reference_data_preparation.ipynb` (steps i-viii): download and format the reference genome, gene annotations, ERCC spike-in reference, dbSNP variants, and build the STAR / RSEM / RefFlat / SUPPA indices.\n", - "2. `generalized_TADB.ipynb` (step ix): generate topologically associated domain (TAD) files and their boundaries.\n", - "3. `notebook_for_LD_block_reference_panel.ipynb` (step x): produce LD blocks and the reference panel." + "The commands are organized as selectable routes rather than one mandatory 15-step chain. Steps 1\u201312 prepare the core genome and the RNA-seq, RSEM, Picard, SUPPA, or psichomics resources needed by the selected route. Steps 13\u201315 are independent optional workflows for dbSNP annotation, TAD-based association windows, and RSS LD sketches.\n" ] }, { @@ -41,16 +44,23 @@ "kernel": "SoS" }, "source": [ - "## Input Files\n", + "## Steps\n", "\n", - "The download steps need only internet access; nothing local is required to begin. The later formatting and indexing steps consume the products of the preceding steps under the `reference_data/` working directory.\n", + "Choose a route before running commands; the 15 commands are not one mandatory chain.\n", "\n", - "| File | Description |\n", - "| :--- | :--- |\n", - "| `GRCh38_full_analysis_set_plus_decoy_hla.fa` | Reference genome FASTA (downloaded) |\n", - "| `Homo_sapiens.GRCh38.103.chr.gtf` | Ensembl gene annotation GTF (downloaded) |\n", - "| `ERCC92.fa` / `ERCC92.gtf` | ERCC spike-in reference (downloaded) |\n", - "| `00-All.vcf.gz` | dbSNP variant reference (downloaded) |" + "| **Analysis goal** | **Commands to run, in order** | **Inputs** |\n", + "| --- | --- | --- |\n", + "| Basic genome and gene annotation | 1 \u2192 2 \u2192 5 \u2192 6 | - |\n", + "| Bulk RNA-seq alignment with STAR | 1 \u2192 2 \u2192 3 \u2192 5 \u2192 6 \u2192 7 \u2192 8 | - |\n", + "| Transcript quantification with RSEM | 1 \u2192 2 \u2192 3 \u2192 5 \u2192 6 \u2192 7 \u2192 8 \u2192 9 | - |\n", + "| Picard RNA-seq quality control | 1 \u2192 2 \u2192 3 \u2192 5 \u2192 6 \u2192 7 \u2192 8 \u2192 10 | - |\n", + "| SUPPA splicing annotation | 1 \u2192 2 \u2192 3 \u2192 5 \u2192 6 \u2192 7 \u2192 11 | - |\n", + "| psichomics HG38 annotation | 1 \u2192 2 \u2192 3 \u2192 5 \u2192 6 \u2192 7 \u2192 12 | `input/reference_data/hgnc_complete_set.txt` |\n", + "| Add dbSNP rsIDs to a study VCF | 4 \u2192 13 | Internet access and a study VCF |\n", + "| TAD-based association windows | 14 | Tissue-specific TAD calls and gene coordinates |\n", + "| RSS fine-mapping or TWAS | 15 | LD-block definitions and genotype VCFs |\n", + "\n", + "Run only the row matching the intended analysis goal, following its commands in numerical order.\n" ] }, { @@ -59,7 +69,20 @@ "kernel": "SoS" }, "source": [ - "## Steps" + "### 1. [Download the human genome](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", + "\n", + "**What it does:** Download the GRCh38 reference FASTA used by sequence-aware tools.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_hg_reference --cwd output/reference_data" ] }, { @@ -68,9 +91,20 @@ "kernel": "SoS" }, "source": [ - "### 1. [Download Reference Data](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#i-download-reference-data)\n", + "### 2. [Download the gene annotation](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Download the human reference genome, the Ensembl gene annotation, the ERCC spike-in reference, and the dbSNP variant file into the `reference_data` directory." + "**What it does:** Download the Ensembl gene annotation used to define genes and transcripts.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_gene_annotation --cwd output/reference_data" ] }, { @@ -79,7 +113,20 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~varies by dataset on typical compute infrastructure." + "### 3. [Download the ERCC reference](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", + "\n", + "**What it does:** Download ERCC spike-in sequences and annotations for RNA-seq reference construction.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_ercc_reference --cwd output/reference_data" ] }, { @@ -88,31 +135,19 @@ "kernel": "SoS" }, "source": [ - "## Output Files\n", + "### 4. [Download dbSNP](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "| File | Description |\n", - "| --- | --- |\n", - "| `reference_data/*.reference.fasta` | Formatted genome reference |\n", - "| `reference_data/*.gtf` (and gene feature files) | Formatted gene annotation |\n", - "| `reference_data/STAR_Index/` | STAR aligner index |\n", - "| `reference_data/RSEM_Index/` | RSEM quantification index |\n", - "| `reference_data/*.refFlat` | Picard-compatible refFlat annotation |\n", - "| `reference_data/*_suppa_annotation` | SUPPA annotation for psichomics |\n", - "| `reference_data/TAD/*.bed` | Topologically associated domain windows |\n", - "| `reference_data/LD_blocks/` | LD blocks and reference panel |\n" + "**What it does:** Download the dbSNP variant resource used when rsID annotation is required.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb download_hg_reference --cwd output/reference_data\n", - "sos run pipeline/reference_data_preparation.ipynb download_gene_annotation --cwd output/reference_data\n", - "sos run pipeline/reference_data_preparation.ipynb download_ercc_reference --cwd output/reference_data\n", "sos run pipeline/reference_data_preparation.ipynb download_dbsnp --cwd output/reference_data" ] }, @@ -122,23 +157,20 @@ "kernel": "SoS" }, "source": [ - "### 2. [Format Reference Data](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#ii-format-reference-data)\n", + "### 5. [Format and index the genome](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Merge the human genome with the ERCC spike-in sequences and standardise the FASTA so downstream tools share one consistent reference." + "**What it does:** Remove unsupported alternate sequences, append ERCC sequences and create FASTA indices.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb hg_reference \\\n", - " --cwd reference_data \\\n", - " --ercc-reference reference_data/ERCC92.fa \\\n", - " --hg-reference reference_data/GRCh38_full_analysis_set_plus_decoy_hla.fa\n" + "sos run pipeline/reference_data_preparation.ipynb hg_reference --cwd output/reference_data --ercc-reference output/reference_data/ERCC92.fa --hg-reference output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.fa" ] }, { @@ -147,25 +179,20 @@ "kernel": "SoS" }, "source": [ - "### 3. [Format Gene Feature Data](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#iii-format-gene-feature-data)\n", + "### 6. [Format the gene annotation](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Reformat the gene annotation (and append the ERCC features) to produce the collapsed and full GTFs used for expression quantification." + "**What it does:** Add chromosome prefixes and construct the protocol-compatible gene models.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb gene_annotation \\\n", - " --cwd reference_data \\\n", - " --ercc-gtf reference_data/ERCC92.gtf \\\n", - " --hg-gtf reference_data/Homo_sapiens.GRCh38.103.chr.gtf \\\n", - " --hg-reference reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta \\\n", - " --stranded\n" + "sos run pipeline/reference_data_preparation.ipynb hg_gtf --cwd output/reference_data --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.gtf --hg-reference output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta --stranded" ] }, { @@ -174,22 +201,20 @@ "kernel": "SoS" }, "source": [ - "### 4. [Generate STAR Index](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#iv-generate-star-index)\n", + "### 7. [Combine gene and ERCC annotations](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Build the STAR genome index used by the RNA-seq alignment step. This is compute- and memory-intensive." + "**What it does:** Combine the processed human and ERCC annotations into the GTF used downstream.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb STAR_index \\\n", - " --cwd reference_data \\\n", - " --hg-reference reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta\n" + "sos run pipeline/reference_data_preparation.ipynb gene_annotation --cwd output/reference_data --ercc-gtf output/reference_data/ERCC92.gtf --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.gtf --hg-reference output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta --stranded" ] }, { @@ -198,23 +223,20 @@ "kernel": "SoS" }, "source": [ - "### 5. [Generate RSEM Index](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#v-generate-rsem-index)\n", + "### 8. [Build the STAR index](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Build the RSEM index used for transcript-level expression quantification." + "**What it does:** Build the STAR genome index used for RNA-seq alignment.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb RSEM_index \\\n", - " --cwd reference_data \\\n", - " --hg-reference reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta \\\n", - " --hg-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf\n" + "sos run pipeline/reference_data_preparation.ipynb STAR_index --cwd output/reference_data --hg-reference output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta --numThreads 10 --mem 40G" ] }, { @@ -223,22 +245,20 @@ "kernel": "SoS" }, "source": [ - "### 6. [Generate RefFlat Annotation for Picard](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#vi-generate-refflat-annotation-for-picard)\n", + "### 9. [Build the RSEM index](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Generate the RefFlat-format annotation used by Picard for RNA-seq QC metrics." + "**What it does:** Build the RSEM reference used for transcript-level expression quantification.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb RefFlat_generation \\\n", - " --cwd reference_data \\\n", - " --hg-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf\n" + "sos run pipeline/reference_data_preparation.ipynb RSEM_index --cwd output/reference_data --hg-reference output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf" ] }, { @@ -247,22 +267,20 @@ "kernel": "SoS" }, "source": [ - "### 7. [Generate SUPPA Annotation for Psichomics](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html#vii-generate-suppa-annotation-for-psichomics)\n", + "### 10. [Generate RefFlat annotation](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Generate the SUPPA splicing-event annotation consumed by the psichomics splicing workflow." + "**What it does:** Convert the processed GTF into the RefFlat annotation used by Picard RNA-seq QC.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb SUPPA_annotation \\\n", - " --cwd reference_data \\\n", - " --hg-gtf reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf\n" + "sos run pipeline/reference_data_preparation.ipynb RefFlat_generation --cwd output/reference_data --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf" ] }, { @@ -271,21 +289,69 @@ "kernel": "SoS" }, "source": [ - "### 8. [Extract rsIDs for Known Variants](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/VCF_QC.html#optional-dbsnp-annotation)\n", + "### 11. [Generate SUPPA event annotation](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", "\n", - "Annotate the genotype VCF with dbSNP rsIDs. This optional step is implemented in the `VCF_QC.ipynb` module." + "**What it does:** Generate SUPPA event files and the SUPPA annotation RDS used for event-level splicing analysis.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb SUPPA_annotation --cwd output/reference_data --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 12. [Generate the psichomics HG38 annotation](https://statfungen.github.io/xqtl-protocol/code/reference_data/reference_data_preparation.html)\n", + "\n", + "**What it does:** Reconcile the processed GTF with an HGNC database and create `psichomics_hg38_annotation.rds`. The regular example-input bundle does not currently include the required HGNC table.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb psi_hg38_annotation \\\n", + " --hg-gtf output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf \\\n", + " --hgrc-db input/reference_data/hgnc_complete_set.txt \\\n", + " --cwd output/reference_data\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### 13. [Annotate a study VCF with dbSNP identifiers (optional)](https://statfungen.github.io/xqtl-protocol/code/data_preprocessing/genotype/VCF_QC.html)\n", + "\n", + "**What it does:** Add rsIDs to a study VCF when downstream tools require named variants.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/VCF_QC.ipynb dbsnp_annotate \\\n", - " --genoFile reference_data/00-All.vcf.gz\n" + " --genoFile input/genotype/protocol_example.genotype.chr22.vcf.gz \\\n", + " --cwd output/vcf_qc" ] }, { @@ -294,21 +360,23 @@ "kernel": "SoS" }, "source": [ - "### 9. [Generate Topologically Associated Domains](https://statfungen.github.io/xqtl-protocol/code/reference_data/generalized_TADB.html)\n", + "### 14. [Construct generalized TAD boundaries (optional)](https://statfungen.github.io/xqtl-protocol/code/reference_data/generalized_TADB.html)\n", "\n", - "TAD files and their boundaries are produced with the interactive `generalized_TAD.ipynb` notebook." + "**What it does:** Combine tissue-specific TAD calls into customized cis-association windows.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ - "# interactive notebook\n", - "generalized_TAD.ipynb" + "sos run pipeline/generalized_TADB.ipynb default \\\n", + " --tad-input input/tadb/protocol_example.brain_TADs.txt \\\n", + " --gene-coords input/tadb/protocol_example.gene_start_end.tsv \\\n", + " --cwd output/tadb" ] }, { @@ -317,9 +385,24 @@ "kernel": "SoS" }, "source": [ - "### 10. [Produce LD Blocks and Reference Panel](https://statfungen.github.io/xqtl-protocol/code/reference_data/rss_ld_sketch.html)\n", + "### 15. [Construct an LD sketch for RSS analysis (optional)](https://statfungen.github.io/xqtl-protocol/code/reference_data/rss_ld_sketch.html)\n", "\n", - "LD blocks and the reference panel are produced with the interactive `notebook_for_LD_block_reference_panel.ipynb` notebook. See the linked documentation for the interactive walk-through." + "**What it does:** Generate, process and merge LD-sketch products for summary-statistics regression.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "SoS" + }, + "outputs": [], + "source": [ + "sos run pipeline/rss_ld_sketch.ipynb generate_W --n-samples 60 --output-dir output/rss_ld_sketch --B 50 --seed 123 --cwd output/rss_ld_sketch\n", + "\n", + "sos run pipeline/rss_ld_sketch.ipynb process_block --ld-block-file input/rss_ld_sketch/protocol_example.ld_blocks.bed --chrom 22 --vcf-base input/rss_ld_sketch --vcf-prefix protocol_example.genotype. --output-dir output/rss_ld_sketch --W-matrix output/rss_ld_sketch/W_B50.rds --B 50 --cohort-id protocol_example --cwd output/rss_ld_sketch\n", + "\n", + "sos run pipeline/rss_ld_sketch.ipynb merge_chrom --output-dir output/rss_ld_sketch --cohort-id protocol_example --chrom 22 --cwd output/rss_ld_sketch" ] }, { @@ -328,19 +411,36 @@ "kernel": "SoS" }, "source": [ - "## Anticipated Results\n", + "## Output Files\n", "\n", - "The pipeline uses the following reference data for RNA-seq expression quantification:\n", + "| Route | Output products and relative paths |\n", + "| --- | --- |\n", + "| Downloads | `output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.fa`; `output/reference_data/Homo_sapiens.GRCh38.103.chr.gtf`; `output/reference_data/ERCC92.fa`; `output/reference_data/ERCC92.gtf`; `output/reference_data/00-All.vcf.gz`; `output/reference_data/00-All.vcf.gz.tbi` |\n", + "| Basic genome | `output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta`; `output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta`; `output/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.dict` and FASTA index |\n", + "| Basic annotation | `output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.gtf`; `output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.gtf`; `output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.gtf` |\n", + "| STAR | `output/reference_data/STAR_Index/` |\n", + "| RSEM | `output/reference_data/RSEM_Index/` |\n", + "| Picard QC | `output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.ref.flat` |\n", + "| SUPPA | `output/reference_data/hg38.Homo_sapiens.GRCh38.103.chr.reformatted.ERCC_SE_strict.ioe` and the other SUPPA `.ioe` event files; `output/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds` |\n", + "| psichomics | `output/reference_data/psichomics_hg38_annotation.rds` |\n", + "| dbSNP study-VCF annotation | `output/reference_data/00-All.variants.gz` lookup plus the annotated VCF under `output/vcf_qc/` |\n", + "| TAD windows | `output/tadb/generalized_TAD.tsv`; `output/tadb/generalized_TADB.tsv`; `output/tadb/TADB_enhanced_cis.bed`; `output/tadb/extended_TADB.bed` |\n", + "| RSS LD sketch | `output/rss_ld_sketch/W_B50.rds`; block-level `output/rss_ld_sketch/protocol_example..dosage.gz`; chromosome-level `output/rss_ld_sketch/protocol_example.22.pgen` products |" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Anticipated Results\n", "\n", - "1. `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.{dict,fasta,fasta.fai}`\n", - "2. `Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` for the stranded protocol, and `Homo_sapiens.GRCh38.103.chr.reformatted.gene.ERCC.gtf` for the unstranded protocol.\n", - "3. Everything under the `STAR_Index` folder.\n", - "4. Everything under the `RSEM_Index` folder.\n", - "5. Optionally, for quality control, `gtf_ref.flat`.\n", + "After the selected route among steps 1\u201312, the reference directory contains the formatted genome and the annotations required by that analysis. The basic route produces the processed genome and gene annotation; the RNA-seq routes additionally produce the combined ERCC annotation and, as selected, the STAR index, RSEM index, RefFlat annotation, SUPPA event annotation, or psichomics HG38 annotation.\n", "\n", - "For alternative splicing: `Homo_sapiens.GRCh38.103.chr.reformatted.ERCC.SUPPA_annotation.rds` (psichomics).\n", + "Optional step 13 produces a study VCF annotated with dbSNP rsIDs. Optional step 14 produces generalized TAD and TAD-boundary files such as `generalized_TAD.tsv`, `generalized_TADB.tsv`, `TADB_enhanced_cis.bed`, and `extended_TADB.bed`. Optional step 15 produces the random-projection matrix and the block- and chromosome-level LD-sketch products consumed by RSS workflows.\n", "\n", - "For topologically associated domains and boundary files: `generalized_TAD.tsv`, `generalized_TADB.tsv`, `TADB_enhanced_cis.bed`, and `extended_TADB.bed`." + "Proceed to the molecular-phenotype or genotype-preprocessing mini-protocol required by the selected analysis route.\n" ] }, { diff --git a/code/SoS/reference_data/reference_data_preparation.ipynb b/code/SoS/reference_data/reference_data_preparation.ipynb index 9f30becd0..138e121f4 100644 --- a/code/SoS/reference_data/reference_data_preparation.ipynb +++ b/code/SoS/reference_data/reference_data_preparation.ipynb @@ -6,7 +6,9 @@ "kernel": "SoS" }, "source": [ - "# Reference Data Standardization" + "# Reference Data Standardization\n", + "\n", + "Downloads and standardises the genome, annotation and variant reference files that the rest of the protocol reads." ] }, { @@ -15,7 +17,18 @@ "kernel": "SoS" }, "source": [ - "## Description" + "## Overview\n", + "\n", + "Every study that uses this protocol should start from the same reference files: the same\n", + "genome build, the same gene annotation, the same variant lists. When those differ between\n", + "steps or between cohorts, the failures are quiet ones - coordinates that shift by a base,\n", + "genes that exist in one annotation and not the other, meta-analyses that silently drop\n", + "variants.\n", + "\n", + "This notebook downloads and standardises that reference set once, so the rest of the\n", + "protocol reads from a consistent source.\n", + "\n", + "**When to run it.** Run this module once, before downstream workflows that require a reference genome, gene annotation, transcript annotation, or aligner index.\n" ] }, { @@ -24,7 +37,7 @@ "kernel": "SoS" }, "source": [ - "We follow the [TOPMed workflow from Broad](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md) for the aquisition and preparation of reference files for use throughout our pipeline. Our processed reference data may be found [in this folder on Synapse](https://www.synapse.org/#!Synapse:syn36416587). We have included the PDF document compiled by Data Standardization Working Group in the [on Synapse](https://www.synapse.org/#!Synapse:syn36416587) as well as on [ADSP Dashboard](https://www.niagads.org/adsp/content/adspgcadgenomeresources-v2pdf). It contains the reference data to use for the project.\n", + "This module follows the [TOPMed workflow from Broad](https://github.com/broadinstitute/gtex-pipeline/blob/master/TOPMed_RNAseq_pipeline.md) for the aquisition and preparation of reference files for use throughout the pipeline. The processed reference data can be found [in this folder on Synapse](https://www.synapse.org/#!Synapse:syn36416587). The PDF document compiled by Data Standardization Working Group is [on Synapse](https://www.synapse.org/#!Synapse:syn36416587) as well as on [ADSP Dashboard](https://www.niagads.org/adsp/content/adspgcadgenomeresources-v2pdf). It contains the reference data to use for the project.\n", "\n" ] }, @@ -34,9 +47,43 @@ "kernel": "SoS" }, "source": [ - "## Command interface\n", + "### Notes on the reference files\n", + "\n", + "**Why the GTF is modified.** Three reasons. RSEM requires the GTF to use the same chromosome naming\n", + "as the FASTA (a `chr` prefix); for STAR this could be handled with `--sjdbGTFchrPrefix \"chr\"`, but\n", + "RSEM needs it in the file. The GTEx gene-model collapsing script `collapse_annotation.py` expects\n", + "`transcript_type` rather than `transcript_biotype`, so that attribute is renamed here -- it could\n", + "instead be patched in `collapse_annotation.py` when building the container, but since the GTF is\n", + "already being customised for the `chr` prefix, this is folded in. ERCC records are appended at the\n", + "same time. The first two could be dropped if the RSEM requirement goes away.\n", "\n", - "The pipeline below is organized as a sequence of standalone steps, each with its own narrative and `sos run` command. All steps write into a shared `output/reference_data` working directory so that later steps can consume the artefacts produced by earlier ones." + "**The collapsed gene model.** Gene-level expression and eQTLs in GTEx are computed on a collapsed\n", + "gene model -- all isoforms of a gene combined into one transcript -- under three rules: transcripts\n", + "annotated `retained_intron` or `read_through` are excluded, and transcripts overlapping annotated\n", + "read-through transcripts may be blacklisted (blacklists exist for GENCODE v19, v24 and v25; none for\n", + "v26); the union of each gene's exon intervals is taken; and intervals overlapping between genes are\n", + "excluded from all of them. That last rule mainly removes genes annotated on both strands, which\n", + "cannot be quantified unambiguously from unstranded RNA-seq -- for a stranded protocol it can be\n", + "skipped with `--collapse_only`. Rules quoted from the\n", + "[GTEx gene_model documentation](https://github.com/broadinstitute/gtex-pipeline/tree/master/gene_model);\n", + "see also the [GTEx Portal](https://gtexportal.org/home/documentationPage#staticTextAnalysisMethods).\n", + "\n", + "**STAR and RSEM indices.** Both take the reference `fasta` and a `gtf` that must be unzipped and must\n", + "be the pre-collapsing GTF. `sjdbOverhang` sets how much genomic sequence around each annotated\n", + "junction goes into the splice-junction database; it should ideally be the read length minus one. The\n", + "value 100 used here follows the TOPMed pipeline\n", + "([discussion](https://groups.google.com/g/rna-star/c/h9oh10UlvhI/m/BfSPGivUHmsJ)). STAR needs at\n", + "least 40 GB of memory." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**When to run it.** First, before any data processing, and again only when you change\n", + "genome build or annotation release." ] }, { @@ -45,21 +92,128 @@ "kernel": "SoS" }, "source": [ - "## 1. Download reference data\n", + "## Input\n", + "\n", + "The four `download_*` workflows take no options -- they fetch the reference files from their public\n", + "sources. Everything else consumes files those downloads produce, or that this module derives:\n", "\n", - "This step downloads the unmodified source files that every downstream step builds upon: the human reference genome, the Ensembl gene annotation, the ERCC spike-in sequences, and the dbSNP variant call set.\n", + "- `--hg-reference` (required by `hg_reference_1`, `hg_gtf_1`, `gene_annotation`): the reference\n", + " genome FASTA, e.g. `input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta`.\n", + "- `--hg-gtf` (required by `hg_gtf_1`, `gene_annotation`, `psi_hg38_annotation`): the gene model GTF.\n", + "- `--gff3-file` (required by `gff3_to_gtf`): a GFF3 to convert to GTF.\n", + "- `--ercc-reference` (required by `hg_reference_2`): the ERCC spike-in FASTA, merged into the genome.\n", + "- `--ercc-gtf` (required by `ercc_gtf`): the ERCC annotation to patch and append.\n", + "- `--stranded` / `--no-stranded` (required by `hg_gtf_2`): whether the library is stranded.\n", + "- `--hgrc-db` (required by `psi_hg38_annotation`): reference database for the psichomics\n", + " annotation. Undocumented: the code does not say what this file is or where to obtain it.\n", + "- `--TAD-list`, `--region-list`, `--TAD-genotype` (all required by `Tad_annotateion`): the TAD\n", + " definitions, the regions to annotate and the genotypes to annotate them against.\n", + "- `--genoFile` (used by `download_dbsnp`): the dbSNP VCF to index, e.g.\n", + " `output/reference_data/00-All.vcf.gz`.\n", + "- `--cwd` (default `output`) and `--modular-script-dir` (default `code/script`).\n", + "\n", + "Cluster resources: `--numThreads` (default `8`), `--job-size` (default `1`), `--walltime` (default\n", + "`5h`), `--mem` (default `16G`), `--container`.\n", + "\n", + "Reference files shipped with the protocol, under `input/reference_data/`:\n", + "\n", + "- `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta` -- the genome before ERCC merge.\n", + "- `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta` (+ `.fai`) -- after merge.\n", + "- `Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf` -- the collapsed gene model.\n", + "- `00-All.add_chr.variants.gz` (+ `.tbi`) -- chr-renamed dbSNP variants.\n", + "- `look_up_gene_id.tsv`, `STAR_Index/`, `TAD/` -- gene-ID map, STAR index and TAD definitions." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Output\n", + "\n", + "- `.fasta` / `.fa` (+ `.fai`) -- from `hg_reference_1..3`: the reference genome after HLA/ALT\n", + " and decoy removal, merged with the ERCC spike-in reference and indexed.\n", + "- `.dict` -- the sequence dictionary Picard tools require alongside the FASTA.\n", + "- `.collapse_only.gene.gtf` -- from `gene_annotation`: the collapsed gene model, one record per\n", + " gene, used wherever a gene-level annotation is needed.\n", + "- `ERCC92.gtf` and `ERCC92.genes.patched.gtf` -- from `ercc_gtf`: the ERCC annotation, and the patched\n", + " form appended to the gene model.\n", + "- `.ref.flat` -- from `RefFlat_generation`: the RefFlat annotation Picard uses for RNA metrics.\n", + "- `00-All.vcf.gz` (+ `.tbi`) -- from `download_dbsnp`: the dbSNP VCF, bgzipped and tabix-indexed.\n", + "- `RSEM_Index/rsem_reference.grp` and `rsem_reference.n2g.idx.fa` -- from `RSEM_index`.\n", + "- `_SE_strict.ioe` -- from `SUPPA_annotation_1`: the SUPPA event definitions.\n", + "- `.SUPPA_annotation.rds` and `psichomics_hg38_annotation.rds` -- from `SUPPA_annotation_2` and\n", + " `psi_hg38_annotation`.\n", + "- `look_up_gene_id.txt` -- the gene-ID lookup table written alongside the gene annotation.\n", + "- `STAR_Index/` and the RSEM index -- from `STAR_index` and `RSEM_index`.\n", + "- the SUPPA and TAD annotations -- from `SUPPA_annotation_1..2` and `psi_hg38_annotation`.\n", + "\n", + "All paths are relative to `--cwd`.\n", + "\n", + "`output/reference_data/ERCC92.gtf`:\n", + "\n", + "```\n", + "ERCC-00002\tERCC\texon\t1\t1061\t0.000000\t+\t.\tgene_id \"ERCC-00002\"; transcript_id \"DQ459430\";\n", + "ERCC-00003\tERCC\texon\t1\t1023\t0.000000\t+\t.\tgene_id \"ERCC-00003\"; transcript_id \"DQ516784\";\n", + "```\n", + "\n", + "`output/reference_data/ERCC92.ref.flat`:\n", + "\n", + "```\n", + "\tDQ459430\tERCC-00002\t+\t0\t1061\t1061\t1061\t1\t0,\t1061,\n", + "\tDQ516784\tERCC-00003\t+\t0\t1023\t1023\t1023\t1\t0,\t1023,\n", + "```\n", + "\n", + "**Only the ERCC products have committed example output.** `output/reference_data/` holds\n", + "`ERCC92.gtf`, `ERCC92.genes.patched.gtf` and `ERCC92.ref.flat`; the genome merge, collapsed gene\n", + "model, STAR and RSEM indices and the SUPPA/TAD annotations were not run here, so no dump is shown\n", + "for them." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "### Preparing the reference data\n", "\n", - "**Input**: None.\n", + "These are not one sequential pipeline, so the blocks below are entry points rather than numbered\n", + "steps. The four downloads are independent of each other and of everything else. Three do have to run\n", + "in order -- format the reference genome, then process the transcript and gene model, then assemble\n", + "the gene annotation -- because each reads what the one before it wrote. The remaining generators\n", + "(STAR, RSEM, RefFlat, SUPPA, rsID and TAD) each read the formatted references and are independent of\n", + "one another, so run only the ones the analysis needs." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Download the ERCC spike-in reference\n", "\n", - "**Output**:\n", - "* `00-All.vcf.gz`\n", - "* `00-All.vcf.gz.tbi`\n", - "* `ERCC92.fa`\n", - "* `ERCC92.gtf`\n", - "* `ERCC92.zip`\n", - "* `GRCh38_full_analysis_set_plus_decoy_hla.fa`\n", - "* `Homo_sapiens.GRCh38.103.chr.gtf`\n", - "* `Homo_sapiens.GRCh38.103.chr.gtf.gz`" + "Fetches the ERCC spike-in sequences and annotation." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -70,10 +224,7 @@ }, "outputs": [], "source": [ - "sos run pipeline/reference_data_preparation.ipynb download_hg_reference --cwd output/reference_data\n", - "sos run pipeline/reference_data_preparation.ipynb download_gene_annotation --cwd output/reference_data\n", - "sos run pipeline/reference_data_preparation.ipynb download_ercc_reference --cwd output/reference_data\n", - "sos run pipeline/reference_data_preparation.ipynb download_dbsnp --cwd output/reference_data" + "sos run pipeline/reference_data_preparation.ipynb download_ercc_reference --cwd output/reference_data" ] }, { @@ -82,19 +233,111 @@ "kernel": "SoS" }, "source": [ - "## 2. Format reference genome\n", + "#### Download the gene annotation\n", "\n", - "The downloaded genome is reformatted into the version used by the rest of the protocol: the HLA, ALT and Decoy records are removed because none of the downstream RNA-seq calling components handle them properly, the ERCC spike-in sequences are appended (these do no harm even when ERCC is not part of the RNA-seq library), and the resulting FASTA is indexed.\n", + "Fetches the Ensembl gene annotation GTF and its compressed form." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_gene_annotation --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Download the reference genome\n", "\n", - "**Input**: a reference FASTA file.\n", + "Fetches the unmodified human reference genome FASTA." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_hg_reference --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Download dbSNP variants\n", + "\n", + "Fetches the dbSNP call set and tabix-indexes it, writing `00-All.vcf.gz` and its `.tbi`." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb download_dbsnp \\ --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "#### Format reference genome\n", "\n", - "**Output**: a reference FASTA file without HLA, ALT and Decoy but with ERCC:\n", - "* `ERCC92.patched.fa`\n", - "* `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta`\n", - "* `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.dict`\n", - "* `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta`\n", - "* `GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta.fai`\n", - "* `Homo_sapiens.GRCh38.103.chr.reformatted.gtf`" + "The downloaded genome is reformatted into the version used by the rest of the protocol: the HLA, ALT and Decoy records are removed because none of the downstream RNA-seq calling components handle them properly, the ERCC spike-in sequences are appended (these do no harm even when ERCC is not part of the RNA-seq library), and the resulting FASTA is indexed." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -117,15 +360,18 @@ "kernel": "SoS" }, "source": [ - "## 3. Transcript and gene model reference processing\n", - "\n", - "This step modifies the GTF file for two reasons. First, RSEM requires the GTF to use the same chromosome naming convention (with a `chr` prefix) as the FASTA file; although this can also be addressed with the `--sjdbGTFchrPrefix \"chr\"` option for STAR, the `chr` prefix is added to the GTF for use with RSEM. Second, the gene-model collapsing script `collapse_annotation.py` from GTEx expects the GTF to carry a `transcript_type` attribute rather than `transcript_biotype`; this is renamed here while building the Docker image. ERCC information is also added to the GTF reference as a further customization.\n", - "\n", - "**Collapsed gene model.** Gene-level expression and eQTLs in the GTEx project are computed on a collapsed gene model (all isoforms of a gene combined into a single transcript), following these rules: transcripts annotated as `retained_intron` or `read_through` are excluded, and transcripts overlapping annotated read-through transcripts may be blacklisted (blacklists for GENCODE v19, v24 and v25 are provided in the GTEx repository; no transcripts were blacklisted for v26); the union of all exon intervals of each gene is taken; and overlapping intervals between genes are excluded. Excluding overlapping regions (step 3) primarily removes genes annotated on both strands that cannot be unambiguously quantified from unstranded RNA-seq; for stranded protocols this step can be skipped with the `--collapse_only` flag. Further documentation is available on the [GTEx Portal](https://gtexportal.org/home/documentationPage#staticTextAnalysisMethods).\n", + "#### Transcript and gene model reference processing\n", "\n", - "**Input**: an uncompressed GFF3 file (i.e. one that can be read with `cat`) and a GTF file.\n", - "\n", - "**Output**: a GTF file with a collapsed gene model." + "This step modifies the GTF file for two reasons. First, RSEM requires the GTF to use the same chromosome naming convention (with a `chr` prefix) as the FASTA file; although this can also be addressed with the `--sjdbGTFchrPrefix \"chr\"` option for STAR, the `chr` prefix is added to the GTF for use with RSEM. Second, the gene-model collapsing script `collapse_annotation.py` from GTEx expects the GTF to carry a `transcript_type` attribute rather than `transcript_biotype`; this is renamed here while building the Docker image. ERCC information is also added to the GTF reference as a further customization." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -149,13 +395,18 @@ "kernel": "SoS" }, "source": [ - "## 4. Gene annotation\n", - "\n", - "This step assembles the gene annotation used downstream by combining the ERCC GTF, the reformatted Ensembl GTF, and the formatted reference genome into a single coherent annotation set.\n", + "#### Gene annotation\n", "\n", - "**Input**: a GTF file and an accompanying FASTA file.\n", - "\n", - "**Output**: the formatted gene annotation reference." + "This step assembles the gene annotation used downstream by combining the ERCC GTF, the reformatted Ensembl GTF, and the formatted reference genome into a single coherent annotation set." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -180,15 +431,18 @@ "kernel": "SoS" }, "source": [ - "## 5. Generate STAR index\n", - "\n", - "This step generates the index file used for STAR alignment. The index needs to be generated only once and can then be re-used. **At least 40GB of memory is required.**\n", + "#### Generate STAR index\n", "\n", - "The `gtf` and `fasta` parameters give the paths to the reference sequence and both must be unzipped; the `gtf` should be the one prior to collapsing by gene. The `sjdbOverhang` parameter specifies the length of genomic sequence around each annotated junction used when constructing the splice-junction database; ideally it should equal the read length minus one, where read length is the length of the reads. A value of 100 is used here as recommended by the TOPMed pipeline (see [additional discussion](https://groups.google.com/g/rna-star/c/h9oh10UlvhI/m/BfSPGivUHmsJ)).\n", - "\n", - "**Input**: a GTF file and an accompanying FASTA file.\n", - "\n", - "**Output**: an index folder stored in `{cwd}/STAR_Index`, used by STAR." + "This step generates the index file used for STAR alignment. The index needs to be generated only once and can then be re-used. **At least 40GB of memory is required.**" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -212,15 +466,18 @@ "kernel": "SoS" }, "source": [ - "## 6. Generate RSEM index\n", + "#### Generate RSEM index\n", "\n", - "This step generates the indexing file used for RSEM. The index needs to be generated only once.\n", - "\n", - "The `gtf` and `fasta` parameters give the paths to the reference sequence; the `gtf` should be the one prior to collapsing by gene. The `sjdbOverhang` parameter specifies the length of genomic sequence around each annotated junction used when constructing the splice-junction database; ideally it should equal the read length minus one.\n", - "\n", - "**Input**: a GTF file and an accompanying FASTA file.\n", - "\n", - "**Output**: an index folder stored in `RSEM_Index`, used by RSEM." + "This step generates the indexing file used for RSEM. The index needs to be generated only once." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -243,13 +500,18 @@ "kernel": "SoS" }, "source": [ - "## 7. Generate RefFlat annotation\n", - "\n", - "This file is required by the Picard `CollectRnaSeqMetrics` module, which produces metrics describing the distribution of bases within the transcripts. It calculates the total numbers and fractions of nucleotides within specific genomic regions, including untranslated regions (UTRs), introns, intergenic sequences (between discrete genes), and peptide-coding sequences (exons). The tool also determines the number of bases that pass quality filters specific to Illumina data (PF_BASES).\n", + "#### Generate RefFlat annotation\n", "\n", - "**Input**: a GTF file.\n", - "\n", - "**Output**: a `ref.flat` file." + "This file is required by the Picard `CollectRnaSeqMetrics` module, which produces metrics describing the distribution of bases within the transcripts. It calculates the total numbers and fractions of nucleotides within specific genomic regions, including untranslated regions (UTRs), introns, intergenic sequences (between discrete genes), and peptide-coding sequences (exons). The tool also determines the number of bases that pass quality filters specific to Illumina data (PF_BASES)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -271,13 +533,18 @@ "kernel": "SoS" }, "source": [ - "## 8. Generate SUPPA annotation\n", - "\n", - "The custom alternative-splicing annotation is generated for psichomics, based on [this tutorial](https://rpubs.com/nuno-agostinho/preparing-AS-annotation); the procedure for generating the local alternative-splicing SUPPA output is documented on the [SUPPA GitHub page](https://github.com/comprna/SUPPA). Because the original annotation provided by the psichomics package uses gene symbols, it is modified here to use Ensembl IDs. The modified annotation is then used for [detecting RNA alternative splicing with psichomics](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html).\n", + "#### Generate SUPPA annotation\n", "\n", - "**Input**: a GTF file.\n", - "\n", - "**Output**: a `.SUPPA_annotation.rds` file." + "The custom alternative-splicing annotation is generated for psichomics, based on [this tutorial](https://rpubs.com/nuno-agostinho/preparing-AS-annotation); the procedure for generating the local alternative-splicing SUPPA output is documented on the [SUPPA GitHub page](https://github.com/comprna/SUPPA). Because the original annotation provided by the psichomics package uses gene symbols, it is modified here to use Ensembl IDs. The modified annotation is then used for [detecting RNA alternative splicing with psichomics](https://statfungen.github.io/xqtl-protocol/code/molecular_phenotypes/calling/splicing_calling.html)." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -299,13 +566,26 @@ "kernel": "SoS" }, "source": [ - "## 9. Extract rsIDs and TAD annotation\n", - "\n", - "The dbSNP call set is processed to extract rsIDs for known variants, producing a lookup used to annotate variants throughout the protocol. The TAD-associated index is built from the topologically associating domains defined in [Wang et al.](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7895846/) to delimit the genotype cis region used for fine-mapping across phenotypes; the TAD dataframe for each cell type and tissue is downloaded from the [hg38 TAD resource](http://3dgenome.fsm.northwestern.edu/publications.html). The TAD file is generated in three steps: the union of TADs across tissues, extension with TAD boundaries, and extension with cis windows.\n", + "#### Extract rsIDs for known variants (handled elsewhere)\n", "\n", - "**Input**: a `.vcf.gz` file (for rsIDs) and a file containing a list of TADs and a region list (for TAD annotation).\n", + "Annotating the dbSNP call set with rsIDs is done by `VCF_QC.ipynb` (`dbsnp_annotate`), not by this\n", + "module. Run it there against `output/reference_data/00-All.vcf.gz`." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Convert GFF3 to GTF\n", "\n", - "**Output**: a `.variants.gz` file (rsIDs) and a `.annotation` file (TAD)." + "`gff3_to_gtf` converts a GFF3 annotation to GTF. The protocol ships no example GFF3, so supply your own." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -316,41 +596,223 @@ }, "outputs": [], "source": [ - "sos run pipeline/VCF_QC.ipynb dbsnp_annotate \\\n", - " --genoFile output/reference_data/00-All.vcf.gz \\\n", - " --cwd output/reference_data " + "sos run pipeline/reference_data_preparation.ipynb gff3_to_gtf \\\n", + " --gff3-file /annotation.gff3 \\\n", + " --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Patch the ERCC annotation\n", + "\n", + "`ercc_gtf` patches the downloaded ERCC GTF so it can be appended to the gene model." ] }, { "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": { - "kernel": "SoS" + "kernel": "Bash" }, + "outputs": [], "source": [ - "## Output\n", + "sos run pipeline/reference_data_preparation.ipynb ercc_gtf \\\n", + " --ercc-gtf output/reference_data/ERCC92.gtf \\\n", + " --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Generate psichomics annotation\n", "\n", - "The steps above write a standardized reference bundle that the rest of the protocol consumes:\n", + "`psi_hg38_annotation` builds the psichomics annotation. `--hgrc-db` is undocumented: the code does not say what this file is or where to obtain it." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb psi_hg38_annotation \\\n", + " --hg-gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \\\n", + " --hgrc-db /hgrc_db \\\n", + " --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### TAD annotation\n", "\n", - "| File | Produced by |\n", - "| --- | --- |\n", - "| Cleaned reference genome (FASTA) and matched gene model (GTF) | Steps 1–2 (download & format reference data) |\n", - "| Per-feature gene-coordinate table | Step 3 (format gene feature data) |\n", - "| STAR genome index | Step 4 (generate STAR index) |\n", - "| RSEM reference | Step 5 (generate RSEM index) |\n", - "| RefFlat annotation (for Picard RNA-seq metrics) | Step 6 |\n", - "| SUPPA event annotation (for psichomics splicing) | Step 7 |\n", - "| rsID lookup for known variants | Step 8 (extract rsIDs) |" + "`Tad_annotateion` annotates TADs. The protocol ships `input/reference_data/TAD/` but no example region list or TAD genotype." ] }, { "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "kernel": "Bash" + }, + "outputs": [], + "source": [ + "sos run pipeline/reference_data_preparation.ipynb Tad_annotateion \\\n", + " --TAD-list input/reference_data/TAD/ \\\n", + " --region-list /region_list.txt \\\n", + " --TAD-genotype /tad_genotype \\\n", + " --cwd output/reference_data" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Command Interface" + ] + }, + { + "cell_type": "code", + "execution_count": null, "metadata": { "kernel": "SoS" }, + "outputs": [], "source": [ - "## Anticipated Results\n", + "sos run pipeline/reference_data_preparation.ipynb -h" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/reference_data_preparation.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " download_hg_reference\n", + " download_gene_annotation\n", + " download_ercc_reference\n", + " download_dbsnp\n", + " gff3_to_gtf\n", + " hg_reference\n", + " hg_gtf\n", + " ercc_gtf\n", + " gene_annotation\n", + " STAR_index\n", + " RSEM_index\n", + " RefFlat_generation\n", + " SUPPA_annotation\n", + " psi_hg38_annotation\n", + " Tad_annotateion\n", + "\n", + "Global Workflow Options:\n", + " --modular-script-dir code/script (as path)\n", + " --cwd output (as path)\n", + " The output directory for generated files.\n", + " --job-size 1 (as int)\n", + " For cluster jobs, number commands to run per job\n", + " --walltime 5h\n", + " Wall clock time expected\n", + " --mem 16G\n", + " Memory expected\n", + " --numThreads 8 (as int)\n", + " Number of threads\n", + " --container ''\n", + " Software container option\n", "\n", - "Running all eight steps produces a complete, standardized reference-data bundle for the rest of the protocol: a cleaned reference genome and matched gene-model annotation (GTF), per-feature gene-coordinate tables, a STAR genome index and an RSEM reference for RNA-seq alignment/quantification, a RefFlat annotation for Picard RNA-seq metrics, a SUPPA event annotation for psichomics-based splicing analysis, and an rsID lookup for known variants. These files are written once and then reused as fixed inputs by the molecular-phenotype, association, and downstream modules, so that every analysis in the protocol is run against the same curated reference." + "Sections\n", + " download_hg_reference:\n", + " download_gene_annotation:\n", + " download_ercc_reference:\n", + " download_dbsnp:\n", + " gff3_to_gtf:\n", + " Workflow Options:\n", + " --gff3-file VAL (as path, required)\n", + " hg_reference_1:\n", + " Workflow Options:\n", + " --hg-reference VAL (as path, required)\n", + " Path to HG reference file\n", + " hg_reference_2:\n", + " Workflow Options:\n", + " --ercc-reference VAL (as path, required)\n", + " hg_reference_3:\n", + " hg_gtf_1:\n", + " Workflow Options:\n", + " --hg-reference VAL (as path, required)\n", + " --hg-gtf VAL (as path, required)\n", + " hg_gtf_2:\n", + " Workflow Options:\n", + " --[no-]stranded (required)\n", + " ercc_gtf:\n", + " Workflow Options:\n", + " --ercc-gtf VAL (as path, required)\n", + " gene_annotation:\n", + " STAR_index:\n", + " Workflow Options:\n", + " --hg-reference VAL (as path, required)\n", + " RSEM_index:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " --hg-reference VAL (as path, required)\n", + " RefFlat_generation:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " SUPPA_annotation_1:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " SUPPA_annotation_2:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " psi_hg38_annotation:\n", + " Workflow Options:\n", + " --hg-gtf VAL (as path, required)\n", + " --hgrc-db VAL (as path, required)\n", + " FIXME: Please document what this file is and where do we\n", + " get it @xuanhe.\n", + " Tad_annotateion:\n", + " Workflow Options:\n", + " --TAD-list VAL (as path, required)\n", + " The tad file downloads from\n", + " --region-list VAL (as path, required)\n", + " --TAD-genotype VAL (as path, required)\n", + "```" ] }, { @@ -740,25 +1202,11 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": null, "metadata": { - "kernel": "SoS", - "tags": [] + "kernel": "SoS" }, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/home/hs3163/miniconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3441: FutureWarning: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only.\n", - " exec(code_obj, self.user_global_ns, self.user_ns)\n", - "/home/hs3163/miniconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3441: FutureWarning: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only.\n", - " exec(code_obj, self.user_global_ns, self.user_ns)\n", - "/home/hs3163/miniconda3/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3441: FutureWarning: In a future version of pandas all arguments of read_csv except for the argument 'filepath_or_buffer' will be keyword-only.\n", - " exec(code_obj, self.user_global_ns, self.user_ns)\n" - ] - } - ], + "outputs": [], "source": [ "[Tad_annotateion]\n", "## The tad file downloads from\n", diff --git a/code/SoS/reference_data/rss_ld_sketch.ipynb b/code/SoS/reference_data/rss_ld_sketch.ipynb index f3bb04b19..2646a3baa 100644 --- a/code/SoS/reference_data/rss_ld_sketch.ipynb +++ b/code/SoS/reference_data/rss_ld_sketch.ipynb @@ -7,7 +7,9 @@ "kernel": "SoS" }, "source": [ - "# RSS LD Sketch Pipeline" + "# RSS LD Sketch Pipeline\n", + "\n", + "Builds a compact stochastic sketch of a genotype panel for use as an LD reference in summary-statistic fine-mapping." ] }, { @@ -17,21 +19,27 @@ "kernel": "SoS" }, "source": [ - "## Description\n", + "## Overview\n", "\n", - "This pipeline generates a stochastic genotype sample **U = W\u1d40G** from whole-genome sequencing VCF files and stores it as a PLINK2 pgen file for use as an LD reference panel with SuSiE-RSS fine-mapping.\n", + "This pipeline generates a stochastic genotype sample **U = WᵀG** from whole-genome sequencing VCF files and stores it as a PLINK2 pgen file for use as an LD reference panel with SuSiE-RSS fine-mapping.\n", "\n", - "**Key idea:** Rather than storing the full genotype matrix G (n \u00d7 p), we compute U = W\u1d40G (B \u00d7 p) using a random projection matrix $W \\sim N(0, 1/\\sqrt{n})$. The approximate LD matrix $R = U^T U / B \\approx G^T G / n$ by the Johnson\u2013Lindenstrauss lemma. G is never stored.\n", + "Rather than storing the full genotype matrix G (n × p), the sketch computes U = WᵀG (B × p) using a random projection matrix $W \\sim N(0, 1/\\sqrt{n})$. The approximate LD matrix $R = U^T U / B \\approx G^T G / n$ by the Johnson–Lindenstrauss lemma. G is never stored.\n", "\n", "**Matrix dimensions:**\n", - "- G : (n \u00d7 p) \u2014 n individuals \u00d7 p variants\n", - "- W : (n \u00d7 B) \u2014 projection matrix, generated once per cohort\n", - "- U : (B \u00d7 p) \u2014 stochastic genotype sample = W\u1d40G, stored in pgen\n", - "- $\\hat{R}$ : (p \u00d7 p) \u2014 approximate LD matrix, computed on-the-fly by SuSiE-RSS from U\n", + "- G : (n × p) — n individuals × p variants\n", + "- W : (n × B) — projection matrix, generated once per cohort\n", + "- U : (B × p) — stochastic genotype sample = WᵀG, stored in pgen\n", + "- $\\hat{R}$ : (p × p) — approximate LD matrix, computed on-the-fly by SuSiE-RSS from U\n", "\n", "The workflow has three steps run in order: `generate_W` (build the projection matrix), `process_block` (read VCF per LD block and write per-block dosage sketches), and `merge_chrom` (merge per-block dosages into one per-chromosome pgen).\n", "\n", - "**Note on data:** This example runs on a clearly-labeled synthetic toy dataset \u2014 a chr22 VCF (`protocol_example.genotype.chr22.bgz`, 60 individuals) and a 3-block LD-block BED (`protocol_example.ld_blocks.bed`). No access-controlled individual-level human genomic data is used." + "Summary-statistic fine-mapping needs an LD matrix, and storing the full genotype matrix for\n", + "a whole-genome panel is expensive. The sketch keeps a random projection of the genotypes\n", + "instead: small enough to distribute, but sufficient to reconstruct the LD structure that\n", + "SuSiE-RSS actually uses.\n", + "\n", + "**When to run it.** Once per reference panel, before any `rss_analysis` run that needs an\n", + "LD reference. The output is reference data, not a per-study result." ] }, { @@ -43,25 +51,95 @@ "source": [ "## Input\n", "\n", - "- **LD-block BED** (`--ld-block-file`): tab-separated file with columns `chr`, `start`, `end` (0-based half-open) defining the regions to sketch. Toy file: `input/rss_ld_sketch/protocol_example.ld_blocks.bed` (3 chr22 blocks).\n", - "- **VCF directory** (`--vcf-base`) and **prefix** (`--vcf-prefix`): bgzipped (`.bgz`) + tabix-indexed VCF(s) named `{vcf_prefix}{chr}.*.bgz`. Toy file: `input/rss_ld_sketch/protocol_example.genotype.chr22.bgz` (60 individuals), discovered with `--vcf-base input/rss_ld_sketch --vcf-prefix protocol_example.genotype.`\n", - "- **`--n-samples`**: number of individuals in the VCF (here 60). Must match the VCF sample count.\n", - "- **`--B`**: number of sketch (pseudo-)samples / projection dimension (the toy uses a small B for speed; production uses ~10000).\n", - "- **`--chrom`**: chromosome to process (e.g. 22; 0 = all autosomes found).\n", - "- **`--cohort-id`**: label used to name output files.\n", + "- `--ld-block-file` **`input/rss_ld_sketch/protocol_example.ld_blocks.bed`**\n", + "(regions to sketch, tab-separated with columns `chr`, `start`, `end` in 0-based half-open coordinates; the toy file holds 3 chr22 blocks)\n", + "\n", + "```\n", + "#chr\tstart\tend\n", + "chr22\t16000000\t20000000\n", + "chr22\t30000000\t34000000\n", + "```\n", + "\n", + "- `--vcf-base` **`input/rss_ld_sketch`** together with `--vcf-prefix protocol_example.genotype.`\n", + "(directory of bgzipped, tabix-indexed VCFs named `{vcf_prefix}{chr}.*.bgz`; the toy cohort is `protocol_example.genotype.chr22.bgz`, 60 individuals)\n", + "\n", + "```\n", + "#CHROM\tPOS\tID\tREF\tALT\tQUAL\tFILTER\tINFO\tFORMAT\tSAMPLE_001\t...\n", + "```\n", + "\n", + "- `--n-samples 60` (number of individuals in the VCF. Must match the VCF sample count, or `process_block` fails with a W shape mismatch.)\n", + "- `--B 50` (number of sketch (pseudo-)samples to project down to. Sets the second dimension of W.)\n", "\n", - "Filter thresholds (defaults shown in the implementation): `--maf-min 0.0005`, `--mac-min 5`, `--msng-min 0.05`." + "- `--cwd output/rss_ld_sketch` (working directory for logs and job files. Defaults to `output`.)\n", + "- `--output-dir output/rss_ld_sketch` (directory the sketch products are written to)\n", + "- `--seed 999` (random seed for the projection matrix, so a sketch can be reproduced)\n", + "- `--W-matrix` **`output/rss_ld_sketch/W_B50.npy`**\n", + "(the shared projection matrix, passed to `process_block` after `generate_W` has written it)\n", + "- `--chrom chr22` (chromosome to process)\n", + "- `--cohort-id protocol_example` (tag used in the per-block and merged output filenames)" ] }, { "cell_type": "markdown", - "id": "dce33bc7", + "id": "ac3cfb79", "metadata": { "kernel": "SoS" }, "source": [ - "## Steps\n", + "## Output\n", + "\n", + "- **`output/rss_ld_sketch/W_B50.npy`**\n", + "(shared projection matrix written once by `generate_W`, shape n_samples x B; `process_block` reads it back for every LD block so all blocks share one projection)\n", + "\n", + "```\n", + "float32 (60, 50)\n", + "[[-0.1402 0.1288 0.0365 -0.1945 -0.0747]\n", + " [-0.1671 -0.1341 0.2251 -0.1030 0.0038]]\n", + "```\n", + "\n", + "- **`output/rss_ld_sketch/chr22/chr22__/.chr22__.dosage.gz`** (`process_block`)\n", + "(the per-LD-block sketch: B pseudo-samples x the variants in that block, gzipped dosage text. One directory per block, written before `merge_chrom` concatenates them.)\n", + "\n", + "- **`output/rss_ld_sketch/chr22/protocol_example.chr22.pgen`** (with `.pvar`, `.psam`, `.afreq`)\n", + "(per-chromosome PLINK2 genotype sketch assembled by `merge_chrom`: B pseudo-samples x p variants. The `.pgen` is binary; the three companion files describe it.)\n", "\n", + "- **`output/rss_ld_sketch/chr22/protocol_example.chr22.pvar`** (variant information)\n", + "\n", + "```\n", + "#CHROM\tPOS\tID\tREF\tALT\n", + "22\t16073625\tchr22:16073625:G:T\tG\tT\n", + "22\t16102937\tchr22:16102937:C:T\tC\tT\n", + "```\n", + "\n", + "- **`output/rss_ld_sketch/chr22/protocol_example.chr22.psam`** (the B sketch pseudo-samples, named `S1`..`S{B}`)\n", + "\n", + "```\n", + "#FID\tIID\tSEX\n", + "S1\tS1\tNA\n", + "S2\tS2\tNA\n", + "```\n", + "\n", + "- **`output/rss_ld_sketch/chr22/protocol_example.chr22.afreq`** (allele frequencies and the sketch value range per variant)\n", + "\n", + "```\n", + "#CHROM\tID\tREF\tALT\tALT_FREQS\tOBS_CT\tU_MIN\tU_MAX\n", + "chr22\tchr22:16073625:G:T\tG\tT\t0.108333\t120\t-2.588204\t2.248544\n", + "chr22\tchr22:16102937:C:T\tC\tT\t0.308333\t120\t-1.849294\t2.069429\n", + "```\n", + "\n", + "These feed SuSiE-RSS fine-mapping: load with a metadata TSV (one row per chromosome, columns `#chrom start end path`, `path` = pgen prefix). Use the X (genotype) interface for `susie_rss(z, X=X)` or the R (correlation) interface for `susie_rss(z, R=R)`.\n", + "\n", + "The `generate_W` step declares its output as `W_B.rds`, but the example on disk is `W_B50.npy`. The code is authoritative; the example data predates the current naming." + ] + }, + { + "cell_type": "markdown", + "id": "6a51df29", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "## Minimal Working Example\n", "Run the three workflows in order. `generate_W` builds the shared projection matrix once; `process_block` sketches each LD block; `merge_chrom` assembles the per-chromosome pgen." ] }, @@ -72,7 +150,7 @@ "kernel": "SoS" }, "source": [ - "**Timing:** ~10-20 min (chr22) on typical compute infrastructure." + "**Timing**: ~10-20 min (on toy dataset)" ] }, { @@ -85,6 +163,16 @@ "### Step 1. Generate the projection matrix W (run once per cohort; `--n-samples` must equal the VCF sample count)." ] }, + { + "cell_type": "markdown", + "id": "5bc92199", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": 4, @@ -97,7 +185,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", + "/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", " import pkg_resources\n", "INFO: Running \u001b[32mgenerate_W\u001b[0m: \n", "INFO: \u001b[32mgenerate_W\u001b[0m is \u001b[32mcompleted\u001b[0m.\n", @@ -122,7 +210,17 @@ "kernel": "SoS" }, "source": [ - "### Step 2. Process all LD blocks for the chromosome \u2014 read the VCF, filter variants, and write per-block dosage sketches U = W\u1d40G.\n" + "### Step 2. Process all LD blocks for the chromosome — read the VCF, filter variants, and write per-block dosage sketches U = WᵀG.\n" + ] + }, + { + "cell_type": "markdown", + "id": "522e08c1", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" ] }, { @@ -137,7 +235,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", + "/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", " import pkg_resources\n", "INFO: Running \u001b[32mprocess_block\u001b[0m: \n", " 3 LD blocks queued\n", @@ -172,6 +270,16 @@ "### Step 3. Merge the per-block dosage sketches into one per-chromosome PLINK2 pgen." ] }, + { + "cell_type": "markdown", + "id": "9e53d301", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "**Timing**: TBD (on toy dataset)" + ] + }, { "cell_type": "code", "execution_count": 6, @@ -184,7 +292,7 @@ "name": "stdout", "output_type": "stream", "text": [ - "/restricted/projectnb/xqtl/jaempawi/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", + "/.pixi/envs/python/lib/python3.12/site-packages/sos/targets.py:22: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81.\n", " import pkg_resources\n", "INFO: Running \u001b[32mmerge_chrom\u001b[0m: \n", "PLINK v2.0.0-a.6.9LM 64-bit Intel (29 Jan 2025) cog-genomics.org/plink/2.0/\n", @@ -252,23 +360,86 @@ "kernel": "SoS" }, "source": [ - "## Command interface\n", - "\n", - "List every workflow and its parameters:" + "## Command Interface" ] }, { "cell_type": "code", "execution_count": null, - "id": "f3569a70", + "id": "cli-cmd-rss_ld_sketch", "metadata": { - "kernel": "Bash" + "kernel": "SoS" }, "outputs": [], "source": [ "sos run pipeline/rss_ld_sketch.ipynb -h" ] }, + { + "cell_type": "markdown", + "id": "cli-out-rss_ld_sketch", + "metadata": { + "kernel": "SoS" + }, + "source": [ + "```\n", + "usage: sos run pipeline/rss_ld_sketch.ipynb\n", + " [workflow_name | -t targets] [options] [workflow_options]\n", + " workflow_name: Single or combined workflows defined in this script\n", + " targets: One or more targets to generate\n", + " options: Single-hyphen sos parameters (see \"sos run -h\" for details)\n", + " workflow_options: Double-hyphen workflow-specific parameters\n", + "\n", + "Workflows:\n", + " generate_W\n", + " process_block\n", + " merge_chrom\n", + "\n", + "Global Workflow Options:\n", + " --cwd output (as path)\n", + " --modular-script-dir code/script (as path)\n", + " Directory holding the modular analysis scripts\n", + " (code/script)\n", + " --job-size 1 (as int)\n", + " --walltime '24:00:00'\n", + " --mem 32G\n", + " --numThreads 8 (as int)\n", + "\n", + "Sections\n", + " generate_W:\n", + " Workflow Options:\n", + " --n-samples VAL (as int, required)\n", + " Generate projection matrix $W \\sim N(0, 1/\\sqrt{n})$,\n", + " shape (n x B). Run ONCE before processing any\n", + " chromosome; W depends only on n and B, and all\n", + " chromosomes reuse the same W so per-chromosome sketches\n", + " are mergeable.\n", + " --output-dir VAL (as str, required)\n", + " --B 10000 (as int)\n", + " --seed 123 (as int)\n", + " process_block:\n", + " Workflow Options:\n", + " --ld-block-file VAL (as str, required)\n", + " --chrom 0 (as int)\n", + " --vcf-base VAL (as str, required)\n", + " --vcf-prefix VAL (as str, required)\n", + " --cohort-id 'ADSP.R5.EUR'\n", + " --output-dir VAL (as str, required)\n", + " --W-matrix VAL (as str, required)\n", + " --B 10000 (as int)\n", + " --maf-min 0.0005 (as float)\n", + " --mac-min 5 (as int)\n", + " --msng-min 0.05 (as float)\n", + " --sample-list ''\n", + " merge_chrom:\n", + " Workflow Options:\n", + " --chrom 0 (as int)\n", + " --output-dir VAL (as str, required)\n", + " --cohort-id VAL (as str, required)\n", + " --plink2-bin plink2\n", + "```" + ] + }, { "cell_type": "markdown", "id": "ac50d174", @@ -288,7 +459,16 @@ }, "outputs": [], "source": [ - "[global]\nparameter: cwd = path(\"output\")\n# Directory holding the modular analysis scripts (code/script)\nparameter: modular_script_dir = path('code/script')\nparameter: job_size = 1\nparameter: walltime = \"24:00:00\"\nparameter: mem = \"32G\"\nparameter: numThreads = 8\n\ncwd = path(f'{cwd:a}')\n" + "[global]\n", + "parameter: cwd = path(\"output\")\n", + "# Directory holding the modular analysis scripts (code/script)\n", + "parameter: modular_script_dir = path('code/script')\n", + "parameter: job_size = 1\n", + "parameter: walltime = \"24:00:00\"\n", + "parameter: mem = \"32G\"\n", + "parameter: numThreads = 8\n", + "\n", + "cwd = path(f'{cwd:a}')\n" ] }, { @@ -300,7 +480,24 @@ }, "outputs": [], "source": [ - "[generate_W]\n# Generate projection matrix $W \\sim N(0, 1/\\sqrt{n})$, shape (n x B).\n# Run ONCE before processing any chromosome; W depends only on n and B, and all\n# chromosomes reuse the same W so per-chromosome sketches are mergeable.\nparameter: n_samples = int\nparameter: output_dir = str\nparameter: B = 10000\nparameter: seed = 123\ninput: []\noutput: f'{output_dir}/W_B{B}.rds'\ntask: trunk_workers = 1, trunk_size = 1, walltime = '00:05:00', mem = '4G', cores = 1\nbash: expand = \"${ }\", stdout = f'{_output:n}.stdout', stderr = f'{_output:n}.stderr'\n Rscript ${modular_script_dir}/reference_data/rss_ld_sketch.R \\\n --step generate_w \\\n --n-samples ${n_samples} \\\n --B ${B} \\\n --seed ${seed} \\\n --output ${_output}\n" + "[generate_W]\n", + "# Generate projection matrix $W \\sim N(0, 1/\\sqrt{n})$, shape (n x B).\n", + "# Run ONCE before processing any chromosome; W depends only on n and B, and all\n", + "# chromosomes reuse the same W so per-chromosome sketches are mergeable.\n", + "parameter: n_samples = int\n", + "parameter: output_dir = str\n", + "parameter: B = 10000\n", + "parameter: seed = 123\n", + "input: []\n", + "output: f'{output_dir}/W_B{B}.rds'\n", + "task: trunk_workers = 1, trunk_size = 1, walltime = '00:05:00', mem = '4G', cores = 1\n", + "bash: expand = \"${ }\", stdout = f'{_output:n}.stdout', stderr = f'{_output:n}.stderr'\n", + " Rscript ${modular_script_dir}/reference_data/rss_ld_sketch.R \\\n", + " --step generate_w \\\n", + " --n-samples ${n_samples} \\\n", + " --B ${B} \\\n", + " --seed ${seed} \\\n", + " --output ${_output}\n" ] }, { @@ -312,7 +509,58 @@ }, "outputs": [], "source": [ - "[process_block]\nparameter: ld_block_file = str\nparameter: chrom = 0\nparameter: vcf_base = str\nparameter: vcf_prefix = str\nparameter: cohort_id = \"ADSP.R5.EUR\"\nparameter: output_dir = str\nparameter: W_matrix = str\nparameter: B = 10000\nparameter: maf_min = 0.0005\nparameter: mac_min = 5\nparameter: msng_min = 0.05\nparameter: sample_list = \"\"\n\n# Build the LD-block list from the BED (chr1..chr22; optional single-chrom filter).\nblocks = []\nwith open(ld_block_file) as _fh:\n for _line in _fh:\n if _line.startswith(\"#\") or not _line.strip():\n continue\n _p = _line.split()\n _c = _p[0]\n if not (_c.startswith(\"chr\") and _c[3:].isdigit()):\n continue\n _cnum = int(_c[3:])\n if not (1 <= _cnum <= 22):\n continue\n if chrom != 0 and _cnum != chrom:\n continue\n blocks.append({\"chr\": _c, \"start\": int(_p[1]), \"end\": int(_p[2])})\ndel _fh\nstop_if(len(blocks) == 0, msg = f\"No blocks found for chrom={chrom} in {ld_block_file}\")\n\ninput: for_each = \"blocks\"\noutput: f'{output_dir}/{_blocks[\"chr\"]}/{_blocks[\"chr\"]}_{_blocks[\"start\"]}_{_blocks[\"end\"]}/{cohort_id}.{_blocks[\"chr\"]}_{_blocks[\"start\"]}_{_blocks[\"end\"]}.dosage.gz'\ntask: trunk_workers = 1, trunk_size = 1, walltime = walltime, mem = mem, cores = numThreads\nbash: expand = \"${ }\"\n Rscript ${modular_script_dir}/reference_data/rss_ld_sketch.R \\\n --step process_block \\\n --vcf-base ${vcf_base} \\\n --vcf-prefix ${vcf_prefix} \\\n --chrom ${_blocks[\"chr\"]} \\\n --block-start ${_blocks[\"start\"]} \\\n --block-end ${_blocks[\"end\"]} \\\n --w-matrix ${W_matrix} \\\n --cohort-id ${cohort_id} \\\n --output-dir ${output_dir} \\\n --B ${B} \\\n --maf-min ${maf_min} \\\n --mac-min ${mac_min} \\\n --msng-min ${msng_min} \\\n --sample-list \"${sample_list}\"\n" + "[process_block]\n", + "parameter: ld_block_file = str\n", + "parameter: chrom = 0\n", + "parameter: vcf_base = str\n", + "parameter: vcf_prefix = str\n", + "parameter: cohort_id = \"ADSP.R5.EUR\"\n", + "parameter: output_dir = str\n", + "parameter: W_matrix = str\n", + "parameter: B = 10000\n", + "parameter: maf_min = 0.0005\n", + "parameter: mac_min = 5\n", + "parameter: msng_min = 0.05\n", + "parameter: sample_list = \"\"\n", + "\n", + "# Build the LD-block list from the BED (chr1..chr22; optional single-chrom filter).\n", + "blocks = []\n", + "with open(ld_block_file) as _fh:\n", + " for _line in _fh:\n", + " if _line.startswith(\"#\") or not _line.strip():\n", + " continue\n", + " _p = _line.split()\n", + " _c = _p[0]\n", + " if not (_c.startswith(\"chr\") and _c[3:].isdigit()):\n", + " continue\n", + " _cnum = int(_c[3:])\n", + " if not (1 <= _cnum <= 22):\n", + " continue\n", + " if chrom != 0 and _cnum != chrom:\n", + " continue\n", + " blocks.append({\"chr\": _c, \"start\": int(_p[1]), \"end\": int(_p[2])})\n", + "del _fh\n", + "stop_if(len(blocks) == 0, msg = f\"No blocks found for chrom={chrom} in {ld_block_file}\")\n", + "\n", + "input: for_each = \"blocks\"\n", + "output: f'{output_dir}/{_blocks[\"chr\"]}/{_blocks[\"chr\"]}_{_blocks[\"start\"]}_{_blocks[\"end\"]}/{cohort_id}.{_blocks[\"chr\"]}_{_blocks[\"start\"]}_{_blocks[\"end\"]}.dosage.gz'\n", + "task: trunk_workers = 1, trunk_size = 1, walltime = walltime, mem = mem, cores = numThreads\n", + "bash: expand = \"${ }\"\n", + " Rscript ${modular_script_dir}/reference_data/rss_ld_sketch.R \\\n", + " --step process_block \\\n", + " --vcf-base ${vcf_base} \\\n", + " --vcf-prefix ${vcf_prefix} \\\n", + " --chrom ${_blocks[\"chr\"]} \\\n", + " --block-start ${_blocks[\"start\"]} \\\n", + " --block-end ${_blocks[\"end\"]} \\\n", + " --w-matrix ${W_matrix} \\\n", + " --cohort-id ${cohort_id} \\\n", + " --output-dir ${output_dir} \\\n", + " --B ${B} \\\n", + " --maf-min ${maf_min} \\\n", + " --mac-min ${mac_min} \\\n", + " --msng-min ${msng_min} \\\n", + " --sample-list \"${sample_list}\"\n" ] }, { @@ -334,7 +582,7 @@ "kernel": "SoS" }, "source": [ - "## Troubleshooting\n", + "### Troubleshooting\n", "\n", "| Symptom | Cause | Fix |\n", "|---|---|---|\n", @@ -344,36 +592,6 @@ "| `No blocks found for chrom=XX` | `--chrom` does not match any BED rows | Ensure the BED `chr` column matches (e.g. `chr22`) and `--chrom` is the matching number. |\n", "| Region query returns nothing | Missing tabix index | Run `tabix -p vcf file.bgz` to create the `.tbi`. |" ] - }, - { - "cell_type": "markdown", - "id": "ac3cfb79", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Output\n", - "\n", - "Per chromosome, under `--cwd`:\n", - "- `{cohort_id}.chr{N}.pgen` \u2014 binary genotype-sketch data (B pseudo-samples \u00d7 p variants)\n", - "- `{cohort_id}.chr{N}.pvar` \u2014 variant information\n", - "- `{cohort_id}.chr{N}.psam` \u2014 sample (sketch) information\n", - "- `{cohort_id}.chr{N}.afreq` \u2014 allele frequencies\n", - "\n", - "These feed SuSiE-RSS fine-mapping: load with a metadata TSV (one row per chromosome, columns `#chrom start end path`, `path` = pgen prefix). Use the X (genotype) interface for `susie_rss(z, X=X)` or the R (correlation) interface for `susie_rss(z, R=R)`." - ] - }, - { - "cell_type": "markdown", - "id": "ff927c9c", - "metadata": { - "kernel": "SoS" - }, - "source": [ - "## Anticipated Results\n", - "\n", - "The pipeline produces output files in the `output/` subdirectory named after the workflow step. Verify success by checking that output files exist and are non-empty. See the **Output** section above for the expected file names and formats." - ] } ], "metadata": { diff --git a/code/SoS/xqtl_protocol_landing_page.ipynb b/code/SoS/xqtl_protocol_landing_page.ipynb index 673b09c08..9d8cf61c1 100644 --- a/code/SoS/xqtl_protocol_landing_page.ipynb +++ b/code/SoS/xqtl_protocol_landing_page.ipynb @@ -3,565 +3,7 @@ { "cell_type": "markdown", "metadata": {}, - "source": [ - "# Which pipelines do I need?\n", - "\n", - "````{raw} html\n", - "
\n", - "\n", - "\n", - "
\n", - "

FunGen-xQTL computational protocol

\n", - "

Molecular QTL analysis from raw genotypes and phenotypes through discovery,\n", - " meta-analysis, fine-mapping and GWAS integration.

\n", - "
\n", - "\n", - "
\n", - "
\n", - "

Tell us about your data and goal

\n", - "
\n", - "
\n", - " \n", - " \n", - " \n", - "
\n", - "

\n", - "
\n", - "\n", - "

Inputs

Reference Data

Quantification

Molecular Phenotype Quantification

Bulk RNA-seq
Single-nuclei / pseudobulk
Alternative splicing
DNA methylation
Polyadenylation

Pre-processing

Data Pre-processing

Genotype
Phenotype
Covariate

Discovery

QTL Association Testing

Multivariate modelling

Cross-cohort Meta-analysis

Multivariate Mixture (MASH)

Regression

High-dimensional Regression

Individual level
Summary statistics level

Integration

GWAS Integration

Rare-variant xQTL

Interpretation

Enrichment & Validation

xQTL Modifier Score

\n", - "
\n", - "\n", - "\n", - "\n", - "
\n", - "\n", - "\n", - "````\n" - ] + "source": "# Which pipelines do I need?\n\n````{raw} html\n
\n\n\n
\n

FunGen-xQTL computational protocol

\n

Molecular QTL analysis from raw genotypes and phenotypes through discovery,\n meta-analysis, fine-mapping and GWAS integration.

\n
\n\n
\n
\n

Tell us about your data and goal

\n
\n
\n \n \n \n
\n

\n
\n\n

Inputs

Reference Data

Quantification

Molecular Phenotype Quantification

Bulk RNA-seq
Single-nuclei / pseudobulk
Alternative splicing
DNA methylation
Polyadenylation

Pre-processing

Data Pre-processing

Genotype
Phenotype
Covariate

Discovery

QTL Association Testing

Multivariate modelling

Cross-cohort Meta-analysis

Multivariate Mixture (MASH)

Regression

High-dimensional Regression

Individual level
Summary statistics level

Integration

GWAS Integration

Rare-variant xQTL

Interpretation

Enrichment & Validation

xQTL Modifier Score

\n
\n\n\n\n
\n\n\n````\n" } ], "metadata": { diff --git a/code/script/molecular_phenotypes/QC/pseudobulk_preprocessing.R b/code/script/molecular_phenotypes/QC/pseudobulk_preprocessing.R index bf6ac21ed..ad0f6ac70 100644 --- a/code/script/molecular_phenotypes/QC/pseudobulk_preprocessing.R +++ b/code/script/molecular_phenotypes/QC/pseudobulk_preprocessing.R @@ -27,6 +27,8 @@ parser <- add_argument(parser, "--step", type = "character", help = "pseudobulk_counts | sampleid_mapping | pseudobulk_qc | phenotype_formatting") parser <- add_argument(parser, "--output-dir", type = "character", default = "output", help = "output directory") +parser <- add_argument(parser, "--name", type = "character", default = "protocol_example", + help = "prefix for output filenames") # pseudobulk_counts parser <- add_argument(parser, "--seurat-files", type = "character", nargs = Inf, default = character(0), help = "[pseudobulk_counts] Seurat .rds objects") @@ -81,9 +83,9 @@ run_pseudobulk_counts <- function(argv) { seurat_files <- argv$seurat_files celltype <- argv$celltype min_cells <- argv$min_cells - outdir <- file.path(argv$output_dir, "0_pseudobulk_counts") + outdir <- argv$output_dir dir.create(outdir, recursive = TRUE, showWarnings = FALSE) - out_file <- file.path(outdir, sprintf("pseudobulk_counts_%s.csv.gz", celltype)) + out_file <- file.path(outdir, sprintf("%s.pseudobulk_counts_%s.csv.gz", argv$name, celltype)) message("Loading and subsetting Seurat objects for: ", celltype) subsets <- list() @@ -132,7 +134,7 @@ run_pseudobulk_counts <- function(argv) { # =========================================================================== run_sampleid_mapping <- function(argv) { suppressPackageStartupMessages(library(dplyr)) - outdir <- file.path(argv$output_dir, "1_files_with_sampleid") + outdir <- argv$output_dir dir.create(outdir, recursive = TRUE, showWarnings = FALSE) map_df <- vroom::vroom(argv$map_file, delim = ",", show_col_types = FALSE, progress = FALSE) @@ -253,7 +255,7 @@ run_pseudobulk_qc <- function(argv) { meta_file <- meta_files[i]; counts_file <- count_files[i] ct <- sub("\\.csv$", "", sub("^.*metadata_", "", basename(meta_file))) message("\nProcessing: ", ct) - outdir <- file.path(argv$output_dir, "2_residuals", ct) + outdir <- argv$output_dir dir.create(outdir, recursive = TRUE, showWarnings = FALSE) counts_raw <- as.data.frame(vroom::vroom(counts_file, delim = ",", @@ -310,7 +312,7 @@ run_pseudobulk_qc <- function(argv) { dge <- dge[keep, , keep.lib.sizes = FALSE] message(feat_label, " after filter: ", nrow(dge)) - write.table(dge$counts, file.path(outdir, paste0(ct, "_filtered_raw_counts.txt")), + write.table(dge$counts, file.path(outdir, paste0(argv$name, ".", ct, ".filtered_raw_counts.txt")), sep = "\t", quote = FALSE, col.names = NA) dge <- calcNormFactors(dge, method = "TMM") @@ -360,7 +362,7 @@ run_pseudobulk_qc <- function(argv) { res <- residuals(fit, v$E) final <- off + res - out_file <- file.path(outdir, paste0(ct, "_residuals.txt")) + out_file <- file.path(outdir, paste0(argv$name, ".", ct, ".residuals.txt")) write.table(final, out_file, sep = "\t", quote = FALSE, col.names = NA) message("Saved: ", out_file) @@ -373,13 +375,13 @@ run_pseudobulk_qc <- function(argv) { if (quant_norm) { final_qn <- t(apply(final, 1, rank, ties.method = "average")) final_qn <- stats::qnorm(final_qn / (ncol(final_qn) + 1)) - write.table(final_qn, file.path(outdir, paste0(ct, "_residuals_qn.txt")), + write.table(final_qn, file.path(outdir, paste0(argv$name, ".", ct, ".residuals_qn.txt")), sep = "\t", quote = FALSE, col.names = NA) saveRDS(c(common_rds, list(final_data_qn = final_qn, quant_norm = TRUE)), - file.path(outdir, paste0(ct, "_results_qn.rds"))) + file.path(outdir, paste0(argv$name, ".", ct, ".results_qn.rds"))) } else { saveRDS(c(common_rds, list(quant_norm = FALSE)), - file.path(outdir, paste0(ct, "_results.rds"))) + file.path(outdir, paste0(argv$name, ".", ct, ".results.rds"))) } message("Completed: ", ct, " -> ", outdir) } @@ -390,7 +392,7 @@ run_pseudobulk_qc <- function(argv) { # =========================================================================== run_phenotype_formatting <- function(argv) { suppressPackageStartupMessages({ library(dplyr); library(rtracklayer) }) - out_dir <- file.path(argv$output_dir, "3_pheno_reformat") + out_dir <- argv$output_dir dir.create(out_dir, recursive = TRUE, showWarnings = FALSE) gene_positions <- NULL @@ -416,7 +418,11 @@ run_phenotype_formatting <- function(argv) { fmt <- function(x) sprintf("%.15f", x) for (res_path in argv$residual_files) { - ct <- basename(dirname(res_path)) + ct <- basename(res_path) + prefix <- paste0(argv$name, ".") + if (startsWith(ct, prefix)) ct <- substring(ct, nchar(prefix) + 1) + ct <- sub(".residuals_qn.txt", "", ct, fixed = TRUE) + ct <- sub(".residuals.txt", "", ct, fixed = TRUE) message("\nPhenotype Formatting: ", ct) if (!file.exists(res_path)) { message("WARNING: ", res_path, " not found, skipping."); next } r <- read_residuals(res_path) @@ -445,7 +451,7 @@ run_phenotype_formatting <- function(argv) { val_cols <- setdiff(colnames(bed), c("#chr", "start", "end", "ID")) bed[val_cols] <- lapply(bed[val_cols], fmt) - out_bed <- file.path(out_dir, paste0(ct, "_phenotype.bed")) + out_bed <- file.path(out_dir, paste0(argv$name, ".", ct, ".phenotype.bed")) vroom::vroom_write(bed, out_bed, delim = "\t", quote = "none", escape = "none") Rsamtools::bgzip(out_bed, dest = paste0(out_bed, ".gz"), overwrite = TRUE) file.remove(out_bed) diff --git a/code/script/molecular_phenotypes/snRNAseq_preprocessing.R b/code/script/molecular_phenotypes/snRNAseq_preprocessing.R index 6079017e9..6bdd868a7 100644 --- a/code/script/molecular_phenotypes/snRNAseq_preprocessing.R +++ b/code/script/molecular_phenotypes/snRNAseq_preprocessing.R @@ -27,6 +27,8 @@ parser <- add_argument(parser, "--step", type = "character", help = "sctk_qc | cell_annotation") parser <- add_argument(parser, "--output-dir", type = "character", default = "output", help = "output directory") +parser <- add_argument(parser, "--name", type = "character", default = "", + help = "output filename prefix, e.g. protocol_example.snrnaseq; empty = no prefix") parser <- add_argument(parser, "--num-threads", type = "numeric", default = 8, help = "future multicore workers") # sctk_qc @@ -62,6 +64,10 @@ parser <- add_argument(parser, "--cluster-threshold", type = "numeric", default argv <- parse_args(parser) +# Prefix an output filename with the dataset tag (--name) when provided; +# an empty --name leaves filenames unprefixed (the direct-worker default). +prefixed <- function(base) if (nzchar(argv$name)) paste0(argv$name, ".", base) else base + # ============================================================ # Step: sctk_qc @@ -80,8 +86,8 @@ run_sctk_qc <- function(argv) { input_dir <- argv$input_dir output_dir <- argv$output_dir - rds_out <- file.path(output_dir, "SCTK_results", "filtered_seuratobj.rds") - qc_table_out <- file.path(output_dir, "QC_table", "SCTK_QC_table.csv") + rds_out <- file.path(output_dir, "SCTK_results", prefixed("filtered_seuratobj.rds")) + qc_table_out <- file.path(output_dir, "QC_table", prefixed("SCTK_QC_table.csv")) doublet_method <- argv$doublet_method ambient_method <- argv$ambient_method @@ -241,7 +247,7 @@ run_sctk_qc <- function(argv) { message("Saved: ", rds_out) rm(processed_seurat); gc() - qc_csv <- file.path(dirname(rds_out), "QC_summary.csv") + qc_csv <- file.path(dirname(rds_out), prefixed("QC_summary.csv")) write.csv(qc_summary, qc_csv, row.names = FALSE) message("QC summary saved: ", qc_csv) } @@ -269,8 +275,8 @@ run_cell_annotation <- function(argv) { downsample_n <- argv$downsample_n cluster_threshold <- argv$cluster_threshold - anno_file <- file.path(output_dir, "annotated_seuratobj.rds") - out_file <- file.path(output_dir, "celltyped_seuratobj.rds") + anno_file <- file.path(output_dir, prefixed("annotated_seuratobj.rds")) + out_file <- file.path(output_dir, prefixed("celltyped_seuratobj.rds")) # ── Create output directory ─────────────────────────────────── dir.create(output_dir, showWarnings = FALSE, recursive = TRUE) diff --git a/tests/fixtures/apa_calling/protocol_example.SAMPLE_001.wig.gz b/tests/fixtures/apa_calling/protocol_example.SAMPLE_001.wig.gz new file mode 100644 index 000000000..5232ce782 Binary files /dev/null and b/tests/fixtures/apa_calling/protocol_example.SAMPLE_001.wig.gz differ diff --git a/tests/fixtures/apa_calling/protocol_example.SAMPLE_002.wig.gz b/tests/fixtures/apa_calling/protocol_example.SAMPLE_002.wig.gz new file mode 100644 index 000000000..c1631e027 Binary files /dev/null and b/tests/fixtures/apa_calling/protocol_example.SAMPLE_002.wig.gz differ diff --git a/tests/fixtures/apa_calling/protocol_example.depth.txt b/tests/fixtures/apa_calling/protocol_example.depth.txt new file mode 100644 index 000000000..b9d55cc43 --- /dev/null +++ b/tests/fixtures/apa_calling/protocol_example.depth.txt @@ -0,0 +1,2 @@ +SAMPLE_001 12709 +SAMPLE_002 14497 diff --git a/tests/fixtures/apa_calling/protocol_example.expected_3UTR.bed b/tests/fixtures/apa_calling/protocol_example.expected_3UTR.bed new file mode 100644 index 000000000..0b2728330 --- /dev/null +++ b/tests/fixtures/apa_calling/protocol_example.expected_3UTR.bed @@ -0,0 +1,329 @@ +chr22 16654066 16654076 ENST00000456726|NA|chr22|- 0 - +chr22 16669464 16669620 ENST00000457060|ANKRD62P1-PARP4P3|chr22|- 0 - +chr22 17116297 17121360 ENST00000331437|TMEM121B|chr22|- 0 - +chr22 17116299 17120143 ENST00000399875|TMEM121B|chr22|- 0 - +chr22 17696141 17696209 ENST00000399781|BCL2L13|chr22|+ 0 + +chr22 17702243 17702428 ENST00000399782|BCL2L13|chr22|+ 0 + +chr22 17726677 17730855 ENST00000337612|BCL2L13|chr22|+ 0 + +chr22 17726677 17728699 ENST00000498133|BCL2L13|chr22|+ 0 + +chr22 17692356 17692395 ENST00000464649|BCL2L13|chr22|+ 0 + +chr22 17702243 17703733 ENST00000493680|BCL2L13|chr22|+ 0 + +chr22 17726677 17730622 ENST00000355028|BCL2L13|chr22|+ 0 + +chr22 17726677 17729140 ENST00000399777|BCL2L13|chr22|+ 0 + +chr22 17702243 17702363 ENST00000479296|BCL2L13|chr22|+ 0 + +chr22 17726677 17727670 ENST00000485631|BCL2L13|chr22|+ 0 + +chr22 18946791 18947732 ENST00000638240|AC007326.4|chr22|+ 0 + +chr22 18946791 18947741 ENST00000640084|AC007326.5|chr22|+ 0 + +chr22 18946791 18947692 ENST00000638287|AC007326.5|chr22|+ 0 + +chr22 18946791 18946971 ENST00000623496|AC007326.5|chr22|+ 0 + +chr22 19146993 19149095 ENST00000086933|GSC2|chr22|- 0 - +chr22 19523024 19524542 ENST00000406028|CLDN5|chr22|- 0 - +chr22 19523027 19524400 ENST00000618236|CLDN5|chr22|- 0 - +chr22 19523027 19525383 ENST00000403084|CLDN5|chr22|- 0 - +chr22 19523052 19524542 ENST00000413119|CLDN5|chr22|- 0 - +chr22 20111875 20112794 ENST00000252136|TRMT2A|chr22|- 0 - +chr22 20112301 20112794 ENST00000480339|TRMT2A|chr22|- 0 - +chr22 20112304 20112816 ENST00000404751|TRMT2A|chr22|- 0 - +chr22 20112328 20113007 ENST00000487668|TRMT2A|chr22|- 0 - +chr22 20112338 20112794 ENST00000439169|TRMT2A|chr22|- 0 - +chr22 20112499 20112794 ENST00000487378|TRMT2A|chr22|- 0 - +chr22 20112568 20112794 ENST00000444256|TRMT2A|chr22|- 0 - +chr22 20112892 20113007 ENST00000494820|TRMT2A|chr22|- 0 - +chr22 20113118 20113234 ENST00000492988|TRMT2A|chr22|- 0 - +chr22 20113486 20113507 ENST00000471040|TRMT2A|chr22|- 0 - +chr22 20113650 20113808 ENST00000488335|TRMT2A|chr22|- 0 - +chr22 20113704 20113808 ENST00000463710|TRMT2A|chr22|- 0 - +chr22 20114767 20114876 ENST00000459644|TRMT2A|chr22|- 0 - +chr22 20115337 20115780 ENST00000468917|TRMT2A|chr22|- 0 - +chr22 20115349 20115554 ENST00000480460|TRMT2A|chr22|- 0 - +chr22 20115577 20115780 ENST00000494641|TRMT2A|chr22|- 0 - +chr22 20115610 20115780 ENST00000464535|TRMT2A|chr22|- 0 - +chr22 20116242 20116612 ENST00000445045|TRMT2A|chr22|- 0 - +chr22 20949711 20953747 ENST00000354336|CRKL|chr22|+ 0 + +chr22 20953206 20953747 ENST00000411769|CRKL|chr22|+ 0 + +chr22 21114607 21116187 ENST00000420508|AP000550.1|chr22|- 0 - +chr22 21207973 21208284 ENST00000405188|GGT2|chr22|- 0 - +chr22 21207974 21208284 ENST00000401924|GGT2|chr22|- 0 - +chr22 21300990 21301424 ENST00000447720|FAM230H|chr22|- 0 - +chr22 21300991 21301424 ENST00000436681|FAM230H|chr22|- 0 - +chr22 21300997 21301424 ENST00000416615|FAM230H|chr22|- 0 - +chr22 21309821 21311344 ENST00000416405|FAM230H|chr22|- 0 - +chr22 21311740 21311773 ENST00000453273|FAM230H|chr22|- 0 - +chr22 21319270 21319356 ENST00000451574|FAM230H|chr22|- 0 - +chr22 21321948 21322327 ENST00000452952|FAM230H|chr22|- 0 - +chr22 21322141 21322327 ENST00000411581|FAM230H|chr22|- 0 - +chr22 22484421 22489466 ENST00000626650|ZNF280B|chr22|- 0 - +chr22 22484858 22485978 ENST00000619852|ZNF280B|chr22|- 0 - +chr22 22484873 22485978 ENST00000613655|ZNF280B|chr22|- 0 - +chr22 23161500 23164350 ENST00000263116|RAB36|chr22|+ 0 + +chr22 23161500 23161564 ENST00000341989|RAB36|chr22|+ 0 + +chr22 23155968 23156311 ENST00000420895|RAB36|chr22|+ 0 + +chr22 23884649 23886309 ENST00000345044|SLC2A11|chr22|+ 0 + +chr22 23884649 23885536 ENST00000398356|SLC2A11|chr22|+ 0 + +chr22 23877042 23877328 ENST00000405847|SLC2A11|chr22|+ 0 + +chr22 23882759 23882952 ENST00000467660|SLC2A11|chr22|+ 0 + +chr22 23882759 23882951 ENST00000405286|SLC2A11|chr22|+ 0 + +chr22 23884649 23884933 ENST00000255830|SLC2A11|chr22|+ 0 + +chr22 23884649 23885551 ENST00000489322|SLC2A11|chr22|+ 0 + +chr22 23875117 23875211 ENST00000473740|SLC2A11|chr22|+ 0 + +chr22 23884623 23886112 ENST00000611880|SLC2A11|chr22|+ 0 + +chr22 23862104 23862325 ENST00000492516|SLC2A11|chr22|+ 0 + +chr22 23877042 23877287 ENST00000423972|SLC2A11|chr22|+ 0 + +chr22 23875117 23875189 ENST00000418102|SLC2A11|chr22|+ 0 + +chr22 23877042 23877172 ENST00000436643|SLC2A11|chr22|+ 0 + +chr22 23884649 23885553 ENST00000405340|SLC2A11|chr22|+ 0 + +chr22 23884649 23884867 ENST00000316185|SLC2A11|chr22|+ 0 + +chr22 23884649 23884784 ENST00000472526|SLC2A11|chr22|+ 0 + +chr22 23882759 23883307 ENST00000473357|SLC2A11|chr22|+ 0 + +chr22 23895040 23895223 ENST00000433835|AP000350.4|chr22|+ 0 + +chr22 23870182 23873277 ENST00000624923|AP000350.7|chr22|- 0 - +chr22 24103037 24103354 ENST00000444093|AC253536.3|chr22|+ 0 + +chr22 24414534 24417739 ENST00000437398|SPECC1L|chr22|+ 0 + +chr22 24330256 24330401 ENST00000421374|SPECC1L|chr22|+ 0 + +chr22 24414534 24417738 ENST00000314328|SPECC1L|chr22|+ 0 + +chr22 24414534 24417206 ENST00000651059|SPECC1L|chr22|+ 0 + +chr22 24324220 24324304 ENST00000416735|SPECC1L|chr22|+ 0 + +chr22 24414534 24414773 ENST00000541492|SPECC1L|chr22|+ 0 + +chr22 24321288 24321688 ENST00000440893|SPECC1L|chr22|+ 0 + +chr22 24414534 24414752 ENST00000472799|SPECC1L|chr22|+ 0 + +chr22 24645171 24647261 ENST00000639904|AP000356.2|chr22|- 0 - +chr22 25319767 25320086 ENST00000650352|AL022324.4|chr22|+ 0 + +chr22 26610368 26611453 ENST00000668614|Z95115.2|chr22|+ 0 + +chr22 26599278 26599673 ENST00000647684|CRYBB1|chr22|- 0 - +chr22 26601949 26602021 ENST00000647569|CRYBB1|chr22|- 0 - +chr22 26630340 26630669 ENST00000354760|CRYBA4|chr22|+ 0 + +chr22 26630340 26630641 ENST00000466315|CRYBA4|chr22|+ 0 + +chr22 26719141 26719282 ENST00000651474|MIATNB|chr22|+ 0 + +chr22 26734273 26734455 ENST00000444388|MIATNB|chr22|+ 0 + +chr22 26776827 26776848 ENST00000450963|MIATNB|chr22|+ 0 + +chr22 26779884 26780100 ENST00000449017|MIATNB|chr22|+ 0 + +chr22 26778456 26778635 ENST00000435162|MIATNB|chr22|+ 0 + +chr22 26779884 26780207 ENST00000437071|MIATNB|chr22|+ 0 + +chr22 26776827 26776882 ENST00000440816|MIATNB|chr22|+ 0 + +chr22 26718140 26718392 ENST00000421253|MIATNB|chr22|+ 0 + +chr22 26743640 26743965 ENST00000653953|MIATNB|chr22|+ 0 + +chr22 26717253 26719686 ENST00000668496|MIATNB|chr22|+ 0 + +chr22 26742739 26742838 ENST00000446336|MIATNB|chr22|+ 0 + +chr22 26721650 26722172 ENST00000417083|MIATNB|chr22|+ 0 + +chr22 26738062 26738240 ENST00000662474|MIATNB|chr22|+ 0 + +chr22 26779884 26780893 ENST00000669899|MIATNB|chr22|+ 0 + +chr22 28687743 28687986 ENST00000434810|CHEK2|chr22|- 0 - +chr22 28687744 28687986 ENST00000648295|CHEK2|chr22|- 0 - +chr22 28687749 28687986 ENST00000472807|CHEK2|chr22|- 0 - +chr22 28687751 28687986 ENST00000649563|CHEK2|chr22|- 0 - +chr22 28687762 28687986 ENST00000405598|CHEK2|chr22|- 0 - +chr22 28687763 28687986 ENST00000382580|CHEK2|chr22|- 0 - +chr22 28687766 28687986 ENST00000650281|CHEK2|chr22|- 0 - +chr22 28687887 28687986 ENST00000417588|CHEK2|chr22|- 0 - +chr22 28687897 28687986 ENST00000403642|CHEK2|chr22|- 0 - +chr22 28696902 28696987 ENST00000433028|CHEK2|chr22|- 0 - +chr22 28696944 28696987 ENST00000491919|CHEK2|chr22|- 0 - +chr22 28699764 28699937 ENST00000439346|CHEK2|chr22|- 0 - +chr22 28711909 28712017 ENST00000439200|CHEK2|chr22|- 0 - +chr22 28724965 28725124 ENST00000454252|CHEK2|chr22|- 0 - +chr22 28725041 28725124 ENST00000650233|CHEK2|chr22|- 0 - +chr22 28725083 28725124 ENST00000398017|CHEK2|chr22|- 0 - +chr22 29053579 29057488 ENST00000544604|ZNRF3|chr22|+ 0 + +chr22 29053579 29053685 ENST00000402174|ZNRF3|chr22|+ 0 + +chr22 29053579 29053965 ENST00000406323|ZNRF3|chr22|+ 0 + +chr22 29436534 29442129 ENST00000461286|RFPL1S|chr22|- 0 - +chr22 29438422 29439193 ENST00000248980|RFPL1S|chr22|- 0 - +chr22 29440767 29442129 ENST00000661328|RFPL1S|chr22|- 0 - +chr22 29440792 29442129 ENST00000657516|RFPL1S|chr22|- 0 - +chr22 29470265 29471027 ENST00000669415|RFPL1S|chr22|- 0 - +chr22 29471941 29472449 ENST00000419368|RFPL1S|chr22|- 0 - +chr22 29694752 29698594 ENST00000413209|NF2|chr22|+ 0 + +chr22 29694752 29694945 ENST00000672805|NF2|chr22|+ 0 + +chr22 29683701 29684162 ENST00000403435|NF2|chr22|+ 0 + +chr22 29697261 29697525 ENST00000672461|NF2|chr22|+ 0 + +chr22 29683020 29683915 ENST00000403999|NF2|chr22|+ 0 + +chr22 29694752 29698598 ENST00000338641|NF2|chr22|+ 0 + +chr22 29683701 29683915 ENST00000334961|NF2|chr22|+ 0 + +chr22 29694752 29694811 ENST00000353887|NF2|chr22|+ 0 + +chr22 29694752 29695058 ENST00000673312|NF2|chr22|+ 0 + +chr22 29694752 29695059 ENST00000361166|NF2|chr22|+ 0 + +chr22 30331988 30334695 ENST00000215793|SF3A1|chr22|- 0 - +chr22 30337801 30337897 ENST00000411423|SF3A1|chr22|- 0 - +chr22 30337817 30337897 ENST00000444440|SF3A1|chr22|- 0 - +chr22 30338840 30339034 ENST00000485618|SF3A1|chr22|- 0 - +chr22 30338961 30339251 ENST00000498259|SF3A1|chr22|- 0 - +chr22 30342320 30342350 ENST00000447376|SF3A1|chr22|- 0 - +chr22 30342547 30342879 ENST00000471037|SF3A1|chr22|- 0 - +chr22 30344910 30345190 ENST00000471342|SF3A1|chr22|- 0 - +chr22 30346221 30346519 ENST00000463818|SF3A1|chr22|- 0 - +chr22 30352545 30353072 ENST00000496189|SF3A1|chr22|- 0 - +chr22 30428462 30428990 ENST00000454552|AC004832.3|chr22|+ 0 + +chr22 30428462 30428987 ENST00000439838|AC004832.3|chr22|+ 0 + +chr22 30427122 30427151 ENST00000629597|MTFP1|chr22|+ 0 + +chr22 30428462 30429054 ENST00000266263|MTFP1|chr22|+ 0 + +chr22 30426717 30427192 ENST00000614920|MTFP1|chr22|+ 0 + +chr22 30428462 30429053 ENST00000355143|MTFP1|chr22|+ 0 + +chr22 30428462 30428643 ENST00000412752|MTFP1|chr22|+ 0 + +chr22 30428462 30428951 ENST00000407550|MTFP1|chr22|+ 0 + +chr22 30646598 30647893 ENST00000343605|SLC35E4|chr22|+ 0 + +chr22 30667601 30669016 ENST00000451479|SLC35E4|chr22|+ 0 + +chr22 30652051 30652297 ENST00000430175|DUSP18|chr22|- 0 - +chr22 30652096 30652297 ENST00000461301|DUSP18|chr22|- 0 - +chr22 30654146 30654461 ENST00000377087|DUSP18|chr22|- 0 - +chr22 30654184 30654437 ENST00000412865|DUSP18|chr22|- 0 - +chr22 30663299 30663728 ENST00000403268|DUSP18|chr22|- 0 - +chr22 30663299 30664080 ENST00000334679|DUSP18|chr22|- 0 - +chr22 30663515 30664080 ENST00000342474|DUSP18|chr22|- 0 - +chr22 30663971 30664080 ENST00000442752|DUSP18|chr22|- 0 - +chr22 30906197 30906554 ENST00000438716|OSBP2|chr22|+ 0 + +chr22 30906197 30907632 ENST00000407373|OSBP2|chr22|+ 0 + +chr22 30906197 30907824 ENST00000403222|OSBP2|chr22|+ 0 + +chr22 30906197 30907813 ENST00000332585|OSBP2|chr22|+ 0 + +chr22 30906197 30906406 ENST00000446658|OSBP2|chr22|+ 0 + +chr22 30870429 30870613 ENST00000477355|OSBP2|chr22|+ 0 + +chr22 30887426 30887491 ENST00000445781|OSBP2|chr22|+ 0 + +chr22 30906197 30906772 ENST00000401475|OSBP2|chr22|+ 0 + +chr22 30844483 30844687 ENST00000464341|OSBP2|chr22|+ 0 + +chr22 30872309 30872523 ENST00000496367|OSBP2|chr22|+ 0 + +chr22 30889490 30889635 ENST00000424224|OSBP2|chr22|+ 0 + +chr22 30906194 30907824 ENST00000437268|OSBP2|chr22|+ 0 + +chr22 30889520 30889617 ENST00000454145|OSBP2|chr22|+ 0 + +chr22 30893122 30893135 ENST00000453621|OSBP2|chr22|+ 0 + +chr22 30906197 30907623 ENST00000431368|OSBP2|chr22|+ 0 + +chr22 30906197 30907643 ENST00000452656|OSBP2|chr22|+ 0 + +chr22 30893638 30894261 ENST00000496575|OSBP2|chr22|+ 0 + +chr22 30893638 30894463 ENST00000433183|OSBP2|chr22|+ 0 + +chr22 31082156 31083565 ENST00000609017|AC005005.3|chr22|- 0 - +chr22 31104772 31105128 ENST00000402395|SELENOM|chr22|- 0 - +chr22 31104777 31105128 ENST00000490967|SELENOM|chr22|- 0 - +chr22 31104779 31105128 ENST00000611680|SELENOM|chr22|- 0 - +chr22 31104926 31105128 ENST00000465536|SELENOM|chr22|- 0 - +chr22 31105001 31105128 ENST00000491958|SELENOM|chr22|- 0 - +chr22 31105013 31105128 ENST00000495533|SELENOM|chr22|- 0 - +chr22 31105025 31105128 ENST00000460642|SELENOM|chr22|- 0 - +chr22 31105114 31105286 ENST00000469262|SELENOM|chr22|- 0 - +chr22 31105439 31105965 ENST00000465447|SELENOM|chr22|- 0 - +chr22 34206082 34206653 ENST00000655904|LINC01643|chr22|+ 0 + +chr22 34218508 34218794 ENST00000652942|LINC01643|chr22|+ 0 + +chr22 34206082 34207090 ENST00000665701|LINC01643|chr22|+ 0 + +chr22 34218508 34218790 ENST00000669802|LINC01643|chr22|+ 0 + +chr22 34218508 34218796 ENST00000658589|LINC01643|chr22|+ 0 + +chr22 34218508 34218792 ENST00000654009|LINC01643|chr22|+ 0 + +chr22 34175390 34175779 ENST00000658014|LINC01643|chr22|+ 0 + +chr22 34206082 34206631 ENST00000670742|LINC01643|chr22|+ 0 + +chr22 34206082 34206637 ENST00000665458|LINC01643|chr22|+ 0 + +chr22 34188330 34188425 ENST00000412218|LINC01643|chr22|+ 0 + +chr22 34175390 34175780 ENST00000668901|LINC01643|chr22|+ 0 + +chr22 35127142 35127419 ENST00000610215|Z99755.2|chr22|+ 0 + +chr22 36467046 36467917 ENST00000216185|TXN2|chr22|- 0 - +chr22 36467549 36467917 ENST00000487725|TXN2|chr22|- 0 - +chr22 36467591 36467917 ENST00000403313|TXN2|chr22|- 0 - +chr22 36467884 36467917 ENST00000411915|TXN2|chr22|- 0 - +chr22 36991120 36991276 ENST00000442538|TEX33|chr22|- 0 - +chr22 36991125 36991276 ENST00000402860|TEX33|chr22|- 0 - +chr22 37182735 37182850 ENST00000419128|Z82188.2|chr22|+ 0 + +chr22 37180166 37182429 ENST00000337843|C1QTNF6|chr22|- 0 - +chr22 37180167 37180867 ENST00000397110|C1QTNF6|chr22|- 0 - +chr22 37180171 37182429 ENST00000493023|C1QTNF6|chr22|- 0 - +chr22 37182174 37182429 ENST00000434784|C1QTNF6|chr22|- 0 - +chr22 37190553 37190677 ENST00000467564|C1QTNF6|chr22|- 0 - +chr22 37372034 37372858 ENST00000609322|Z94160.2|chr22|+ 0 + +chr22 37816929 37817176 ENST00000323205|GCAT|chr22|+ 0 + +chr22 37813277 37813300 ENST00000445195|GCAT|chr22|+ 0 + +chr22 37813277 37813485 ENST00000415371|GCAT|chr22|+ 0 + +chr22 37812887 37813076 ENST00000478203|GCAT|chr22|+ 0 + +chr22 37816567 37816897 ENST00000248924|GCAT|chr22|+ 0 + +chr22 37815126 37815208 ENST00000426858|GCAT|chr22|+ 0 + +chr22 37813277 37813609 ENST00000451984|GCAT|chr22|+ 0 + +chr22 38032165 38033155 ENST00000410099|AL031587.1|chr22|- 0 - +chr22 38232048 38232248 ENST00000420172|AL020993.1|chr22|+ 0 + +chr22 38426327 38428171 ENST00000303592|KCNJ4|chr22|- 0 - +chr22 38436303 38436686 ENST00000662373|Z97056.3|chr22|+ 0 + +chr22 38518948 38520089 ENST00000216024|DMC1|chr22|- 0 - +chr22 38518949 38520089 ENST00000428462|DMC1|chr22|- 0 - +chr22 38538295 38538409 ENST00000439567|DMC1|chr22|- 0 - +chr22 38545768 38546130 ENST00000616615|DMC1|chr22|- 0 - +chr22 38549498 38549997 ENST00000478820|DMC1|chr22|- 0 - +chr22 38552671 38552707 ENST00000415483|DMC1|chr22|- 0 - +chr22 38569284 38569390 ENST00000464842|DMC1|chr22|- 0 - +chr22 38677510 38677800 ENST00000666731|AL021707.9|chr22|+ 0 + +chr22 38734725 38736380 ENST00000405510|SUN2|chr22|- 0 - +chr22 38734736 38736380 ENST00000405018|SUN2|chr22|- 0 - +chr22 38735909 38736380 ENST00000406622|SUN2|chr22|- 0 - +chr22 38737760 38738265 ENST00000455125|SUN2|chr22|- 0 - +chr22 38738238 38738265 ENST00000470642|SUN2|chr22|- 0 - +chr22 38738926 38738988 ENST00000477262|SUN2|chr22|- 0 - +chr22 38739341 38739426 ENST00000469086|SUN2|chr22|- 0 - +chr22 38740292 38740432 ENST00000464202|SUN2|chr22|- 0 - +chr22 38745075 38745145 ENST00000430185|SUN2|chr22|- 0 - +chr22 38745687 38745811 ENST00000438058|SUN2|chr22|- 0 - +chr22 38748713 38748783 ENST00000456894|SUN2|chr22|- 0 - +chr22 38749766 38749859 ENST00000480307|SUN2|chr22|- 0 - +chr22 38750225 38750320 ENST00000420859|SUN2|chr22|- 0 - +chr22 38750888 38751035 ENST00000452294|SUN2|chr22|- 0 - +chr22 38750898 38751373 ENST00000494273|SUN2|chr22|- 0 - +chr22 38750992 38751035 ENST00000433561|SUN2|chr22|- 0 - +chr22 38751007 38751094 ENST00000417332|SUN2|chr22|- 0 - +chr22 38751020 38751035 ENST00000439339|SUN2|chr22|- 0 - +chr22 38778508 38779613 ENST00000216068|DNAL4|chr22|- 0 - +chr22 38778853 38779613 ENST00000486019|DNAL4|chr22|- 0 - +chr22 38780718 38781009 ENST00000406199|DNAL4|chr22|- 0 - +chr22 38785305 38785997 ENST00000475512|DNAL4|chr22|- 0 - +chr22 38952961 38953416 ENST00000495988|APOBEC3A|chr22|+ 0 + +chr22 38962495 38963183 ENST00000402255|APOBEC3A|chr22|+ 0 + +chr22 38959542 38959686 ENST00000488758|APOBEC3A|chr22|+ 0 + +chr22 38992431 38992778 ENST00000618553|APOBEC3A|chr22|+ 0 + +chr22 38962495 38963184 ENST00000249116|APOBEC3A|chr22|+ 0 + +chr22 38992431 38992546 ENST00000407298|APOBEC3B|chr22|+ 0 + +chr22 38992431 38992779 ENST00000333467|APOBEC3B|chr22|+ 0 + +chr22 38992034 38992804 ENST00000402182|APOBEC3B|chr22|+ 0 + +chr22 38992431 38992761 ENST00000335760|APOBEC3B|chr22|+ 0 + +chr22 38991559 38991618 ENST00000513758|APOBEC3B-AS1|chr22|- 0 - +chr22 39032198 39033276 ENST00000381568|AL022318.4|chr22|+ 0 + +chr22 39044941 39045192 ENST00000491387|APOBEC3F|chr22|+ 0 + +chr22 39044083 39044423 ENST00000381565|APOBEC3F|chr22|+ 0 + +chr22 39052577 39055972 ENST00000308521|APOBEC3F|chr22|+ 0 + +chr22 39052074 39052287 ENST00000476513|APOBEC3F|chr22|+ 0 + +chr22 39521773 39522683 ENST00000404241|ATF4|chr22|+ 0 + +chr22 39521773 39522668 ENST00000674920|ATF4|chr22|+ 0 + +chr22 39521773 39522602 ENST00000679776|ATF4|chr22|+ 0 + +chr22 39521354 39521953 ENST00000680748|ATF4|chr22|+ 0 + +chr22 39521354 39521528 ENST00000676430|ATF4|chr22|+ 0 + +chr22 42085526 42086314 ENST00000498737|NDUFA6|chr22|- 0 - +chr22 42085527 42086314 ENST00000617763|NDUFA6|chr22|- 0 - +chr22 42086116 42086314 ENST00000470753|NDUFA6|chr22|- 0 - +chr22 42089630 42090028 ENST00000602718|AL021878.2|chr22|- 0 - +chr22 42274988 42279493 ENST00000609564|OGFRP1|chr22|+ 0 + +chr22 42273894 42279534 ENST00000332965|OGFRP1|chr22|+ 0 + +chr22 42274988 42275033 ENST00000446578|OGFRP1|chr22|+ 0 + +chr22 42274988 42277001 ENST00000415205|OGFRP1|chr22|+ 0 + +chr22 42276696 42277052 ENST00000420096|OGFRP1|chr22|+ 0 + +chr22 42446163 42446195 ENST00000428765|AL022316.1|chr22|+ 0 + +chr22 46055740 46056515 ENST00000439423|AL121672.1|chr22|- 0 - +chr22 46275248 46275285 ENST00000417709|TTC38|chr22|+ 0 + +chr22 46292791 46294008 ENST00000381031|TTC38|chr22|+ 0 + +chr22 46268514 46268927 ENST00000475467|TTC38|chr22|+ 0 + +chr22 46280069 46280242 ENST00000421359|TTC38|chr22|+ 0 + +chr22 46269142 46269192 ENST00000629918|TTC38|chr22|+ 0 + +chr22 46283973 46284032 ENST00000422713|TTC38|chr22|+ 0 + +chr22 46292791 46292933 ENST00000451998|TTC38|chr22|+ 0 + +chr22 46360834 46363187 ENST00000262738|CELSR1|chr22|- 0 - +chr22 46361174 46364251 ENST00000473624|CELSR1|chr22|- 0 - +chr22 46361174 46363247 ENST00000674500|CELSR1|chr22|- 0 - +chr22 46361986 46363247 ENST00000674159|CELSR1|chr22|- 0 - +chr22 46365225 46365689 ENST00000674423|CELSR1|chr22|- 0 - +chr22 46368859 46369258 ENST00000674341|CELSR1|chr22|- 0 - +chr22 46372913 46373057 ENST00000468025|CELSR1|chr22|- 0 - +chr22 46384501 46384686 ENST00000674379|CELSR1|chr22|- 0 - +chr22 46390528 46391075 ENST00000674359|CELSR1|chr22|- 0 - +chr22 46390864 46391033 ENST00000674312|CELSR1|chr22|- 0 - +chr22 46399762 46399902 ENST00000674315|CELSR1|chr22|- 0 - +chr22 46462779 46462918 ENST00000454637|CELSR1|chr22|- 0 - +chr22 46530308 46530500 ENST00000497509|CELSR1|chr22|- 0 - +chr22 48254903 48256574 ENST00000648313|AL008720.1|chr22|- 0 - +chr22 48415399 48415571 ENST00000648629|Z72006.1|chr22|+ 0 + +chr22 49773283 49774416 ENST00000438393|BRD1|chr22|- 0 - +chr22 49773293 49774416 ENST00000457780|BRD1|chr22|- 0 - +chr22 49775261 49775745 ENST00000479985|BRD1|chr22|- 0 - +chr22 49818212 49818383 ENST00000459821|BRD1|chr22|- 0 - +chr22 49820833 49820986 ENST00000494833|BRD1|chr22|- 0 - +chr22 50199090 50199328 ENST00000608025|AL022328.4|chr22|- 0 - +chr22 50739694 50740359 ENST00000533930|ACR|chr22|+ 0 + +chr22 50744653 50745339 ENST00000216139|ACR|chr22|+ 0 + +chr22 50744546 50744910 ENST00000527761|ACR|chr22|+ 0 + +chr22 50740757 50740840 ENST00000532913|AC002056.2|chr22|- 0 - diff --git a/tests/fixtures/apa_calling/protocol_example.expected_gene_annotation.bed b/tests/fixtures/apa_calling/protocol_example.expected_gene_annotation.bed new file mode 100644 index 000000000..79723ade6 --- /dev/null +++ b/tests/fixtures/apa_calling/protocol_example.expected_gene_annotation.bed @@ -0,0 +1,403 @@ +chr22 16654065 16675540 ENST00000456726 0 - 16654065 16675539 0 9 11,132,112,80,159,45,71,153,418, 0,5431,5792,7410,15396,16151,17452,19534,21057, +chr22 16669463 16675452 ENST00000457060 0 - 16669463 16675451 0 4 157,45,71,330, 0,753,2054,5659, +chr22 17116296 17121360 ENST00000331437 0 - 17121124 17119390 0 1 5064, 0, +chr22 17116298 17121367 ENST00000399875 0 - 17120059 17119390 0 2 3845,116, 0,4953, +chr22 17628854 17696209 ENST00000399781 0 + 17628854 17696208 0 5 52,599,171,108,69, 0,9247,26807,54359,67286, +chr22 17628915 17702428 ENST00000399782 0 + 17655711 17702389 0 7 90,599,171,108,157,70,186, 0,9186,26746,54298,60070,67225,73327, +chr22 17638583 17730855 ENST00000337612 0 + 17655711 17726687 0 5 303,171,108,144,4179, 0,17078,44630,63659,88093, +chr22 17638583 17730855 ENST00000418951 0 + 17702272 17727531 0 6 303,171,108,157,144,4179, 0,17078,44630,50402,63659,88093, +chr22 17638583 17730855 ENST00000538149 0 + 17655711 17726687 0 4 303,171,144,4179, 0,17078,63659,88093, +chr22 17638583 17730855 ENST00000543133 0 + 17702272 17727531 0 6 303,171,108,70,144,4179, 0,17078,44630,57557,63659,88093, +chr22 17638583 17730855 ENST00000611738 0 + 17638693 17727531 0 5 303,108,157,70,4179, 0,44630,50402,57557,88093, +chr22 17638583 17730855 ENST00000616863 0 + 17655711 17726687 0 4 303,171,108,4179, 0,17078,44630,88093, +chr22 17638583 17730855 ENST00000618481 0 + 17638693 17727531 0 6 303,108,157,70,144,4179, 0,44630,50402,57557,63659,88093, +chr22 17638740 17728699 ENST00000498133 0 + 17655711 17696145 0 6 146,171,108,70,144,2023, 0,16921,44473,57400,63502,87936, +chr22 17638756 17692395 ENST00000464649 0 + 17638756 17692394 0 4 130,108,157,40, 0,44457,50229,53599, +chr22 17638756 17730855 ENST00000317582 0 + 17655711 17727531 0 7 130,171,108,157,70,144,4179, 0,16905,44457,50229,57384,63486,87920, +chr22 17638771 17703733 ENST00000493680 0 + 17655711 17702389 0 6 115,171,108,157,70,1491, 0,16890,44442,50214,57369,63471, +chr22 17638810 17730622 ENST00000355028 0 + 17655711 17726803 0 5 76,171,108,157,3946, 0,16851,44403,50175,87866, +chr22 17689073 17729140 ENST00000399777 0 + 17689073 17729139 0 3 69,144,2464, 0,13169,37603, +chr22 17695737 17702363 ENST00000479296 0 + 17695737 17702362 0 2 473,121, 0,6505, +chr22 17706709 17727670 ENST00000485631 0 + 17706709 17727669 0 2 116,994, 0,19967, +chr22 18906237 18947732 ENST00000638240 0 + 18906374 18939699 0 6 247,161,101,141,77,942, 0,327,3934,4650,33435,40553, +chr22 18936410 18947741 ENST00000640084 0 + 18936410 18947740 0 4 238,116,77,951, 0,941,3262,10380, +chr22 18939445 18947692 ENST00000638287 0 + 18939445 18947691 0 2 312,902, 0,7345, +chr22 18945122 18946971 ENST00000623496 0 + 18945122 18946970 0 2 47,181, 0,1668, +chr22 19146992 19150292 ENST00000086933 0 - 19150280 19148990 0 3 2103,254,268, 0,2670,3032, +chr22 19523023 19527545 ENST00000406028 0 - 19524507 19523598 0 2 1519,1029, 0,3493, +chr22 19523026 19524400 ENST00000618236 0 - 19524252 19523598 0 1 1374, 0, +chr22 19523026 19525383 ENST00000403084 0 - 19524507 19523598 0 1 2357, 0, +chr22 19523051 19525423 ENST00000413119 0 - 19524507 19523598 0 2 1491,269, 0,2103, +chr22 20111874 20117226 ENST00000252136 0 - 20116903 20112562 0 12 920,97,117,76,123,112,116,115,182,109,575,344, 0,1036,1243,1557,1811,2699,2886,3090,3391,3797,4163,5008, +chr22 20111874 20117392 ENST00000403707 0 - 20116903 20112562 0 13 920,97,117,76,123,112,116,115,182,109,575,90,296, 0,1036,1243,1557,1811,2699,2886,3090,3391,3797,4163,5008,5222, +chr22 20112300 20113178 ENST00000480339 0 - 20112300 20113177 0 2 494,268, 0,610, +chr22 20112300 20113507 ENST00000444845 0 - 20112300 20113506 0 4 494,52,117,76, 0,655,817,1131, +chr22 20112303 20117245 ENST00000404751 0 - 20116903 20112773 0 12 513,97,117,76,123,112,116,115,182,109,575,363, 0,607,814,1128,1382,2270,2457,2661,2962,3368,3734,4579, +chr22 20112327 20113798 ENST00000487668 0 - 20112327 20113797 0 4 680,117,130,113, 0,790,1104,1358, +chr22 20112337 20117222 ENST00000439169 0 - 20116903 20112562 0 12 457,97,117,130,123,112,116,115,182,109,575,340, 0,573,780,1094,1348,2236,2423,2627,2928,3334,3700,4545, +chr22 20112498 20113378 ENST00000487378 0 - 20112498 20113377 0 3 296,97,261, 0,412,619, +chr22 20112567 20113808 ENST00000444256 0 - 20112567 20113807 0 3 227,76,123, 0,864,1118, +chr22 20112891 20115812 ENST00000494820 0 - 20112891 20115811 0 9 116,117,76,123,112,116,115,182,141, 0,226,540,794,1682,1869,2073,2374,2780, +chr22 20113117 20115688 ENST00000492988 0 - 20113117 20115687 0 8 117,76,123,108,116,115,182,17, 0,314,568,1456,1643,1847,2148,2554, +chr22 20113485 20115439 ENST00000471040 0 - 20113485 20115438 0 5 22,123,112,116,475, 0,200,1088,1275,1479, +chr22 20113649 20114868 ENST00000488335 0 - 20113649 20114867 0 3 159,112,108, 0,924,1111, +chr22 20113703 20115392 ENST00000463710 0 - 20113703 20115391 0 4 105,108,116,428, 0,870,1057,1261, +chr22 20114766 20115622 ENST00000459644 0 - 20114766 20115621 0 3 110,115,357, 0,198,499, +chr22 20115336 20116550 ENST00000468917 0 - 20115336 20116549 0 2 444,513, 0,701, +chr22 20115348 20116100 ENST00000480460 0 - 20115348 20116099 0 3 206,109,63, 0,323,689, +chr22 20115576 20117183 ENST00000494641 0 - 20115576 20117182 0 3 204,555,301, 0,481,1306, +chr22 20115609 20117203 ENST00000464535 0 - 20115609 20117202 0 4 171,575,90,107, 0,428,1273,1487, +chr22 20116241 20117239 ENST00000445045 0 - 20116241 20117238 0 2 371,211, 0,787, +chr22 20917406 20953747 ENST00000354336 0 + 20917934 20949842 0 3 839,466,4037, 0,16372,32304, +chr22 20917433 20953747 ENST00000411769 0 + 20917934 20949842 0 4 812,466,217,542, 0,16345,32277,35772, +chr22 21114606 21124451 ENST00000420508 0 - 21114606 21124450 0 6 1581,915,129,107,376,1725, 0,2473,4045,6207,7369,8120, +chr22 21207972 21225554 ENST00000405188 0 - 21225551 21208137 0 12 312,114,113,98,188,137,150,154,197,87,131,164, 0,616,811,1026,1386,5092,5752,7952,8498,13893,14111,17418, +chr22 21207973 21227637 ENST00000401924 0 - 21225551 21208137 0 15 311,114,113,128,188,137,150,154,197,87,131,171,174,69,242, 0,615,810,1025,1385,5091,5751,7951,8497,13892,14110,17417,18131,18620,19422, +chr22 21300989 21325042 ENST00000447720 0 - 21300989 21325041 0 12 435,155,41,73,1966,34,62,66,87,25,59,212, 0,5079,5696,5963,6569,10750,11249,13310,18280,21313,21806,23841, +chr22 21300990 21309881 ENST00000436681 0 - 21300990 21309880 0 3 434,957,2323, 0,5078,6568, +chr22 21300996 21325042 ENST00000416615 0 - 21300996 21325041 0 9 428,957,34,62,66,87,25,59,212, 0,5072,10743,11242,13303,18273,21306,21799,23834, +chr22 21309820 21322854 ENST00000416405 0 - 21309820 21322853 0 7 1524,34,62,66,87,25,59, 0,1919,2418,4479,9449,12482,12975, +chr22 21311739 21324937 ENST00000453273 0 - 21311739 21324936 0 7 34,62,66,87,25,189,107, 0,499,2560,7530,10563,11056,13091, +chr22 21311739 21325042 ENST00000431488 0 - 21311739 21325041 0 8 34,62,66,87,128,25,59,212, 0,499,2560,7530,9852,10563,11056,13091, +chr22 21319269 21324967 ENST00000451574 0 - 21319269 21324966 0 4 87,133,59,137, 0,2925,3526,5561, +chr22 21321947 21324967 ENST00000452952 0 - 21321947 21324966 0 3 380,59,137, 0,848,2883, +chr22 21322140 21322935 ENST00000411581 0 - 21322140 21322934 0 2 187,140, 0,655, +chr22 22484420 22508742 ENST00000626650 0 - 22489395 22487766 0 4 5046,118,61,84, 0,9642,23389,24238, +chr22 22484857 22508733 ENST00000619852 0 - 22489395 22487766 0 5 1121,2606,118,61,75, 0,2003,9205,22952,23801, +chr22 22484872 22489468 ENST00000613655 0 - 22489395 22487766 0 2 1106,2608, 0,1988, +chr22 23145325 23164350 ENST00000263116 0 + 23146616 23161561 0 11 226,81,92,66,102,65,52,82,91,120,2851, 0,1279,4737,7135,7707,10642,12666,13572,13837,15553,16174, +chr22 23145365 23161564 ENST00000341989 0 + 23146616 23161561 0 10 186,81,92,102,65,52,82,91,120,65, 0,1239,4697,7667,10602,12626,13532,13797,15513,16134, +chr22 23150112 23156311 ENST00000420895 0 + 23150112 23156310 0 4 42,66,102,344, 0,2348,2920,5855, +chr22 23856702 23886309 ENST00000345044 0 + 23856970 23884846 0 12 289,99,161,125,130,149,188,111,102,76,128,1661, 0,5401,11778,18414,20339,21018,25756,26056,27069,27246,27599,27946, +chr22 23856862 23870182 ENST00000403208 0 + 23856970 23870038 0 4 129,99,161,175, 0,5241,11618,13145, +chr22 23856871 23885536 ENST00000398356 0 + 23857489 23884846 0 13 120,111,99,161,125,130,149,188,111,102,76,128,888, 0,549,5232,11609,18245,20170,20849,25587,25887,26900,27077,27430,27777, +chr22 23856933 23877328 ENST00000405847 0 + 23856970 23877172 0 5 58,99,161,125,287, 0,5170,11547,18183,20108, +chr22 23856945 23882952 ENST00000467660 0 + 23856945 23882951 0 9 46,111,99,161,125,130,149,188,194, 0,475,5158,11535,18171,20096,20775,25513,25813, +chr22 23856950 23882951 ENST00000405286 0 + 23856950 23882950 0 8 41,111,99,161,125,130,188,193, 0,470,5153,11530,18166,20091,25508,25808, +chr22 23856956 23884933 ENST00000255830 0 + 23856970 23875133 0 11 35,99,161,121,130,188,111,102,76,128,285, 0,5147,11524,18164,20085,25502,25802,26815,26992,27345,27692, +chr22 23856956 23885551 ENST00000489322 0 + 23856956 23885550 0 9 35,99,161,121,130,188,111,658,903, 0,5147,11524,18164,20085,25502,25802,26815,27692, +chr22 23856961 23866806 ENST00000440493 0 + 23856961 23866805 0 4 30,111,99,384, 0,459,5142,9461, +chr22 23856999 23875211 ENST00000473740 0 + 23856999 23875210 0 4 532,99,161,95, 0,5104,11481,18117, +chr22 23856999 23886112 ENST00000611880 0 + 23857489 23884943 0 11 532,99,161,125,130,149,188,111,151,128,1490, 0,5104,11481,18117,20042,20721,25459,25759,26874,27302,27623, +chr22 23857335 23862325 ENST00000492516 0 + 23857335 23862324 0 2 196,222, 0,4768, +chr22 23857416 23877287 ENST00000423972 0 + 23857489 23875133 0 5 115,99,161,121,246, 0,4687,11064,17704,19625, +chr22 23857470 23875189 ENST00000418102 0 + 23857489 23867737 0 5 61,99,165,161,73, 0,4633,10264,11010,17646, +chr22 23857874 23868796 ENST00000491948 0 + 23857874 23868795 0 3 155,99,316, 0,4229,10606, +chr22 23857894 23877172 ENST00000436643 0 + 23857999 23875133 0 5 135,99,161,157,131, 0,4209,10586,17190,19147, +chr22 23857918 23885553 ENST00000405340 0 + 23858135 23877514 0 12 238,99,161,125,130,485,188,111,102,76,128,905, 0,4185,10562,17198,19123,19466,24540,24840,25853,26030,26383,26730, +chr22 23857960 23885536 ENST00000461809 0 + 23857960 23885535 0 9 69,99,161,125,130,188,1266,128,888, 0,4143,10520,17156,19081,24498,24798,26341,26688, +chr22 23857962 23884867 ENST00000316185 0 + 23857999 23884846 0 12 67,99,161,125,130,149,188,111,102,76,128,219, 0,4141,10518,17154,19079,19758,24496,24796,25809,25986,26339,26686, +chr22 23875159 23882952 ENST00000482576 0 + 23875159 23882951 0 4 82,130,152,194, 0,1882,7335,7599, +chr22 23877857 23884784 ENST00000472526 0 + 23877857 23884783 0 6 12,188,111,76,128,136, 0,4601,4901,6091,6444,6791, +chr22 23880408 23883307 ENST00000473357 0 + 23880408 23883306 0 2 2238,549, 0,2350, +chr22 23882959 23885536 ENST00000486907 0 + 23882959 23885535 0 2 1470,888, 0,1689, +chr22 23862187 23895223 ENST00000433835 0 + 23862187 23895222 0 6 15,161,125,130,173,184, 0,6293,12929,14854,32584,32852, +chr22 23865247 23873277 ENST00000624923 0 - 23865247 23873276 0 1 8030, 0, +chr22 24101688 24103354 ENST00000444093 0 + 24101688 24103353 0 3 49,191,318, 0,523,1348, +chr22 24270816 24417739 ENST00000437398 0 + 24302231 24414620 0 16 167,190,154,1631,208,74,176,164,92,91,84,157,103,117,60,3206, 0,31378,42496,50471,53403,58029,59439,63593,67569,76269,92444,94659,98401,140771,141831,143717, +chr22 24270821 24330401 ENST00000421374 0 + 24270821 24330400 0 7 162,190,154,1631,208,74,146, 0,31373,42491,50466,53398,58024,59434, +chr22 24270830 24417738 ENST00000314328 0 + 24302231 24414620 0 17 153,104,190,154,1631,208,74,176,164,92,91,84,157,103,117,60,3205, 0,5869,31364,42482,50457,53389,58015,59425,63579,67555,76255,92430,94645,98387,140757,141817,143703, +chr22 24270836 24417206 ENST00000651059 0 + 24302231 24414620 0 19 147,104,190,138,154,36,1514,208,74,176,164,92,91,84,157,103,117,60,2673, 0,5863,31358,41157,42476,50451,50568,53383,58009,59419,63573,67549,76249,92424,94639,98381,140751,141811,143697, +chr22 24270882 24324304 ENST00000416735 0 + 24270882 24324303 0 5 101,190,154,36,85, 0,31312,42430,50405,53337, +chr22 24270882 24414773 ENST00000541492 0 + 24302231 24414620 0 15 101,190,154,1631,208,74,176,164,92,91,84,157,103,60,240, 0,31312,42430,50405,53337,57963,59373,63527,67503,76203,92378,94593,98335,141765,143651, +chr22 24304395 24321688 ENST00000440893 0 + 24304395 24321687 0 3 57,154,401, 0,8917,16892, +chr22 24412159 24414752 ENST00000472799 0 + 24412159 24414751 0 2 548,219, 0,2374, +chr22 24645170 24651657 ENST00000639904 0 - 24645170 24651656 0 4 2091,915,129,1499, 0,2983,4554,4988, +chr22 25282612 25320086 ENST00000650352 0 + 25282612 25320085 0 4 443,77,119,320, 0,18102,35644,37154, +chr22 26597027 26611453 ENST00000668614 0 + 26597027 26611452 0 3 56,241,1086, 0,10794,13340, +chr22 26599277 26618027 ENST00000647684 0 - 26616316 26599489 0 6 396,143,133,119,199,51, 0,2601,8611,12794,16862,18699, +chr22 26601948 26608329 ENST00000647569 0 - 26601948 26608328 0 3 73,133,111, 0,5940,6270, +chr22 26621962 26630669 ENST00000354760 0 + 26622596 26630484 0 6 24,51,119,142,143,330, 0,622,1271,3518,6325,8377, +chr22 26621982 26630641 ENST00000466315 0 + 26621982 26630640 0 5 4,51,142,143,302, 0,602,3498,6305,8357, +chr22 26672746 26719282 ENST00000651474 0 + 26672746 26719281 0 4 241,207,92,142, 0,44506,45393,46394, +chr22 26672766 26734455 ENST00000444388 0 + 26672766 26734454 0 5 221,156,207,151,183, 0,20914,44486,53877,61506, +chr22 26672776 26776848 ENST00000450963 0 + 26672776 26776847 0 5 211,156,207,62,22, 0,20904,44476,101379,104050, +chr22 26672790 26780100 ENST00000449017 0 + 26672790 26780099 0 9 197,179,207,77,179,62,128,130,217, 0,39039,44462,53853,65271,101365,104036,105665,107093, +chr22 26672804 26778635 ENST00000435162 0 + 26672804 26778634 0 5 183,207,62,128,180, 0,44448,101351,104022,105651, +chr22 26672804 26780207 ENST00000437071 0 + 26672804 26780206 0 6 183,179,62,128,130,324, 0,65257,101351,104022,105651,107079, +chr22 26672813 26776882 ENST00000440816 0 + 26672813 26776881 0 5 174,207,92,62,56, 0,44439,45326,101342,104013, +chr22 26672855 26718392 ENST00000421253 0 + 26672855 26718391 0 3 132,207,253, 0,44397,45284, +chr22 26677661 26743965 ENST00000653953 0 + 26677661 26743964 0 3 131,207,326, 0,39591,65978, +chr22 26693692 26719686 ENST00000668496 0 + 26693692 26719685 0 2 144,2434, 0,23560, +chr22 26717251 26742838 ENST00000446336 0 + 26717251 26742837 0 3 208,151,100, 0,9392,25487, +chr22 26717368 26722172 ENST00000417083 0 + 26717368 26722171 0 3 91,92,523, 0,771,4281, +chr22 26735073 26738240 ENST00000662474 0 + 26735073 26738239 0 2 71,179, 0,2988, +chr22 26775522 26780100 ENST00000664301 0 + 26775522 26780099 0 3 1432,130,217, 0,2933,4361, +chr22 26779186 26780893 ENST00000669899 0 + 26779186 26780892 0 2 455,1010, 0,697, +chr22 28687742 28711931 ENST00000434810 0 - 28687742 28711930 0 10 244,81,86,83,164,87,100,62,54,23, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166, +chr22 28687742 28711955 ENST00000456369 0 - 28687742 28711954 0 6 244,81,100,62,54,47, 0,1392,12095,15762,22263,24166, +chr22 28687742 28712146 ENST00000464581 0 - 28712131 28687896 0 11 244,81,86,116,164,87,100,62,54,109,35, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166,24369, +chr22 28687742 28734727 ENST00000402731 0 - 28734718 28687896 0 13 244,81,86,116,164,87,100,62,54,109,38,125,325, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166,37143,37500,46660, +chr22 28687742 28741811 ENST00000425190 0 - 28719411 28687896 0 14 244,81,86,116,164,87,100,62,54,109,91,148,125,43, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166,31652,37234,37500,54026, +chr22 28687742 28741820 ENST00000404276 0 - 28734718 28687896 0 15 244,81,86,116,164,87,100,62,54,109,91,148,125,325,52, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166,31652,37234,37500,46660,54026, +chr22 28687742 28741834 ENST00000348295 0 - 28734718 28687896 0 14 244,81,86,116,164,100,62,54,109,91,148,125,325,66, 0,1392,6289,7384,7967,12095,15762,22263,24166,31652,37234,37500,46660,54026, +chr22 28687742 28742422 ENST00000416671 0 - 28734718 28721599 0 16 244,81,86,116,164,87,100,62,54,109,91,114,148,125,325,654, 0,1392,6289,7384,7967,9158,12095,15762,22263,24166,31652,33775,37234,37500,46660,54026, +chr22 28687743 28712495 ENST00000648295 0 - 28687743 28712494 0 11 243,81,86,116,164,87,100,62,54,109,235, 0,1391,6288,7383,7966,9157,12094,15761,22262,24165,24517, +chr22 28687748 28689410 ENST00000472807 0 - 28687748 28689409 0 2 238,276, 0,1386, +chr22 28687750 28741806 ENST00000649563 0 - 28719411 28687896 0 12 236,81,86,116,164,87,100,62,54,109,91,38, 0,1384,6281,7376,7959,9150,12087,15754,22255,24158,31644,54018, +chr22 28687761 28741800 ENST00000405598 0 - 28734718 28687896 0 16 225,81,86,116,164,87,100,62,54,109,91,148,125,325,154,32, 0,1373,6270,7365,7948,9139,12076,15743,22244,24147,31633,37215,37481,46641,50123,54007, +chr22 28687762 28741838 ENST00000382580 0 - 28734718 28687896 0 16 224,81,86,116,164,87,100,62,54,109,91,148,125,129,325,70, 0,1372,6269,7364,7947,9138,12075,15742,22243,24146,31632,37214,37480,42657,46640,54006, +chr22 28687765 28741806 ENST00000650281 0 - 28734718 28687896 0 16 221,81,86,116,164,87,100,62,54,109,91,148,125,325,116,38, 0,1369,6266,7361,7944,9135,12072,15739,22240,24143,31629,37211,37477,46637,50316,54003, +chr22 28687886 28734721 ENST00000417588 0 - 28734718 28711997 0 13 100,81,86,116,164,87,100,62,54,109,148,125,319, 0,1248,6145,7240,7823,9014,11951,15618,22119,24022,37090,37356,46516, +chr22 28687886 28734721 ENST00000433728 0 - 28734718 28699913 0 13 100,81,86,116,164,87,100,54,109,91,148,125,319, 0,1248,6145,7240,7823,9014,11951,22119,24022,31508,37090,37356,46516, +chr22 28687886 28734721 ENST00000448511 0 - 28734718 28719469 0 14 100,81,86,116,164,87,100,62,54,109,91,38,125,319, 0,1248,6145,7240,7823,9014,11951,15618,22119,24022,31508,36999,37356,46516, +chr22 28687896 28734721 ENST00000403642 0 - 28734718 28687896 0 12 90,81,86,116,164,87,100,62,54,109,91,319, 0,1238,6135,7230,7813,9004,11941,15608,22109,24012,31498,46506, +chr22 28696901 28741806 ENST00000433028 0 - 28734718 28724881 0 10 86,100,62,54,109,91,359,125,325,38, 0,2936,6603,13104,15007,22493,27663,28341,37501,44867, +chr22 28696943 28712257 ENST00000491919 0 - 28696943 28712256 0 5 44,100,62,54,349, 0,2894,6561,13062,14965, +chr22 28699763 28725248 ENST00000439346 0 - 28699763 28725247 0 6 174,62,54,109,148,6, 0,3741,10242,12145,25213,25479, +chr22 28711908 28741783 ENST00000439200 0 - 28711908 28741782 0 7 109,91,148,125,93,325,15, 0,7486,13068,13334,18547,22494,29860, +chr22 28724964 28730501 ENST00000454252 0 - 28724964 28730500 0 6 160,125,117,143,95,82, 0,278,1280,3015,4317,5455, +chr22 28725040 28741820 ENST00000650233 0 - 28725040 28741819 0 4 84,125,325,39, 0,202,9362,16741, +chr22 28725082 28741802 ENST00000398017 0 - 28725082 28741801 0 6 42,125,325,64,123,34, 0,160,9320,12177,12833,16686, +chr22 28883571 29057488 ENST00000544604 0 + 28883766 29053619 0 9 495,126,75,132,111,168,103,1752,3910, 0,103504,158923,159727,161208,163144,164817,165625,170007, +chr22 28917388 29053685 ENST00000402174 0 + 28987075 29053619 0 9 93,126,75,132,111,168,103,1752,107, 0,69687,125106,125910,127391,129327,131000,131808,136190, +chr22 28987051 29053965 ENST00000406323 0 + 28987075 29053619 0 8 150,75,132,111,168,103,1752,387, 0,55443,56247,57728,59664,61337,62145,66527, +chr22 29436533 29478175 ENST00000461286 0 - 29436533 29478174 0 3 5596,141,166, 0,35772,41476, +chr22 29438421 29478136 ENST00000248980 0 - 29438421 29478135 0 3 772,144,127, 0,33884,39588, +chr22 29440766 29478138 ENST00000661328 0 - 29440766 29478137 0 3 1363,144,129, 0,31539,37243, +chr22 29440766 29478868 ENST00000658349 0 - 29440766 29478867 0 4 1363,144,65,55, 0,31539,37243,38047, +chr22 29440791 29478602 ENST00000657516 0 - 29440791 29478601 0 2 1338,593, 0,37218, +chr22 29470264 29478156 ENST00000669415 0 - 29470264 29478155 0 3 763,141,147, 0,2041,7745, +chr22 29471940 29478070 ENST00000419368 0 - 29471940 29478069 0 2 509,61, 0,6069, +chr22 29603555 29698594 ENST00000413209 0 + 29603998 29694799 0 5 557,126,123,84,3843, 0,33195,35534,38646,91196, +chr22 29603567 29694945 ENST00000672805 0 + 29603998 29636751 0 17 545,116,126,123,84,69,83,76,135,75,114,123,218,106,128,163,194, 0,25090,33183,35522,38634,51089,52026,54621,57637,61422,64765,68258,69701,71268,74628,77871,91184, +chr22 29603587 29684162 ENST00000403435 0 + 29603998 29683052 0 17 525,126,123,84,69,83,76,135,75,114,36,218,106,128,163,45,462, 0,33163,35502,38614,51069,52006,54601,57617,61402,64745,68325,69681,71248,74608,77851,79432,80113, +chr22 29603602 29697525 ENST00000672461 0 + 29603998 29683052 0 18 510,126,123,84,69,83,76,135,75,114,123,218,106,128,163,45,492,265, 0,33148,35487,38599,51054,51991,54586,57602,61387,64730,68223,69666,71233,74593,77836,79417,91149,93658, +chr22 29603616 29698594 ENST00000361452 0 + 29603998 29683052 0 16 496,126,84,69,83,76,135,75,114,123,218,106,128,163,45,3843, 0,33134,38585,51040,51977,54572,57588,61373,64716,68209,69652,71219,74579,77822,79403,91135, +chr22 29603632 29683915 ENST00000403999 0 + 29603998 29683052 0 16 480,126,123,84,69,83,76,135,75,114,123,218,106,128,163,896, 0,33118,35457,38569,51024,51961,54556,57572,61357,64700,68193,69636,71203,74563,77806,79387, +chr22 29603632 29698598 ENST00000338641 0 + 29603998 29694799 0 16 480,126,123,84,69,83,76,135,75,114,123,218,106,128,163,3847, 0,33118,35457,38569,51024,51961,54556,57572,61357,64700,68193,69636,71203,74563,77806,91119, +chr22 29603632 29698598 ENST00000672896 0 + 29603998 29683052 0 17 480,126,123,84,69,83,76,135,75,114,123,218,106,128,163,45,3847, 0,33118,35457,38569,51024,51961,54556,57572,61357,64700,68193,69636,71203,74563,77806,79387,91119, +chr22 29603726 29683915 ENST00000334961 0 + 29603998 29683052 0 15 386,84,69,83,76,135,75,114,123,218,106,128,163,45,215, 0,38475,50930,51867,54462,57478,61263,64606,68099,69542,71109,74469,77712,79293,79974, +chr22 29603746 29694811 ENST00000353887 0 + 29603998 29683052 0 15 366,84,69,83,76,135,75,114,123,218,106,128,163,45,60, 0,38455,50910,51847,54442,57458,61243,64586,68079,69522,71089,74449,77692,79273,91005, +chr22 29603948 29694945 ENST00000432151 0 + 29603998 29678227 0 8 164,84,135,75,114,106,128,194, 0,38253,57256,61041,64384,70887,74247,90803, +chr22 29603998 29694811 ENST00000361676 0 + 29603998 29683052 0 16 114,123,84,69,83,76,135,75,114,123,218,106,128,163,45,60, 0,35091,38203,50658,51595,54190,57206,60991,64334,67827,69270,70837,74197,77440,79021,90753, +chr22 29603998 29694811 ENST00000397789 0 + 29603998 29683052 0 17 114,126,123,84,69,83,76,135,75,114,123,218,106,128,163,60,60, 0,32752,35091,38203,50658,51595,54190,57206,60991,64334,67827,69270,70837,74197,77440,79021,90753, +chr22 29604085 29695058 ENST00000673312 0 + 29604085 29695057 0 17 27,126,123,84,69,106,83,76,135,75,114,123,218,106,128,163,307, 0,32665,35004,38116,50571,50889,51508,54103,57119,60904,64247,67740,69183,70750,74110,77353,90666, +chr22 29654656 29695059 ENST00000361166 0 + 29654656 29695058 0 11 69,83,76,75,114,123,218,106,128,163,308, 0,937,3532,10333,13676,17169,18612,20179,23539,26782,40095, +chr22 30331987 30356894 ENST00000215793 0 - 30356789 30334593 0 16 2708,72,102,155,208,246,122,186,118,194,151,75,258,208,122,165, 0,3479,3664,5038,5702,6801,7142,8208,8707,9704,10212,10817,12945,14324,20963,24742, +chr22 30337800 30356884 ENST00000411423 0 - 30356789 30339030 0 4 97,246,50,155, 0,988,1329,18929, +chr22 30337816 30341850 ENST00000444440 0 - 30337816 30341849 0 5 81,246,173,118,159, 0,972,2392,2878,3875, +chr22 30338839 30340471 ENST00000485618 0 - 30338839 30340470 0 3 195,122,276, 0,290,1356, +chr22 30338960 30340779 ENST00000498259 0 - 30338960 30340778 0 2 291,584, 0,1235, +chr22 30342319 30356919 ENST00000447376 0 - 30356789 30342872 0 4 31,75,122,190, 0,485,10631,14410, +chr22 30342546 30345154 ENST00000471037 0 - 30342546 30345153 0 2 333,222, 0,2386, +chr22 30344909 30346489 ENST00000471342 0 - 30344909 30346488 0 2 281,178, 0,1402, +chr22 30346220 30356891 ENST00000463818 0 - 30346220 30356890 0 3 299,122,162, 0,6730,10509, +chr22 30352544 30356894 ENST00000496189 0 - 30352544 30356893 0 2 528,165, 0,4185, +chr22 30409254 30428990 ENST00000454552 0 + 30409254 30428989 0 5 28,61,84,170,529, 0,171,1341,6979,19207, +chr22 30409261 30428987 ENST00000439838 0 + 30409261 30428986 0 9 21,61,84,107,140,170,128,233,526, 0,164,1334,6497,6686,6972,17455,17909,19200, +chr22 30409262 30428990 ENST00000439023 0 + 30409262 30428989 0 4 20,61,84,529, 0,163,1333,19199, +chr22 30425622 30427151 ENST00000629597 0 + 30425879 30427148 0 3 324,128,30, 0,1094,1499, +chr22 30425767 30429054 ENST00000266263 0 + 30425879 30428531 0 4 179,128,233,593, 0,949,1403,2694, +chr22 30425774 30427192 ENST00000614920 0 + 30425774 30427191 0 2 172,476, 0,942, +chr22 30425775 30429053 ENST00000355143 0 + 30425879 30428671 0 3 171,128,592, 0,941,2686, +chr22 30425779 30428643 ENST00000412752 0 + 30425879 30427148 0 4 167,128,282,182, 0,937,1342,2682, +chr22 30425816 30428951 ENST00000407550 0 + 30425879 30428531 0 4 130,128,164,490, 0,900,1423,2645, +chr22 30635780 30647893 ENST00000343605 0 + 30636450 30647028 0 2 1289,1296, 0,10817, +chr22 30636322 30663299 ENST00000406566 0 + 30636450 30649242 0 3 747,94,1240, 0,12837,25737, +chr22 30636522 30669016 ENST00000451479 0 + 30636522 30669015 0 3 547,67,1416, 0,28970,31078, +chr22 30652050 30663506 ENST00000430175 0 - 30652050 30663505 0 3 247,248,103, 0,10962,11353, +chr22 30652050 30667843 ENST00000404885 0 - 30664000 30663436 0 3 247,677,382, 0,11353,15411, +chr22 30652050 30667860 ENST00000407308 0 - 30664000 30663436 0 3 247,677,1054, 0,11353,14756, +chr22 30652095 30667887 ENST00000461301 0 - 30652095 30667886 0 3 202,132,426, 0,14711,15366, +chr22 30654145 30667809 ENST00000377087 0 - 30664000 30663436 0 3 316,1068,348, 0,8867,13316, +chr22 30654183 30663457 ENST00000412865 0 - 30654183 30663456 0 2 254,445, 0,8829, +chr22 30661444 30667855 ENST00000403268 0 - 30664000 30663539 0 3 2284,242,394, 0,2394,6017, +chr22 30661444 30667875 ENST00000334679 0 - 30664000 30663436 0 2 2636,414, 0,6017, +chr22 30663514 30667885 ENST00000342474 0 - 30663514 30667884 0 3 566,167,424, 0,1440,3947, +chr22 30663970 30667353 ENST00000442752 0 - 30663970 30667352 0 2 110,547, 0,2836, +chr22 30693781 30906554 ENST00000438716 0 + 30694060 30906336 0 15 291,137,209,254,193,118,55,147,246,121,104,96,185,233,358, 0,426,47379,176647,193644,194441,195398,195708,196946,199340,199681,199856,200035,212055,212415, +chr22 30694075 30907632 ENST00000407373 0 + 30694219 30906336 0 14 269,209,254,193,118,58,147,246,121,104,96,185,233,1436, 0,47085,176353,193350,194147,195101,195414,196652,199046,199387,199562,199741,211761,212121, +chr22 30694205 30907824 ENST00000403222 0 + 30741353 30906336 0 14 139,209,254,197,114,55,147,246,121,104,96,185,233,1628, 0,46955,176223,193220,194021,194974,195284,196522,198916,199257,199432,199611,211631,211991, +chr22 30694873 30907813 ENST00000332585 0 + 30694909 30906336 0 14 680,209,254,193,118,58,147,246,121,104,96,185,233,1617, 0,46287,175555,192552,193349,194303,194616,195854,198248,198589,198764,198943,210963,211323, +chr22 30694888 30906406 ENST00000446658 0 + 30694909 30906336 0 14 665,209,254,193,118,55,147,246,121,104,96,185,233,210, 0,46272,175540,192537,193334,194291,194601,195839,198233,198574,198749,198928,210948,211308, +chr22 30764252 30870613 ENST00000477355 0 + 30764252 30870612 0 4 140,99,123,185, 0,6330,8870,106176, +chr22 30764252 30887491 ENST00000445781 0 + 30764252 30887490 0 4 140,99,254,66, 0,6330,106176,123173, +chr22 30764252 30906772 ENST00000401475 0 + 30870673 30906336 0 13 140,254,193,118,55,147,246,121,104,96,185,233,576, 0,106176,123173,123970,124927,125237,126475,128869,129210,129385,129564,141584,141944, +chr22 30764335 30844687 ENST00000464341 0 + 30764335 30844686 0 4 57,99,58,205, 0,6247,78317,80147, +chr22 30770659 30872523 ENST00000496367 0 + 30770659 30872522 0 3 22,254,215, 0,99769,101649, +chr22 30803085 30889635 ENST00000424224 0 + 30803085 30889634 0 6 92,254,193,118,58,146, 0,67343,84340,85137,86091,86404, +chr22 30822515 30907824 ENST00000437268 0 + 30822630 30906336 0 13 194,254,193,118,58,147,246,121,104,96,185,233,1631, 0,47913,64910,65707,66661,66974,68212,70606,70947,71122,71301,83321,83678, +chr22 30881680 30889617 ENST00000454145 0 + 30881680 30889616 0 5 122,193,118,58,98, 0,5745,6542,7496,7839, +chr22 30881680 30893135 ENST00000453621 0 + 30881680 30893134 0 7 122,193,118,55,147,246,14, 0,5745,6542,7499,7809,9047,11441, +chr22 30881680 30907623 ENST00000431368 0 + 30881680 30907622 0 12 122,193,118,58,147,246,121,104,96,185,233,1427, 0,5745,6542,7496,7809,9047,11441,11782,11957,12136,24156,24516, +chr22 30881680 30907824 ENST00000535268 0 + 30888287 30906336 0 12 122,193,118,55,147,246,121,104,96,185,233,1628, 0,5745,6542,7499,7809,9047,11441,11782,11957,12136,24156,24516, +chr22 30887425 30907643 ENST00000452656 0 + 30887425 30907642 0 10 193,118,58,147,246,121,104,96,233,1447, 0,797,1751,2064,3302,5696,6037,6212,18411,18771, +chr22 30890948 30894261 ENST00000496575 0 + 30890948 30894260 0 3 25,104,624, 0,2514,2689, +chr22 30893462 30894463 ENST00000433183 0 + 30893462 30894462 0 2 104,826, 0,175, +chr22 31082155 31083565 ENST00000609017 0 - 31082155 31083564 0 1 1410, 0, +chr22 31104771 31120069 ENST00000402395 0 - 31107502 31104969 0 7 357,79,35,36,157,203,187, 0,436,886,1158,2605,2912,15111, +chr22 31104776 31107533 ENST00000490967 0 - 31104776 31107532 0 4 352,79,35,1604, 0,431,881,1153, +chr22 31104776 31107568 ENST00000400299 0 - 31107502 31104969 0 5 352,79,35,36,192, 0,431,881,1153,2600, +chr22 31104778 31107568 ENST00000611680 0 - 31107502 31104969 0 6 350,79,35,21,12,192, 0,429,879,1151,1175,2598, +chr22 31104925 31107528 ENST00000465536 0 - 31104925 31107527 0 5 203,79,35,234,152, 0,282,732,1004,2451, +chr22 31105000 31107553 ENST00000491958 0 - 31105000 31107552 0 5 128,79,35,186,177, 0,207,657,929,2376, +chr22 31105012 31105764 ENST00000495533 0 - 31105012 31105763 0 2 116,557, 0,195, +chr22 31105024 31107541 ENST00000460642 0 - 31105024 31107540 0 5 104,79,35,117,165, 0,183,633,905,2352, +chr22 31105113 31107466 ENST00000469262 0 - 31105113 31107465 0 4 173,35,36,90, 0,544,816,2263, +chr22 31105438 31107556 ENST00000465447 0 - 31105438 31107555 0 2 527,180, 0,1938, +chr22 34017421 34206653 ENST00000655904 0 + 34017421 34206652 0 8 106,59,84,109,196,66,138,572, 0,66547,82936,91904,144174,154291,156888,188660, +chr22 34017425 34218794 ENST00000652942 0 + 34017425 34218793 0 8 102,59,84,196,66,138,113,287, 0,66543,82932,144170,154287,156884,188656,201082, +chr22 34017425 34218794 ENST00000664480 0 + 34017425 34218793 0 11 102,59,84,51,109,137,196,66,138,113,287, 0,66543,82932,90513,91900,130570,144170,154287,156884,188656,201082, +chr22 34017425 34207090 ENST00000665701 0 + 34017425 34207089 0 8 102,59,84,51,109,66,138,1009, 0,66543,82932,90513,91900,154287,156884,188656, +chr22 34017431 34218790 ENST00000669802 0 + 34017431 34218789 0 10 96,59,84,51,109,66,138,113,159,283, 0,66537,82926,90507,91894,154281,156878,188650,196380,201076, +chr22 34017431 34218794 ENST00000656244 0 + 34017431 34218793 0 9 96,59,84,55,109,66,138,113,287, 0,66537,82926,90507,91894,154281,156878,188650,201076, +chr22 34017431 34218796 ENST00000658589 0 + 34017431 34218795 0 9 96,59,84,109,196,66,138,241,289, 0,66537,82926,91894,144164,154281,156878,170753,201076, +chr22 34017431 34218796 ENST00000658699 0 + 34017431 34218795 0 7 96,59,84,66,138,113,289, 0,66537,82926,154281,156878,188650,201076, +chr22 34017431 34218796 ENST00000664743 0 + 34017431 34218795 0 10 96,59,84,196,66,138,51,86,113,289, 0,66537,82926,144164,154281,156878,157958,188041,188650,201076, +chr22 34017431 34218794 ENST00000667570 0 + 34017431 34218793 0 10 96,59,84,109,137,66,138,113,159,287, 0,66537,82926,91894,130564,154281,156878,188650,196380,201076, +chr22 34017431 34218796 ENST00000656434 0 + 34017431 34218795 0 10 96,59,84,51,109,196,66,138,113,289, 0,66537,82926,90507,91894,144164,154281,156878,188650,201076, +chr22 34017431 34218796 ENST00000655455 0 + 34017431 34218795 0 11 96,59,84,51,109,196,66,138,113,159,289, 0,66537,82926,90507,91894,144164,154281,156878,188650,196380,201076, +chr22 34017437 34218792 ENST00000654009 0 + 34017437 34218791 0 12 90,59,84,51,109,137,96,196,66,138,113,285, 0,66531,82920,90501,91888,130558,132486,144158,154275,156872,188644,201070, +chr22 34017437 34218794 ENST00000664028 0 + 34017437 34218793 0 8 90,59,84,109,66,138,113,287, 0,66531,82920,91888,154275,156872,188644,201070, +chr22 34017437 34218796 ENST00000661903 0 + 34017437 34218795 0 10 90,59,84,109,196,66,138,51,113,289, 0,66531,82920,91888,144158,154275,156872,157952,188644,201070, +chr22 34017450 34175779 ENST00000658014 0 + 34017450 34175778 0 7 77,84,109,196,66,138,390, 0,82907,91875,144145,154262,156859,157939, +chr22 34017450 34218796 ENST00000665392 0 + 34017450 34218795 0 9 77,59,84,109,66,138,86,113,289, 0,66518,82907,91875,154262,156859,188022,188631,201057, +chr22 34017450 34218796 ENST00000669488 0 + 34017450 34218795 0 9 77,59,84,196,66,138,113,108,289, 0,66518,82907,144145,154262,156859,188631,196361,201057, +chr22 34017450 34218796 ENST00000663820 0 + 34017450 34218795 0 9 77,59,84,51,109,66,138,82,289, 0,66518,82907,90488,91875,154262,156859,188631,201057, +chr22 34017451 34218796 ENST00000658055 0 + 34017451 34218795 0 9 76,59,84,109,196,66,138,113,289, 0,66517,82906,91874,144144,154261,156858,188630,201056, +chr22 34017469 34206631 ENST00000670742 0 + 34017469 34206630 0 9 58,59,84,51,109,137,66,138,550, 0,66499,82888,90469,91856,130526,154243,156840,188612, +chr22 34017469 34206637 ENST00000665458 0 + 34017469 34206636 0 11 58,59,84,51,109,196,66,138,96,62,556, 0,66499,82888,90469,91856,144126,154243,156840,170860,175227,188612, +chr22 34017472 34188425 ENST00000412218 0 + 34017472 34188424 0 8 55,59,84,63,196,66,138,96, 0,66496,82885,134392,144123,154240,156837,170857, +chr22 34017472 34175780 ENST00000668901 0 + 34017472 34175779 0 10 55,59,84,194,51,109,196,66,138,391, 0,66496,82885,85150,90466,91853,144123,154240,156837,157917, +chr22 34017472 34218796 ENST00000653369 0 + 34017472 34218795 0 6 55,59,66,138,113,289, 0,66496,154240,156837,188609,201035, +chr22 34017472 34218796 ENST00000659067 0 + 34017472 34218795 0 9 55,59,84,51,109,196,66,138,289, 0,66496,82885,90466,91853,144123,154240,156837,201035, +chr22 34017472 34175779 ENST00000668175 0 + 34017472 34175778 0 9 55,226,59,84,109,196,66,138,390, 0,43802,66496,82885,91853,144123,154240,156837,157917, +chr22 34017472 34218796 ENST00000661800 0 + 34017472 34218795 0 10 55,59,84,109,196,66,138,113,159,289, 0,66496,82885,91853,144123,154240,156837,188609,196339,201035, +chr22 34017472 34218796 ENST00000670329 0 + 34017472 34218795 0 7 55,84,51,109,113,159,289, 0,82885,90466,91853,188609,196339,201035, +chr22 34017472 34218794 ENST00000671554 0 + 34017472 34218793 0 9 55,59,84,109,66,138,51,113,287, 0,66496,82885,91853,154240,156837,157917,188609,201035, +chr22 34017477 34218796 ENST00000657115 0 + 34017477 34218795 0 9 50,59,84,51,109,66,138,113,289, 0,66491,82880,90461,91848,154235,156832,188604,201030, +chr22 35122660 35127419 ENST00000610215 0 + 35122660 35127418 0 2 86,278, 0,4481, +chr22 36467045 36481640 ENST00000216185 0 - 36480834 36467803 0 4 872,124,263,77, 0,9687,13529,14518, +chr22 36467045 36481634 ENST00000416967 0 - 36476810 36467803 0 4 872,124,213,71, 0,9687,13529,14518, +chr22 36467548 36481632 ENST00000487725 0 - 36467548 36481631 0 4 369,124,174,69, 0,9184,13026,14015, +chr22 36467590 36481340 ENST00000403313 0 - 36480834 36467803 0 4 327,124,263,198, 0,9142,12984,13552, +chr22 36467883 36481596 ENST00000411915 0 - 36480834 36468663 0 5 34,116,124,263,33, 0,718,8849,12691,13680, +chr22 36991119 37002256 ENST00000442538 0 - 36991119 37002255 0 4 157,111,145,64, 0,361,8720,11073, +chr22 36991124 37007798 ENST00000402860 0 - 37002067 36991178 0 6 152,111,145,448,60,70, 0,356,8715,10712,12841,16604, +chr22 36991124 37007841 ENST00000405091 0 - 37003984 36991178 0 7 152,111,145,467,60,96,118, 0,356,8715,10712,12841,16347,16599, +chr22 36991124 37007851 ENST00000381821 0 - 37003984 36991178 0 6 152,111,145,467,60,123, 0,356,8715,10712,12841,16604, +chr22 37166756 37182850 ENST00000419128 0 + 37166756 37182849 0 2 208,422, 0,15672, +chr22 37180165 37188247 ENST00000337843 0 - 37188210 37182187 0 3 2570,238,85, 0,5052,7997, +chr22 37180166 37188286 ENST00000397110 0 - 37188210 37182187 0 4 701,584,238,124, 0,1985,5051,7996, +chr22 37180166 37198301 ENST00000470655 0 - 37180166 37198300 0 9 701,431,92,238,176,314,64,66,2921, 0,1985,2569,5051,5704,7996,10698,11505,15214, +chr22 37180170 37185948 ENST00000493023 0 - 37180170 37185947 0 2 2565,731, 0,5047, +chr22 37182173 37188236 ENST00000434784 0 - 37188210 37184375 0 4 562,101,238,74, 0,2163,3044,5989, +chr22 37190552 37197748 ENST00000467564 0 - 37190552 37197747 0 5 125,64,66,78,146, 0,312,1119,4828,7050, +chr22 37190552 37199385 ENST00000497071 0 - 37190552 37199384 0 6 125,64,66,132,239,62, 0,312,1119,4828,7050,8771, +chr22 37371683 37372858 ENST00000609322 0 + 37371683 37372857 0 2 85,825, 0,350, +chr22 37807904 37817176 ENST00000323205 0 + 37807967 37816715 0 10 259,209,102,147,155,83,172,122,159,248, 0,2044,4982,5558,7221,7513,7758,8295,8662,9024, +chr22 37807915 37813300 ENST00000445195 0 + 37807915 37813299 0 4 248,209,102,24, 0,2033,4971,5361, +chr22 37807922 37813485 ENST00000415371 0 + 37807922 37813484 0 3 241,102,209, 0,4964,5354, +chr22 37807933 37813076 ENST00000478203 0 + 37807933 37813075 0 3 230,131,190, 0,2093,4953, +chr22 37807933 37816897 ENST00000248924 0 + 37807967 37816715 0 9 230,131,102,147,155,83,172,122,331, 0,2093,4953,5529,7192,7484,7729,8266,8633, +chr22 37807937 37815208 ENST00000426858 0 + 37807967 37812963 0 4 226,102,147,83, 0,4949,5525,7188, +chr22 37808013 37813609 ENST00000451984 0 + 37808013 37813608 0 4 150,131,102,333, 0,2013,4873,5263, +chr22 38032164 38034228 ENST00000410099 0 - 38032164 38034227 0 2 991,64, 0,2000, +chr22 38231319 38232248 ENST00000420172 0 + 38231319 38232247 0 2 96,201, 0,728, +chr22 38426326 38455199 ENST00000303592 0 - 38428129 38426794 0 2 1845,220, 0,28653, +chr22 38434306 38436686 ENST00000662373 0 + 38434306 38436685 0 3 117,119,384, 0,536,1996, +chr22 38518947 38570183 ENST00000216024 0 - 38568253 38520019 0 14 1142,117,61,115,74,92,73,42,53,83,147,45,84,141, 0,2660,18644,19347,19591,20373,30977,33718,36409,43339,47642,48635,49258,51095, +chr22 38518948 38568409 ENST00000428462 0 - 38568253 38520019 0 11 1141,117,61,115,74,42,53,83,147,45,204, 0,2659,18643,19346,19590,33717,36408,43338,47641,48634,49257, +chr22 38538294 38570131 ENST00000439567 0 - 38538294 38570130 0 9 115,74,42,53,83,147,45,84,78, 0,244,14371,17062,23992,28295,29288,29911,31759, +chr22 38545767 38570184 ENST00000616615 0 - 38568253 38549920 0 9 363,636,42,53,83,147,45,84,142, 0,3594,6898,9589,16519,20822,21815,22438,24275, +chr22 38549497 38570184 ENST00000478820 0 - 38549497 38570183 0 8 500,42,53,83,147,45,84,142, 0,3168,5859,12789,17092,18085,18708,20545, +chr22 38552670 38568409 ENST00000415483 0 - 38552670 38568408 0 6 37,53,83,147,45,204, 0,2686,9616,13919,14912,15535, +chr22 38569283 38570204 ENST00000464842 0 - 38569283 38570203 0 2 107,162, 0,759, +chr22 38675875 38677800 ENST00000666731 0 + 38675875 38677799 0 2 194,291, 0,1634, +chr22 38734724 38755528 ENST00000405510 0 - 38752625 38736266 0 19 1656,93,168,116,85,222,166,44,78,255,128,71,94,96,138,164,159,65,257, 0,3448,3862,4148,4617,4997,5542,6282,6769,7576,10959,13988,15041,15500,16173,16485,17782,19917,20547, +chr22 38734735 38755999 ENST00000405018 0 - 38752625 38736266 0 18 1645,93,168,116,85,222,166,44,78,255,128,71,94,159,138,164,159,237, 0,3437,3851,4137,4606,4986,5531,6271,6758,7565,10948,13977,15030,15489,16162,16474,17771,21027, +chr22 38735908 38794143 ENST00000406622 0 - 38752625 38736266 0 19 472,93,168,116,85,222,166,44,78,255,128,71,94,96,138,164,159,100,76, 0,2264,2678,2964,3433,3813,4358,5098,5585,6392,9775,12804,13857,14316,14989,15301,16598,30325,58159, +chr22 38737759 38739423 ENST00000455125 0 - 38737759 38739422 0 4 506,168,116,82, 0,827,1113,1582, +chr22 38738237 38739247 ENST00000470642 0 - 38738237 38739246 0 3 28,168,375, 0,349,635, +chr22 38738925 38742438 ENST00000477262 0 - 38738925 38742437 0 7 63,85,222,166,162,78,138, 0,416,796,1341,1963,2568,3375, +chr22 38739340 38742481 ENST00000469086 0 - 38739340 38742480 0 5 86,222,784,78,181, 0,381,926,2153,2960, +chr22 38740291 38742578 ENST00000464202 0 - 38740291 38742577 0 4 141,44,78,278, 0,715,1202,2009, +chr22 38745074 38750314 ENST00000430185 0 - 38745074 38750313 0 5 71,128,71,94,90, 0,609,3638,4691,5150, +chr22 38745686 38756000 ENST00000438058 0 - 38745686 38755999 0 8 125,71,94,96,164,159,65,238, 0,3026,4079,4538,5523,6820,8955,10076, +chr22 38748712 38754993 ENST00000456894 0 - 38748712 38754992 0 7 71,94,96,138,164,159,352, 0,1053,1512,2185,2497,3794,5929, +chr22 38749765 38751441 ENST00000480307 0 - 38749765 38751440 0 4 94,96,138,232, 0,459,1132,1444, +chr22 38750224 38754951 ENST00000420859 0 - 38750224 38754950 0 5 96,164,159,65,54, 0,985,2282,4417,4673, +chr22 38750887 38754982 ENST00000452294 0 - 38750887 38754981 0 5 148,164,159,65,85, 0,322,1619,3754,4010, +chr22 38750897 38754943 ENST00000494273 0 - 38750897 38754942 0 4 476,159,65,46, 0,1609,3744,4000, +chr22 38750991 38755634 ENST00000433561 0 - 38750991 38755633 0 4 44,164,159,77, 0,218,1515,4566, +chr22 38751006 38754775 ENST00000417332 0 - 38751006 38754774 0 4 88,164,159,134, 0,203,1500,3635, +chr22 38751019 38755429 ENST00000439339 0 - 38751019 38755428 0 5 16,164,159,49,158, 0,190,1487,3622,4252, +chr22 38778507 38794143 ENST00000216068 0 - 38782728 38779448 0 4 1106,84,208,76, 0,2418,4155,15560, +chr22 38778852 38794148 ENST00000486019 0 - 38778852 38794147 0 2 761,81, 0,15215, +chr22 38780717 38794198 ENST00000406199 0 - 38782728 38780871 0 3 292,208,131, 0,1945,13350, +chr22 38785304 38794132 ENST00000475512 0 - 38785304 38794131 0 2 693,65, 0,8763, +chr22 38952740 38953416 ENST00000495988 0 + 38952740 38953415 0 2 110,456, 0,220, +chr22 38952750 38963183 ENST00000402255 0 + 38957691 38962506 0 6 100,133,145,295,116,689, 0,4837,6791,8636,9347,9744, +chr22 38957521 38959686 ENST00000488758 0 + 38957521 38959685 0 2 199,145, 0,2020, +chr22 38957521 38992778 ENST00000618553 0 + 38957691 38992442 0 5 199,145,295,116,348, 0,2020,3865,4576,34909, +chr22 38957608 38963184 ENST00000249116 0 + 38957691 38962506 0 5 112,145,295,116,690, 0,1933,3778,4489,4886, +chr22 38982346 38992546 ENST00000407298 0 + 38982453 38992442 0 8 124,157,280,115,154,220,116,116, 0,1728,3465,3951,7110,9060,9687,10084, +chr22 38982346 38992779 ENST00000333467 0 + 38982453 38992442 0 8 124,157,280,115,154,295,116,349, 0,1728,3465,3951,7110,8985,9687,10084, +chr22 38982398 38992804 ENST00000402182 0 + 38982453 38992485 0 7 72,157,280,115,154,295,771, 0,1676,3413,3899,7058,8933,9635, +chr22 38982405 38992761 ENST00000335760 0 + 38982453 38991515 0 7 65,157,280,115,295,116,331, 0,1669,3406,3892,8926,9628,10025, +chr22 38991558 38998209 ENST00000513758 0 - 38991558 38998208 0 5 60,184,66,257,124, 0,839,1379,5922,6527, +chr22 39014362 39033276 ENST00000381568 0 + 39014362 39032313 0 7 17,193,280,115,157,280,1079, 0,8459,10707,11194,15000,17331,17835, +chr22 39040603 39045192 ENST00000491387 0 + 39040603 39045191 0 3 164,154,252, 0,2333,4337, +chr22 39040856 39044423 ENST00000381565 0 + 39040960 39044214 0 3 121,154,341, 0,2080,3226, +chr22 39040863 39055972 ENST00000308521 0 + 39040960 39052692 0 7 114,154,280,115,157,280,3396, 0,2073,4077,4564,8561,11210,11713, +chr22 39045183 39052287 ENST00000476513 0 + 39045183 39052286 0 3 359,157,214, 0,4241,6890, +chr22 39519694 39522683 ENST00000404241 0 + 39521445 39522599 0 4 107,574,318,911, 0,483,1659,2078, +chr22 39520552 39522668 ENST00000674920 0 + 39521445 39522599 0 3 199,318,896, 0,801,1220, +chr22 39520562 39522602 ENST00000679776 0 + 39521445 39522599 0 3 90,318,830, 0,791,1210, +chr22 39520563 39522602 ENST00000675582 0 + 39521445 39522599 0 4 188,122,109,830, 0,790,999,1209, +chr22 39520563 39522683 ENST00000337304 0 + 39521445 39522599 0 2 1108,911, 0,1209, +chr22 39520575 39522602 ENST00000676346 0 + 39521445 39522599 0 3 176,300,830, 0,796,1197, +chr22 39520575 39522668 ENST00000396680 0 + 39521445 39522599 0 3 176,414,896, 0,682,1197, +chr22 39520577 39522602 ENST00000680446 0 + 39521798 39522599 0 2 174,830, 0,1195, +chr22 39520578 39522602 ENST00000674568 0 + 39521445 39522599 0 3 173,240,830, 0,853,1194, +chr22 39520588 39521953 ENST00000680748 0 + 39521445 39521736 0 2 163,600, 0,765, +chr22 39520603 39522602 ENST00000674835 0 + 39521445 39522599 0 3 148,297,830, 0,771,1169, +chr22 39520746 39521528 ENST00000676430 0 + 39520746 39521525 0 2 5,175, 0,607, +chr22 42085525 42090772 ENST00000498737 0 - 42090741 42086182 0 3 789,116,167, 0,1534,5080, +chr22 42085526 42090884 ENST00000617763 0 - 42090819 42086182 0 3 788,116,279, 0,1533,5079, +chr22 42086115 42087335 ENST00000470753 0 - 42087140 42086182 0 2 199,276, 0,944, +chr22 42089629 42090028 ENST00000602718 0 - 42089629 42090027 0 1 399, 0, +chr22 42269702 42279493 ENST00000609564 0 + 42269702 42279492 0 2 323,4506, 0,5285, +chr22 42269743 42279534 ENST00000332965 0 + 42269743 42279533 0 2 282,5641, 0,4150, +chr22 42269767 42275033 ENST00000446578 0 + 42269767 42275032 0 4 258,81,166,46, 0,4126,4888,5220, +chr22 42269784 42277001 ENST00000415205 0 + 42269784 42277000 0 3 241,166,2014, 0,4871,5203, +chr22 42276354 42277052 ENST00000420096 0 + 42276354 42277051 0 2 188,357, 0,341, +chr22 42438022 42446195 ENST00000428765 0 + 42438022 42446194 0 4 310,114,115,33, 0,2468,7679,8140, +chr22 46055739 46058160 ENST00000439423 0 - 46055739 46058159 0 2 776,405, 0,2016, +chr22 46267960 46275285 ENST00000417709 0 + 46268039 46269189 0 6 112,78,148,82,172,38, 0,553,1181,4374,5937,7287, +chr22 46268007 46294008 ENST00000381031 0 + 46268039 46292881 0 14 65,78,82,172,174,76,120,60,39,82,166,160,74,1218, 0,506,4327,5890,7240,10578,13591,15965,17233,19065,20415,21394,21818,24783, +chr22 46268007 46268927 ENST00000475467 0 + 46268007 46268926 0 2 65,414, 0,506, +chr22 46268007 46280242 ENST00000421359 0 + 46268007 46280241 0 7 65,78,82,172,174,76,174, 0,506,4327,5890,7240,10578,12061, +chr22 46268039 46269192 ENST00000629918 0 + 46268039 46269189 0 3 33,78,51, 0,474,1102, +chr22 46272371 46284032 ENST00000422713 0 + 46272371 46284031 0 7 45,172,174,76,120,181,60, 0,1526,2876,6214,9227,9599,11601, +chr22 46288509 46292933 ENST00000451998 0 + 46288509 46292932 0 5 79,160,74,126,143, 0,892,1316,3693,4281, +chr22 46360833 46537620 ENST00000262738 0 - 46537167 46363177 0 35 2354,256,225,150,104,95,126,127,80,113,175,201,127,168,205,144,184,210,95,102,184,121,142,175,114,186,167,126,164,158,89,116,223,639,3994, 0,3162,3678,4397,4752,5552,6159,6895,8345,8858,12049,16227,17757,19954,21012,23709,25568,28456,29558,30352,30799,33308,35771,36840,37690,38883,48162,48921,49564,50768,72559,75340,78355,102873,172793, +chr22 46361173 46366438 ENST00000473624 0 - 46361173 46366437 0 5 3078,225,150,104,53, 0,3338,4057,4412,5212, +chr22 46361173 46537620 ENST00000674500 0 - 46537167 46363222 0 35 2074,256,225,150,104,95,126,127,80,113,175,201,127,168,205,144,184,210,95,102,184,121,142,175,114,186,167,126,164,158,89,116,223,639,3994, 0,2822,3338,4057,4412,5212,5819,6555,8005,8518,11709,15887,17417,19614,20672,23369,25228,28116,29218,30012,30459,32968,35431,36500,37350,38543,47822,48581,49224,50428,72219,75000,78015,102533,172453, +chr22 46361985 46374084 ENST00000674159 0 - 46361985 46374083 0 11 1262,256,225,150,104,95,126,127,80,113,1202, 0,2010,2526,3245,3600,4400,5007,5743,7193,7706,10897, +chr22 46365224 46366549 ENST00000674423 0 - 46365224 46366548 0 2 465,164, 0,1161, +chr22 46368858 46409274 ENST00000674341 0 - 46368858 46409273 0 19 400,546,175,201,127,168,205,144,184,210,95,102,184,121,142,175,114,210,279, 0,833,4024,8202,9732,11929,12987,15684,17543,20431,21533,22327,22774,25283,27746,28815,29665,30858,40137, +chr22 46372912 46377624 ENST00000468025 0 - 46372912 46377623 0 3 145,201,277, 0,4148,4435, +chr22 46384500 46386497 ENST00000674379 0 - 46384500 46386496 0 2 186,96, 0,1901, +chr22 46390527 46409826 ENST00000674359 0 - 46390527 46409825 0 10 548,102,184,121,142,175,114,186,167,72, 0,658,1105,3614,6077,7146,7996,9189,18468,19227, +chr22 46390863 46398609 ENST00000674312 0 - 46390863 46398608 0 7 170,102,184,121,142,175,86, 0,322,769,3278,5741,6810,7660, +chr22 46399761 46409276 ENST00000674315 0 - 46399761 46409275 0 2 141,281, 0,9234, +chr22 46462778 46537170 ENST00000454637 0 - 46537167 46462907 0 3 140,639,3544, 0,928,70848, +chr22 46530307 46534200 ENST00000497509 0 - 46530307 46534199 0 2 193,574, 0,3319, +chr22 48254902 48259116 ENST00000648313 0 - 48254902 48259115 0 3 1672,509,335, 0,2291,3879, +chr22 48403461 48415571 ENST00000648629 0 + 48403461 48415570 0 5 249,151,108,103,173, 0,1827,10193,11266,11937, +chr22 49773282 49823213 ENST00000438393 0 - 49773282 49823212 0 12 1134,155,110,128,136,133,261,313,129,132,157,263, 0,2308,2767,3751,4395,14107,20751,24522,25275,25705,30921,49668, +chr22 49773282 49824804 ENST00000216267 0 - 49824314 49774232 0 12 1134,155,110,128,136,105,261,313,129,132,157,1854, 0,2308,2767,3751,4395,14107,20751,24522,25275,25705,30921,49668, +chr22 49773282 49825900 ENST00000404034 0 - 49824314 49774232 0 13 1134,155,110,128,136,105,261,313,129,132,157,1381,171, 0,2308,2767,3751,4395,14107,20751,24522,25275,25705,30921,49668,52447, +chr22 49773282 49827512 ENST00000404760 0 - 49824314 49774232 0 13 1134,155,110,128,136,498,261,313,129,132,157,1381,16, 0,2308,2767,3751,4395,14107,20751,24522,25275,25705,30921,49668,54214, +chr22 49773292 49824804 ENST00000457780 0 - 49824314 49774232 0 12 1124,155,110,128,136,498,261,313,129,132,157,1854, 0,2298,2757,3741,4385,14097,20741,24512,25265,25695,30911,49658, +chr22 49775260 49776115 ENST00000479985 0 - 49775260 49776114 0 2 485,66, 0,789, +chr22 49818211 49823301 ENST00000459821 0 - 49818211 49823300 0 2 172,351, 0,4739, +chr22 49820832 49823205 ENST00000494833 0 - 49820832 49823204 0 2 154,255, 0,2118, +chr22 50199089 50200837 ENST00000608025 0 - 50199089 50200836 0 2 239,762, 0,986, +chr22 50738195 50740359 ENST00000533930 0 + 50738195 50740358 0 3 117,204,666, 0,1075,1498, +chr22 50738203 50745339 ENST00000216139 0 + 50738235 50745204 0 5 109,204,284,146,687, 0,1067,1490,5857,6449, +chr22 50738229 50740757 ENST00000529621 0 + 50738235 50740691 0 4 83,204,284,137, 0,1041,1464,2391, +chr22 50744143 50744910 ENST00000527761 0 + 50744143 50744909 0 2 63,365, 0,402, +chr22 50740592 50743520 ENST00000532913 0 - 50740592 50743519 0 2 248,36, 0,2892, diff --git a/tests/fixtures/apa_calling/protocol_example.expected_pdui_data.txt b/tests/fixtures/apa_calling/protocol_example.expected_pdui_data.txt new file mode 100644 index 000000000..643f3d72c --- /dev/null +++ b/tests/fixtures/apa_calling/protocol_example.expected_pdui_data.txt @@ -0,0 +1,15 @@ +ENST00000638240|AC007326.4|chr22|+ 0.5 18946942 chr22:18946791-18947732 0.20 NA +ENST00000640084|AC007326.5|chr22|+ 0.5 18946942 chr22:18946791-18947741 0.20 NA +ENST00000638287|AC007326.5|chr22|+ 0.5 18946942 chr22:18946791-18947692 0.19 NA +ENST00000498259|SF3A1|chr22|- 1.2 30339100 chr22:30338961-30339251 0.00 NA +ENST00000471037|SF3A1|chr22|- 0.6 30342728 chr22:30342547-30342879 0.00 NA +ENST00000377087|DUSP18|chr22|- 0.8 30654287 chr22:30654146-30654461 0.00 NA +ENST00000412865|DUSP18|chr22|- 0.5 30654286 chr22:30654184-30654437 0.00 0.00 +ENST00000405510|SUN2|chr22|- 0.0 38736202 chr22:38734725-38736380 NA 0.00 +ENST00000405018|SUN2|chr22|- 0.0 38736202 chr22:38734736-38736380 NA 0.00 +ENST00000406622|SUN2|chr22|- 0.1 38736202 chr22:38735909-38736380 NA 0.00 +ENST00000680748|ATF4|chr22|+ 0.2 39521638 chr22:39521354-39521953 0.38 0.00 +ENST00000498737|NDUFA6|chr22|- 0.5 42086141 chr22:42085526-42086314 0.21 NA +ENST00000617763|NDUFA6|chr22|- 0.5 42086141 chr22:42085527-42086314 0.21 NA +ENST00000609564|OGFRP1|chr22|+ 0.0 42275216 chr22:42274988-42279493 NA 0.00 +ENST00000415205|OGFRP1|chr22|+ 0.0 42275216 chr22:42274988-42277001 NA 0.00 diff --git a/tests/fixtures/apa_calling/protocol_example.expected_transcript_to_geneName.txt b/tests/fixtures/apa_calling/protocol_example.expected_transcript_to_geneName.txt new file mode 100644 index 000000000..618e76f46 --- /dev/null +++ b/tests/fixtures/apa_calling/protocol_example.expected_transcript_to_geneName.txt @@ -0,0 +1,403 @@ +ENST00000456726 ANKRD62P1-PARP4P3 +ENST00000457060 ANKRD62P1-PARP4P3 +ENST00000331437 TMEM121B +ENST00000399875 TMEM121B +ENST00000399781 BCL2L13 +ENST00000399782 BCL2L13 +ENST00000337612 BCL2L13 +ENST00000418951 BCL2L13 +ENST00000538149 BCL2L13 +ENST00000543133 BCL2L13 +ENST00000611738 BCL2L13 +ENST00000616863 BCL2L13 +ENST00000618481 BCL2L13 +ENST00000498133 BCL2L13 +ENST00000464649 BCL2L13 +ENST00000317582 BCL2L13 +ENST00000493680 BCL2L13 +ENST00000355028 BCL2L13 +ENST00000399777 BCL2L13 +ENST00000479296 BCL2L13 +ENST00000485631 BCL2L13 +ENST00000638240 AC007326.4 +ENST00000640084 AC007326.5 +ENST00000638287 AC007326.5 +ENST00000623496 AC007326.5 +ENST00000086933 GSC2 +ENST00000406028 CLDN5 +ENST00000618236 CLDN5 +ENST00000403084 CLDN5 +ENST00000413119 CLDN5 +ENST00000252136 TRMT2A +ENST00000403707 TRMT2A +ENST00000480339 TRMT2A +ENST00000444845 TRMT2A +ENST00000404751 TRMT2A +ENST00000487668 TRMT2A +ENST00000439169 TRMT2A +ENST00000487378 TRMT2A +ENST00000444256 TRMT2A +ENST00000494820 TRMT2A +ENST00000492988 TRMT2A +ENST00000471040 TRMT2A +ENST00000488335 TRMT2A +ENST00000463710 TRMT2A +ENST00000459644 TRMT2A +ENST00000468917 TRMT2A +ENST00000480460 TRMT2A +ENST00000494641 TRMT2A +ENST00000464535 TRMT2A +ENST00000445045 TRMT2A +ENST00000354336 CRKL +ENST00000411769 CRKL +ENST00000420508 AP000550.1 +ENST00000405188 GGT2 +ENST00000401924 GGT2 +ENST00000447720 FAM230H +ENST00000436681 FAM230H +ENST00000416615 FAM230H +ENST00000416405 FAM230H +ENST00000453273 FAM230H +ENST00000431488 FAM230H +ENST00000451574 FAM230H +ENST00000452952 FAM230H +ENST00000411581 FAM230H +ENST00000626650 ZNF280B +ENST00000619852 ZNF280B +ENST00000613655 ZNF280B +ENST00000263116 RAB36 +ENST00000341989 RAB36 +ENST00000420895 RAB36 +ENST00000345044 SLC2A11 +ENST00000403208 SLC2A11 +ENST00000398356 SLC2A11 +ENST00000405847 SLC2A11 +ENST00000467660 SLC2A11 +ENST00000405286 SLC2A11 +ENST00000255830 SLC2A11 +ENST00000489322 SLC2A11 +ENST00000440493 SLC2A11 +ENST00000473740 SLC2A11 +ENST00000611880 SLC2A11 +ENST00000492516 SLC2A11 +ENST00000423972 SLC2A11 +ENST00000418102 SLC2A11 +ENST00000491948 SLC2A11 +ENST00000436643 SLC2A11 +ENST00000405340 SLC2A11 +ENST00000461809 SLC2A11 +ENST00000316185 SLC2A11 +ENST00000482576 SLC2A11 +ENST00000472526 SLC2A11 +ENST00000473357 SLC2A11 +ENST00000486907 SLC2A11 +ENST00000433835 AP000350.4 +ENST00000624923 AP000350.7 +ENST00000444093 AC253536.3 +ENST00000437398 SPECC1L +ENST00000421374 SPECC1L +ENST00000314328 SPECC1L +ENST00000651059 SPECC1L +ENST00000416735 SPECC1L +ENST00000541492 SPECC1L +ENST00000440893 SPECC1L +ENST00000472799 SPECC1L +ENST00000639904 AP000356.2 +ENST00000650352 AL022324.4 +ENST00000668614 Z95115.2 +ENST00000647684 CRYBB1 +ENST00000647569 CRYBB1 +ENST00000354760 CRYBA4 +ENST00000466315 CRYBA4 +ENST00000651474 MIATNB +ENST00000444388 MIATNB +ENST00000450963 MIATNB +ENST00000449017 MIATNB +ENST00000435162 MIATNB +ENST00000437071 MIATNB +ENST00000440816 MIATNB +ENST00000421253 MIATNB +ENST00000653953 MIATNB +ENST00000668496 MIATNB +ENST00000446336 MIATNB +ENST00000417083 MIATNB +ENST00000662474 MIATNB +ENST00000664301 MIATNB +ENST00000669899 MIATNB +ENST00000434810 CHEK2 +ENST00000456369 CHEK2 +ENST00000464581 CHEK2 +ENST00000402731 CHEK2 +ENST00000425190 CHEK2 +ENST00000404276 CHEK2 +ENST00000348295 CHEK2 +ENST00000416671 CHEK2 +ENST00000648295 CHEK2 +ENST00000472807 CHEK2 +ENST00000649563 CHEK2 +ENST00000405598 CHEK2 +ENST00000382580 CHEK2 +ENST00000650281 CHEK2 +ENST00000417588 CHEK2 +ENST00000433728 CHEK2 +ENST00000448511 CHEK2 +ENST00000403642 CHEK2 +ENST00000433028 CHEK2 +ENST00000491919 CHEK2 +ENST00000439346 CHEK2 +ENST00000439200 CHEK2 +ENST00000454252 CHEK2 +ENST00000650233 CHEK2 +ENST00000398017 CHEK2 +ENST00000544604 ZNRF3 +ENST00000402174 ZNRF3 +ENST00000406323 ZNRF3 +ENST00000461286 RFPL1S +ENST00000248980 RFPL1S +ENST00000661328 RFPL1S +ENST00000658349 RFPL1S +ENST00000657516 RFPL1S +ENST00000669415 RFPL1S +ENST00000419368 RFPL1S +ENST00000413209 NF2 +ENST00000672805 NF2 +ENST00000403435 NF2 +ENST00000672461 NF2 +ENST00000361452 NF2 +ENST00000403999 NF2 +ENST00000338641 NF2 +ENST00000672896 NF2 +ENST00000334961 NF2 +ENST00000353887 NF2 +ENST00000432151 NF2 +ENST00000361676 NF2 +ENST00000397789 NF2 +ENST00000673312 NF2 +ENST00000361166 NF2 +ENST00000215793 SF3A1 +ENST00000411423 SF3A1 +ENST00000444440 SF3A1 +ENST00000485618 SF3A1 +ENST00000498259 SF3A1 +ENST00000447376 SF3A1 +ENST00000471037 SF3A1 +ENST00000471342 SF3A1 +ENST00000463818 SF3A1 +ENST00000496189 SF3A1 +ENST00000454552 AC004832.3 +ENST00000439838 AC004832.3 +ENST00000439023 AC004832.3 +ENST00000629597 MTFP1 +ENST00000266263 MTFP1 +ENST00000614920 MTFP1 +ENST00000355143 MTFP1 +ENST00000412752 MTFP1 +ENST00000407550 MTFP1 +ENST00000343605 SLC35E4 +ENST00000406566 SLC35E4 +ENST00000451479 SLC35E4 +ENST00000430175 DUSP18 +ENST00000404885 DUSP18 +ENST00000407308 DUSP18 +ENST00000461301 DUSP18 +ENST00000377087 DUSP18 +ENST00000412865 DUSP18 +ENST00000403268 DUSP18 +ENST00000334679 DUSP18 +ENST00000342474 DUSP18 +ENST00000442752 DUSP18 +ENST00000438716 OSBP2 +ENST00000407373 OSBP2 +ENST00000403222 OSBP2 +ENST00000332585 OSBP2 +ENST00000446658 OSBP2 +ENST00000477355 OSBP2 +ENST00000445781 OSBP2 +ENST00000401475 OSBP2 +ENST00000464341 OSBP2 +ENST00000496367 OSBP2 +ENST00000424224 OSBP2 +ENST00000437268 OSBP2 +ENST00000454145 OSBP2 +ENST00000453621 OSBP2 +ENST00000431368 OSBP2 +ENST00000535268 OSBP2 +ENST00000452656 OSBP2 +ENST00000496575 OSBP2 +ENST00000433183 OSBP2 +ENST00000609017 AC005005.3 +ENST00000402395 SELENOM +ENST00000490967 SELENOM +ENST00000400299 SELENOM +ENST00000611680 SELENOM +ENST00000465536 SELENOM +ENST00000491958 SELENOM +ENST00000495533 SELENOM +ENST00000460642 SELENOM +ENST00000469262 SELENOM +ENST00000465447 SELENOM +ENST00000655904 LINC01643 +ENST00000652942 LINC01643 +ENST00000664480 LINC01643 +ENST00000665701 LINC01643 +ENST00000669802 LINC01643 +ENST00000656244 LINC01643 +ENST00000658589 LINC01643 +ENST00000658699 LINC01643 +ENST00000664743 LINC01643 +ENST00000667570 LINC01643 +ENST00000656434 LINC01643 +ENST00000655455 LINC01643 +ENST00000654009 LINC01643 +ENST00000664028 LINC01643 +ENST00000661903 LINC01643 +ENST00000658014 LINC01643 +ENST00000665392 LINC01643 +ENST00000669488 LINC01643 +ENST00000663820 LINC01643 +ENST00000658055 LINC01643 +ENST00000670742 LINC01643 +ENST00000665458 LINC01643 +ENST00000412218 LINC01643 +ENST00000668901 LINC01643 +ENST00000653369 LINC01643 +ENST00000659067 LINC01643 +ENST00000668175 LINC01643 +ENST00000661800 LINC01643 +ENST00000670329 LINC01643 +ENST00000671554 LINC01643 +ENST00000657115 LINC01643 +ENST00000610215 Z99755.2 +ENST00000216185 TXN2 +ENST00000416967 TXN2 +ENST00000487725 TXN2 +ENST00000403313 TXN2 +ENST00000411915 TXN2 +ENST00000442538 TEX33 +ENST00000402860 TEX33 +ENST00000405091 TEX33 +ENST00000381821 TEX33 +ENST00000419128 Z82188.2 +ENST00000337843 C1QTNF6 +ENST00000397110 C1QTNF6 +ENST00000470655 C1QTNF6 +ENST00000493023 C1QTNF6 +ENST00000434784 C1QTNF6 +ENST00000467564 C1QTNF6 +ENST00000497071 C1QTNF6 +ENST00000609322 Z94160.2 +ENST00000323205 GCAT +ENST00000445195 GCAT +ENST00000415371 GCAT +ENST00000478203 GCAT +ENST00000248924 GCAT +ENST00000426858 GCAT +ENST00000451984 GCAT +ENST00000410099 AL031587.1 +ENST00000420172 AL020993.1 +ENST00000303592 KCNJ4 +ENST00000662373 Z97056.3 +ENST00000216024 DMC1 +ENST00000428462 DMC1 +ENST00000439567 DMC1 +ENST00000616615 DMC1 +ENST00000478820 DMC1 +ENST00000415483 DMC1 +ENST00000464842 DMC1 +ENST00000666731 AL021707.9 +ENST00000405510 SUN2 +ENST00000405018 SUN2 +ENST00000406622 SUN2 +ENST00000455125 SUN2 +ENST00000470642 SUN2 +ENST00000477262 SUN2 +ENST00000469086 SUN2 +ENST00000464202 SUN2 +ENST00000430185 SUN2 +ENST00000438058 SUN2 +ENST00000456894 SUN2 +ENST00000480307 SUN2 +ENST00000420859 SUN2 +ENST00000452294 SUN2 +ENST00000494273 SUN2 +ENST00000433561 SUN2 +ENST00000417332 SUN2 +ENST00000439339 SUN2 +ENST00000216068 DNAL4 +ENST00000486019 DNAL4 +ENST00000406199 DNAL4 +ENST00000475512 DNAL4 +ENST00000495988 APOBEC3A +ENST00000402255 APOBEC3A +ENST00000488758 APOBEC3A +ENST00000618553 APOBEC3A +ENST00000249116 APOBEC3A +ENST00000407298 APOBEC3B +ENST00000333467 APOBEC3B +ENST00000402182 APOBEC3B +ENST00000335760 APOBEC3B +ENST00000513758 APOBEC3B-AS1 +ENST00000381568 AL022318.4 +ENST00000491387 APOBEC3F +ENST00000381565 APOBEC3F +ENST00000308521 APOBEC3F +ENST00000476513 APOBEC3F +ENST00000404241 ATF4 +ENST00000674920 ATF4 +ENST00000679776 ATF4 +ENST00000675582 ATF4 +ENST00000337304 ATF4 +ENST00000676346 ATF4 +ENST00000396680 ATF4 +ENST00000680446 ATF4 +ENST00000674568 ATF4 +ENST00000680748 ATF4 +ENST00000674835 ATF4 +ENST00000676430 ATF4 +ENST00000498737 NDUFA6 +ENST00000617763 NDUFA6 +ENST00000470753 NDUFA6 +ENST00000602718 AL021878.2 +ENST00000609564 OGFRP1 +ENST00000332965 OGFRP1 +ENST00000446578 OGFRP1 +ENST00000415205 OGFRP1 +ENST00000420096 OGFRP1 +ENST00000428765 AL022316.1 +ENST00000439423 AL121672.1 +ENST00000417709 TTC38 +ENST00000381031 TTC38 +ENST00000475467 TTC38 +ENST00000421359 TTC38 +ENST00000629918 TTC38 +ENST00000422713 TTC38 +ENST00000451998 TTC38 +ENST00000262738 CELSR1 +ENST00000473624 CELSR1 +ENST00000674500 CELSR1 +ENST00000674159 CELSR1 +ENST00000674423 CELSR1 +ENST00000674341 CELSR1 +ENST00000468025 CELSR1 +ENST00000674379 CELSR1 +ENST00000674359 CELSR1 +ENST00000674312 CELSR1 +ENST00000674315 CELSR1 +ENST00000454637 CELSR1 +ENST00000497509 CELSR1 +ENST00000648313 AL008720.1 +ENST00000648629 Z72006.1 +ENST00000438393 BRD1 +ENST00000216267 BRD1 +ENST00000404034 BRD1 +ENST00000404760 BRD1 +ENST00000457780 BRD1 +ENST00000479985 BRD1 +ENST00000459821 BRD1 +ENST00000494833 BRD1 +ENST00000608025 AL022328.4 +ENST00000533930 ACR +ENST00000216139 ACR +ENST00000529621 ACR +ENST00000527761 ACR +ENST00000532913 AC002056.2 diff --git a/tests/fixtures/pca/protocol_example.pca_pheno.txt b/tests/fixtures/pca/protocol_example.pca_pheno.txt new file mode 100644 index 000000000..7d0288fb5 --- /dev/null +++ b/tests/fixtures/pca/protocol_example.pca_pheno.txt @@ -0,0 +1,61 @@ +FID IID msex age_death pmi study race +SAMPLE_001 SAMPLE_001 1 90.97 10.57 1 1 +SAMPLE_002 SAMPLE_002 1 80.24 7.87 0 1 +SAMPLE_003 SAMPLE_003 1 83.9 9.93 0 1 +SAMPLE_004 SAMPLE_004 1 74.1 2.91 0 1 +SAMPLE_005 SAMPLE_005 1 93.94 8.54 0 1 +SAMPLE_006 SAMPLE_006 0 89.95 2.63 0 1 +SAMPLE_007 SAMPLE_007 0 91.39 8.0 1 1 +SAMPLE_008 SAMPLE_008 1 78.22 10.42 0 1 +SAMPLE_009 SAMPLE_009 1 79.99 8.62 1 1 +SAMPLE_010 SAMPLE_010 1 77.2 7.51 0 1 +SAMPLE_011 SAMPLE_011 1 74.46 4.3 1 1 +SAMPLE_012 SAMPLE_012 0 67.11 9.66 1 1 +SAMPLE_013 SAMPLE_013 0 90.4 5.87 0 1 +SAMPLE_014 SAMPLE_014 0 71.41 11.27 0 1 +SAMPLE_015 SAMPLE_015 1 76.26 9.09 1 1 +SAMPLE_016 SAMPLE_016 0 81.99 3.98 1 1 +SAMPLE_017 SAMPLE_017 1 67.61 5.33 1 1 +SAMPLE_018 SAMPLE_018 0 69.04 9.07 0 1 +SAMPLE_019 SAMPLE_019 0 78.95 6.87 0 1 +SAMPLE_020 SAMPLE_020 1 80.27 11.85 0 1 +SAMPLE_021 SAMPLE_021 1 84.31 3.17 1 2 +SAMPLE_022 SAMPLE_022 0 65.01 10.64 1 2 +SAMPLE_023 SAMPLE_023 0 71.32 5.94 0 2 +SAMPLE_024 SAMPLE_024 0 94.68 4.13 1 2 +SAMPLE_025 SAMPLE_025 0 88.18 5.29 1 2 +SAMPLE_026 SAMPLE_026 1 67.2 2.9 0 2 +SAMPLE_027 SAMPLE_027 0 83.04 5.72 1 2 +SAMPLE_028 SAMPLE_028 0 93.77 6.84 0 2 +SAMPLE_029 SAMPLE_029 1 70.48 3.54 0 2 +SAMPLE_030 SAMPLE_030 0 86.76 3.58 0 2 +SAMPLE_031 SAMPLE_031 1 91.47 8.04 1 2 +SAMPLE_032 SAMPLE_032 0 68.12 2.39 1 2 +SAMPLE_033 SAMPLE_033 0 87.19 5.92 1 2 +SAMPLE_034 SAMPLE_034 1 73.8 3.75 0 2 +SAMPLE_035 SAMPLE_035 0 71.85 7.59 0 2 +SAMPLE_036 SAMPLE_036 1 71.37 11.15 0 2 +SAMPLE_037 SAMPLE_037 0 73.08 6.46 0 2 +SAMPLE_038 SAMPLE_038 0 70.29 5.69 0 2 +SAMPLE_039 SAMPLE_039 0 75.86 10.91 1 2 +SAMPLE_040 SAMPLE_040 0 82.7 11.24 1 2 +SAMPLE_041 SAMPLE_041 1 86.03 11.63 0 3 +SAMPLE_042 SAMPLE_042 0 79.47 9.3 1 3 +SAMPLE_043 SAMPLE_043 0 94.98 2.75 1 3 +SAMPLE_044 SAMPLE_044 0 92.01 9.37 0 3 +SAMPLE_045 SAMPLE_045 1 75.56 8.85 0 3 +SAMPLE_046 SAMPLE_046 1 93.33 2.3 1 3 +SAMPLE_047 SAMPLE_047 0 83.75 5.82 0 3 +SAMPLE_048 SAMPLE_048 0 67.41 8.39 1 3 +SAMPLE_049 SAMPLE_049 1 86.85 5.88 1 3 +SAMPLE_050 SAMPLE_050 1 78.88 7.41 0 3 +SAMPLE_051 SAMPLE_051 1 83.04 6.81 0 3 +SAMPLE_052 SAMPLE_052 0 79.92 8.15 1 3 +SAMPLE_053 SAMPLE_053 1 91.89 5.68 0 3 +SAMPLE_054 SAMPLE_054 0 80.55 9.54 1 3 +SAMPLE_055 SAMPLE_055 1 79.95 4.41 1 3 +SAMPLE_056 SAMPLE_056 1 70.96 6.31 0 3 +SAMPLE_057 SAMPLE_057 0 76.53 7.83 1 3 +SAMPLE_058 SAMPLE_058 0 69.09 6.96 0 3 +SAMPLE_059 SAMPLE_059 0 93.5 4.77 0 3 +SAMPLE_060 SAMPLE_060 0 78.52 4.75 0 3 diff --git a/tests/notebooks/data_preprocessing/phenotype/test_gene_annotation.py b/tests/notebooks/data_preprocessing/phenotype/test_gene_annotation.py index f072d5eef..33a53dc1d 100644 --- a/tests/notebooks/data_preprocessing/phenotype/test_gene_annotation.py +++ b/tests/notebooks/data_preprocessing/phenotype/test_gene_annotation.py @@ -91,15 +91,19 @@ def test_annotate_psichomics_isoforms(run_sos, repo_root, tmp_path): assert (out / "protocol_example.psichomics.phenotype.phenotype_group.txt").exists() -def test_annotate_coord_biomart(run_sos, repo_root, tmp_path): - """End-to-end against Ensembl biomaRt (requires network).""" - out = tmp_path / "out" - p = run_sos(repo_root / NB, "annotate_coord_biomart", - {**_base(repo_root, out), - "phenoFile": repo_root / FX / "protocol_example.rnaseq.gene_ID.tsv", - "ensembl_version": 115}, - cwd=repo_root, timeout=300) - assert p.returncode == 0, p.stdout + p.stderr - bed = out / "protocol_example.rnaseq.gene_ID.bed.gz" - assert bed.exists() and (out / "protocol_example.rnaseq.gene_ID.bed.gz.tbi").exists() - assert (out / "protocol_example.rnaseq.gene_ID.region_list.txt").exists() +# Commented out: this test hits the live Ensembl biomaRt web service +# (biomaRt::useEnsembl -> *.archive.ensembl.org), which times out / is +# unreliable from CI runners. Run it manually when validating the +# annotate_coord_biomart step against Ensembl. +# def test_annotate_coord_biomart(run_sos, repo_root, tmp_path): +# """End-to-end against Ensembl biomaRt (requires network).""" +# out = tmp_path / "out" +# p = run_sos(repo_root / NB, "annotate_coord_biomart", +# {**_base(repo_root, out), +# "phenoFile": repo_root / FX / "protocol_example.rnaseq.gene_ID.tsv", +# "ensembl_version": 115}, +# cwd=repo_root, timeout=300) +# assert p.returncode == 0, p.stdout + p.stderr +# bed = out / "protocol_example.rnaseq.gene_ID.bed.gz" +# assert bed.exists() and (out / "protocol_example.rnaseq.gene_ID.bed.gz.tbi").exists() +# assert (out / "protocol_example.rnaseq.gene_ID.region_list.txt").exists() diff --git a/tests/notebooks/molecular_phenotypes/QC/test_pseudobulk_preprocessing.py b/tests/notebooks/molecular_phenotypes/QC/test_pseudobulk_preprocessing.py index 11fd6c5d5..99ecba4b2 100644 --- a/tests/notebooks/molecular_phenotypes/QC/test_pseudobulk_preprocessing.py +++ b/tests/notebooks/molecular_phenotypes/QC/test_pseudobulk_preprocessing.py @@ -50,7 +50,7 @@ def test_pseudobulk_counts(run_r, repo_root, tmp_path): ["--step", "pseudobulk_counts", "--seurat-files", fix / "seurat_MIC.rds", "--celltype", "MIC", "--output-dir", tmp_path]) assert p.returncode == 0, p.stdout + p.stderr - got = gzip.open(tmp_path / "0_pseudobulk_counts/pseudobulk_counts_MIC.csv.gz", "rt").read() + got = gzip.open(tmp_path / "protocol_example.pseudobulk_counts_MIC.csv.gz", "rt").read() exp = gzip.open(fix / "expected_pseudobulk_counts_MIC.csv.gz", "rt").read() assert got == exp @@ -61,7 +61,7 @@ def test_sampleid_mapping(run_r, repo_root, tmp_path): ["--step", "sampleid_mapping", "--map-file", fix / "id_map.csv", "--meta-files", fix / "metadata_MIC.csv", "--output-dir", tmp_path]) assert p.returncode == 0, p.stdout + p.stderr - got = (tmp_path / "1_files_with_sampleid/metadata_MIC.csv").read_text() + got = (tmp_path / "metadata_MIC.csv").read_text() exp = (fix / "expected_metadata_MIC.csv").read_text() assert got == exp @@ -73,27 +73,26 @@ def test_pseudobulk_qc(run_r, repo_root, tmp_path): "--count-files", fix / "counts_MIC.csv.gz", "--tech-vars-file", fix / "tech_vars_MIC.csv", "--output-dir", tmp_path]) assert p.returncode == 0, p.stdout + p.stderr - d = tmp_path / "2_residuals/MIC" + d = tmp_path # filtered_raw_counts: version-independent -> byte exact - assert (d / "MIC_filtered_raw_counts.txt").read_text() == \ + assert (d / "protocol_example.MIC.filtered_raw_counts.txt").read_text() == \ (fix / "expected_MIC_filtered_raw_counts.txt").read_text() # residuals: voom-derived -> tight numeric (labels/header exact) - _assert_num_match((d / "MIC_residuals.txt").read_text(), + _assert_num_match((d / "protocol_example.MIC.residuals.txt").read_text(), (fix / "expected_MIC_residuals.txt").read_text(), label_cols=1) def test_phenotype_formatting(run_r, repo_root, tmp_path): fix = repo_root / FIX - # ct = basename(dirname(residual_file)) -> place the ATAC residuals under MIC/ - ct_dir = tmp_path / "MIC" - ct_dir.mkdir() - (ct_dir / "atac_MIC_residuals.txt").write_text((fix / "atac_MIC_residuals.txt").read_text()) + # worker derives ct from the residual filename: {name}.{ct}.residuals.txt + res = tmp_path / "protocol_example.MIC.residuals.txt" + res.write_text((fix / "atac_MIC_residuals.txt").read_text()) p = run_r(repo_root / WORKER, ["--step", "phenotype_formatting", - "--residual-files", ct_dir / "atac_MIC_residuals.txt", "--output-dir", tmp_path]) + "--residual-files", res, "--output-dir", tmp_path]) assert p.returncode == 0, p.stdout + p.stderr - out = tmp_path / "3_pheno_reformat/MIC_phenotype.bed.gz" - assert (tmp_path / "3_pheno_reformat/MIC_phenotype.bed.gz.tbi").exists() + out = tmp_path / "protocol_example.MIC.phenotype.bed.gz" + assert (tmp_path / "protocol_example.MIC.phenotype.bed.gz.tbi").exists() got = gzip.open(out, "rt").read() exp = gzip.open(fix / "expected_MIC_phenotype.bed.gz", "rt").read() assert got == exp diff --git a/tests/notebooks/molecular_phenotypes/test_snrnaseq_preprocessing.py b/tests/notebooks/molecular_phenotypes/test_snrnaseq_preprocessing.py index fd1d77ebc..7338c2e8f 100644 --- a/tests/notebooks/molecular_phenotypes/test_snrnaseq_preprocessing.py +++ b/tests/notebooks/molecular_phenotypes/test_snrnaseq_preprocessing.py @@ -93,5 +93,7 @@ def test_sctk_qc_via_sos(run_sos, repo_root, tmp_path): "numThreads": 2, "modular_script_dir": repo_root / MSD}) assert p.returncode == 0, p.stdout + p.stderr - assert (tmp_path / "SCTK_results" / "filtered_seuratobj.rds").exists() - assert (tmp_path / "QC_table" / "SCTK_QC_table.csv").exists() + # SoS runs with the default global --name = protocol_example.snrnaseq, so + # the worker prefixes its outputs with that dataset tag. + assert (tmp_path / "SCTK_results" / "protocol_example.snrnaseq.filtered_seuratobj.rds").exists() + assert (tmp_path / "QC_table" / "protocol_example.snrnaseq.SCTK_QC_table.csv").exists() diff --git a/website/_toc.yml b/website/_toc.yml index 7d0afe75b..ee19ca87a 100644 --- a/website/_toc.yml +++ b/website/_toc.yml @@ -24,6 +24,8 @@ parts: - file: RNA_calling.ipynb - file: bulk_expression_QC.ipynb - file: bulk_expression_normalization.ipynb + - file: single_cell.ipynb + sections: - file: snRNAseq_preprocessing.ipynb - file: pseudobulk_preprocessing.ipynb - file: methylation.ipynb @@ -64,8 +66,9 @@ parts: - file: qtl_association_postprocessing.ipynb - caption: Multivariate Mixture Model chapters: - - file: multivariate_mixture_vignette.ipynb + - file: MASH.ipynb sections: + - file: multivariate_mixture_vignette.ipynb - file: mash_preprocessing.ipynb - file: mixture_prior.ipynb - file: mash_fit.ipynb @@ -84,15 +87,20 @@ parts: - file: mnm_postprocessing.ipynb - caption: GWAS Integration chapters: - - file: SuSiE_enloc.ipynb - - file: twas_ctwas.ipynb - - file: colocboost.ipynb + - file: gwas_integration.ipynb + sections: + - file: SuSiE_enloc.ipynb + - file: twas_ctwas.ipynb + - file: intact.ipynb + - file: colocboost.ipynb - caption: Enrichment and Validation chapters: - - file: eoo_enrichment.ipynb - - file: gsea.ipynb - - file: gregor.ipynb - - file: sldsc_enrichment.ipynb + - file: enrichment_validation.ipynb + sections: + - file: eoo_enrichment.ipynb + - file: gsea.ipynb + - file: gregor.ipynb + - file: sldsc_enrichment.ipynb - caption: xQTL Modifier Score chapters: - file: ems_training.ipynb