From 3bab9549e64d6b77c6b9d0bc860503641426a9cc Mon Sep 17 00:00:00 2001 From: Kim Rutherford Date: Sat, 6 Apr 2024 01:18:51 +1300 Subject: [PATCH] Add start of --change-gene-id admin action Refs pombase/canto#2677 --- lib/Canto/Track/TrackUtil.pm | 38 ++++++++++++++++++++++++++++++++++++ script/canto_admin.pl | 13 ++++++++++++ 2 files changed, 51 insertions(+) diff --git a/lib/Canto/Track/TrackUtil.pm b/lib/Canto/Track/TrackUtil.pm index ae29ab1ce..b127be4c2 100644 --- a/lib/Canto/Track/TrackUtil.pm +++ b/lib/Canto/Track/TrackUtil.pm @@ -426,4 +426,42 @@ sub update_annotation_curators Canto::Track::curs_map($self->config(), $track_schema, $proc); } +=head2 change_gene_id + + Usage : $util->change_gene_id($from_id, $to_id) + Function: Change a gene ID (primary_identifier) in every session. + Also change allele IDs containing the $from_id. + Args : $from_id - an existing primary_identifier + $to_id + Returns : nothing - dies on failures + +=cut + +sub change_gene_id +{ + my $self = shift; + + my $from_id = shift; + my $to_id = shift; + + my $track_schema = $self->schema(); + + my $proc = sub { + my $curs = shift; + my $cursdb = shift; + + my $gene_rs = $cursdb->resultset('Gene'); + + while (defined (my $gene = $gene_rs->next())) { + if ($gene->primary_identifier() eq $from_id) { + print $curs->curs_key(), "\n"; + $gene->primary_identifier($to_id); + $gene->update(); + } + } + }; + + Canto::Track::curs_map($self->config(), $track_schema, $proc); +} + 1; diff --git a/script/canto_admin.pl b/script/canto_admin.pl index d2a4217d4..e7ac5532a 100755 --- a/script/canto_admin.pl +++ b/script/canto_admin.pl @@ -39,6 +39,7 @@ BEGIN my $change_taxonid = undef; my $delete_unused_strains = undef; my $update_annotation_curators = undef; +my $change_gene_id = undef; my $dry_run = 0; my $do_help = 0; @@ -49,6 +50,7 @@ BEGIN "change-taxonid" => \$change_taxonid, "delete-unused-strains" => \$delete_unused_strains, "update-annotation-curators" => \$update_annotation_curators, + "change-gene-id" => \$change_gene_id, "dry-run|d" => \$dry_run, "help|h" => \$do_help); @@ -84,6 +86,8 @@ sub usage Set the curator_orcid field of the annotations if available in the person table + $0 --change-gene-id + Change to for all genes and alleles in every session |; } @@ -191,6 +195,15 @@ sub usage warn "failing to update annotation curator field: $_\n"; }; } + + if (defined $change_gene_id) { + my $from_id = shift @ARGV; + my $to_id = shift @ARGV; + + $util->change_gene_id($from_id, $to_id); + + $exit_flag = 0; + } }; if (defined $refresh_gene_cache) {