Skip to content

Commit

Permalink
Merge pull request #7 from clingen-data-model/cvc-script-updates
Browse files Browse the repository at this point in the history
clinvar cvc function and script updates in prep of move from stage to…
  • Loading branch information
larrybabb authored Oct 21, 2024
2 parents 278ac30 + d507819 commit 5cebac0
Show file tree
Hide file tree
Showing 12 changed files with 857 additions and 155 deletions.
84 changes: 27 additions & 57 deletions scripts/clinvar-curartion/cvc-baseline-annotations-as-of-func.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
CREATE OR REPLACE TABLE FUNCTION `clinvar_curator.cvc_baseline_annotations_as_of`(as_of_date DATE, incl_finalized BOOL, only_latest BOOL) AS (
WITH anno AS
(
SELECT
rel.release_date,
CAST(UNIX_MILLIS(annotation_date) AS STRING) as annotation_id,
a.vcv_id as vcv_axn,
SPLIT(a.scv_id,'.')[OFFSET(0)] AS scv_id,
CAST(SPLIT(a.scv_id,'.')[OFFSET(1)] AS INT64) AS scv_ver,
CAST(a.variation_id AS String) AS variation_id,
CAST(a.submitter_id AS String) AS submitter_id,
LOWER(a.action) AS action,
SPLIT(a.curator_email,'@')[OFFSET(0)] AS curator,
a.annotation_date AS annotated_on,
DATE(a.annotation_date) AS annotated_date,
TIME(a.annotation_date) AS annotated_time_utc,
a.reason,
a.notes,
SPLIT(a.vcv_id,'.')[OFFSET(0)] AS vcv_id,
CAST(SPLIT(a.vcv_id,'.')[OFFSET(1)] AS INT64) AS vcv_ver,
-- if there are no other scv_id annotations after when orderd by annotation date then it is the latest
(
COUNT(a.annotation_date)
OVER (
PARTITION BY SPLIT(a.scv_id,'.')[OFFSET(0)]
ORDER BY a.annotation_date
ROWS BETWEEN 1 FOLLOWING AND UNBOUNDED FOLLOWING
) = 0
) AS is_latest

FROM `clinvar_curator.clinvar_annotations` a,
`clinvar_ingest.schema_on`(as_of_date) rel
WHERE
DATE(a.annotation_date) <= as_of_date
WITH
anno AS (
SELECT
rel.release_date,
av.annotation_id,
av.vcv_axn,
av.scv_id,
av.scv_ver,
av.variation_id,
av.submitter_id,
av.action,
av.curator,
av.annotated_on,
av.annotated_date,
av.annotated_time_utc,
av.reason,
av.notes,
av.vcv_id,
av.vcv_ver,
av.is_latest,
av.annotation_label
FROM `clinvar_curator.cvc_annotations_view` av,
`clinvar_ingest.schema_on`(as_of_date) rel
WHERE
av.annotated_date <= as_of_date
),
reviewed_anno AS (
SELECT
Expand Down Expand Up @@ -67,18 +59,6 @@ WITH anno AS
rev.notes,
sbm.batch_id
),
anno_label as (
SELECT
a.annotation_id,
FORMAT(
'%t (%s) %s: %s',
a.annotated_date,
IFNULL(a.curator,'n/a'),
IF(a.action ='flagging candidate','flag',IF(a.action = 'no change', 'no chg', 'n/a or unk' )),
LEFT(IFNULL(a.reason,'n/a'), 20)||IF(LENGTH(a.reason) > 20,'...','')
) as annotation_label
FROM anno a
),
ra_priors AS (
SELECT
a.annotation_id,
Expand All @@ -89,7 +69,7 @@ WITH anno AS
FORMAT(
'v%i %s %s',
prior_a.scv_ver,
prior_a_label.annotation_label,
prior_a.annotation_label,
if(prior_ra.review_label is not null, FORMAT('[ %s ]',prior_ra.review_label), '')
),
'\n'
Expand All @@ -105,10 +85,6 @@ WITH anno AS
ON
prior_a.scv_id = a.scv_id and
prior_a.annotation_id < a.annotation_id
JOIN anno_label prior_a_label
ON
prior_a.annotation_id = prior_a_label.annotation_id

LEFT JOIN reviewed_anno as prior_ra
ON
prior_ra.annotation_id = prior_a.annotation_id
Expand Down Expand Up @@ -140,13 +116,7 @@ WITH anno AS
a.reason,
a.notes,
a.submitter_id,
FORMAT(
'%t (%s) %s: %s',
a.annotated_date,
IFNULL(a.curator,'n/a'),
IF(a.action ='flagging candidate','flag',IF(a.action = 'no change', 'no chg', 'n/a or unk' )),
LEFT(IFNULL(a.reason,'n/a'), 20)||IF(LENGTH(a.reason) > 20,'...','')
) as annotation_label,
a.annotation_label,
a.is_latest,
-- finalized rev info
ra.annotation_id as finalized_review_id,
Expand Down
Loading

0 comments on commit 5cebac0

Please sign in to comment.