%cc
= (
all
=> 1,
nucleus
=>
'GO:0005634'
,
extracellular
=>
'GO:0005576'
,
cytoplasm
=>
'GO:0005737'
,
peroxisome
=>
'GO:0005777'
,
glycosome
=>
'GO:0020015'
,
glyoxisome
=>
'GO:0009514'
,
golgi
=>
'GO:0005794'
,
er
=>
'GO:0005783'
,
lysosome
=>
'GO:0005764'
,
endosome
=>
'GO:0005768'
,
plasma_membrane
=>
'GO:0005886'
,
);
my
$ANALYSIS_NAME
=
'ELM'
;
my
$INPUT_SPEC
=
[
{
'mandatory'
=>
'true'
,
'type'
=>
'Bio::PrimarySeqI'
,
'name'
=>
'seq'
,
},
{
'mandatory'
=>
'false'
,
'type'
=>
'taxon_id or Bio::Species object'
,
'name'
=>
'species'
,
'default'
=>
'9606'
,
},
{
'mandatory'
=>
'false'
,
'type'
=>
'string'
,
'name'
=>
'compartment'
,
'default'
=> [1],
},
];
my
$RESULT_SPEC
=
{
''
=>
'bulk'
,
'Bio::SeqFeatureI'
=>
'ARRAY of Bio::SeqFeature::Generic'
,
'parsed'
=> '{
motif1_name
=>{
locus
=>[],
peptide
=>[],
regexp
=>[]
},
}',
};
my
$ANALYSIS_SPEC
= {
name
=>
'ELM'
,
type
=>
'Protein'
,
version
=>
'n/a'
,
supplier
=>
'BioComputing Unit, EMBL'
,
description
=>'Prediction of linear functional motifs
in proteins',
reference
=>
'NAR, 31:3625-3630'
};
sub
_init {
my
$self
=
shift
;
$self
->url(
$URL
);
$self
->{
'_ANALYSIS_SPEC'
} =
$ANALYSIS_SPEC
;
$self
->{
'_INPUT_SPEC'
} =
$INPUT_SPEC
;
$self
->{
'_RESULT_SPEC'
} =
$RESULT_SPEC
;
$self
->{
'_ANALYSIS_NAME'
} =
$ANALYSIS_NAME
;
return
$self
;
}
sub
compartment {
my
(
$self
,
$arg
) =
@_
;
if
(
$arg
) {
if
(
ref
(
$arg
) ne
'ARRAY'
) {
$arg
= [
$arg
];
}
for
my
$param
(
@$arg
) {
if
(
exists
(
$cc
{
lc
(
$param
)})) {
push
@{
$self
->{
'_compartment'
}} ,
$cc
{
$param
};
}
else
{
$self
->
warn
(
"invalid argument ! Must be one of "
.
join
"\n"
,
keys
%cc
);
}
}
}
return
defined
(
$self
->{
'_compartment'
})?
$self
->{
'_compartment'
}
:
$self
->input_spec()->[2]{
'default'
};
}
sub
species {
my
(
$self
,
$arg
) =
@_
;
if
(
$arg
) {
if
(
ref
(
$arg
) &&
$arg
->isa(
'Bio::Species'
)) {
$self
->{
'_species'
} =
$arg
->ncbi_taxid();
}
elsif
(
$arg
=~ /^\d+$/) {
$self
->{
'_species'
} =
$arg
;
}
else
{
$self
->
warn
(
"Argument must be a Bio::Species object or "
.
" an integer NCBI taxon id. "
);
}
}
return
defined
(
$self
->{
'_species'
})?
$self
->{
'_species'
}
:
$self
->input_spec()->[1]{
'default'
};
}
sub
_run {
my
$self
=
shift
;
$self
->delay(1);
$self
->status(
'TERMINATED_BY_ERROR'
);
my
@cc_str
;
my
@cmpts
= @{
$self
->compartment()};
for
(
my
$i
= 0;
$i
<=
$#cmpts
;
$i
++) {
splice
@cc_str
,
@cc_str
, 0,
'userCC'
,
$cmpts
[
$i
];
}
my
%h
= (
swissprotId
=>
""
,
sequence
=>
$self
->seq->seq,
userSpecies
=>
$self
->species,
typedUserSpecies
=>
''
,
fun
=>
"Submit"
);
splice
(
@cc_str
,
@cc_str
,0, (
map
{
$_
,
$h
{
$_
}}
keys
%h
));
my
$request
= POST
$self
->url(),
Content_Type
=>
'form-data'
,
Content
=> \
@cc_str
;
$self
->debug(
$request
->as_string);
my
$r1
=
$self
->request(
$request
);
if
(
$r1
->is_error ) {
$self
->
warn
(
ref
(
$self
).
" Request Error:\n"
.
$r1
->as_string);
return
;
}
my
$text
=
$r1
->content;
my
(
$url
) =
$text
=~ /URL=\S+(fun=\S+r=\d)/s;
my
(
$resp2
);
$url
=
$URL
.
"?"
.
$url
;
while
(1) {
my
$req2
= HTTP::Request->new(
GET
=>
$url
);
my
$r2
=
$self
->request (
$req2
);
if
(
$r2
->is_error ) {
$self
->
warn
(
ref
(
$self
).
" Request Error:\n"
.
$r2
->as_string);
return
;
}
$resp2
=
$r2
->content();
if
(
$resp2
!~ /patient/s) {
$self
->status(
'COMPLETED'
);
$resp2
=~ s/<[^>]+>/ /sg;
$self
->{
'_result'
} =
$resp2
;
return
;
}
else
{
print
"."
if
$self
->verbose > 0;
$self
->
sleep
(1);
}
}
}
sub
result {
my
(
$self
,
$val
) =
@_
;
if
(
$val
) {
if
(!
exists
(
$self
->{
'_parsed'
}) ) {
$self
->_parse_raw();
}
if
(
$val
eq
'Bio::SeqFeatureI'
) {
my
@fts
;
for
my
$motif
(
keys
%{
$self
->{
'_parsed'
}}) {
for
(
my
$i
= 0;
$i
<
scalar
@{
$self
->{
'_parsed'
}{
$motif
}{
'locus'
}};
$i
++) {
my
(
$st
,
$end
) =
split
/\-/,
$self
->{
'_parsed'
}{
$motif
}{
'locus'
}[
$i
];
push
@fts
, Bio::SeqFeature::Generic->new
(
-start
=>
$st
,
-end
=>
$end
,
-primary_tag
=>
'Domain'
,
-source
=>
'ELM'
,
-tag
=> {
method
=>
'ELM'
,
motif
=>
$motif
,
peptide
=>
$self
->{
'_parsed'
}{
$motif
}{
'peptide'
}[
$i
],
concensus
=>
$self
->{
'_parsed'
}{
$motif
}{
'regexp'
}[0],
});
}
}
return
@fts
;
}
return
$self
->{
'_parsed'
};
}
return
$self
->{
'_result'
};
}
sub
_parse_raw {
my
$self
=
shift
;
my
$result
= IO::String->new(
$self
->{
'_result'
});
my
$in_results
= 0;
my
$name
;
my
%results
;
my
$last
;
while
(
my
$l
= <
$result
>) {
next
unless
$in_results
> 0 ||
$l
=~ /^\s+Elm\s+Name\s+Instances/;
$in_results
++;
last
if
$l
=~ /List of excluded/;
next
unless
$in_results
>1;
my
@line_parts
=
split
/\s+/,
$l
;
shift
@line_parts
;
if
(
scalar
@line_parts
== 1 &&
$line_parts
[0]=~ /^\s*(\w+_\w+)/) {
$name
= $1;
next
;
}
elsif
(
@line_parts
> 1) {
my
$index
= 0;
my
$read_loci
= 0;
while
(
$index
<=
$#line_parts
) {
my
$word
=
$line_parts
[
$index
++];
if
(
$read_loci
==0 &&
$word
=~/_/) {
$name
=
$word
;
}
elsif
(
$read_loci
== 0 &&
$word
=~ /^\w+$/ ) {
push
@{
$results
{
$name
}{
'peptide'
}},
$word
;
}
elsif
(
$word
=~ /\d+\-\d+/) {
$read_loci
= 1;
push
@{
$results
{
$name
}{
'locus'
}},
$word
;
}
else
{
last
;
}
}
push
@{
$results
{
$name
}{
'regexp'
}},
$line_parts
[
$#line_parts
];
}
}
$self
->{
'_parsed'
} = \
%results
;
}
1;