Reference Data Standardization#

Downloads and standardises the genome, annotation and variant reference files that the rest of the protocol reads.

Overview#

Every study that uses this protocol should start from the same reference files: the same genome build, the same gene annotation, the same variant lists. When those differ between steps or between cohorts, the failures are quiet ones - coordinates that shift by a base, genes that exist in one annotation and not the other, meta-analyses that silently drop variants.

This notebook downloads and standardises that reference set once, so the rest of the protocol reads from a consistent source.

When to run it. Run this module once, before downstream workflows that require a reference genome, gene annotation, transcript annotation, or aligner index.

This module follows the TOPMed workflow from Broad 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. The PDF document compiled by Data Standardization Working Group is on Synapse as well as on ADSP Dashboard. It contains the reference data to use for the project.

Notes on the reference files#

Why the GTF is modified. Three reasons. RSEM requires the GTF to use the same chromosome naming as the FASTA (a chr prefix); for STAR this could be handled with --sjdbGTFchrPrefix "chr", but RSEM needs it in the file. The GTEx gene-model collapsing script collapse_annotation.py expects transcript_type rather than transcript_biotype, so that attribute is renamed here – it could instead be patched in collapse_annotation.py when building the container, but since the GTF is already being customised for the chr prefix, this is folded in. ERCC records are appended at the same time. The first two could be dropped if the RSEM requirement goes away.

The collapsed gene model. Gene-level expression and eQTLs in GTEx are computed on a collapsed gene model – all isoforms of a gene combined into one transcript – under three rules: transcripts annotated retained_intron or read_through are excluded, and transcripts overlapping annotated read-through transcripts may be blacklisted (blacklists exist for GENCODE v19, v24 and v25; none for v26); the union of each gene’s exon intervals is taken; and intervals overlapping between genes are excluded from all of them. That last rule mainly removes genes annotated on both strands, which cannot be quantified unambiguously from unstranded RNA-seq – for a stranded protocol it can be skipped with --collapse_only. Rules quoted from the GTEx gene_model documentation; see also the GTEx Portal.

STAR and RSEM indices. Both take the reference fasta and a gtf that must be unzipped and must be the pre-collapsing GTF. sjdbOverhang sets how much genomic sequence around each annotated junction goes into the splice-junction database; it should ideally be the read length minus one. The value 100 used here follows the TOPMed pipeline (discussion). STAR needs at least 40 GB of memory.

When to run it. First, before any data processing, and again only when you change genome build or annotation release.

Input#

The four download_* workflows take no options – they fetch the reference files from their public sources. Everything else consumes files those downloads produce, or that this module derives:

  • --hg-reference (required by hg_reference_1, hg_gtf_1, gene_annotation): the reference genome FASTA, e.g. input/reference_data/GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta.

  • --hg-gtf (required by hg_gtf_1, gene_annotation, psi_hg38_annotation): the gene model GTF.

  • --gff3-file (required by gff3_to_gtf): a GFF3 to convert to GTF.

  • --ercc-reference (required by hg_reference_2): the ERCC spike-in FASTA, merged into the genome.

  • --ercc-gtf (required by ercc_gtf): the ERCC annotation to patch and append.

  • --stranded / --no-stranded (required by hg_gtf_2): whether the library is stranded.

  • --hgrc-db (required by psi_hg38_annotation): reference database for the psichomics annotation. Undocumented: the code does not say what this file is or where to obtain it.

  • --TAD-list, --region-list, --TAD-genotype (all required by Tad_annotateion): the TAD definitions, the regions to annotate and the genotypes to annotate them against.

  • --genoFile (used by download_dbsnp): the dbSNP VCF to index, e.g. output/reference_data/00-All.vcf.gz.

  • --cwd (default output) and --modular-script-dir (default code/script).

Cluster resources: --numThreads (default 8), --job-size (default 1), --walltime (default 5h), --mem (default 16G), --container.

Reference files shipped with the protocol, under input/reference_data/:

  • GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy.fasta – the genome before ERCC merge.

  • GRCh38_full_analysis_set_plus_decoy_hla.noALT_noHLA_noDecoy_ERCC.fasta (+ .fai) – after merge.

  • Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf – the collapsed gene model.

  • 00-All.add_chr.variants.gz (+ .tbi) – chr-renamed dbSNP variants.

  • look_up_gene_id.tsv, STAR_Index/, TAD/ – gene-ID map, STAR index and TAD definitions.

