seedlot upload with accession synonyms. seedlot upload works to update existing seedlots
[sgn.git] / lib / SGN / Controller / Bulk / Download.pm
blobb366b1ff5908dae358c1deade8a7c41d0c83fcee
2 package SGN::Controller::Bulk::Download;
4 use Moose;
6 BEGIN { extends 'Catalyst::Controller' };
8 use Data::Dumper;
9 use File::Slurp qw | read_file |;
10 use Cache::File;
11 use File::Spec::Functions;
13 use CXGN::Bulk::BAC;
14 use CXGN::Bulk::UnigeneConverter;
15 use CXGN::Bulk::UnigeneIDUnigene;
16 use CXGN::Bulk::BACEndRaw;
17 use CXGN::Bulk::BACEndTrim;
18 use CXGN::Bulk::CloneEST;
19 use CXGN::Bulk::CloneUnigene;
20 use CXGN::Bulk::ArraySpotEST;
21 use CXGN::Bulk::ArraySpotUnigene;
22 use CXGN::Bulk::UnigeneMemberInfo;
23 use CXGN::Bulk::Converter;
25 sub download : Path('/tools/bulk/download') Args(0) {
26 my $self = shift;
27 my $c = shift;
29 my $params = $c->req->params();
31 print STDERR "PARAMS: ".Data::Dumper::Dumper($params);
33 _invalid_params($c) unless $params->{idType};
35 $params->{dbc} = $c->dbc->dbh();
36 $params->{tempdir} = $c->path_to( $c->tempfiles_subdir('bulk') );
38 #create correct bulk object
39 my $bulk;
40 my $idType = $params->{idType};
41 if ( $idType eq "bac" ) {
42 $bulk = CXGN::Bulk::BAC->new($params);
44 elsif ( $idType eq "bac_end" ) {
45 if ( $params->{bac_seq_type} eq "raw_seq" ) {
46 $bulk = CXGN::Bulk::BACEndRaw->new($params);
48 elsif ( $params->{bac_seq_type} eq "trim_seq" ) {
49 $bulk = CXGN::Bulk::BACEndTrim->new($params);
52 elsif ( $idType eq "clone" ) {
53 if ( $params->{seq_type} eq "est_seq" ) {
54 $bulk = CXGN::Bulk::CloneEST->new($params);
56 elsif ( $params->{seq_type} eq "unigene_seq" ) {
57 $bulk = CXGN::Bulk::CloneUnigene->new($params);
60 elsif ( $idType eq "microarray" ) {
61 if ( $params->{seq_type} eq "est_seq" ) {
62 $bulk = CXGN::Bulk::ArraySpotEST->new($params);
64 elsif ( $params->{seq_type} eq "unigene_seq" ) {
65 $bulk = CXGN::Bulk::ArraySpotUnigene->new($params);
68 elsif ( $idType eq "unigene_convert" ) {
70 elsif ( $idType eq "unigene" ) {
71 if ( $params->{unigene_mode} eq "unigene_info" ) {
72 $bulk = CXGN::Bulk::UnigeneIDUnigene->new($params);
74 elsif ( $params->{unigene_mode} eq "member_info" ) {
75 $bulk = CXGN::Bulk::UnigeneMemberInfo->new($params);
77 } elsif($idType eq "converter") {
78 my @files = split /\s+/, $c->config->{solyc_conversion_files};
79 $params->{solyc_conversion_files} = \@files;
81 if ($params->{converter_type} eq "unigene_solyc_converter") {
82 print STDERR "CREATING UnigeneConverter object\n";
83 $bulk = CXGN::Bulk::Converter->new($params);
85 elsif ($params->{converter_type} eq "unigene_version_converter") {
86 print STDERR "CREATING Converter object\n";
87 $bulk = CXGN::Bulk::UnigeneConverter->new($params);
90 else {
91 die "Don't know about converter type $params->{converter_type}";
94 else {
95 die "invalid idtype '$idType'";
98 if ( $bulk->process_parameters() ) {
99 $bulk->process_ids();
100 $bulk->create_dumpfile();
102 my $dumpfile = $bulk->get_dumpfile();
103 my $notfoundfile = $bulk->get_notfoundfile();
105 $bulk->result_summary();
107 $c->forward("Bulk::Display", "display_summary_page", [ $dumpfile ]);
109 else {
110 $c->stash->{message} = $bulk->error_message();
111 $c->stash->{template} = '/generic_message.mas';
115 =head2 get_parameters
117 Desc: sub get_parameters
118 Args: array; example: get_parameters($ARGV[0]);
119 Ret : modified parameter array
121 Retrives parameters from CXGN::Page object (passed from the user).
123 =cut
125 sub get_parameters {
126 my $self = shift;
127 my $c = shift;
129 my $params = {};
130 $params->{idType} = $c->req->param("idType");
131 $params->{outputType} = $c->req->param("outputType");
132 $params->{debug} = $c->req->param("debug");
133 $params->{fasta} = $c->req->param("fasta");
134 $params->{seq_type} = $c->req->param("seq_type") || '';
135 $params->{build_id} = $c->req->param("build_id") || '';
136 $params->{automatic_annotation} = $c->req->param("automatic_annotation");
137 $params->{best_arabidopsis_match} =
138 $c->req->param("best_arabidopsis_match");
139 $params->{best_genbank_match} = $c->req->param("best_genbank_match");
140 $params->{manual_annotation} = $c->req->param("manual_annotation");
142 # the file name of the file used in the upload:
143 $params->{file} = $c->req->param("file");
145 # the name of the dumpfile, if available:
146 $params->{dumpfile} = $c->req->param("dumpfile");
147 $params->{page_number} = $c->req->param("page_number");
149 # if this is true, the summary page is displayed again.
150 $params->{summary} = $c->req->param("summary");
151 ### Build id to deal with: $params->{build_id}
152 ### seq_type:$params->{seq_type}
153 $params->{group_by_unigene} = $c->req->param("group_by_unigene");
154 $params->{unigene_mode} = $c->req->param("unigene_mode");
155 $params->{associated_loci} = $c->req->param("associated_loci");
156 $params->{sequence} = $c->req->param("sequence");
157 $params->{seq_type} = $c->req->param("seq_type");
158 $params->{unigene_seq} = $c->req->param("unigene_seq");
159 $params->{seq_mode} = $c->req->param("seq_mode");
160 $params->{est_seq} = $c->req->param("est_seq");
161 $params->{uni_seq} = $c->req->param("uni_seq");
163 # bac search parameters
164 $params->{bac_seq_type} = $c->req->param("bac_seq_type");
165 $params->{bac_id} = $c->req->param("bac_id");
166 $params->{bac_end_sequence} = $c->req->param("bac_end_sequence");
167 $params->{qual_value_seq} = $c->req->param("qual_value_seq");
168 $params->{arizona_clone_name} = $c->req->param("arizona_clone_name");
169 $params->{chr_clone_name} = $c->req->param("chr_clone_name");
170 $params->{cornell_clone_name} = $c->req->param("cornell_clone_name");
171 $params->{clone_type} = $c->req->param("clone_type");
172 $params->{org_name} = $c->req->param("org_name");
173 $params->{accession_name} = $c->req->param("accession_name");
174 $params->{library_name} = $c->req->param("library_name");
175 $params->{estimated_length} = $c->req->param("estimated_length");
176 $params->{genbank_accession} = $c->req->param("genbank_accession");
177 $params->{overgo_matches} = $c->req->param("overgo_matches");
178 $params->{SGN_S} = $c->req->param("SGN_S");
179 $params->{SGN_C} = $c->req->param("SGN_C");
180 $params->{SGN_T} = $c->req->param("SGN_T");
181 $params->{SGN_E} = $c->req->param("SGN_E");
182 $params->{SGN_U} = $c->req->param("SGN_U");
183 $params->{chipname} = $c->req->param("chipname");
184 $params->{TUS} = $c->req->param("TUS");
185 $params->{clone_name} = $c->req->param("clone_name");
186 $params->{build_nr} = $c->req->param("build_nr");
187 $params->{evalue} = $c->req->param("evalue");
188 $params->{SGN_U_U} = $c->req->param("SGN_U_U");
189 $params->{SGN_U_M} = $c->req->param("SGN_U_M");
190 $params->{convert_to_current} = $c->req->param("convert_to_current");
192 # add a new line so that the first id from the file upload is separated
193 # from the last id here, only if user submits ids in field and as file.
195 if ( $c->req->param("ids") =~ /\S/ ) {
196 $params->{ids_string} = $c->req->param("ids") . "\n";
199 # get an upload object to upload a file
200 my $upload = $c->req->upload();
202 # if there is a file add it to the ids_string
203 if ( defined $upload ) {
204 my $fh = $upload->fh;
205 if ($fh) {
206 ### Uploading file...
207 while (<$fh>) {
208 $params->{ids} .= $_;
213 ### size of uploaded ids_string: length $params->{ids_string}
215 return $params;
219 sub post_only {
220 my ($page) = @_;
221 $page->error_page('This page can only accept HTTP POST requests. Please go to <a href="input.pl">Bulk Download</a> to make your selections.');
224 sub _invalid_params {
225 my $self =shift;
226 my $c = shift;
228 $c->throw(
229 title => "An Error has occured",
230 message => "ID Type must be provided",
231 notify => 0,
232 is_error => 0,
238 =head1 BUGS
240 None known.
242 =head1 AUTHOR
244 based on original bulk download script by Lukas Mueller
245 August 12, 2003
247 Modified August 11, 2005 by
248 Summer Intern Caroline N. Nyenke
250 Modified July 7, 2006
251 Summer Intern Emily Hart
253 Alexander Naydich and Matthew Crumb (interns)
254 July 3, 2007
256 Refactored as a Catalyst Controller
257 Lukas, Nov 2013
259 =head1 SEE ALSO
261 /bulk/display.pl
262 /bulk/input.pl
264 =cut