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

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