Output#

  • <genome>.fasta / .fa (+ .fai) – from hg_reference_1..3: the reference genome after HLA/ALT and decoy removal, merged with the ERCC spike-in reference and indexed.

  • <genome>.dict – the sequence dictionary Picard tools require alongside the FASTA.

  • <gtf>.collapse_only.gene.gtf – from gene_annotation: the collapsed gene model, one record per gene, used wherever a gene-level annotation is needed.

  • ERCC92.gtf and ERCC92.genes.patched.gtf – from ercc_gtf: the ERCC annotation, and the patched form appended to the gene model.

  • <name>.ref.flat – from RefFlat_generation: the RefFlat annotation Picard uses for RNA metrics.

  • 00-All.vcf.gz (+ .tbi) – from download_dbsnp: the dbSNP VCF, bgzipped and tabix-indexed.

  • RSEM_Index/rsem_reference.grp and rsem_reference.n2g.idx.fa – from RSEM_index.

  • <gtf>_SE_strict.ioe – from SUPPA_annotation_1: the SUPPA event definitions.

  • <gtf>.SUPPA_annotation.rds and psichomics_hg38_annotation.rds – from SUPPA_annotation_2 and psi_hg38_annotation.

  • look_up_gene_id.txt – the gene-ID lookup table written alongside the gene annotation.

  • STAR_Index/ and the RSEM index – from STAR_index and RSEM_index.

  • the SUPPA and TAD annotations – from SUPPA_annotation_1..2 and psi_hg38_annotation.

All paths are relative to --cwd.

output/reference_data/ERCC92.gtf:

ERCC-00002	ERCC	exon	1	1061	0.000000	+	.	gene_id "ERCC-00002"; transcript_id "DQ459430";
ERCC-00003	ERCC	exon	1	1023	0.000000	+	.	gene_id "ERCC-00003"; transcript_id "DQ516784";

output/reference_data/ERCC92.ref.flat:

	DQ459430	ERCC-00002	+	0	1061	1061	1061	1	0,	1061,
	DQ516784	ERCC-00003	+	0	1023	1023	1023	1	0,	1023,

Only the ERCC products have committed example output. output/reference_data/ holds ERCC92.gtf, ERCC92.genes.patched.gtf and ERCC92.ref.flat; the genome merge, collapsed gene model, STAR and RSEM indices and the SUPPA/TAD annotations were not run here, so no dump is shown for them.

Minimal Working Example#

Preparing the reference data#

These are not one sequential pipeline, so the blocks below are entry points rather than numbered steps. The four downloads are independent of each other and of everything else. Three do have to run in order – format the reference genome, then process the transcript and gene model, then assemble the gene annotation – because each reads what the one before it wrote. The remaining generators (STAR, RSEM, RefFlat, SUPPA, rsID and TAD) each read the formatted references and are independent of one another, so run only the ones the analysis needs.

Download the ERCC spike-in reference#

Fetches the ERCC spike-in sequences and annotation.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb download_ercc_reference --cwd output/reference_data

Download the gene annotation#

Fetches the Ensembl gene annotation GTF and its compressed form.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb download_gene_annotation --cwd output/reference_data

Download the reference genome#

Fetches the unmodified human reference genome FASTA.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb download_hg_reference --cwd output/reference_data

Download dbSNP variants#

Fetches the dbSNP call set and tabix-indexes it, writing 00-All.vcf.gz and its .tbi.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb download_dbsnp \ --cwd output/reference_data

Format reference genome#

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.

Timing: TBD (on toy dataset)

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 

Transcript and gene model reference processing#

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.

Timing: TBD (on toy dataset)

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 

Gene annotation#

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.

Timing: TBD (on toy dataset)

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 

Generate STAR index#

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.

Timing: TBD (on toy dataset)

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

Generate RSEM index#

This step generates the indexing file used for RSEM. The index needs to be generated only once.

Timing: TBD (on toy dataset)

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

Generate RefFlat annotation#

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).

Timing: TBD (on toy dataset)

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

Generate SUPPA annotation#

The custom alternative-splicing annotation is generated for psichomics, based on this tutorial; the procedure for generating the local alternative-splicing SUPPA output is documented on the SUPPA GitHub page. 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.

Timing: TBD (on toy dataset)

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 

Extract rsIDs for known variants (handled elsewhere)#

Annotating the dbSNP call set with rsIDs is done by VCF_QC.ipynb (dbsnp_annotate), not by this module. Run it there against output/reference_data/00-All.vcf.gz.

Convert GFF3 to GTF#

gff3_to_gtf converts a GFF3 annotation to GTF. The protocol ships no example GFF3, so supply your own.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb gff3_to_gtf \
    --gff3-file <path>/annotation.gff3 \
    --cwd output/reference_data

