Skip to content

Instantly share code, notes, and snippets.

@acoffman
Last active February 24, 2022 19:13
Show Gist options
  • Save acoffman/320d2a142278cb93fb2eba11a6fa9351 to your computer and use it in GitHub Desktop.
Save acoffman/320d2a142278cb93fb2eba11a6fa9351 to your computer and use it in GitHub Desktop.
require 'csv'
civic_bot = User.find(385)
fout = File.open('fusion_renames.tsv', 'w')
fusion_variant_type_id = VariantType.find_by(soid: 'SO:0001886').id
CSV.foreach('civic-fusions.tsv', col_sep: "\t", headers: true, encoding: 'iso-8859-1:utf-8') do |row|
variant = Variant.find(Integer(row['Id'])) rescue next
new_name = variant.name.sub("-", "::")
if new_name != variant.name
existing_alias_ids = variant.variant_alias_ids
new_alias_id = VariantAlias.get_or_create_by_name(variant.name).id
name_sc = SuggestedChange.create!(
user: civic_bot,
moderated: variant,
status: 'new',
suggested_changes: {
'name' => [variant.name, new_name],
'variant_alias_ids' => [existing_alias_ids, existing_alias_ids + [new_alias_id]]
}
)
Event.create!(
action: 'change suggested',
originating_user: civic_bot,
subject: variant,
state_params: name_sc.state_params
)
fout.puts("http://localhost:3000/links/revision/#{name_sc.id}")
existing_types = variant.variant_type_ids
if !existing_types.include?(fusion_variant_type_id)
variant_type_sc = SuggestedChange.create!(
user: civic_bot,
moderated: variant,
status: 'new',
suggested_changes: {
'variant_type_ids' => [existing_types, existing_types + [fusion_variant_type_id]]
}
)
Event.create!(
action: 'change suggested',
originating_user: civic_bot,
subject: variant,
state_params: variant_type_sc.state_params
)
fout.puts("http://localhost:3000/links/revision/#{variant_type_sc.id}")
end
end
end
fout.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment