【问题标题】:Snakemake: validate nested yaml based on jsonschemaSnakemake:基于 jsonschema 验证嵌套 yaml
【发布时间】:2023-03-28 21:57:01
【问题描述】:

我正在使用snakemake validate 函数,它似乎在很大程度上基于jsonschema,对于简单的示例它工作正常,但是我不确定如何进行更复杂的参数设置。

假设我为多个峰值调用者(例如 macs2 和 genrich)实现了选项。目前我的config.yaml 看起来像这样:

peak_caller:
  - macs2:
      --shift -100 --extsize 200 
  - genrich:
      -y -j

如果没有指定峰值调用者,我希望它使用这些参数默认为 macs2,如果指定了这两个峰值调用者中的一个或两个以外的任何其他参数,我希望它失败。

我用枚举器和数组尝试了不​​同的东西,但我永远无法让它正常工作:

$schema: "http://json-schema.org/draft-06/schema#"

description: snakemake-workflows peak calling configuration

properties:
  # peak caller algorithms
  peak_caller:
    description: which peak caller(s) to use. Currently macs2 (default) and genrich are supported.
    type: array
    default: [macs2]

我最好保留yaml 格式,但我愿意接受以json 编写的配置。

【问题讨论】:

    标签: python json yaml snakemake


    【解决方案1】:
    properties:
      peak_caller:
        type: array
        items:
          anyOf:
            - type: object
              properties:
                macs2: {type: string}
              required: [macs2]
              additionalProperties: false
            - type: object
              properties:
                genrich: {type: string}
              required: [genrich]
              additionalProperties: false
         maxItems: 2
         uniqueItems: true
       default:
          - macs2: --shift -100 --extsize 200
    

    但是请注意,此架构不禁止使用不同的参数两次提供 macs2genrich。据我所知,用你当前使用的结构是不可能禁止的。但是,如果项目的顺序不重要,您可以简单地删除数组并使用这样的对象:

    peak_caller:
      macs2:
        --shift -100 --extsize 200 
      genrich:
        -y -j
    

    对应架构:

    properties:
      peak_caller:
        type: object
        properties:
          macs2: {type: string}
          genrich: {type: string}
        minProperties: 1   # if you want to have at least one
        additionalProperties: false
        default:
          macs2: --shift -100 --extsize 200
    

    默认情况下,JSONSchema 不需要属性值,因此该模式只需定义一个选项即可。

    【讨论】:

      猜你喜欢
      • 2017-06-20
      • 2021-07-29
      • 2022-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-15
      相关资源
      最近更新 更多