Patch the ERCC annotation#

ercc_gtf patches the downloaded ERCC GTF so it can be appended to the gene model.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb ercc_gtf \
    --ercc-gtf output/reference_data/ERCC92.gtf \
    --cwd output/reference_data

Generate psichomics annotation#

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.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb psi_hg38_annotation \
    --hg-gtf input/reference_data/Homo_sapiens.GRCh38.103.chr.reformatted.collapse_only.gene.ERCC.gtf \
    --hgrc-db <path>/hgrc_db \
    --cwd output/reference_data

TAD annotation#

Tad_annotateion annotates TADs. The protocol ships input/reference_data/TAD/ but no example region list or TAD genotype.

Timing: TBD (on toy dataset)

sos run pipeline/reference_data_preparation.ipynb Tad_annotateion \
    --TAD-list input/reference_data/TAD/<tad_list> \
    --region-list <path>/region_list.txt \
    --TAD-genotype <path>/tad_genotype \
    --cwd output/reference_data

Command Interface#

sos run pipeline/reference_data_preparation.ipynb -h
usage: sos run pipeline/reference_data_preparation.ipynb
               [workflow_name | -t targets] [options] [workflow_options]
  workflow_name:        Single or combined workflows defined in this script
  targets:              One or more targets to generate
  options:              Single-hyphen sos parameters (see "sos run -h" for details)
  workflow_options:     Double-hyphen workflow-specific parameters

Workflows:
  download_hg_reference
  download_gene_annotation
  download_ercc_reference
  download_dbsnp
  gff3_to_gtf
  hg_reference
  hg_gtf
  ercc_gtf
  gene_annotation
  STAR_index
  RSEM_index
  RefFlat_generation
  SUPPA_annotation
  psi_hg38_annotation
  Tad_annotateion

Global Workflow Options:
  --modular-script-dir code/script (as path)
  --cwd output (as path)
                        The output directory for generated files.
  --job-size 1 (as int)
                        For cluster jobs, number commands to run per job
  --walltime 5h
                        Wall clock time expected
  --mem 16G
                        Memory expected
  --numThreads 8 (as int)
                        Number of threads
  --container ''
                        Software container option

Sections
  download_hg_reference:
  download_gene_annotation:
  download_ercc_reference:
  download_dbsnp:
  gff3_to_gtf:
    Workflow Options:
      --gff3-file VAL (as path, required)
  hg_reference_1:
    Workflow Options:
      --hg-reference VAL (as path, required)
                        Path to HG reference file
  hg_reference_2:
    Workflow Options:
      --ercc-reference VAL (as path, required)
  hg_reference_3:
  hg_gtf_1:
    Workflow Options:
      --hg-reference VAL (as path, required)
      --hg-gtf VAL (as path, required)
  hg_gtf_2:
    Workflow Options:
      --[no-]stranded (required)
  ercc_gtf:
    Workflow Options:
      --ercc-gtf VAL (as path, required)
  gene_annotation:
  STAR_index:
    Workflow Options:
      --hg-reference VAL (as path, required)
  RSEM_index:
    Workflow Options:
      --hg-gtf VAL (as path, required)
      --hg-reference VAL (as path, required)
  RefFlat_generation:
    Workflow Options:
      --hg-gtf VAL (as path, required)
  SUPPA_annotation_1:
    Workflow Options:
      --hg-gtf VAL (as path, required)
  SUPPA_annotation_2:
    Workflow Options:
      --hg-gtf VAL (as path, required)
  psi_hg38_annotation:
    Workflow Options:
      --hg-gtf VAL (as path, required)
      --hgrc-db VAL (as path, required)
                        FIXME: Please document what this file is and where do we
                        get it @xuanhe.
  Tad_annotateion:
    Workflow Options:
      --TAD-list VAL (as path, required)
                        The tad file downloads from
      --region-list VAL (as path, required)
      --TAD-genotype VAL (as path, required)

Workflow implementation#

The SoS step definitions below implement the commands described above.

[global]
parameter: modular_script_dir = path('code/script')  # override with --modular-script-dir
# The output directory for generated files.
parameter: cwd = path("output")
# For cluster jobs, number commands to run per job
parameter: job_size = 1
# Wall clock time expected
parameter: walltime = "5h"
# Memory expected
parameter: mem = "16G"
# Number of threads
parameter: numThreads = 8
# Software container option
parameter: container = ""
cwd = path(f'{cwd:a}')
from sos.utils import expand_size
[download_hg_reference]
output: f"{cwd:a}/GRCh38_full_analysis_set_plus_decoy_hla.fa"
download: dest_dir = cwd
    ftp://ftp.1000genomes.ebi.ac.uk/vol1/ftp/technical/reference/GRCh38_reference_genome/GRCh38_full_analysis_set_plus_decoy_hla.fa
