Skip to content

Commit

Permalink
Change validator structure of base records.
Browse files Browse the repository at this point in the history
  • Loading branch information
niyarin committed Jul 19, 2023
1 parent 0f78812 commit 0a03b50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 31 deletions.
54 changes: 24 additions & 30 deletions src/cljam/io/vcf/util/validator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,30 @@
(every? keyword? filt))))

(defn- check-base-records [variant meta-included-contig? meta-included-format?]
(cond-> nil
(some #{\< \> \, \space \tab} (:chr variant))
(update :chr (fnil conj []) "Must not contain whitespaces commas or angle brackets.")

(not (meta-included-contig? (:chr variant)))
(update :chr (fnil conj []) "Must be contained in contig header.")

(not (integer? (:pos variant)))
(update :pos (fnil conj []) "Position must be Integer.")

(not (valid-ref? (:ref variant)))
(update :ref (fnil conj []) "Not include invalid char.")

(and (seq (:alt variant))
(not (sequential? (:alt variant))))
(update :alt (fnil conj []) "Must be sequence.")

(and (sequential? (:alt variant))
(not (every? #(vcf-util/inspect-allele % (:ref variant))
(:alt variant))))
(update :alt (fnil conj []) "Invalid allele.")

(not (valid-qual? (:qual variant)))
(update :qual (fnil conj []) "Qual must be float.")

(not (valid-filter? (:filter variant)))
(update :filter (fnil conj []) "Invalid filter.")

(not (meta-included-format? (:format variant)))
(update :format (fnil conj []) "Must be contain meta")))
(reduce-kv
(fn [m k vs]
(reduce
(fn [m [pred msg]]
(cond-> m (not (pred (k variant))) (update k (fnil conj []) msg)))
m
vs))
nil
{:chr
[[(complement (partial some #{\< \> \, \space \tab}))
"Must not contain whitespaces commas or angle brackets."]
[meta-included-contig? (format (str "CHROM %s must be declared in a "
"##contig field in the header.")
(:chr variant))]],
:pos [[integer? "Position must be Integer."]],
:ref [[valid-ref? "Not include invalid char."]]
:alt [[(some-fn (complement seq) sequential?) "Must be sequence."]
[(some-fn
(complement sequential?)
(partial every? #(vcf-util/inspect-allele % (:ref variant))))
"Invalid allele."]]
:qual [[valid-qual? "Qual must be float."]]
:filter [[valid-filter? "Invalid filter."]]
:format [[meta-included-format? "Must be contain meta"]]}))

(defn- check-entry-type [entry type-str]
((case type-str
Expand Down
6 changes: 5 additions & 1 deletion test/cljam/io/vcf/util/validator_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@
{:chr "c hr10" :pos 10}
{:contig [{:id "c hr10"}]}
base-header))
["Must not contain whitespaces commas or angle brackets."])))
["Must not contain whitespaces commas or angle brackets."]))
(is (= (:chr
(validator/invalid-variant? {:chr "chr10" :pos 10}
{} base-header))
["CHROM chr10 must be declared in a ##contig field in the header."])))
(testing "ref check"
(is (= (:ref
(validator/invalid-variant?
Expand Down

0 comments on commit 0a03b50

Please sign in to comment.