comparison ctd.pl @ 0:4a32700dcaa2 draft default tip

Uploaded tool tarball.
author devteam
date Wed, 25 Sep 2013 10:23:26 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4a32700dcaa2
1 #!/usr/bin/perl -w
2 use strict;
3 use LWP::UserAgent;
4 require HTTP::Cookies;
5
6 #######################################################
7 # ctd.pl
8 # Submit a batch query to CTD and fetch results into galaxy history
9 # usage: ctd.pl inFile idCol inputType resultType actionType outFile
10 #######################################################
11
12 if (!@ARGV or scalar @ARGV != 6) {
13 print "usage: ctd.pl inFile idCol inputType resultType actionType outFile\n";
14 exit;
15 }
16
17 my $in = shift @ARGV;
18 my $col = shift @ARGV;
19 if ($col < 1) {
20 print "The column number is with a 1 start\n";
21 exit 1;
22 }
23 my $type = shift @ARGV;
24 my $resType = shift @ARGV;
25 my $actType = shift @ARGV;
26 my $out = shift @ARGV;
27
28 my @data;
29 open(FH, $in) or die "Couldn't open $in, $!\n";
30 while (<FH>) {
31 chomp;
32 my @f = split(/\t/);
33 if (scalar @f < $col) {
34 print "ERROR the requested column is not in the file $col\n";
35 exit 1;
36 }
37 push(@data, $f[$col-1]);
38 }
39 close FH or die "Couldn't close $in, $!\n";
40
41 my $url = 'http://ctdbase.org/tools/batchQuery.go';
42 #my $url = 'http://ctd.mdibl.org/tools/batchQuery.go';
43 my $d = join("\n", @data);
44 #list maintains order, where hash doesn't
45 #order matters at ctd
46 #to use input file (gives error can't find file)
47 #my @form = ('inputType', $type, 'inputTerms', '', 'report', $resType,
48 #'queryFile', [$in, ''], 'queryFileColumn', $col, 'format', 'tsv', 'action', 'Submit');
49 my @form = ('inputType', $type, 'inputTerms', $d, 'report', $resType,
50 'queryFile', '', 'format', 'tsv', 'action', 'Submit');
51 if ($resType eq 'cgixns') { #only add if this type
52 push(@form, 'actionTypes', $actType);
53 }
54 if ($resType eq 'go' or $resType eq 'go_enriched') {
55 push(@form, 'ontology', 'go_bp', 'ontology', 'go_mf', 'ontology', 'go_cc');
56 }
57 my $ua = LWP::UserAgent->new;
58 $ua->cookie_jar(HTTP::Cookies->new( () ));
59 $ua->agent('Mozilla/5.0');
60 my $page = $ua->post($url, \@form, 'Content_Type'=>'form-data');
61 if ($page->is_success) {
62 open(FH, ">", $out) or die "Couldn't open $out, $!\n";
63 print FH "#";
64 print FH $page->content, "\n";
65 close FH or die "Couldn't close $out, $!\n";
66 }else {
67 print "ERROR failed to get page from CTD, ", $page->status_line, "\n";
68 print $page->content, "\n";
69 my $req = $page->request();
70 print "Requested \n";
71 foreach my $k(keys %$req) {
72 if ($k eq '_headers') {
73 my $t = $req->{$k};
74 foreach my $k2 (keys %$t) { print "$k2 => $t->{$k2}\n"; }
75 }else { print "$k => $req->{$k}\n"; }
76 }
77 exit 1;
78 }
79 exit;
80