Skip to content

Commit

Permalink
Tweak contig pattern to be more compliant to spec
Browse files Browse the repository at this point in the history
  • Loading branch information
athos committed Oct 3, 2023
1 parent 28b7303 commit 6a2d342
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/cljam/io/vcf/util/validator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@
(defn- prep-contig-defs [_validator contigs]
(into {} (map (juxt :id identity)) contigs))

(def ^:private ^:const contig-pattern
#"[0-9A-Za-z!#$%&+./:;?@^_|~-][0-9A-Za-z!#$%&*+./:;=?@^_|~-]*")

(defn- validate-chrom [validator {:keys [chr]}]
(if (and (string? chr) (re-matches #"[^<>, \t]+" chr))
(if (and (string? chr) (re-matches contig-pattern chr))
(when-not (get-in validator [:defs :contig chr])
(error-on-bcf validator [:chr] "Contig %s not defined in meta info" chr))
(error [:chr]
Expand Down
4 changes: 3 additions & 1 deletion test/cljam/io/vcf/util/validator_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,13 @@
(let [validator (v/map->VCFValidator {})
prepped (#'v/prep-contig-defs validator
[{:id "1" :length 248956422}
{:id "2" :length 242193529}])
{:id "2" :length 242193529}
{:id "HLA-A*01:01:01:01" :length 3503}])
validator (assoc validator :defs {:contig prepped})]
(are [variant expected]
(= expected (#'v/validate-chrom validator variant))
{:chr "1"} nil
{:chr "HLA-A*01:01:01:01"} nil

{:chr 1}
{:errors
Expand Down

0 comments on commit 6a2d342

Please sign in to comment.