[download_gene_annotation]
output: f"{cwd:a}/Homo_sapiens.GRCh38.103.chr.gtf"
download: dest_dir = cwd, decompress=True
    http://ftp.ensembl.org/pub/release-103/gtf/homo_sapiens/Homo_sapiens.GRCh38.103.chr.gtf.gz
[download_ercc_reference]
output: f"{cwd:a}/ERCC92.gtf", f"{cwd:a}/ERCC92.fa"
download: dest_dir = cwd, decompress=True
    https://assets.thermofisher.com/TFS-Assets/LSG/manuals/ERCC92.zip
[download_dbsnp]
output: f"{cwd:a}/00-All.vcf.gz", f"{cwd:a}/00-All.vcf.gz.tbi"
download: dest_dir = cwd
    ftp://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606/VCF/00-All.vcf.gz
    ftp://ftp.ncbi.nlm.nih.gov/snp/organisms/human_9606/VCF/00-All.vcf.gz.tbi
[gff3_to_gtf]
parameter: gff3_file = path
input: gff3_file
output: f'{cwd}/{_input:bn}.gtf'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: container=container, expand= "${ }", stderr = f'{_output:n}.stderr', stdout = f'{_output:n}.stdout'
        Rscript ${modular_script_dir}/reference_data/gff3_to_gtf.R \
            --input ${_input} \
            --output ${_output}
[hg_reference_1 (HLA ALT Decoy removal)]
# Path to HG reference file
parameter: hg_reference = path
input: hg_reference
output:  f'{cwd}/{_input:bn}.noALT_noHLA_noDecoy.fasta'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout', container = container
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step hg_reference_1 \
        --input ${_input} \
        --output ${_output}
[hg_reference_2 (merge with ERCC reference)]
parameter: ercc_reference = path
output: f'{cwd}/{_input:bn}_ERCC.fasta'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output[0]}.stderr', stdout = f'{_output}.stdout', container = container
    sed 's/ERCC-/ERCC_/g' ${ercc_reference} > ${ercc_reference:n}.patched.fa
    cat ${_input} ${ercc_reference:n}.patched.fa > ${_output}
[hg_reference_3 (index the fasta file)]
output: f'{cwd}/{_input:bn}.dict'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout', container = container
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step faidx \
        --input ${_input}
    picard CreateSequenceDictionary \
        R=${_input} \
        O=${_output}
[hg_gtf_1 (add chr prefix to gtf file)]
parameter: hg_reference = path
parameter: hg_gtf = path
input: hg_reference, hg_gtf
output: f'{cwd}/{_input[1]:bn}.reformatted.gtf'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout', container = container
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step hg_gtf_1 \
        --hg-reference ${_input[0]} \
        --hg-gtf ${_input[1]} \
        --output ${_output}
[hg_gtf_2 (collapsed gene model)]
parameter: stranded = bool
output: f'{_input:n}{".collapse_only" if stranded else ""}.gene.gtf'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout', container = container
    Rscript ${modular_script_dir}/reference_data/collapse_annotation.R \
        ${"--collapse-only" if stranded else ""} \
        --input ${_input} \
        --output ${_output}
[ercc_gtf (Preprocess ERCC gtf file)]
parameter: ercc_gtf = path
input: ercc_gtf
output: f'{cwd}/{_input:bn}.genes.patched.gtf'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout', container = container
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step ercc_gtf \
        --input ${_input} \
        --output ${_output}
[gene_annotation]
input: output_from("hg_gtf_1"), output_from("hg_gtf_2"), output_from("ercc_gtf")
output: f'{cwd}/{_input[0]:bn}.ERCC.gtf', f'{cwd}/{_input[1]:bn}.ERCC.gtf'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime,  mem = mem, tags = f'{step_name}_{_output:bn}'
bash: expand = "${ }", stderr = f'{_output[0]}.stderr', stdout = f'{_output[0]}.stdout', container = container
    cat ${_input[0]} ${_input[2]} > ${_output[0]}
    cat ${_input[1]} ${_input[2]} > ${_output[1]}
[STAR_index]
parameter: hg_reference = path
# Specifies the length of the genomic sequence around the annotated junction to be used in constructing the splice junctions database. Ideally, this length should be equal to the ReadLength-1, where ReadLength is the length of the reads.
# Default choice follows from TOPMed pipeline recommendation.
if expand_size(mem) < expand_size('40G'):
    print("Insufficent memory for STAR, changing to 40G")
    star_mem = '40G'
