-
-
Save acoffman/320d2a142278cb93fb2eba11a6fa9351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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