Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Emmanuel QUEVILLON
BIGSdb
Commits
f5e79710
Commit
f5e79710
authored
Jan 14, 2015
by
Keith Jolley
Browse files
Refactor CurateProfileAddPage::profile_exists.
Use existing scheme view.
parent
f4733341
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/BIGSdb/CurateProfileAddPage.pm
View file @
f5e79710
#Written by Keith Jolley
#Written by Keith Jolley
#Copyright (c) 2010-201
4
, University of Oxford
#Copyright (c) 2010-201
5
, University of Oxford
#E-mail: keith.jolley@zoo.ox.ac.uk
#E-mail: keith.jolley@zoo.ox.ac.uk
#
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
...
@@ -231,37 +231,27 @@ sub _upload {
...
@@ -231,37 +231,27 @@ sub _upload {
sub
profile_exists
{
sub
profile_exists
{
my
(
$self
,
$scheme_id
,
$primary_key
,
$newdata
)
=
@_
;
my
(
$self
,
$scheme_id
,
$primary_key
,
$newdata
)
=
@_
;
my
(
$profile_exists
,
$msg
);
my
(
$profile_exists
,
$msg
);
my
$
qry
=
"
SELECT profiles.profile_id FROM profiles LEFT JOIN profile_members ON profiles.
scheme_id
=
"
my
$
scheme_view
=
$self
->
{'
datastore
'}
->
materialized_view_exists
(
$scheme_id
)
?
"
mv_scheme_
$scheme_id
"
:
"
scheme_
$
scheme_id
"
;
.
"
profile_members.scheme_id AND profiles.profile_id = profile_members.profile_id WHERE profiles.scheme_id=
$scheme_id
AND
";
my
$qry
=
"
SELECT
$primary_key
FROM
$scheme_view
WHERE
";
my
$loci
=
$self
->
{'
datastore
'}
->
get_scheme_loci
(
$scheme_id
);
my
$loci
=
$self
->
{'
datastore
'}
->
get_scheme_loci
(
$scheme_id
);
my
(
@locus_temp
,
@values
);
my
(
@locus_temp
,
@values
);
foreach
my
$locus
(
@$loci
)
{
foreach
my
$locus
(
@$loci
)
{
next
if
$newdata
->
{"
locus:
$locus
"}
eq
'
N
';
#N can be any allele so can not be used to differentiate profiles
next
if
$newdata
->
{"
locus:
$locus
"}
eq
'
N
';
#N can be any allele so can not be used to differentiate profiles
(
my
$cleaned
=
$locus
)
=~
s/'/
\\'
/g
;
(
my
$cleaned
=
$locus
)
=~
s/'/
_PRIME_
/g
;
push
@locus_temp
,
"
(
locus=E'
$cleaned
' AND (allele_id=? OR allele_i
d='N')
)
";
push
@locus_temp
,
"
(
$cleaned
=? OR
$cleane
d
='N')
";
push
@values
,
$newdata
->
{"
locus:
$locus
"};
push
@values
,
$newdata
->
{"
locus:
$locus
"};
}
}
local
$"
=
'
OR
';
local
$"
=
'
AND
';
$qry
.=
"
(
@locus_temp
)
";
$qry
.=
"
(
@locus_temp
)
";
$qry
.=
'
GROUP BY profiles.profile_id having count(*)=
'
.
scalar
@locus_temp
;
#This may be called many times for batch inserts so cache query statements
my
$qry_hash
=
Digest::MD5::
md5_hex
(
$qry
);
if
(
!
$self
->
{'
cache
'}
->
{'
sql
'}
->
{
$qry_hash
}
)
{
$self
->
{'
cache
'}
->
{'
sql
'}
->
{
$qry_hash
}
=
$self
->
{'
db
'}
->
prepare
(
$qry
);
}
if
(
@locus_temp
)
{
if
(
@locus_temp
)
{
eval
{
$self
->
{'
cache
'}
->
{'
sql
'}
->
{
$qry_hash
}
->
execute
(
@values
)
};
my
$matching_profiles
=
$logger
->
error
(
$@
)
if
$@
;
$self
->
{'
datastore
'}
my
@matching_profiles
;
->
run_query
(
$qry
,
\
@values
,
{
fetch
=>
'
col_arrayref
',
cache
=>
"
CurateProfileAddPage:profile_exists::
$scheme_id
"
}
);
while
(
my
(
$match
)
=
$self
->
{'
cache
'}
->
{'
sql
'}
->
{
$qry_hash
}
->
fetchrow_array
)
{
push
@matching_profiles
,
$match
;
}
$newdata
->
{"
field:
$primary_key
"}
//
=
'';
$newdata
->
{"
field:
$primary_key
"}
//
=
'';
if
(
@matching_profiles
&&
!
(
@matching_profiles
==
1
&&
$matching_profiles
[
0
]
eq
$newdata
->
{"
field:
$primary_key
"}
)
)
{
if
(
@
$
matching_profiles
&&
!
(
@
$
matching_profiles
==
1
&&
$matching_profiles
->
[
0
]
eq
$newdata
->
{"
field:
$primary_key
"}
)
)
{
if
(
@locus_temp
<
@$loci
)
{
if
(
@locus_temp
<
@$loci
)
{
my
$first_match
;
my
$first_match
;
foreach
(
@matching_profiles
)
{
foreach
(
@
$
matching_profiles
)
{
if
(
$_
ne
$newdata
->
{"
field:
$primary_key
"}
)
{
if
(
$_
ne
$newdata
->
{"
field:
$primary_key
"}
)
{
$first_match
=
$_
;
$first_match
=
$_
;
last
;
last
;
...
@@ -269,14 +259,14 @@ sub profile_exists {
...
@@ -269,14 +259,14 @@ sub profile_exists {
}
}
$msg
.=
"
Profiles containing an arbitrary allele (N) at a particular locus may match profiles with actual values at
"
$msg
.=
"
Profiles containing an arbitrary allele (N) at a particular locus may match profiles with actual values at
"
.
"
that locus and cannot therefore be defined. This profile matches
$primary_key
-
$first_match
";
.
"
that locus and cannot therefore be defined. This profile matches
$primary_key
-
$first_match
";
my
$other_matches
=
@matching_profiles
-
1
;
my
$other_matches
=
@
$
matching_profiles
-
1
;
$other_matches
--
if
(
any
{
$newdata
->
{"
field:
$primary_key
"}
eq
$_
}
@matching_profiles
);
#if updating don't match to self
$other_matches
--
if
(
any
{
$newdata
->
{"
field:
$primary_key
"}
eq
$_
}
@
$
matching_profiles
);
#if updating don't match to self
if
(
$other_matches
)
{
if
(
$other_matches
)
{
$msg
.=
"
and
$other_matches
other
"
.
(
$other_matches
>
1
?
'
s
'
:
''
);
$msg
.=
"
and
$other_matches
other
"
.
(
$other_matches
>
1
?
'
s
'
:
''
);
}
}
$msg
.=
'
.
';
$msg
.=
'
.
';
}
else
{
}
else
{
$msg
.=
"
This allelic profile has already been defined as
$primary_key
-
$matching_profiles
[0].
";
$msg
.=
"
This allelic profile has already been defined as
$primary_key
-
$matching_profiles
->
[0].
";
}
}
$profile_exists
=
1
;
$profile_exists
=
1
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment