Skip to content

Commit

Permalink
add new task to flag invalid clinvar ids
Browse files Browse the repository at this point in the history
  • Loading branch information
acoffman committed Jan 28, 2025
1 parent f7beda9 commit 47c9b99
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
72 changes: 72 additions & 0 deletions server/app/jobs/find_invalid_clinvar_records.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
class FindInvalidClinvarRecords < ApplicationJob
KNOWN_GOOD_ID = 16609

def perform
#Bail early if this fails. Maybe the site is down or something.
check_clinvar_id(KNOWN_GOOD_ID) do |succeeded|
if !succeeded
raise StandardError.new("ClinVar ID #{KNOWN_GOOD_ID} did not return a 200. Aborting checks.")
end
end

Variant.joins(:clinvar_entries).distinct.find_each do |variant|
variant.clinvar_entries.each do |clinvar_entry|
clinvar_id = clinvar_entry.clinvar_id

if clinvar_id == 'N/A' || clinvar_id == 'NONE FOUND'
next
end

if has_existing_flag?(variant, clinvar_id)
next
end

check_clinvar_id(clinvar_id) do |succeeded|
if !succeeded
flag_variant(variant, clinvar_id)
end
end

sleep 0.25
end
end
end

private
def url_for_clinvar_id(id)
"https://www.ncbi.nlm.nih.gov/clinvar/variation/#{id}/"
end

def check_clinvar_id(id)
url = URI.parse(url_for_clinvar_id(id))
response = Net::HTTP.get_response(url)
case response.code
when "200"
yield true
else
yield false
end
end

def has_existing_flag?(variant, clinvar_id)
verbiage = flag_verbiage(variant, clinvar_id)
variant.flags.where(state: 'open', flagging_user_id: Constants::CIVICBOT_USER_ID)
.any? { |f| f.open_activity.note == verbiage }
end

def flag_variant(variant, clinvar_id)
verbiage = flag_verbiage(variant, clinvar_id)
civicbot_user = User.find(Constants::CIVICBOT_USER_ID)

Activities::FlagEntity.new(
flagging_user: civicbot_user,
flaggable: variant,
organization_id: nil,
note: verbiage
).perform
end

def flag_verbiage(variant, clinvar_id)
"This Variant links to a ClinVar ID that is no longer valid: #{clinvar_id}"
end
end
6 changes: 6 additions & 0 deletions server/config/scheduled_tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,9 @@ FindRetractedSources:
description: Check whether sources have been retracted
queue: default
class: FindRetractedSources

FindInvalidClinvarRecords:
cron: '0 22 1 * *'
description: Find and flag Variants that link to invalid ClinVar Records
queue: default
class: FindInvalidClinvarRecords

0 comments on commit 47c9b99

Please sign in to comment.