name: rsem_prepare_reference
namespace: rsem
description: | 
  RSEM is a software package for estimating gene and isoform expression levels from RNA-Seq data. This component prepares transcript references for RSEM.
keywords: ["Transcriptome", "Index"]
links:
  homepage: http://deweylab.github.io/RSEM
  documentation: https://deweylab.github.io/RSEM/rsem-prepare-reference.html
  repository: https://github.com/deweylab/RSEM
references: 
  doi: 10.1186/1471-2105-12-323
license: GPL-3.0 
requirements:
  commands: [ rsem-prepare-reference ]
authors:
  - __merge__: /src/_authors/sai_nirmayi_yasa.yaml
    roles: [ author, maintainer ]

argument_groups:
  - name: Inputs
    arguments:
      - name: --reference_fasta_files
        type: file
        description: | 
          Semi-colon separated list of Multi-FASTA formatted files OR a directory name. If a directory name is specified, RSEM will read all files with suffix ".fa" or ".fasta" in this directory. The files should contain either the sequences of transcripts or an entire genome, depending on whether the '--gtf' option is used.
        required: true
        multiple: true
        example: read1.fasta
      - name: --reference_name
        type: string
        description: | 
          The name of the reference used. RSEM will generate several reference-related files that are prefixed by this name. This name can contain path information (e.g. '/ref/mm9').
        required: true
        example: /ref/mm9 
  
  - name: Outputs
    arguments:
      - name: --output
        type: file
        description: Directory containing reference files generated by RSEM. 
        required: true
        direction: output

  - name: Other options
    arguments: 
      - name: --gtf
        type: file
        description: Assume that 'reference_fasta_files' contains the sequence of a genome, and extract transcript reference sequences using the gene annotations specified in the GTF file. If this and '--gff3' options are not provided, RSEM will assume 'reference_fasta_files' contains the reference transcripts. In this case, RSEM assumes that name of each sequence in the Multi-FASTA files is its transcript_id.
        example: annotations.gtf
      - name: --gff3
        type: file
        description: GFF3 annotation file. Converted to GTF format with the file name 'reference_name.gtf'. Please make sure that 'reference_name.gtf' does not exist. 
        example: annotations.gff
      - name: --gff3_rna_patterns
        type: string
        description: List of transcript categories (separated by semi-colon). Only transcripts that match the string will be extracted.
        multiple: true
        example: mRNA;rRNA
      - name: --gff3_genes_as_transcripts
        type: boolean_true
        description: This option is designed for untypical organisms, such as viruses, whose GFF3 files only contain genes. RSEM will assume each gene as a unique transcript when it converts the GFF3 file into GTF format.
      - name: --trusted_sources
        type: string
        description: List of trusted sources (separated by semi-colon). Only transcripts coming from these sources will be extracted. If this option is off, all sources are accepted.
        multiple: true
        example: ENSEMBL;HAVANA
      - name: --transcript_to_gene_map
        type: file
        description: | 
          Use information from this file to map from transcript (isoform) ids to gene ids. Each line of this file should be of the form: 
            gene_id transcript_id
          with the two fields separated by a tab character.
          If you are using a GTF file for the "UCSC Genes" gene set from the UCSC Genome Browser, then the "knownIsoforms.txt" file (obtained from the "Downloads" section of the UCSC Genome Browser site) is of this format. 
          If this option is off, then the mapping of isoforms to genes depends on whether the '--gtf' option is specified. If '--gtf' is specified, then RSEM uses the "gene_id" and "transcript_id" attributes in the GTF file. Otherwise, RSEM assumes that each sequence in the reference sequence files is a separate gene.
        example: isoforms.txt
      - name: --allele_to_gene_map 
        type: file
        description: |
          Use information from <file> to provide gene_id and transcript_id information for each allele-specific transcript. Each line of <file> should be of the form:
            gene_id transcript_id allele_id
          with the fields separated by a tab character.
          This option is designed for quantifying allele-specific expression. It is only valid if '--gtf' option is not specified. allele_id should be the sequence names presented in the Multi-FASTA-formatted files.
      - name: --polyA
        type: boolean_true
        description: Add poly(A) tails to the end of all reference isoforms. The length of poly(A) tail added is specified by '--polyA-length' option. STAR aligner users may not want to use this option. 
      - name: --polyA_length 
        type: integer
        description: The length of the poly(A) tails to be added. 
        example: 125
      - name: --no_polyA_subset 
        type: file
        description: Only meaningful if '--polyA' is specified. Do not add poly(A) tails to those transcripts listed in this file containing a list of transcript_ids.
        example: transcript_ids.txt
      - name: --bowtie
        type: boolean_true
        description: Build Bowtie indices. 
      - name: --bowtie2
        type: boolean_true
        description: Build Bowtie 2 indices.
      - name: --star
        type: boolean_true
        description: Build STAR indices.
      - name: --star_sjdboverhang
        type: integer
        description: Length of the genomic sequence around annotated junction. It is only used for STAR to build splice junctions database and not needed for Bowtie or Bowtie2. It will be passed as the --sjdbOverhang option to STAR. According to STAR's manual, its ideal value is max(ReadLength)-1, e.g. for 2x101 paired-end reads, the ideal value is 101-1=100. In most cases, the default value of 100 will work as well as the ideal value. (Default is 100)
        example: 100
      - name: --hisat2_hca
        type: boolean_true
        description: Build HISAT2 indices on the transcriptome according to Human Cell Atlas (HCA) SMART-Seq2 pipeline.
      - name: --quiet
        alternatives: -q
        type: boolean_true
        description: Suppress the output of logging information. 
  
  - name: Prior-enhanced RSEM options
    arguments: 
      - name: --prep_pRSEM
        type: boolean_true
        description: A Boolean indicating whether to prepare reference files for pRSEM, including building Bowtie indices for a genome and selecting training set isoforms. The index files will be used for aligning ChIP-seq reads in prior-enhanced RSEM and the training set isoforms will be used for learning prior. A path to Bowtie executables and a mappability file in bigWig format are required when this option is on. Currently, Bowtie2 is not supported for prior-enhanced RSEM. 
      - name: --mappability_bigwig_file 
        type: file
        description: Full path to a whole-genome mappability file in bigWig format. This file is required for running prior-enhanced RSEM. It is used for selecting a training set of isoforms for prior-learning. This file can be either downloaded from UCSC Genome Browser or generated by GEM (Derrien et al., 2012, PLoS One). 

