Skip to content

Commit

Permalink
Add start of --change-gene-id admin action
Browse files Browse the repository at this point in the history
Refs #2677
  • Loading branch information
kimrutherford committed Apr 5, 2024
1 parent 1d2a27a commit 3bab954
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
38 changes: 38 additions & 0 deletions lib/Canto/Track/TrackUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
13 changes: 13 additions & 0 deletions script/canto_admin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down Expand Up @@ -84,6 +86,8 @@ sub usage
Set the curator_orcid field of the annotations if available in the
person table
$0 --change-gene-id <from_id> <to_id>
Change <from_id> to <to_id> for all genes and alleles in every session
|;
}

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3bab954

Please sign in to comment.