Skip to content

Commit

Permalink
Add --no-rename flag to --change-gene-id
Browse files Browse the repository at this point in the history
If set, does not update alleles with the new gene name.
  • Loading branch information
jseager7 committed May 2, 2024
1 parent b216f8e commit a6524e2
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 7 additions & 3 deletions lib/Canto/Track/TrackUtil.pm
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,8 @@ sub update_annotation_curators
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
$to_id - the primary_identifier that will replace $from_id
$no_rename - if true, do not rename alleles
Returns : nothing - dies on failures
=cut
Expand All @@ -443,6 +444,7 @@ sub change_gene_id

my $from_id = shift;
my $to_id = shift;
my $no_rename = shift;

my $gene_lookup = Canto::Track::get_adaptor($self->config(), 'gene');

Expand Down Expand Up @@ -493,8 +495,10 @@ sub change_gene_id
if ($primary_identifier =~ /^$from_id:/) {
$primary_identifier =~ s/^$from_id:/$to_id:/;
$allele->primary_identifier($primary_identifier);
$allele_name =~ s/$old_name/$new_name/;
$allele->name($allele_name);
if (!$no_rename) {
$allele_name =~ s/$old_name/$new_name/;
$allele->name($allele_name);
}
$allele->update();
}
}
Expand Down
16 changes: 12 additions & 4 deletions script/canto_admin.pl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ BEGIN
my $delete_unused_strains = undef;
my $update_annotation_curators = undef;
my $change_gene_id = undef;
my $no_rename = 0;

my $dry_run = 0;
my $do_help = 0;
Expand All @@ -52,7 +53,8 @@ BEGIN
"update-annotation-curators" => \$update_annotation_curators,
"change-gene-id" => \$change_gene_id,
"dry-run|d" => \$dry_run,
"help|h" => \$do_help);
"help|h" => \$do_help,
"no-rename" => \$no_rename);

sub usage
{
Expand Down Expand Up @@ -86,8 +88,9 @@ 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
$0 --change-gene-id [--no-rename] <from_id> <to_id>
Change <from_id> to <to_id> for all genes and alleles in every session.
If --no-rename is set, skip renaming alleles.
|;
}

Expand Down Expand Up @@ -136,6 +139,11 @@ sub usage
usage();
}

if ($no_rename && !defined $change_gene_id) {
warn "Error: --no-rename is only allowed with --change-gene-id\n\n";
usage();
}

my $config = Canto::Config::get_config();
my $schema = Canto::TrackDB->new(config => $config);

Expand Down Expand Up @@ -205,7 +213,7 @@ sub usage
my $from_id = shift @ARGV;
my $to_id = shift @ARGV;

$util->change_gene_id($from_id, $to_id);
$util->change_gene_id($from_id, $to_id, $no_rename);

$exit_flag = 0;
}
Expand Down

0 comments on commit a6524e2

Please sign in to comment.