1 package SGN
::Controller
::Project
::Secretom
;
3 use namespace
::autoclean
;
5 use MooseX
::Types
::Path
::Class qw
| Dir
|;
7 use JSON
::Any
; my $json = JSON
::Any
->new;
9 BEGIN {extends
'Catalyst::Controller'; }
10 with
'Catalyst::Component::ApplicationAttribute';
13 namespace
=> 'secretom',
23 $self->_app->config->{root
},
30 SGN::Controller::Project::Secretom - Catalyst Controller
43 Does nothing, just forwards to the default template
44 (/secretom/index.mas), see L<Catalyst::Action::RenderView>.
48 sub index :Path
:Args
(0) {
49 my ( $self, $c ) = @_;
51 #$c->response->body('Matched SGN::Controller::Project::Secretom in Project::Secretom.');
56 Just forwards to the template indicated by the request path.
61 my ( $self, $c, @args ) = @_;
62 my $path = join '/', $self->action_namespace, @args;
64 $c->stash->{template
} = my $comp_name = "$path.mas";
67 unless $c->view('Mason')->component_exists( $comp_name );
72 Sets some config needed by the templates.
77 my ( $self, $c, @args ) = @_;
79 # set the root dir for secretom static files. used by some of the
81 $c->stash->{static_dir
} = $self->static_dir;
82 $c->stash->{signalp_search_action
} = $c->uri_for( $self->action_for('signalp_search') );
87 Conduct a search of the signalp results.
91 q - the query text search for
92 file - the file basename to search in, optional
94 Conducts a search and displayes the results as HTML.
98 sub signalp_search
:Path
('search/signalp') {
99 my ( $self, $c ) = @_;
101 my $file = $c->req->param('file');
102 $file =~ s![\\/]!!g; # no dir seps, no badness.
103 $file ||= 'AtBrRiceTomPop.tab'; # use uncompressed file for speed # 'Tair10_all.tab.gz';
104 my $abs_file = $self->static_dir->file( 'data','secretom', 'SecreTarySPTP_predictions', $file );
105 $c->stash->{headings
} = [
111 "SignalP-nn (YES if Dscore >= 0.43, NO otherwise)",
112 "SignalP-nn pred sp len",
113 "SignalP-hmm sp score",
114 "SignalP-hmm sa score",
115 "SignalP-hmm prediction (SP,SA or NS)",
116 "TargetP result (C,M,S,_)",
118 "SecreTary prediction (ST+ if score >= 0.75)"
121 $c->stash->{query
} = my $q = $c->req->param('q');
122 $c->stash->{csv_download
} = $c->uri_for( $self->action_for('signalp_search_csv'), { q
=> $q, file
=> "$file" } );
123 $c->stash->{data
} = [ $self->_search_signalp_file( $q, $abs_file ) ];
124 $c->stash->{template
} = '/secretom/signalp_search_result.mas';
128 =head1 signalp_search_csv
130 Same as signalp_search, except displays the results as CSV.
134 sub signalp_search_csv
:Path
('search/signalp/csv') {
135 my ( $self, $c ) = @_;
136 $c->forward( $self->action_for('signalp_search') );
139 $c->res->content_type('text/csv');
140 $c->res->headers->push_header( 'Content-disposition', 'attachment' );
141 $c->res->headers->push_header( 'Content-disposition', 'filename=signalp_search.csv' );
142 $c->res->body( join '', map "$_\n",
143 map { join ',', map qq|"$_"|, @
$_ }
144 $c->stash->{headings
},,
149 sub _search_signalp_file
{
150 my ( $self, $query, $file ) = @_;
152 # normalize and compile query
154 $query =~ s/ ^\s+ | \s+$ //gx; # remove initial and final whitespace
155 # $query =~ s/ [^\w\s] //gx; # removes characters which are neither
156 # word ([a-zA-Z0-9_]) or whitespace characters. But then somthing like
157 # AT1G37010.1 becomes AT1G370101 and we get no matches.
158 $query =~ s/\s+/'\s+'/ge;
162 # open $fh, "gunzip -c '$file' |" or die "$! unzipping $file";
164 open ($fh, "<", $file) or carp
"Failed to open file: $file for reading.\n";
167 while ( my $line = <$fh> ) {
168 next unless lc($line) =~ $query;
169 # choose the fields in the tab file to keep
170 $line =~ s/\s+$//; # delete whitespace at end of line.
171 my @fields = (split /\t/, $line)[
174 4, # Molecular weight
178 8, # SPnn signal peptide predicted length
180 10, # SPhmm sa (signal anchor) score
181 11, # SPhmm prediction
182 12, # TargetP prediction (C,M,S,_)
183 13, # SecreTary score (>= 0.75 -> pass)
184 14 # SecreTary prediction (pass/fail)
186 my $STpred = pop @fields;
187 $STpred = ($STpred eq 'pass')?
'ST+': 'ST-';
188 push @fields, $STpred;
190 push @results, \
@fields;
203 This library is free software. You can redistribute it and/or modify
204 it under the same terms as Perl itself.
208 __PACKAGE__
->meta->make_immutable;