annotate tools/human_genome_variation/ctd.pl @ 1:cdcb0ce84a1b

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