else:
    star_mem = mem
input: hg_reference
output: f"{cwd}/STAR_Index/chrName.txt", 
        f"{cwd}/STAR_Index/SAindex", f"{cwd}/STAR_Index/SA", f"{cwd}/STAR_Index/genomeParameters.txt", 
        f"{cwd}/STAR_Index/chrStart.txt",
        f"{cwd}/STAR_Index/chrLength.txt", 
        f"{cwd}/STAR_Index/Genome", f"{cwd}/STAR_Index/chrNameLength.txt"
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bd}', cores = numThreads
bash: container=container, expand= "${ }", stderr = f'{_output[1]:n}.stderr', stdout = f'{_output[1]:n}.stdout'
    STAR --runMode genomeGenerate \
         --genomeDir ${_output[0]:d} \
         --genomeFastaFiles ${_input[0]} \
         --runThreadN ${numThreads}
[RSEM_index]
parameter: hg_gtf = path
parameter: hg_reference = path
input: hg_reference, hg_gtf
output: f"{cwd}/RSEM_Index/rsem_reference.n2g.idx.fa", f"{cwd}/RSEM_Index/rsem_reference.grp", 
        f"{cwd}/RSEM_Index/rsem_reference.idx.fa", f"{cwd}/RSEM_Index/rsem_reference.ti", 
        f"{cwd}/RSEM_Index/rsem_reference.chrlist", f"{cwd}/RSEM_Index/rsem_reference.seq", 
        f"{cwd}/RSEM_Index/rsem_reference.transcripts.fa"
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bd}'
bash: container=container, expand= "${ }", stderr = f'{_output[1]:n}.stderr', stdout = f'{_output[1]:n}.stdout'
    rsem-prepare-reference \
            ${_input[0]} \
            ${_output[1]:n} \
            --gtf ${_input[1]} \
            --num-threads ${numThreads}
[RefFlat_generation]
parameter: hg_gtf = path
input: hg_gtf
output: f'{_input:n}.ref.flat'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output[0]:bd}'
bash: container=container, expand= "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'
    gtfToGenePred ${_input}  ${_output}.tmp -genePredExt -geneNameAsName2
    awk -F'\t' -v OFS="\t" '{$1=$12 OFS $1;}7' ${_output}.tmp | cut -f 1-11 > ${_output}
    rm ${_output}.tmp
[SUPPA_annotation_1]
parameter: hg_gtf = path
input: hg_gtf
output: f'{cwd}/hg38.{_input:bn}_SE_strict.ioe' # The stderr file must not shared the same start with the output file
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}'
bash: container=container, expand= "${ }", stderr = f'{cwd}/{_input:bn}.stderr', stdout = f'{cwd}/{_input:bn}.stdout'
    suppa generateEvents -i ${_input} -o ${cwd}/hg38.${_input:bn} -f ioe -e SE SS MX RI FL
[SUPPA_annotation_2]
parameter: hg_gtf = path
output: f'{cwd}/{hg_gtf:bn}.SUPPA_annotation.rds'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}'
bash: container=container, expand= "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step suppa_annot \
        --ioe-dir ${_input:d} \
        --genome hg38 \
        --output ${_output}
[psi_hg38_annotation]
parameter: hg_gtf = path
# FIXME: Please document what this file is and where do we get it @xuanhe.
parameter: hgrc_db = path
input: hg_gtf, hgrc_db
output: f'{cwd}/psichomics_hg38_annotation.rds'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}'
bash: container=container, expand= "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'
    Rscript ${modular_script_dir}/reference_data/psichomics_hg38_annotation.R \
        --hg-gtf ${_input[0]} \
        --hgnc-db ${_input[1]} \
        --output ${_output}
[Tad_annotateion]
## The tad file downloads from
parameter: TAD_list = path
parameter: region_list = path
parameter: TAD_genotype = path
input: TAD_list, region_list
output:f'{cwd:a}/{region_list:bn}.annotation'
task: trunk_workers = 1, trunk_size = job_size, walltime = walltime, mem = mem, tags = f'{step_name}_{_output:bn}'
bash: container=container, expand= "${ }", stderr = f'{_output}.stderr', stdout = f'{_output}.stdout'
    Rscript ${modular_script_dir}/reference_data/reference_data_preparation.R \
        --step tad_annotate \
        --tad-list ${_input[0]} \
        --region-list ${_input[1]} \
        --tad-genotype ${TAD_genotype} \
        --output ${_output}