Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
ocean_atlas
OGA
Commits
cdb301d1
Commit
cdb301d1
authored
Nov 22, 2022
by
nlezzoche
Browse files
Merge branch 'oga_dev'
parents
e901621f
dd2e2339
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
app/Http/Controllers/API/APIController.php
View file @
cdb301d1
...
...
@@ -40,6 +40,26 @@ class APIController extends Controller{
public
function
show
(
Request
$request
){
return
$request
;
}
public
function
gunzipFile
(
$in_filepath
,
$out_filepath
){
// Raising this value may increase performance
$buffer_size
=
4096
;
// read 4kb at a time
// Open our files (in binary mode)
$file
=
gzopen
(
$in_filepath
,
'rb'
);
$out_file
=
fopen
(
$out_filepath
,
'wb'
);
// Keep repeating until the end of the input file
while
(
!
gzeof
(
$file
))
{
// Read buffer-size bytes
// Both fwrite and gzread and binary-safe
fwrite
(
$out_file
,
gzread
(
$file
,
$buffer_size
));
}
// Files are done, close files
fclose
(
$out_file
);
gzclose
(
$file
);
}
public
function
store
(
Request
$request
){
$this
->
uniqid
=
uniqid
();
...
...
@@ -80,46 +100,53 @@ class APIController extends Controller{
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"Invalid Pfam_id"
));
return
response
()
->
json
(
$json
);
}
$url_HMM
=
'http://
pfam.xfam.org/family
/'
.
$Pfam_id
.
'
/
hmm'
;
$
ch
=
curl_init
(
);
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url_HMM
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_
USERAGENT
,
'OGA'
);
//User Agent pour ne pas être identifié en tant que bot malicieux
curl_setopt
(
$ch
,
CURLOPT_
COOKIESESSION
,
true
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
if
(
curl_exec
(
$ch
)
===
false
){
$url_HMM
=
'http
s
://
www.ebi.ac.uk/interpro/api/entry/pfam
/'
.
$Pfam_id
.
'
?annotation=
hmm'
;
$
gz_file_path
=
$this
->
tempFilePath
(
$this
->
uniqid
,
$Pfam_id
,
'.gz'
,
__METHOD__
,
0
);
$ch
=
curl_init
(
$url_HMM
);
$fp
=
fopen
(
$gz_file_path
,
"w"
);
curl_setopt
(
$ch
,
CURLOPT_
FILE
,
$fp
);
curl_setopt
(
$ch
,
CURLOPT_
HEADER
,
0
);
$resp
=
curl_exec
(
$ch
);
if
(
$resp
===
false
){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
curl_error
(
$ch
)));
return
response
()
->
json
(
$json
);
}
$filehmm
=
curl_exec
(
$ch
);
$size
=
curl_getinfo
(
$ch
,
CURLINFO_SIZE_DOWNLOAD
);
if
(
$size
>
104857600
){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"415"
,
"title"
=>
"The HMM file is too large (100 MB max)"
));
return
response
()
->
json
(
$json
);
}
curl_close
(
$ch
);
$error
=
"***ERROR**"
;
if
(
strpos
(
$filehmm
,
$error
)){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"The Pfam ID is invalid"
));
return
response
()
->
json
(
$json
);
}
if
(
!
isset
(
$filehmm
)){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"No HMM file"
));
return
response
()
->
json
(
$json
);
}
$verif1
=
"HMM"
;
$verif2
=
"NAM"
;
$pos1
=
strpos
(
$filehmm
,
$verif1
);
$pos2
=
strpos
(
$filehmm
,
$verif2
);
if
(
$pos1
===
false
||
$pos2
===
false
){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"The HMM file is invalid"
));
return
response
()
->
json
(
$json
);
curl_close
(
$ch
);
$hmm_file_path
=
str_replace
(
'.gz'
,
''
,
$gz_file_path
);
$this
->
gunzipFile
(
$gz_file_path
,
$hmm_file_path
);
$file
=
fopen
(
$hmm_file_path
,
'r'
);
$contents
=
fread
(
$file
,
filesize
(
$hmm_file_path
));
if
(
$file
){
$error
=
"***ERROR**"
;
if
(
strpos
(
$contents
,
$error
)){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"The Pfam ID is invalid"
));
return
response
()
->
json
(
$json
);
}
$verif1
=
"HMM"
;
$verif2
=
"NAM"
;
$pos1
=
strpos
(
$contents
,
$verif1
);
$pos2
=
strpos
(
$contents
,
$verif2
);
if
(
$pos1
===
false
||
$pos2
===
false
){
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"The HMM file is invalid"
));
return
response
()
->
json
(
$json
);
}
}
else
{
$json
=
array
(
"errors"
=>
array
(
"status"
=>
"400"
,
"title"
=>
"The HMM file cannot be opened"
));
return
response
()
->
json
(
$json
);
}
$hmm_file_path
=
$this
->
tempFilePath
(
$this
->
uniqid
,
$Pfam_id
,
'.hmm'
,
__METHOD__
,
0
);
$hmm_file_name
=
$Pfam_id
.
'.hmm'
;
file_put_contents
(
$hmm_file_path
,
file_get_contents
(
$url_HMM
));
fclose
(
$file
);
$hmm_header
=
implode
(
''
,
array_slice
(
file
(
$hmm_file_path
),
0
,
20
));
$header_seq
=
""
;
$hmm_file_name
=
''
;
$seq
=
""
;
$bioseq
=
""
;
...
...
@@ -178,8 +205,9 @@ class APIController extends Controller{
//command line for analyzeManage
//$mapProcess = new Process("nohup php ../artisan analyze:oga $this->uniqid > $mapErr 2>&1 &");
$mapProcess
=
new
Process
([
"nohup"
,
"php"
,
"../artisan
analyze:oga"
,
$this
->
uniqid
]);
$mapProcess
=
new
Process
([
"nohup"
,
"php"
,
"../artisan
"
,
"
analyze:oga"
,
$this
->
uniqid
]);
$mapProcess
->
run
();
$mapProcess
->
setTimeout
(
null
);
if
(
!
$mapProcess
->
isSuccessful
())
{
throw
new
ProcessFailedException
(
$mapProcess
);
...
...
@@ -200,7 +228,7 @@ class APIController extends Controller{
$qrycount
=
$dblog
->
prepare
(
"select count(*) as nb from logs where IP=? and UNIX_TIMESTAMP(subdate)>?"
);
$qrycount
->
execute
(
array
(
$ip
,
$lim
));
}
catch
(
Exception
$ex
)
{
die
(
"Error in request on logs table (APIController): "
.
$e
->
getMessage
());
die
(
"Error in request on logs table (APIController): "
.
$e
x
->
getMessage
());
}
$row
=
$qrycount
->
fetchObject
();
if
(
$row
->
nb
>
config
(
'wimg.lim_api_24h'
)
){
return
true
;}
...
...
app/Http/Controllers/MapController.php
View file @
cdb301d1
...
...
@@ -71,7 +71,49 @@ class MapController extends Controller
}
return
view
(
'form'
,[
'url'
=>
$url
,
'db_options_metaG'
=>
$db_options_metaG
,
'db_options_metaT'
=>
$db_options_metaT
,
'db_options_barcode'
=>
$db_options_barcode
]);
//return view('form',['url'=>$url,'db_options_metaG'=>$db_options_metaG]);
}
}
public
function
gunzipFile
(
$in_filepath
,
$out_filepath
){
// Raising this value may increase performance
$buffer_size
=
4096
;
// read 4kb at a time
// Open our files (in binary mode)
$file
=
gzopen
(
$in_filepath
,
'rb'
);
$out_file
=
fopen
(
$out_filepath
,
'wb'
);
// Keep repeating until the end of the input file
while
(
!
gzeof
(
$file
))
{
// Read buffer-size bytes
// Both fwrite and gzread and binary-safe
fwrite
(
$out_file
,
gzread
(
$file
,
$buffer_size
));
}
// Files are done, close files
fclose
(
$out_file
);
gzclose
(
$file
);
}
public
function
checkHmmFile
(
$filepath
,
$url
){
$file
=
fopen
(
$filepath
,
'r'
);
$contents
=
fread
(
$file
,
filesize
(
$filepath
));
if
(
$file
){
$error
=
"***ERROR**"
;
if
(
strpos
(
$contents
,
$error
)){
return
view
(
'error'
,
array
(
'error'
=>
"The Pfam ID is invalid"
,
'url'
=>
$url
));
}
$verif1
=
"HMM"
;
$verif2
=
"NAM"
;
$pos1
=
strpos
(
$contents
,
$verif1
);
$pos2
=
strpos
(
$contents
,
$verif2
);
if
(
$pos1
===
false
||
$pos2
===
false
){
return
view
(
'error'
,
array
(
'error'
=>
"The HMM file is invalid"
,
'url'
=>
$url
));
}
}
else
{
return
view
(
'error'
,
array
(
'error'
=>
"The HMM file cannot be opened"
,
'url'
=>
$url
));
}
fclose
(
$file
);
}
public
function
results
(
Request
$request
)
...
...
@@ -252,40 +294,32 @@ class MapController extends Controller
}
else
if
(
$option
==
'HMM_id'
){
$tool
=
'hmmer'
;
$url_HMM
=
'http://pfam.xfam.org/family/'
.
$Pfam_id
.
'/hmm'
;
$ch
=
curl_init
();
curl_setopt
(
$ch
,
CURLOPT_URL
,
$url_HMM
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
1
);
curl_setopt
(
$ch
,
CURLOPT_USERAGENT
,
'OGA'
);
//User Agent pour ne pas être identifié en tant que bot malicieux
curl_setopt
(
$ch
,
CURLOPT_COOKIESESSION
,
true
);
curl_setopt
(
$ch
,
CURLOPT_RETURNTRANSFER
,
true
);
if
(
curl_exec
(
$ch
)
===
false
){
$url_HMM
=
'https://www.ebi.ac.uk/interpro/api/entry/pfam/'
.
$Pfam_id
.
'?annotation=hmm'
;
$gz_file_path
=
$this
->
tempFilePath
(
$this
->
uniqid
,
$Pfam_id
,
'.gz'
,
__METHOD__
,
0
);
$ch
=
curl_init
(
$url_HMM
);
$fp
=
fopen
(
$gz_file_path
,
"w"
);
curl_setopt
(
$ch
,
CURLOPT_FILE
,
$fp
);
curl_setopt
(
$ch
,
CURLOPT_HEADER
,
0
);
$resp
=
curl_exec
(
$ch
);
if
(
$resp
===
false
){
return
view
(
'error'
,
array
(
'error'
=>
curl_error
(
$ch
),
'url'
=>
$url
));
}
$filehmm
=
curl_exec
(
$ch
);
if
(
!
isset
(
$resp
)){
return
view
(
'error'
,
array
(
'error'
=>
"No HMM file"
,
'url'
=>
$url
));
}
$size
=
curl_getinfo
(
$ch
,
CURLINFO_SIZE_DOWNLOAD
);
if
(
$size
>
104857600
){
return
view
(
'error'
,
array
(
'error'
=>
"The HMM file is too large (100 MB max)"
,
'url'
=>
$url
));
}
curl_close
(
$ch
);
$error
=
"***ERROR**"
;
if
(
strpos
(
$filehmm
,
$error
)){
return
view
(
'error'
,
array
(
'error'
=>
"The Pfam ID is invalid"
,
'url'
=>
$url
));
}
if
(
!
isset
(
$filehmm
)){
return
view
(
'error'
,
array
(
'error'
=>
"No HMM file"
,
'url'
=>
$url
));
}
$verif1
=
"HMM"
;
$verif2
=
"NAM"
;
$pos1
=
strpos
(
$filehmm
,
$verif1
);
$pos2
=
strpos
(
$filehmm
,
$verif2
);
if
(
$pos1
===
false
||
$pos2
===
false
){
return
view
(
'error'
,
array
(
'error'
=>
"The HMM file is invalid"
,
'url'
=>
$url
));
}
$hmm_file_path
=
$this
->
tempFilePath
(
$this
->
uniqid
,
$Pfam_id
,
'.hmm'
,
__METHOD__
,
0
);
$hmm_file_name
=
$Pfam_id
.
'.hmm'
;
file_put_contents
(
$hmm_file_path
,
file_get_contents
(
$url_HMM
));
curl_close
(
$ch
);
$hmm_file_path
=
str_replace
(
'.gz'
,
''
,
$gz_file_path
);
$this
->
gunzipFile
(
$gz_file_path
,
$hmm_file_path
);
$this
->
checkHmmFile
(
$hmm_file_path
,
$url
);
$hmm_header
=
implode
(
''
,
array_slice
(
file
(
$hmm_file_path
),
0
,
20
));
}
...
...
composer.lock
View file @
cdb301d1
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
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!
Cancel
Please
register
or
sign in
to comment