Merge pull request #4505 from solgenomics/topic/fix_manual_links
[sgn.git] / cgi-bin / bulk / download.pl
blob16e780c452134e4c8a779dc5adf1098d5299994e
1 use CatalystX::GlobalContext qw( $c );
2 # refactored bulk download script for SGN database
3 # Alexander Naydich and Matthew Crumb (interns)
4 # July 3, 2007
6 ## based on original bulk download script by
7 ## Lukas Mueller
8 ## August 12, 2003
10 ## Modified August 11, 2005 by
11 ## Summer Intern Caroline N. Nyenke
13 ## Modified July 7, 2006
14 ## Summer Intern Emily Hart
16 =head1 NAME
18 /bulk/download.pl
20 =head1 DESCRIPTION
22 This perl script is used on the bulk download page. The script collects
23 identifiers submitted by the user and determines the mode the user is searching
24 in (clone, unigene, unigene_member, microarray, bac, bac_end, or unigene_convert).
25 It then uses the appropriate Bulk object to process the input, query the database,
26 format the results and display them on a separate page. Options of viewing
27 or downloading in text or fasta format are available.
29 =cut
31 use strict;
32 use warnings;
34 use CXGN::Page;
35 use CXGN::DB::Connection;
37 use CXGN::Bulk::BAC;
38 use CXGN::Bulk::UnigeneConverter;
39 use CXGN::Bulk::UnigeneIDUnigene;
40 use CXGN::Bulk::BACEndRaw;
41 use CXGN::Bulk::BACEndTrim;
42 use CXGN::Bulk::CloneEST;
43 use CXGN::Bulk::CloneUnigene;
44 use CXGN::Bulk::ArraySpotEST;
45 use CXGN::Bulk::ArraySpotUnigene;
46 use CXGN::Bulk::UnigeneMemberInfo;
49 my $page = CXGN::Page->new();
50 my $params = get_parameters($page);
52 _invalid_params() unless $params->{idType};
55 $params->{dbc} = CXGN::DB::Connection->new;
56 $params->{tempdir} = $c->path_to( $c->tempfiles_subdir('bulk') );
58 #create correct bulk object
59 my $bulk;
60 my $idType = $params->{idType};
61 if ( $idType eq "bac" ) {
62 $bulk = CXGN::Bulk::BAC->new($params);
64 elsif ( $idType eq "bac_end" ) {
65 if ( $params->{bac_seq_type} eq "raw_seq" ) {
66 $bulk = CXGN::Bulk::BACEndRaw->new($params);
68 elsif ( $params->{bac_seq_type} eq "trim_seq" ) {
69 $bulk = CXGN::Bulk::BACEndTrim->new($params);
72 elsif ( $idType eq "clone" ) {
73 if ( $params->{seq_type} eq "est_seq" ) {
74 $bulk = CXGN::Bulk::CloneEST->new($params);
76 elsif ( $params->{seq_type} eq "unigene_seq" ) {
77 $bulk = CXGN::Bulk::CloneUnigene->new($params);
80 elsif ( $idType eq "microarray" ) {
81 if ( $params->{seq_type} eq "est_seq" ) {
82 $bulk = CXGN::Bulk::ArraySpotEST->new($params);
84 elsif ( $params->{seq_type} eq "unigene_seq" ) {
85 $bulk = CXGN::Bulk::ArraySpotUnigene->new($params);
88 elsif ( $idType eq "unigene_convert" ) {
89 $bulk = CXGN::Bulk::UnigeneConverter->new($params);
91 elsif ( $idType eq "unigene" ) {
92 if ( $params->{unigene_mode} eq "unigene_info" ) {
93 $bulk = CXGN::Bulk::UnigeneIDUnigene->new($params);
95 elsif ( $params->{unigene_mode} eq "member_info" ) {
96 $bulk = CXGN::Bulk::UnigeneMemberInfo->new($params);
98 } else {
99 die "invalid idtype '$idType'";
102 if ( $bulk->process_parameters() ) {
103 $bulk->process_ids();
104 #die "process 2 ($bulk)" ;
105 $bulk->result_summary_page($page);
107 else {
108 $bulk->error_message();
110 $bulk->clean_up();
112 exit;
114 =head2 get_parameters
116 Desc: sub get_parameters
117 Args: array; example: get_parameters($ARGV[0]);
118 Ret : modified parameter array
120 Retrives parameters from CXGN::Page object (passed from the user).
122 =cut
124 sub get_parameters {
126 my $page = shift;
128 my $params = { page => $page };
129 $params->{idType} = $page->get_arguments("idType");
130 $params->{outputType} = $page->get_arguments("outputType");
131 $params->{debug} = $page->get_arguments("debug");
132 $params->{fasta} = $page->get_arguments("fasta");
133 $params->{seq_type} = $page->get_arguments("seq_type") || '';
134 $params->{build_id} = $page->get_arguments("build_id") || '';
135 $params->{automatic_annotation} = $page->get_arguments("automatic_annotation");
136 $params->{best_arabidopsis_match} =
137 $page->get_arguments("best_arabidopsis_match");
138 $params->{best_genbank_match} = $page->get_arguments("best_genbank_match");
139 $params->{manual_annotation} = $page->get_arguments("manual_annotation");
141 # the file name of the file used in the upload:
142 $params->{file} = $page->get_arguments("file");
144 # the name of the dumpfile, if available:
145 $params->{dumpfile} = $page->get_arguments("dumpfile");
146 $params->{page_number} = $page->get_arguments("page_number");
148 # if this is true, the summary page is displayed again.
149 $params->{summary} = $page->get_arguments("summary");
150 ### Build id to deal with: $params->{build_id}
151 ### seq_type:$params->{seq_type}
152 $params->{group_by_unigene} = $page->get_arguments("group_by_unigene");
153 $params->{unigene_mode} = $page->get_arguments("unigene_mode");
154 $params->{associated_loci} = $page->get_arguments("associated_loci");
155 $params->{sequence} = $page->get_arguments("sequence");
156 $params->{seq_type} = $page->get_arguments("seq_type");
157 $params->{unigene_seq} = $page->get_arguments("unigene_seq");
158 $params->{seq_mode} = $page->get_arguments("seq_mode");
159 $params->{est_seq} = $page->get_arguments("est_seq");
160 $params->{uni_seq} = $page->get_arguments("uni_seq");
162 # bac search parameters
163 $params->{bac_seq_type} = $page->get_arguments("bac_seq_type");
164 $params->{bac_id} = $page->get_arguments("bac_id");
165 $params->{bac_end_sequence} = $page->get_arguments("bac_end_sequence");
166 $params->{qual_value_seq} = $page->get_arguments("qual_value_seq");
167 $params->{arizona_clone_name} = $page->get_arguments("arizona_clone_name");
168 $params->{chr_clone_name} = $page->get_arguments("chr_clone_name");
169 $params->{cornell_clone_name} = $page->get_arguments("cornell_clone_name");
170 $params->{clone_type} = $page->get_arguments("clone_type");
171 $params->{org_name} = $page->get_arguments("org_name");
172 $params->{accession_name} = $page->get_arguments("accession_name");
173 $params->{library_name} = $page->get_arguments("library_name");
174 $params->{estimated_length} = $page->get_arguments("estimated_length");
175 $params->{genbank_accession} = $page->get_arguments("genbank_accession");
176 $params->{overgo_matches} = $page->get_arguments("overgo_matches");
177 $params->{SGN_S} = $page->get_arguments("SGN_S");
178 $params->{SGN_C} = $page->get_arguments("SGN_C");
179 $params->{SGN_T} = $page->get_arguments("SGN_T");
180 $params->{SGN_E} = $page->get_arguments("SGN_E");
181 $params->{SGN_U} = $page->get_arguments("SGN_U");
182 $params->{chipname} = $page->get_arguments("chipname");
183 $params->{TUS} = $page->get_arguments("TUS");
184 $params->{clone_name} = $page->get_arguments("clone_name");
185 $params->{build_nr} = $page->get_arguments("build_nr");
186 $params->{evalue} = $page->get_arguments("evalue");
187 $params->{SGN_U_U} = $page->get_arguments("SGN_U_U");
188 $params->{SGN_U_M} = $page->get_arguments("SGN_U_M");
189 $params->{convert_to_current} = $page->get_arguments("convert_to_current");
191 # add a new line so that the first id from the file upload is separated
192 # from the last id here, only if user submits ids in field and as file.
194 if ( $page->get_arguments("ids") =~ /\S/ ) {
195 $params->{ids_string} = $page->get_arguments("ids") . "\n";
198 # get an upload object to upload a file
199 my $upload;
200 $upload = $page->get_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_string} .= $_;
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 $c->throw(
226 title => "An Error has occured",
227 message => "ID Type must be provided",
228 notify => 0,
229 is_error => 0,
235 =head1 BUGS
237 None known.
239 =head1 AUTHOR
241 Alexander Naydich and Matthew Crumb (interns)
242 July 3, 2007
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 =head1 SEE ALSO
255 /bulk/display.pl
256 /bulk/input.pl
258 =cut