resources:
  - type: bash_script
    path: script.sh

test_resources:
  - type: bash_script
    path: test.sh
    
engines:
- type: docker
  image: ubuntu:22.04
  setup:
    - type: apt
      packages: 
        - build-essential 
        - gcc 
        - g++ 
        - make 
        - wget 
        - zlib1g-dev 
        - unzip xxd 
        - perl 
        - r-base
        - bowtie2
        - pip 
        - git
    - type: python
      packages: bowtie
    - type: docker
      env: 
        - STAR_VERSION=2.7.11b
        - RSEM_VERSION=1.3.3
        - BOWTIE_VERSION=1.3.1
        - TZ=Europe/Brussels
      run: |
        ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
        cd /tmp && \
        wget --no-check-certificate https://github.com/alexdobin/STAR/archive/refs/tags/${STAR_VERSION}.zip && \
        unzip ${STAR_VERSION}.zip && \
        cd STAR-${STAR_VERSION}/source && \
        make STARstatic CXXFLAGS_SIMD=-std=c++11 && \
        cp STAR /usr/local/bin && \
        cd /tmp && \
        wget --no-check-certificate https://github.com/deweylab/RSEM/archive/refs/tags/v${RSEM_VERSION}.zip && \
        unzip v${RSEM_VERSION}.zip && \
        cd RSEM-${RSEM_VERSION} && \
        make && \
        make install && \
        cd /tmp && \
        wget --no-check-certificate -O bowtie-${BOWTIE_VERSION}-linux-x86_64.zip https://sourceforge.net/projects/bowtie-bio/files/bowtie/${BOWTIE_VERSION}/bowtie-${BOWTIE_VERSION}-linux-x86_64.zip/download  && \
        unzip bowtie-${BOWTIE_VERSION}-linux-x86_64.zip && \
        cp bowtie-${BOWTIE_VERSION}-linux-x86_64/bowtie* /usr/local/bin && \
        cd /tmp && \
        git clone https://github.com/DaehwanKimLab/hisat2.git /tmp/hisat2 && \
        cd /tmp/hisat2 && \
        make && \
        cp -r hisat2* /usr/local/bin && \
        cd && \
        rm -rf /tmp/STAR-${STAR_VERSION} /tmp/${STAR_VERSION}.zip /tmp/bowtie-${BOWTIE_VERSION}-linux-x86_64 /tmp/hisat2 && \
        apt-get --purge autoremove -y ${PACKAGES} && \
        apt-get clean 

    - type: docker
      run: |
        echo "RSEM: `rsem-calculate-expression --version | sed -e 's/Current version: RSEM v//g'`" > /var/software_versions.txt && \
        echo "STAR: `STAR --version`" >> /var/software_versions.txt && \
        echo "bowtie2: `bowtie2 --version | grep -oP '\d+\.\d+\.\d+'`" >> /var/software_versions.txt && \
        echo "bowtie: `bowtie --version | grep -oP 'bowtie-align-s version \K\d+\.\d+\.\d+'`" >> /var/software_versions.txt && \
        echo "HISAT2: `hisat2 --version | grep -oP 'hisat2-align-s version \K\d+\.\d+\.\d+'`" >> /var/software_versions.txt

runners:
  - type: executable
  - type: nextflow