name: freemuxlet
namespace: genetic_demux
scope: "public"
description: |
  Freemuxlet is a software tool to deconvolute sample identity and identify multiplets when
  multiple samples are pooled by barcoded single cell sequencing. If external genotyping
  data is not available, the genotyping-free version demuxlet, freemuxlet, would be recommended.
authors:
  - __merge__: /src/authors/xichen_wu.yaml
    roles: [ author ]
argument_groups:
- name: "Input"
  arguments:
  - name: "--plp"
    type: string
    description: "Prefix of input files generated by dsc-pileup"
  - name: "--init_cluster"
    type: file
    example: init_cluster.txt
    description: "Input file containing the initial cluster information."
  - name: "--nsample"
    type: integer
    default: 2
    description: "Number of samples multiplexed together"
  - name: "--aux_files"
    type: boolean_true
    description: "Turn on writing auxilary output files"
  - name: "--verbose"
    type: integer
    default: 100
    description: "Turn on verbose mode with specific verbosity threshold. 0: fully verbose, 100 : no verbose messages."
  - name: "--doublet_prior"
    type: double
    default: 0.5
    description: "Prior of doublet."
  - name: "--geno_error"
    type: double
    default: 0.1
    description: "Genotype error parameter per cluster."
  - name: "--bf_thres"
    type: double
    default: 5.41
    description: "Bayes Factor Threshold used in the initial clustering."
  - name: "--frac_init_clust"
    type: double
    default: 1
    description: "Fraction of droplets to be clustered in the very first round of initial clustering procedure."
  - name: "--iter_init"
    type: integer
    default: 10
    description: "Iteration for initial cluster assignment (set to zero to skip the iterations)."
  - name: "--keep_init_missing"
    type: boolean_true
    description: "Keep missing cluster assignment as missing in the initial iteration."
  - name: "--randomize_singlet_score"
    type: boolean_true
    description: "Randomize the singlet scores to test its effect."
  - name: "--seed"
    type: integer
    default: 0
    description: "Seed for random number (use clocks if not set)."
  - name: "--cap_bq"
    type: integer
    default: 20
    description: "Maximum base quality (higher BQ will be capped)."
  - name: "--min_bq"
    type: integer
    default: 13
    description: "Minimum base quality to consider (lower BQ will be skipped)."
  - name: "--group_list"
    type: string
    description: "List of tag readgroup/cell barcode to consider in this run. All other barcodes will be ignored. This is useful for parallelized run."
  - name: "--min_total"
    type: integer
    default: 0
    description: "Minimum number of total reads for a droplet/cell to be considered."
  - name: "--min_umi"
    type: integer
    default: 0
    description: "Minimum number of UMIs for a droplet/cell to be considered."
  - name: "--min_snp"
    type: integer
    default: 0
    description: "Minimum number of SNPs with coverage for a droplet/cell to be considered."
- name: "Output"
  arguments:
  - name: "--output"
    alternatives: [ "-o" ]
    type: file
    direction: output
    description: Output directory 
    example: "freemux/"
  - name: "--out"
    type: string
    description: freemuxlet Output file prefix
    example: "freemuxlet"
resources:
  - type: r_script
    path: script.R
  - path: freemuxlet.patch
test_resources:
  - type: bash_script
    path: test.sh
  - path: ../../../resources_test/demuxafy_test_data

engines:
- type: docker
  image: ubuntu:24.04
  setup:
  - type: docker
    copy: ["freemuxlet.patch /opt/freemuxlet.patch"]
  - type: apt
    packages: [ autoconf, wget, git, build-essential, libcurl4-openssl-dev, cmake, libbz2-dev, libssl-dev, liblzma-dev, zlib1g-dev, r-base]
  - type: docker
    run: git clone https://github.com/samtools/htslib.git /tmp/htslib && cd /tmp/htslib && git submodule update --init --recursive && autoreconf -i && ./configure --prefix=/usr/local/ && make && make install
  - type: docker
    run: git clone --depth 1 https://github.com/statgen/popscle.git /tmp/popscle && cd /tmp/popscle && git apply /opt/freemuxlet.patch && mkdir -p /tmp/popscle/build && cd /tmp/popscle/build && cmake .. && make && cp /tmp/popscle/bin/popscle /usr/local/bin
  - type: r
    cran: [ readr, processx, dplyr ]

runners:
- type: executable
- type: nextflow
  directives:
    label: [ midmem, midcpu ]
