Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ensembl
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Merge requests
1
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ensembl-gh-mirror
ensembl
Commits
39e2c760
Commit
39e2c760
authored
20 years ago
by
Arne Stabenau
Browse files
Options
Downloads
Patches
Plain Diff
preliminary version of an attrib_type upload script
parent
0561890c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
misc-scripts/attribute_types/upload_attributes.pl
+132
-6
132 additions, 6 deletions
misc-scripts/attribute_types/upload_attributes.pl
with
132 additions
and
6 deletions
misc-scripts/attribute_types/upload_attributes.pl
+
132
−
6
View file @
39e2c760
...
...
@@ -25,13 +25,10 @@ GetOptions( "host=s", \$host,
$file
||=
$
FindBin::
Bin
.
"
/attrib_type.txt
";
usage
()
if
(
!
$host
);
usage
()
if
((
$release_num
&&
@dbnames
)
||
(
!
$release_num
&&
!
@dbnames
));
#release num XOR dbname are required
usage
()
if
((
$release_num
&&
@dbnames
)
||
(
!
$release_num
&&
!
@dbnames
));
my
$attribs
=
read_attrib_file
(
$file
);
$port
||=
3306
;
my
$dsn
=
"
DBI:mysql:host=
$host
;port=
$port
";
...
...
@@ -55,6 +52,7 @@ print STDERR "The following databases will be external_db updated:\n ";
print
join
("
\n
",
@dbnames
);
print
"
\n
continue with update (yes/no)>
";
my
$input
=
lc
(
<
STDIN
>
);
chomp
(
$input
);
if
(
$input
ne
'
yes
')
{
...
...
@@ -62,16 +60,123 @@ if($input ne 'yes') {
exit
();
}
my
$attribs
=
read_attrib_file
(
$file
);
# if any attrib_types are loaded that are different from
# the file, a consistency problem is reported and the
# upload is not done.
for
my
$database
(
@dbnames
)
{
if
(
check_consistency
(
$attribs
,
$database
,
$db
))
{
# consistent
$db
->
do
(
"
use
$database
"
);
$db
->
do
(
"
delete from attrib_type
"
);
load_attribs
(
$db
,
$attribs
);
}
else
{
print
STDERR
"
Repairing
$database
, not consistent!
\n
";
repair
(
$attribs
,
$database
,
$db
);
}
}
# move attrib types wih the same code to the common attrib_type table
# ones that are not in the table move to an attrib_type_id that is not used
sub
repair
{
my
(
$attribs
,
$database
,
$db
)
=
@_
;
$db
->
do
(
$database
);
my
@tables
=
qw( seq_region_attrib misc_attrib translation_attrib transcript_attrib )
;
my
$ref
=
$db
->
selectall_arrayref
(
"
show create table attib_type
"
);
my
$create_table
=
$ref
->
[
0
]
->
[
0
];
$db
->
do
(
"
alter table attrib_type rename old_attrib_type
"
);
$db
->
do
(
$create_table
);
load_attribs
(
$db
,
$attribs
);
$db
->
do
(
"
delete old_attrib_type
"
.
"
from old_attrib_type oat, attrib_type at
"
.
"
where oat.attrib_type_id = at.attrib_type_id
"
.
"
and oat.code = at.code
"
);
# only the conflicts remain in old attrib type
# move non conflicting entries out of the way to upper part of
# attrib_type table
$db
->
do
(
"
create table tmp_attrib_types
"
.
"
select oat.attrib_type_id, oat.code, oat.name, oat.description
"
.
"
from old_attrib_type oat
"
.
"
left join attrib_type at
"
.
"
on oat.code = at.code
"
.
"
where at.code is null
"
);
$db
->
do
(
"
insert into attrib_type( code, name, description)
"
.
"
select code, name, description
"
.
"
from tmp_attrib_types
"
);
$ref
=
$db
->
selectall_arrayref
(
"
select code from tmp_attrib_type
"
);
$db
->
do
(
"
drop table tmp_attrib_types
"
);
if
(
!
@$ref
)
{
# no problem, thats strange
print
STDERR
"
Strange condition,
$database
didnt have conflicts but
"
.
"
executed conflict code
\n
";
return
;
}
print
STDERR
"
Database
$database
has following codes different from attrib_type.txt.
\n
";
print
STDERR
join
(
"
,
",
map
{
$_
->
[
0
]
}
@$ref
),"
\n
";
# now do multi table updates on all tables
for
my
$up_table
(
@tables
)
{
$db
->
do
(
"
update
$up_table
tb, attrib_type at, old_attrib_type oat
"
.
"
set tb.attrib_type_id = at.attrib_type_id
"
.
"
where tb.attrib_type_id = oat.attrib_type_id
"
.
"
and oat.code = at.code
"
);
}
}
sub
load_attribs
{
my
(
$db
,
$attribs
)
=
@_
;
my
$sth
;
$sth
=
$db
->
prepare
(
"
insert into attrib_type( attrib_type_id, code, name, description)
"
.
"
values(?,?,?,?)
"
);
for
my
$attrib
(
@$attribs
)
{
$sth
->
execute
(
$attrib
->
{'
attrib_type_id
'},
$attrib
->
{'
code
'},
$attrib
->
{'
name
'},
$attrib
->
{'
description
'}
);
}
}
# alternatively consistency can be enforceed to a certain degree
sub
check_consistency
{
my
$attribs
=
shift
;
my
$database
_names
=
shift
;
my
$database
=
shift
;
my
$db
=
shift
;
my
(
%db_codes
,
%file_codes
);
map
{
$file_codes
{
$_
->
{'
attrib_type_id
'}}
=
$_
->
{'
code
'}}
@$attribs
;
$db
->
do
(
"
use
$database
"
);
my
$sth
=
$db
->
prepare
(
"
SELECT attrib_type_id, code, name, description
"
.
"
FROM attrib_type
"
);
$sth
->
execute
();
while
(
my
$arr
=
$sth
->
fetchrow_arrayref
()
)
{
$db_codes
{
$arr
->
[
0
]
}
=
$arr
->
[
1
];
}
# check if any ids in the database colide with the file
my
$consistent
=
1
;
for
my
$dbid
(
keys
%db_codes
)
{
if
(
!
exists
$file_codes
{
$dbid
}
||
$file_codes
{
$dbid
}
ne
$db_codes
{
$dbid
}
)
{
$consistent
=
0
;
}
}
return
$consistent
;
}
...
...
@@ -102,4 +207,25 @@ sub read_attrib_file {
return
\
@rows
;
}
sub
usage
{
GetOptions
(
"
host=s
",
\
$host
,
"
user=s
",
\
$user
,
"
pass=s
",
\
$pass
,
"
port=i
",
\
$port
,
"
file=s
",
\
$file
,
"
dbnames=s@
",
\
@dbnames
,
"
release_num=i
",
\
$release_num
);
print
STDERR
<<EOC
Usage perl upload_attributes.pl -host .. -user .. -port .. -pass ..
and either -dbnames homo_sap_1 -dbname homo_sap_2 -dbnames .....
or -relase_num ..
put -file .. if its not the default
attrib_type.txt right next to this script
EOC
;
exit
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment