seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / Project / Secretom.pm
blob1105e613d081963234ac48cefae787c47b06c88f
1 package SGN::Controller::Project::Secretom;
2 use Moose;
3 use namespace::autoclean;
4 use Carp;
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';
12 __PACKAGE__->config(
13 namespace => 'secretom',
16 has 'static_dir' => (
17 is => 'rw',
18 isa => Dir,
19 coerce => 1,
20 default => sub {
21 my $self = shift;
22 $self->_app->path_to(
23 $self->_app->config->{root},
24 )->stringify
28 =head1 NAME
30 SGN::Controller::Project::Secretom - Catalyst Controller
32 =head1 DESCRIPTION
34 Catalyst Controller.
36 =head1 METHODS
38 =cut
41 =head2 index
43 Does nothing, just forwards to the default template
44 (/secretom/index.mas), see L<Catalyst::Action::RenderView>.
46 =cut
48 sub index :Path :Args(0) {
49 my ( $self, $c ) = @_;
51 #$c->response->body('Matched SGN::Controller::Project::Secretom in Project::Secretom.');
54 =head2 default
56 Just forwards to the template indicated by the request path.
58 =cut
60 sub default :Path {
61 my ( $self, $c, @args ) = @_;
62 my $path = join '/', $self->action_namespace, @args;
64 $c->stash->{template} = my $comp_name = "$path.mas";
66 $c->throw_404
67 unless $c->view('Mason')->component_exists( $comp_name );
70 =head2 auto
72 Sets some config needed by the templates.
74 =cut
76 sub auto :Private {
77 my ( $self, $c, @args ) = @_;
79 # set the root dir for secretom static files. used by some of the
80 # templates.
81 $c->stash->{static_dir} = $self->static_dir;
82 $c->stash->{signalp_search_action} = $c->uri_for( $self->action_for('signalp_search') );
85 =head2 signalp_search
87 Conduct a search of the signalp results.
89 GET params:
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.
96 =cut
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} = [
106 "Locus name",
107 "Annotation",
108 "Protein length",
109 "Molecular weight",
110 "SignalP-nn Dscore",
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,_)",
117 "SecreTary score",
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.
132 =cut
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},,
145 @{$c->stash->{data}}
149 sub _search_signalp_file {
150 my ( $self, $query, $file ) = @_;
152 # normalize and compile query
153 $query = lc $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;
159 $query = qr|$query|;
161 my $fh;
162 # open $fh, "gunzip -c '$file' |" or die "$! unzipping $file";
164 open ($fh, "<", $file) or carp "Failed to open file: $file for reading.\n";
166 my @results;
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)[
172 0, # id
173 1, # protein length
174 4, # Molecular weight
175 5, # Annotation
176 6, # SPnn Dscore
177 7, # SPnn prediction
178 8, # SPnn signal peptide predicted length
179 9, # SPhmm sp score
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;
193 return @results;
197 =head1 AUTHOR
199 Robert Buels
201 =head1 LICENSE
203 This library is free software. You can redistribute it and/or modify
204 it under the same terms as Perl itself.
206 =cut
208 __PACKAGE__->meta->make_immutable;