annotate ctd.pl @ 0:72ce01e2dad9 draft default tip

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