Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Toggle renaming of gene names in alleles in --change-gene-id #2830

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 17 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 @@ -131,6 +134,16 @@ sub usage
usage();
}

if ($change_gene_id && @ARGV != 2) {
warn "Error: --change-gene-id needs two arguments\n\n";
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 @@ -200,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
Loading