Skip to content

Quickstart

detk implements the common operations when working with count matrices from high-throughput sequencing experiments. The following diagram illustrates a simple RNA-seq workflow downstream of quantification:

simple pipeline

This workflow performs the following, all without any custom code:

  1. Takes the output from read counting (e.g. htseq-count) or expression estimation software (e.g. salmon or kallisto) and combines them into a single counts matrix with detk-util gather
  2. Calculates statistics on the zero-ness of genes to guide feature filtering with detk-stats rowzero
  3. Keeps the rows with more than half of their counts nonzero with detk-filter
  4. Normalizes the filtered matrix with the DESeq2 procedure via detk-norm deseq2
  5. Computes principal components on the normalized matrix to identify outlier samples with detk-stats pca
  6. Removes a hypothetical outlier sample with csvcut from csvkit
  7. Runs DESeq2 differential expression with detk-de deseq2
  8. Computes pre-ranked GSEA on the DE statistics with detk-enrich fgsea

On the command line, the core of that workflow is below, for a counts matrix raw_counts.csv, a column data file sample_info.csv whose cond column says which samples are control and which treated, and the gene sets of msigdb_c2cp.gmt. The DESeq2 result names each column by its model term, so the treated-versus-control log fold change, the statistic GSEA ranks by, is cond__treated__log2FoldChange:

detk-stats rowzero -o raw_counts_rowzero_stats.csv raw_counts.csv
detk-filter "nonzero(all) > 0.5" -o raw_counts_filtered.csv raw_counts.csv
detk-norm deseq2 -o norm_counts_filtered.csv raw_counts_filtered.csv
detk-stats pca -o norm_counts_filtered_pca.csv norm_counts_filtered.csv
detk-de deseq2 -o deseq2_results.csv "counts ~ cond[control]" raw_counts_filtered.csv sample_info.csv
detk-enrich fgsea -o gsea_results.csv -i gene -c cond__treated__log2FoldChange msigdb_c2cp.gmt deseq2_results.csv
detk-report generate

detk-de deseq2 does not give the same padj as a default DESeq2 vignette run (DESeq(dds) then results(dds)). It reports the Wald test of every coefficient in the model, and its padj is the Benjamini-Hochberg adjustment over all genes: no independent filtering is performed, and there is no Cook's distance cutoff, so no p-value is set to NA as an outlier. The detk-de deseq2 page states the results() settings this matches and the other ways it differs from the default analysis.

The final command renders every step's recorded JSON into a single self-contained HTML report.

Using a workflow manager

detk tools are plain command-line filters, which makes them trivial to embed in whichever workflow manager you already use. The same workflow in Snakemake:

from glob import glob

rule all:
    input:
        'detk_report/detk_report.html',
        'msigdb_c2cp_gsea_results.csv'

rule gather_counts:
    input: glob('sample_*__salmon_counts/quant.sf')
    output: 'raw_counts.csv'
    shell:
        '''
        detk-util gather --name-from="([^/]+)__salmon_counts/" \
            -o {output} {input}
        '''

rule raw_rowzero:
    input: 'raw_counts.csv'
    output: 'raw_counts_rowzero_stats.csv'
    shell:
        'detk-stats rowzero -o {output} {input}'

rule filter_raw:
    input: 'raw_counts.csv'
    output: 'raw_counts_filtered.csv'
    shell:
        'detk-filter "nonzero(all) > 0.5" -o {output} {input}'

rule deseq2_norm:
    input: 'raw_counts_filtered.csv'
    output: 'norm_counts_filtered.csv'
    shell:
        'detk-norm deseq2 -o {output} {input}'

rule pca:
    input: 'norm_counts_filtered.csv'
    output: 'norm_counts_filtered_pca.csv'
    shell:
        'detk-stats pca -o {output} {input}'

rule de:
    input:
        counts='raw_counts_filtered.csv',
        covs='sample_info.csv'
    output: 'deseq2_results.csv'
    shell:
        'detk-de deseq2 -o {output} "counts ~ cond[control]" {input.counts} {input.covs}'

rule gsea:
    input:
        de='deseq2_results.csv',
        gmt='msigdb_c2cp.gmt'
    output: 'msigdb_c2cp_gsea_results.csv'
    shell:
        'detk-enrich fgsea -o {output} -i gene -c cond__treated__log2FoldChange {input.gmt} {input.de}'

rule generate_detk_report:
    input:
        rules.raw_rowzero.output,
        rules.pca.output,
        rules.de.output
    output: 'detk_report/detk_report.html'
    shell:
        'detk-report generate'

Run with snakemake --cores 1. A Nextflow process wrapping any of these commands looks the same: detk needs nothing from the workflow manager beyond a shell.