name: bedtools_bamtobed
namespace: bedtools
description: Converts BAM alignments to BED6 or BEDPE format.
keywords: [Converts, BAM, BED, BED6, BEDPE]
links:
  documentation: https://bedtools.readthedocs.io/en/latest/content/tools/bamtobed.html
  repository: https://github.com/arq5x/bedtools2
  homepage: https://bedtools.readthedocs.io/en/latest/#
  issue_tracker: https://github.com/arq5x/bedtools2/issues
references:
  doi: 10.1093/bioinformatics/btq033
license: MIT
requirements:
  commands: [bedtools]
authors:
  - __merge__: /src/_authors/theodoro_gasperin.yaml
    roles: [ author, maintainer ]

argument_groups:
  - name: Inputs
    arguments:
      - name: --input
        alternatives: -i
        type: file
        description: Input BAM file.
        required: true
    
  - name: Outputs
    arguments:
      - name: --output
        alternatives: -o
        required: true
        type: file
        direction: output
        description: Output BED file.

  - name: Options
    arguments:
      - name: --bedpe
        type: boolean_true
        description: | 
          Write BEDPE format. Requires BAM to be grouped or sorted by query.
      
      - name: --mate1
        type: boolean_true
        description: | 
          When writing BEDPE (-bedpe) format, always report mate one as the first BEDPE "block".
      
      - name: --bed12
        type: boolean_true
        description: | 
          Write "blocked" BED format (aka "BED12"). Forces -split.
          See http://genome-test.cse.ucsc.edu/FAQ/FAQformat#format1

      - name: --split
        type: boolean_true
        description: | 
          Report "split" BAM alignments as separate BED entries.
          Splits only on N CIGAR operations.

      - name: --splitD
        type: boolean_true
        description: | 
          Split alignments based on N and D CIGAR operators.
          Forces -split.

      - name: --edit_distance
        alternatives: -ed
        type: boolean_true
        description: | 
          Use BAM edit distance (NM tag) for BED score.
          - Default for BED is to use mapping quality.
          - Default for BEDPE is to use the minimum of
            the two mapping qualities for the pair.
          - When -ed is used with -bedpe, the total edit
            distance from the two mates is reported.

      - name: --tag
        type: string
        description: | 
          Use other NUMERIC BAM alignment tag for BED score.
          Default for BED is to use mapping quality. Disallowed with BEDPE output.
        example: "SM"
      
      - name: --color
        type: string
        description: | 
          An R,G,B string for the color used with BED12 format.
          Default is (255,0,0).
        example: "250,250,250"

      - name: --cigar
        type: boolean_true
        description: | 
          Add the CIGAR string to the BED entry as a 7th column.

resources:
  - type: bash_script
    path: script.sh

test_resources:
  - type: bash_script
    path: test.sh
  - path: test_data

engines:
  - type: docker
    image: debian:stable-slim
    setup:
      - type: apt
        packages: [bedtools, procps]
      - type: docker
        run: |
          echo "bedtools: \"$(bedtools --version | sed -n 's/^bedtools //p')\"" > /var/software_versions.txt

runners:
  - type: executable
  - type: nextflow