name: freebayes
namespace: genetic_demux
scope: "public"
description: |
  Freebayes is a Bayesian genetic variant detector designed to
  find small polymorphisms, specifically SNPs.
authors:
  - __merge__: /src/authors/xichen_wu.yaml
    roles: [ author ]
argument_groups:
- name: "Input"
  arguments:
  - name: "--bam"
    type: file
    description: Add FILE to the set of BAM files to be analyzed.
    example: input.bam
  - name: "--bam_list"
    type: file
    description: A file containing a list of BAM files to be analyzed.
    example: bam_list.txt
  - name: "--stdin"
    type: boolean_true
    description: Read BAM input on stdin.
  - name: "--fasta_reference"
    type: file
    description: Use FILE as the reference sequence for analysis. An index file (FILE.fai) will be created if none exists. If neither --targets nor --region are specified, FreeBayes will analyze every position in this reference.
    example: reference.fasta
  - name: "--fasta_reference_index"
    type: file
    description: Use FILE.fai as the index of reference sequence for analysis.
    example: file.fai
  - name: "--targets"
    type: file
    description: Limit analysis to targets listed in the BED-format FILE.
    example: targets.bed
  - name: "--region"
    type: string
    description: Limit analysis to the specified region, 0-base coordinates, end_position not included (same as BED format).
  - name: "--samples"
    type: file
    description: Limit analysis to samples listed (one per line) in the FILE. By default FreeBayes will analyze all samples in its input BAM files.
    example: samples.txt
  - name: "--populations"
    type: file
    description: Each line of FILE should list a sample and a population which it is part of. The population-based bayesian inference model will then be partitioned on the basis of the populations.
    example: populations.txt
  - name: "--cnv_map"
    type: file
    description: Read a copy number map from the BED file FILE, which has either a sample-level ploidy or a region-specific format.
  - name: "--gvcf"
    type: boolean_true
    description: Write gVCF output, which indicates coverage in uncalled regions.
  - name: "--gvcf_chunk"
    type: integer
    description: When writing gVCF output emit a record for every NUM bases.
  - name: "--variant_input"
    type: file
    description: Use variants reported in VCF file as input to the algorithm. Variants in this file will included in the output even if there is not enough support in the data to pass input filters.
    example: variant_input.vcf
  - name: "--only_use_input_alleles"
    type: boolean_true
    description: Only provide variant calls and genotype likelihoods for sites and alleles which are provided in the VCF input, and provide output in the VCF for all input alleles, not just those which have support in the data.
  - name: "--haplotype_basis_alleles"
    type: file
    description: When specified, only variant alleles provided in this input VCF will be used for the construction of complex or haplotype alleles.
  - name: "--report_all_haplotype_alleles"
    type: boolean_true
    description: At sites where genotypes are made over haplotype alleles, provide information about all alleles in output, not only those which are called.
  - name: "--report_monomorphic"
    type: boolean_true
    description: Report even loci which appear to be monomorphic, and report all considered alleles, even those which are not in called genotypes.
  - name: "--pvar"
    type: double
    default: 0.0
    description: Report sites if the probability that there is a polymorphism at the site is greater than N. Note that post-filtering is generally recommended over the use of this parameter.
  - name: "--strict_vcf"
    type: boolean_true
    description: Generate strict VCF format (FORMAT/GQ will be an int).
  - name: "--theta"
    type: double
    default: 0.001
    description: The expected mutation rate or pairwise nucleotide diversity among the population under analysis. This serves as the single parameter to the Ewens Sampling Formula prior model.
  - name: "--ploidy"
    type: integer
    default: 2
    description: Sets the default ploidy for the analysis to N.
  - name: "--pooled_discrete"
    type: boolean_true
    description: Assume that samples result from pooled sequencing. Model pooled samples using discrete genotypes across pools.
  - name: "--pooled_continuous"
    type: boolean_true
    description: Output all alleles which pass input filters, regardles of genotyping outcome or model.
  - name: "--use_reference_allele"
    type: boolean_true
    description: This flag includes the reference allele in the analysis as if it is another sample from the same population.
  - name: "--reference_quality"
    type: string
    description: Assign mapping quality of MQ to the reference allele at each site and base quality of BQ.
    default: "100,60"
  - name: "--throw_away_snp_obs"
    type: boolean_true
    description: Ignore SNP alleles.
  - name: "--throw_away_mnps_obs"
    type: boolean_false
    description: Ignore multi-nuceotide polymorphisms, MNPs. MNPs are excluded as default.
  - name: "--throw_away_indel_obs"
    type: boolean_false
    description: Ignore insertion and deletion alleles. Indels are excluded as default.
  - name: "--throw_away_complex_obs"
    type: boolean_false
    description: Ignore complex events (composites of other classes). Complex are excluded as default
  - name: "--use_best_n_alleles"
    type: integer
    default: 0
    description: Evaluate only the best N SNP alleles, ranked by sum of supporting quality scores.
  - name: "--max_complex_gap"
    type: integer
    default: 3
    description: Allow haplotype calls with contiguous embedded matches of up to this length.
  - name: "--min_repeat_size"
    type: integer
    default: 5
    description: When assembling observations across repeats, require the total repeat length at least this many bp.
  - name: "--min_repeat_entropy"
    type: integer
    default: 1
    description: To detect interrupted repeats, build across sequence until it has entropy > N bits per bp. Set to 0 to turn off.
  - name: "--no_partial_observations"
    type: boolean_true
    description: Exclude observations which do not fully span the dynamically-determined detection window.  (default, use all observations, dividing partial support across matching haplotypes when generating haplotypes.)
  - name: "--dont_left_align_indels"
    type: boolean_true
    description: Turn off left-alignment of indels, which is enabled by default.
  - name: "--use_duplicate_reads"
    type: boolean_true
    description: "Include duplicate-marked alignments in the analysis. default: exclude duplicates marked as such in alignments"
  - name: "--min_mapping_quality"
    type: integer
    default: 1
    description: Exclude alignments from analysis if they have a mapping quality less than Q.
  - name: "--min_base_quality"
    type: integer
    default: 1
    description: Exclude alleles from analysis if their supporting base quality is less than Q. Default value is changed according to the instruction of scSplit.
  - name: "--min_supporting_allele_qsum"
    type: integer
    default: 0
    description: Consider any allele in which the sum of qualities of supporting observations is at least Q.
  - name: "--min_supporting_mapping_qsum"
    type: integer
    default: 0
    description: Consider any allele in which and the sum of mapping qualities of supporting reads is at least.
  - name: "--mismatch_base_quality_threshold"
    type: integer
    default: 10
    description: Count mismatches toward --read-mismatch-limit if the base quality of the mismatch is >= Q.
  - name: "--read_max_mismatch_fraction"
    type: double
    default: 1.0
    description: Exclude reads with more than N mismatches where each mismatch has base quality >= mismatch-base-quality-threshold.
  - name: "--read_mismatch_limit"
    type: integer
    description: Exclude reads with more than N [0,1] fraction of mismatches where each mismatch has base quality >= mismatch-base-quality-threshold.
  - name: "--read_snp_limit"
    type: integer
    description: Exclude reads with more than N base mismatches, ignoring gaps with quality >= mismatch-base-quality-threshold.
  - name: "--read_indel_limit"
    type: integer
    description: Exclude reads with more than N separate gaps.
  - name: "--standard_filters"
    type: boolean_true
    description: Use stringent input base and mapping quality filters, equivalent to -m 30 -q 20 -R 0 -S 0
  - name: "--min_alternate_fraction"
    type: double
    default: 0.05
    description: Require at least this fraction of observations supporting an alternate allele within a single individual in order to evaluate the position.
  - name: "--min_alternate_count"
    type: integer
    default: 2
    description: Require at least this count of observations supporting an alternate allele within a single individual in order to evaluate the position.
  - name: "--min_alternate_qsum"
    type: integer
    default: 0
    description: Require at least this sum of quality of observations supporting an alternate allele within a single individual in order to evaluate the position.
  - name: "--min_alternate_total"
    type: integer
    default: 1
    description: Require at least this count of observations supporting an alternate allele within the total population in order to use the allele in analysis.
  - name: "--min_coverage"
    type: integer
    default: 0
    description: Require at least this coverage to process a site.
  - name: "--max_coverage"
    type: integer
    description: Do not process sites with greater than this coverage.
  - name: "--no_population_priors"
    type: boolean_true
    description:  Equivalent to --pooled-discrete --hwe-priors-off and removal of Ewens Sampling Formula component of priors.
  - name: "--hwe_priors_off"
    type: boolean_true
    description: Disable estimation of the probability of the combination arising under HWE given the allele frequency as estimated by observation frequency.
  - name: "--binomial_obs_priors_off"
    type: boolean_true
    description: Disable incorporation of prior expectations about observations. Uses read placement probability, strand balance probability, and read position probability.
  - name: "--allele_balance_priors_off"
    type: boolean_true
    description: Disable use of aggregate probability of observation balance between alleles as a component of the priors.
  - name: "--observation_bias"
    type: file
    example: observation_bias.txt
    description: Read length-dependent allele observation biases from FILE. The format is [length] [alignment efficiency relative to reference] where the efficiency is 1 if there is no relative observation bias.
  - name: "--base_quality_cap"
    type: integer
    description: Limit estimated observation quality by capping base quality at Q.
  - name: "--prob_contamination"
    type: double
    default: 10e-9
    description: An estimate of contamination to use for all samples.
  - name: "--legacy_gls"
    type: boolean_true
    description: Use legacy (polybayes equivalent) genotype likelihood calculations
  - name: "--contamination_estimates"
    type: file
    example: contamination_estimates.txt
    description: A file containing per-sample estimates of contamination, such as those generated by VerifyBamID.
  - name: "--report_genotype_likelihood_max"
    type: boolean_true
    description: Report genotypes using the maximum-likelihood estimate provided from genotype likelihoods.
  - name: "--genotyping_max_iterations"
    type: integer
    default: 1000
    description: Iterate no more than N times during genotyping step.
  - name: "--genotyping_max_banddepth"
    type: integer
    default: 6
    description: Integrate no deeper than the Nth best genotype by likelihood when genotyping.
  - name: "--posterior_integration_limits"
    type: string
    default: 1,3
    description: Integrate all genotype combinations in our posterior space which include no more than N samples with their Mth best data likelihood.
  - name: "--exclude_unobserved_genotypes"
    type: boolean_true
    description: Skip sample genotypings for which the sample has no supporting reads.
  - name: "--genotype_variant_threshold"
    type: integer
    description: Limit posterior integration to samples where the second-best genotype likelihood is no more than log(N) from the highest genotype likelihood for the sample.
  - name: "--use_mapping_quality"
    type: boolean_true
    description: Use mapping quality of alleles when calculating data likelihoods.
  - name: "--harmonic_indel_quality"
    type: boolean_true
    description: Use a weighted sum of base qualities around an indel, scaled by the
                  distance from the indel. By default use a minimum BQ in flanking sequence.
  - name: "--read_dependence_factor"
    type: double
    default: 0.9
    description: Incorporate non-independence of reads by scaling successive observations by this factor during data likelihood calculations.
  - name: "--genotype_qualities"
    type: boolean_true
    description: Calculate the marginal probability of genotypes and report as GQ in each sample field in the VCF output.
  - name: "--debug"
    type: boolean_true
    description: Print debugging output.
  - name: "--dd"
    type: boolean_true
    description: Print more verbose debugging output
- name: "Output"
  arguments:
  - name: "--output"
    alternatives: [ "-o" ]
    type: file
    direction: output
    description: Output directory 
    example: "freebayes_out/"
  - name: "--vcf"
    type: string
    description: Output VCF-format results to FILE.
    example: "snp.vcf"
resources:
  - type: bash_script
    path: script.sh
test_resources:
  - type: bash_script
    path: test.sh
  - path: ../../../resources_test/demuxafy_test_data
  - path: ../../../resources_test/cellranger_tiny_fastq

engines:
- type: docker
  image: debian:latest
  setup:
    - type: apt
      packages: freebayes

runners:
- type: executable
- type: nextflow
  directives:
    label: [ highmem, highcpu ]
