Commit 4ffacb34 authored by Andy Yates's avatar Andy Yates
Browse files

Check for existing aliases

parent 419ce97a
......@@ -15,7 +15,7 @@ sub run {
$self->check_opts();
my $species = $self->_species();
foreach my $s ( sort { $a->{production} cmp $b->{production} } values %{$species} ) {
$self->v( 'Processing %s', $s->{production} );
$self->v( 'Processing %s (species_id: %d)', $s->{production}, $s->{id} );
my $aliases_to_add = $self->_aliases_to_add($s);
$self->_write_aliases($aliases_to_add, $s);
$self->v('Done');
......@@ -34,7 +34,8 @@ sub args {
mdatabase => 'ensembl_production',
species => [],
write => 0
write => 0,
dieonconflict => 1
};
my @cmd_opts = qw/
......@@ -45,6 +46,7 @@ sub args {
mdatabase|md=s
species|s=s@
verbose|v!
write
help
man
/;
......@@ -134,21 +136,21 @@ sub _enrich {
my ($self, $species) = @_;
foreach my $id (keys %{$species}) {
my $s = $species->{$id};
$s->{aliases} = $self->_aliases($s);
$s->{automatic_aliases} = $self->_automatic_aliases($s);
}
return;
}
sub _aliases {
my ($self, $s) = @_;
my $dbc = $self->_production_dbc();
my $aliases = $dbc->sql_helper()->execute_simple(
-SQL => 'select alias from species_alias where is_current = 1 and species_id =?',
-PARAMS => [$s->{id}]
);
my %hash = map { $_ => 1 } @{$aliases};
return \%hash;
my ($self) = @_;
if(! exists $self->{_aliases}) {
my $dbc = $self->_production_dbc();
my $aliases = $dbc->sql_helper()->execute_simple(
-SQL => 'select alias from species_alias where is_current = 1'
);
$self->{_aliases} = {map { $_ => 1 } @{$aliases}};
}
return $self->{_aliases};
}
sub _automatic_aliases {
......@@ -187,12 +189,19 @@ sub _automatic_aliases {
sub _aliases_to_add {
my ($self, $species) = @_;
my @aliases_to_add;
my $aliases = $self->_aliases();
foreach my $autogenerated (keys %{$species->{automatic_aliases}}) {
if(exists $species->{aliases}->{$autogenerated}) {
$self->v('Skipping %s as it already registered for this species', $autogenerated);
if($species->{aliases}->{$autogenerated} == 1) {
$self->v('SKIPPING WARNING: %s as it already registered for another species', $autogenerated);
}
elsif($species->{aliases}->{$autogenerated} == 2) {
$self->v('SKIPPING WARNING: %s as it has been generated for another species in this session', $autogenerated);
}
}
else {
push(@aliases_to_add, $autogenerated);
$aliases->{$autogenerated} = 2;
$self->v('%s is a new alias', $autogenerated);
}
}
......@@ -243,7 +252,7 @@ generate_default_aliases.pl
[-md database] \\
[-th host] [-tP port] \\
[-tu user] [-tp password] [-td database] \\
[-species] \\
[-species] [-write] \\
[-v]
=head1 DESCRIPTION
......@@ -297,6 +306,10 @@ Name for the production database.
Species to generate the names for. Can use a SQL pattern here and multiple
cmd line entries. Please use B<production_names>.
=item B<--write>
Turns writing on. Not on by default
=item B<--verbose>
Make the script chatty
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment