---
$schema: "https://json-schema.org/draft/2020-12/schema"

$id: /schemas/config.schema.yaml

description: snakemake configuration file

type: object

# possible entries of the config file

properties:
  # start_global
  global:
    type: object
    default:
      assignments:
        split_number: 1
    properties:
      assignments:
        type: object
        properties:
          split_number:
            type: integer
            default: 1
        additionalProperties: false
    additionalProperties: false
  # start_assignments
  assignments:
    description: Assignments to run with configurations
    type: object
    patternProperties:
      description: name of the assignment
      ^([^_\.]+)$:
        type: object
        properties:
          alignment_tool:
            type: object
            properties:
              tool:
                type: string
                enum:
                  - exact
                  - bwa
                  - bbmap
                default: bbmap
            allOf:
              - if:
                  properties:
                    tool:
                      const: bwa
                then:
                  properties:
                    configs:
                      type: object
                      properties:
                        min_mapping_quality:
                          type: integer
                          minimum: 0
                          default: 1
                        sequence_length:
                          type: object
                          properties:
                            min:
                              type: integer
                            max:
                              type: integer
                          additionalProperties: false
                          required:
                            - min
                            - max
                        alignment_start:
                          type: object
                          properties:
                            min:
                              type: integer
                            max:
                              type: integer
                          additionalProperties: false
                          required:
                            - min
                            - max
                      additionalProperties: false
                      required:
                        - sequence_length
                        - alignment_start
                        - min_mapping_quality
                  required:
                    - configs
              - if:
                  properties:
                    tool:
                      const: bbmap
                then:
                  properties:
                    configs:
                      type: object
                      properties:
                        min_mapping_quality:
                          type: integer
                          minimum: 0
                          default: 35
                        sequence_length:
                          type: object
                          properties:
                            min:
                              type: integer
                            max:
                              type: integer
                          additionalProperties: false
                          required:
                            - min
                            - max
                        alignment_start:
                          type: object
                          properties:
                            min:
                              type: integer
                            max:
                              type: integer
                          additionalProperties: false
                          required:
                            - min
                            - max
                      additionalProperties: false
                      required:
                        - min_mapping_quality
                        - sequence_length
                        - alignment_start
                  required:
                    - configs
              - if:
                  properties:
                    tool:
                      const: exact
                then:
                  properties:
                    configs:
                      type: object
                      properties:
                        sequence_length:
                          type: integer
                          minimum: 1
                        alignment_start:
                          type: integer
                          minimum: 1
                      additionalProperties: false
                      required:
                        - sequence_length
                        - alignment_start
                  required:
                    - configs
            required:
              - tool
          bc_length:
            type: integer
          BC_rev_comp:
            type: boolean
            default: false
          linker_length:
            type: integer
          linker:
            type: string
            pattern: ^[ATCGNatcgn]+$
          FW:
            type: array
            items:
              type: string
            minItems: 1
            uniqueItems: true
          BC:
            type: array
            items:
              type: string
            minItems: 1
            uniqueItems: true
          REV:
            type: array
            items:
              type: string
            minItems: 1
            uniqueItems: true
          NGmerge:
            type: object
            properties:
              min_overlap:
                type: integer
                default: 20
              frac_mismatches_allowed:
                type: number
                default: 0.1
              min_dovetailed_overlap:
                type: integer
                default: 50
            required:
              - min_overlap
              - frac_mismatches_allowed
              - min_dovetailed_overlap
            default: {}
            additionalProperties: false
          design_file:
            type: string
          design_check:
            type: object
            properties:
              fast:
                type: boolean
                default: true
              sequence_collitions:
                type: boolean
                default: true
            default: {}
            required:
              - fast
              - sequence_collitions
            additionalProperties: false
          configs:
            type: object
            patternProperties:
              ^([^_\.]+)$:
                type: object
                properties:
                  min_support:
                    type: integer
                    minimum: 1
                    default: 3
                  fraction:
                    type: number
                    exclusiveMinimum: 0.5
                    maximum: 1
                    default: 0.75
                required:
                  - min_support
                  - fraction
                additionalProperties: false
            additionalProperties: false
            minProperties: 1
        oneOf:
          - required:
              - linker_length
          - required:
              - linker
          - required:
              - BC
        required:
          - FW
          - REV
          - bc_length
          - design_file
          - configs
          - alignment_tool
          - NGmerge
        additionalProperties: false
    additionalProperties: false
    minProperties: 1
  # start_experiments
  experiments:
    description: MPRA experiments to run with configurations
    type: object
    patternProperties:
      description: name of the experiment
      ^([^_\.]+)$:
        type: object
        properties:
          bc_length:
            type: integer
            minimum: 1
          umi_length:
            type: integer
            minimum: 1
          adapter:
            type: string
            pattern: ^[ATCGNatcgn]+$
          data_folder:
            type: string
          experiment_file:
            type: string
          demultiplex:
            type: boolean
            default: false
          label_file:
            type: string
          assignments:
            type: object
            patternProperties:
              ^([^_\.]+)$:
                type: object
                properties:
                  type:
                    type: string
                    enum:
                      - file
                      - config
                  assignment_file:
                    type: string
                  assignment_name:
                    type: string
                  assignment_config:
                    type: string
                  sampling:
                    type: object
                    properties:
                      prop:
                        type: number
                        exclusiveMinimum: 0
                        maximum: 1
                      total:
                        type: integer
                        minimum: 1
                required:
                  - type
                additionalProperties: false
                allOf:
                  - if:
                      properties:
                        type:
                          const: config
                      required:
                        - type
                    then:
                      required:
                        - assignment_name
                        - assignment_config
                  - if:
                      properties:
                        type:
                          const: file
                      required:
                        - type
                    then:
                      required:
                        - assignment_file
            additionalProperties: false
          configs:
            type: object
            patternProperties:
              ^([^_\.]+)$:
                type: object
                properties:
                  filter:
                    type: object
                    properties:
                      bc_threshold:
                        type: integer
                        minimum: 1
                        default: 10
                    patternProperties:
                      ^((DNA)|(RNA))$:
                        type: object
                        properties:
                          min_counts:
                            type: integer
                            miminum: 0
                            default: 1
                        additionalProperties: false
                        required:
                          - min_counts
                    default:
                      bc_threshold: 10
                      DNA:
                        min_counts: 1
                      RNA:
                        min_counts: 1
                    required:
                      - bc_threshold
                      - DNA
                      - RNA
                    additionalProperties: false
                  sampling:
                    type: object
                    patternProperties:
                      ^((DNA)|(RNA))$:
                        type: object
                        properties:
                          threshold:
                            type: integer
                            minimum: 1
                          prop:
                            type: number
                            exclusiveMinimum: 0
                            maximum: 1
                          total:
                            type: number
                            minimum: 1
                          seed:
                            type: integer
                        additionalProperties: false
                    additionalProperties: false
                additionalProperties: false
                required:
                  - filter
              additionalProperties: false
          variants:
            type: object
            properties:
              map:
                type: string
              min_barcodes:
                type: array
                items:
                  type: integer
                  minimum: 1
            required:
              - map
              - min_barcodes
        # entries that have to be in the config file for successful validation
        required:
          - bc_length
          - data_folder
          - experiment_file
          - demultiplex
          - assignments
          - configs
      additionalProperties: false
# end_experiments
additionalProperties: false
minProperties: 1
