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
92fb8fc7
Commit
92fb8fc7
authored
Jan 15, 2015
by
Keith Jolley
Browse files
Remove use of deprecated SQL methods.
Source formatting.
parent
1c8a3177
Changes
6
Hide whitespace changes
Inline
Side-by-side
lib/BIGSdb/BatchProfileQueryPage.pm
View file @
92fb8fc7
#Written by Keith Jolley
#Copyright (c) 2010-201
3
, University of Oxford
#Copyright (c) 2010-201
5
, University of Oxford
#E-mail: keith.jolley@zoo.ox.ac.uk
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
...
...
@@ -52,7 +52,7 @@ sub print_content {
my
$desc
=
$self
->
get_db_description
;
if
(
$self
->
{'
system
'}
->
{'
dbtype
'}
ne
'
sequences
'
)
{
say
"
<h1>Batch profile query -
$desc
</h1>
";
say
"
<div class=
\
"
box
\
"
id=
\
"
statusbad
\
"
><p>This function is only available for sequence definition databases.</p></div>
"
;
say
qq(
<div class="box" id="statusbad"><p>This function is only available for sequence definition databases.</p></div>
)
;
return
;
}
say
"
<h1>Batch profile query -
$desc
</h1>
";
...
...
@@ -68,9 +68,9 @@ sub print_content {
my
$profiles
=
$q
->
param
('
profiles
');
my
@rows
=
split
/\n/
,
$profiles
;
local
$"
=
'
</th><th>
';
say
"
<div class=
\
"
box
\
"
id=
\
"
resultstable
\
"
>
"
;
say
"
<div class=
\
"
scrollable
\
"
>
"
;
say
"
<table class=
\
"
resultstable
\
"
><tr><th>Isolate</th><th>
@cleaned_loci
</th>
"
;
say
qq(
<div class="box" id="resultstable">
)
;
say
qq(
<div class="scrollable">
)
;
say
qq(
<table class="resultstable"><tr><th>Isolate</th><th>@cleaned_loci</th>
)
;
my
$scheme_fields
=
$self
->
{'
datastore
'}
->
get_scheme_fields
(
$scheme_id
);
foreach
my
$field
(
@$scheme_fields
)
{
my
$cleaned
=
$field
;
...
...
@@ -86,7 +86,6 @@ sub print_content {
my
$scheme_info
=
$self
->
{'
datastore
'}
->
get_scheme_info
(
$scheme_id
,
{
set_id
=>
$set_id
}
);
local
$"
=
$scheme_info
->
{'
allow_missing_loci
'}
?
"
IN (?, 'N')) AND (
"
:
'
=?) AND (
';
$qry
.=
$scheme_info
->
{'
allow_missing_loci
'}
?
"
(
@cleaned_loci_db
IN (?, 'N'))
"
:
"
(
@cleaned_loci_db
=?)
";
my
$sql
=
$self
->
{'
db
'}
->
prepare
(
$qry
);
say
"
</tr>
";
my
$td
=
1
;
local
$|
=
1
;
...
...
@@ -98,12 +97,12 @@ sub print_content {
$allele
=~
s/^\s+//g
;
$allele
=~
s/\s+$//g
;
}
say
"
<tr class=
\
"
td
$td
\
"
><td>
$isolate
</td>
"
;
say
qq(
<tr class="td$td"><td>$isolate</td>
)
;
for
my
$i
(
0
..
@$loci
-
1
)
{
if
(
$profile
[
$i
]
)
{
print
"
<td>
$profile
[
$i
]</td>
";
}
else
{
print
"
<td class=
\
"
statusbad
\
"
style=
\
"
font-size:2em
\
"
>-</td>
"
;
print
qq(
<td class="statusbad" style="font-size:2em">-</td>
)
;
}
}
my
$incomplete
;
...
...
@@ -112,9 +111,7 @@ sub print_content {
while
(
@profile
>
@$loci
)
{
pop
@profile
;
}
eval
{
$sql
->
execute
(
@profile
)
};
$logger
->
error
(
$@
)
if
$@
;
@field_data
=
$sql
->
fetchrow_array
;
@field_data
=
$self
->
{'
datastore
'}
->
run_query
(
$qry
,
\
@profile
,
{
catch
=>
'
BatchProfileQueryPage::print_content
'
}
);
}
else
{
$incomplete
=
1
;
}
...
...
@@ -123,7 +120,7 @@ sub print_content {
if
(
exists
$field_data
[
$i
]
)
{
print
defined
$field_data
[
$i
]
?
"
<td>
$field_data
[
$i
]</td>
"
:
'
<td></td>
';
}
else
{
print
"
<td class=
\
"
statusbad
\
"
style=
\
"
font-size:2em
\
"
>-</td>
"
;
print
qq(
<td class="statusbad" style="font-size:2em">-</td>
)
;
}
$i
++
;
}
...
...
@@ -137,18 +134,16 @@ sub print_content {
say
"
</table>
\n
</div></div>
";
return
;
}
say
"
<div class=
\
"
box
\
"
id=
\
"
queryform
\
"
>
"
;
say
qq(
<div class="box" id="queryform">
)
;
say
$q
->
start_form
;
say
$q
->
hidden
(
$_
)
foreach
qw (db
page
scheme_id
);
local
$"
=
'
,
';
print
<<"HTML";
<p>Enter allelic profiles below in tab-delimited text format using copy and paste (for example directly from a spreadsheet).
Columns can be separated by any amount of whitespace. The first column should be an isolate identifier and the remaining
columns should comprise the allele numbers (order: @cleaned_loci). Click here for
<a href="$self->{'system'}->{'script_name'}?db=$self->{'instance'}&page=batchProfiles&function=examples&scheme_id=$scheme_id">
example data</a>. Non-numerical characters will be stripped out of the query.</p>
HTML
say
"
<fieldset style=
\"
float:left
\"
><legend>Paste in profiles</legend>
";
say
qq[<p>Enter allelic profiles below in tab-delimited text format using copy and paste (for example directly from a spreadsheet).]
.
qq[Columns can be separated by any amount of whitespace. The first column should be an isolate identifier and the remaining ]
.
qq[columns should comprise the allele numbers (order: @cleaned_loci). Click here for ]
.
qq[<a href="$self->{'system'}->{'script_name'}?db=$self->{'instance'}&page=batchProfiles&function=examples&]
.
qq[scheme_id=$scheme_id">example data</a>. Non-numerical characters will be stripped out of the query.</p>]
;
say
qq(<fieldset style="float:left"><legend>Paste in profiles</legend>)
;
say
$q
->
textarea
(
-
name
=>
'
profiles
',
-
rows
=>
10
,
-
columns
=>
80
,
-
override
=>
1
);
say
"
</fieldset>
";
$self
->
print_action_fieldset
(
{
scheme_id
=>
$scheme_id
}
);
...
...
@@ -176,20 +171,19 @@ sub _print_examples {
print
"
Invalid scheme selected.
\n
";
return
;
}
my
$loci
=
$self
->
{'
datastore
'}
->
run_list_query
(
"
SELECT locus FROM scheme_members WHERE scheme_id=? ORDER BY field_order
",
$scheme_id
);
my
$loci
=
$self
->
{'
datastore
'}
->
get_scheme_loci
(
$scheme_id
);
my
@cleaned_loci
=
@$loci
;
$_
=~
s/'/_PRIME_/g
foreach
@cleaned_loci
;
local
$"
=
'
,
';
my
$scheme_view
=
$self
->
{'
datastore
'}
->
materialized_view_exists
(
$scheme_id
)
?
"
mv_scheme_
$scheme_id
"
:
"
scheme_
$scheme_id
";
my
$
sql
=
$self
->
{'
db
'}
->
prepare
("
SELECT
@cleaned_loci
FROM
$scheme_view
ORDER BY random() LIMIT 15
");
eval
{
$sql
->
execute
};
$logger
->
error
(
$@
)
if
$@
;
my
$
data
=
$self
->
{'
datastore
'}
->
run_query
(
"
SELECT
@cleaned_loci
FROM
$scheme_view
ORDER BY random() LIMIT 15
",
undef
,
{
fetch
=>
'
all_arrayref
'
}
)
;
local
$"
=
"
\t
";
my
$i
=
1
;
while
(
my
@
profile
=
$sql
->
fetchrow_array
)
{
say
"
isolate_
$i
\t
@profile
";
foreach
my
$
profile
(
@$data
)
{
say
"
isolate_
$i
\t
@
$
profile
";
$i
++
;
}
return
;
...
...
lib/BIGSdb/CombinationQueryPage.pm
View file @
92fb8fc7
...
...
@@ -265,7 +265,8 @@ sub _run_query {
push
@loci
,
$
1
;
if
(
$values
{
$
1
}
&&
$q
->
param
(
$param
)
&&
$values
{
$
1
}
ne
$q
->
param
(
$param
)
)
{
my
$aliases
=
$self
->
{'
datastore
'}
->
run_list_query
(
"
SELECT alias FROM locus_aliases WHERE locus=? ORDER BY alias
",
$
1
);
$self
->
{'
datastore
'}
->
run_query
(
"
SELECT alias FROM locus_aliases WHERE locus=? ORDER BY alias
",
$
1
,
{
fetch
=>
'
col_arrayref
'
}
);
local
$"
=
'
,
';
push
@errors
,
"
Locus $1 has been defined with more than one value (due to an alias for this locus also being
"
.
"
used). The following alias(es) exist for this locus: @
$aliases
";
...
...
@@ -409,7 +410,7 @@ sub _run_query {
}
if
(
@errors
)
{
local
$"
=
'
<br />
';
say
"
<div class=
\
"
box
\
"
id=
\
"
statusbad
\
"
><p>Problem with search criteria:</p>
"
;
say
qq(
<div class="box" id="statusbad"><p>Problem with search criteria:</p>
)
;
say
"
<p>
@errors
</p></div>
";
}
elsif
(
$qry
!~
/^ ORDER BY/
)
{
my
@hidden_attributes
;
...
...
lib/BIGSdb/Offline/Scan.pm
View file @
92fb8fc7
...
...
@@ -230,13 +230,13 @@ sub run_script {
my
$out_of_time
;
my
$start_time
=
time
;
my
$locus_prefix
=
BIGSdb::Utils::
get_random
();
my
@
isolates_in_project
;
my
$
isolates_in_project
;
my
$file_prefix
=
BIGSdb::Utils::
get_random
();
if
(
$options
->
{'
project_id
'}
&&
BIGSdb::Utils::
is_int
(
$options
->
{'
project_id
'}
)
)
{
my
$list_ref
=
$self
->
{'
datastore
'}
->
run_list_query
(
"
SELECT isolate_id FROM project_members WHERE project_id=?
",
$options
->
{'
project_id
'}
);
@
isolate
s
_i
n_project
=
@$list_ref
;
$isolates_in_project
=
$self
->
{'
datastore
'}
->
run_query
(
"
SELECT
isolate_i
d FROM project_members WHERE project_id=?
",
$options
->
{'
project_id
'},
{
fetch
=>
'
col_arrayref
'
}
)
;
}
my
$match
=
0
;
my
$seq_filename
=
$self
->
{'
config
'}
->
{'
tmp_dir
'}
.
"
/
$options
->{'scan_job'}
\
_unique_sequences.txt
";
...
...
@@ -247,10 +247,10 @@ sub run_script {
$self
->
_write_match
(
$options
->
{'
scan_job
'},
undef
,
{
reset
=>
1
}
);
$logger
->
info
("
Scan
$self
->{'instance'}:
$options
->{'scan_job'} (
$options
->{'curator_name'}) started
");
my
$table_file
=
"
$self
->{'config'}->{'secure_tmp_dir'}/
$options
->{'scan_job'}_table.html
";
unlink
$table_file
;
#delete file if scan restarted
unlink
$table_file
;
#delete file if scan restarted
foreach
my
$isolate_id
(
@isolate_ids
)
{
next
if
$options
->
{'
project_id
'}
&&
none
{
$isolate_id
==
$_
}
@isolates_in_project
;
next
if
$options
->
{'
project_id
'}
&&
none
{
$isolate_id
==
$_
}
@
$
isolates_in_project
;
if
(
$match
>=
$options
->
{'
limit
'}
)
{
$match_limit_reached
=
1
;
$self
->
_write_status
(
$options
->
{'
scan_job
'},
"
match_limit_reached:1
"
);
...
...
lib/BIGSdb/Offline/Script.pm
View file @
92fb8fc7
#Written by Keith Jolley
#Copyright (c) 2011-201
4
, University of Oxford
#Copyright (c) 2011-201
5
, University of Oxford
#E-mail: keith.jolley@zoo.ox.ac.uk
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
...
...
@@ -93,11 +93,10 @@ sub initiate {
}
}
$self
->
set_system_overrides
;
$self
->
{'
dataConnector
'}
->
initiate
(
$self
->
{'
system
'},
$self
->
{'
config
'}
);
$self
->
db_connect
;
if
(
$self
->
{'
db
'}
)
{
$self
->
setup_datastore
;
if
(
$self
->
{'
db
'}
)
{
$self
->
setup_datastore
;
if
(
defined
$self
->
{'
options
'}
->
{'
v
'}
)
{
my
$view_exists
=
$self
->
{'
datastore
'}
...
...
@@ -219,9 +218,9 @@ sub _get_isolates_excluded_by_project {
my
(
$self
)
=
@_
;
my
@projects
=
split
(
'
,
',
$self
->
{'
options
'}
->
{'
P
'}
);
my
@isolates
;
foreach
(
@projects
)
{
next
if
!
BIGSdb::Utils::
is_int
(
$
_
);
my
$list_ref
=
$self
->
get_project_isolates
(
$
_
);
foreach
my
$project_id
(
@projects
)
{
next
if
!
BIGSdb::Utils::
is_int
(
$
project_id
);
my
$list_ref
=
$self
->
get_project_isolates
(
$
project_id
);
push
@isolates
,
@$list_ref
;
}
@isolates
=
uniq
(
@isolates
);
...
...
@@ -296,7 +295,7 @@ sub get_selected_loci {
}
else
{
$qry
=
"
$loci_qry
ORDER BY id
";
}
my
$loci
=
$self
->
{'
datastore
'}
->
run_
list_
query
(
$qry
);
my
$loci
=
$self
->
{'
datastore
'}
->
run_query
(
$qry
,
undef
,
{
fetch
=>
'
col_arrayref
'
}
);
@$loci
=
uniq
@$loci
;
my
@filtered_list
;
foreach
my
$locus
(
@$loci
)
{
...
...
@@ -309,7 +308,8 @@ sub get_selected_loci {
sub
get_project_isolates
{
my
(
$self
,
$project_id
)
=
@_
;
return
if
!
BIGSdb::Utils::
is_int
(
$project_id
);
return
$self
->
{'
datastore
'}
->
run_list_query
(
"
SELECT isolate_id FROM project_members WHERE project_id=?
",
$project_id
);
return
$self
->
{'
datastore
'}
->
run_query
(
"
SELECT isolate_id FROM project_members WHERE project_id=?
",
$project_id
,
{
fetch
=>
'
col_arrayref
'
}
);
}
sub
delete_temp_files
{
...
...
lib/BIGSdb/Offline/UpdateSchemeCaches.pm
View file @
92fb8fc7
...
...
@@ -2,7 +2,7 @@
#Create scheme profile caches in an isolate database
#
#Written by Keith Jolley
#Copyright (c) 2014, University of Oxford
#Copyright (c) 2014
-2015
, University of Oxford
#E-mail: keith.jolley@zoo.ox.ac.uk
#
#This file is part of Bacterial Isolate Genome Sequence Database (BIGSdb).
...
...
@@ -30,11 +30,11 @@ sub run_script {
die
"
No connection to database (check logs).
\n
"
if
!
defined
$self
->
{'
db
'};
die
"
This script can only be run against an isolate database.
\n
"
if
(
$self
->
{'
system
'}
->
{'
dbtype
'}
//
''
)
ne
'
isolates
';
my
$schemes
=
$self
->
{'
datastore
'}
->
run_list_query
(
"
SELECT id FROM schemes WHERE dbase_name IS NOT NULL AND dbase_table IS NOT NULL ORDER BY id
"
);
$self
->
{'
datastore
'}
->
run_query
(
"
SELECT id FROM schemes WHERE dbase_name IS NOT NULL AND dbase_table IS NOT NULL ORDER BY id
",
undef
,
{
fetch
=>
'
col_arrayref
'
}
);
foreach
my
$scheme_id
(
@$schemes
)
{
my
$scheme_info
=
$self
->
{'
datastore
'}
->
get_scheme_info
(
$scheme_id
,
{
get_pk
=>
1
}
);
if
(
!
defined
$scheme_info
->
{'
primary_key
'}
)
{
my
$scheme_info
=
$self
->
{'
datastore
'}
->
get_scheme_info
(
$scheme_id
,
{
get_pk
=>
1
}
);
if
(
!
defined
$scheme_info
->
{'
primary_key
'}
)
{
say
"
Scheme
$scheme_id
(
$scheme_info
->{'description'}) does not have a primary key - skipping.
";
next
;
}
...
...
lib/BIGSdb/QueryPage.pm
View file @
92fb8fc7
...
...
@@ -75,7 +75,7 @@ END
sub
filters_selected
{
my
(
$self
)
=
@_
;
my
$q
=
$self
->
{'
cgi
'};
my
$q
=
$self
->
{'
cgi
'};
my
%params
=
$q
->
Vars
;
return
1
if
any
{
$_
=~
/_list$/
&&
$params
{
$_
}
ne
''
}
keys
%params
;
return
1
if
$q
->
param
('
include_old
');
...
...
@@ -118,7 +118,7 @@ sub search_users {
elsif
(
$operator
eq
'
NOT contain
'
)
{
$qry
.=
"
NOT
$contains
"
}
elsif
(
$operator
eq
'
=
'
)
{
$qry
.=
$equals
}
else
{
$qry
.=
"
$suffix
$operator
'
$text
'
"
}
my
$ids
=
$self
->
{'
datastore
'}
->
run_
list_
query
(
$qry
);
my
$ids
=
$self
->
{'
datastore
'}
->
run_query
(
$qry
,
undef
,
{
fetch
=>
'
col_arrayref
'
}
);
$ids
=
[
-
999
]
if
!
@$ids
;
#Need to return an integer but not 0 since this is actually the setup user.
local
$"
=
"
' OR
$table
.
$field
= '
";
return
"
(
$table
.
$field
= '@
$ids
')
";
...
...
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