root/galaxy-central/tools/human_genome_variation/ctd.pl

リビジョン 2, 2.3 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

  • 属性 svn:executable の設定値 *
行番号 
1#!/usr/bin/env perl
2
3use strict;
4use warnings;
5
6use LWP::UserAgent;
7require HTTP::Cookies;
8
9#######################################################
10# ctd.pl
11# Submit a batch query to CTD and fetch results into galaxy history
12# usage: ctd.pl inFile idCol inputType resultType actionType outFile
13#######################################################
14
15if (!@ARGV or scalar @ARGV != 6) {
16   print "usage: ctd.pl inFile idCol inputType resultType actionType outFile\n";
17   exit;
18}
19
20my $in = shift @ARGV;
21my $col = shift @ARGV;
22if ($col < 1) {
23   print "The column number is with a 1 start\n";
24   exit 1;
25}
26my $type = shift @ARGV;
27my $resType = shift @ARGV;
28my $actType = shift @ARGV;
29my $out = shift @ARGV;
30
31my @data;
32open(FH, $in) or die "Couldn't open $in, $!\n";
33while (<FH>) {
34   chomp;
35   my @f = split(/\t/);
36   if (scalar @f < $col) {
37      print "ERROR the requested column is not in the file $col\n";
38      exit 1;
39   }
40   push(@data, $f[$col-1]);
41}
42close FH or die "Couldn't close $in, $!\n";
43
44my $url = 'http://ctd.mdibl.org/tools/batchQuery.go';
45#my $url = 'http://globin.bx.psu.edu/cgi-bin/print-query';
46my $d = join("\n", @data);
47#list maintains order, where hash doesn't
48#order matters at ctd
49#to use input file (gives error can't find file)
50#my @form = ('inputType', $type, 'inputTerms', '', 'report', $resType,
51   #'queryFile', [$in, ''], 'queryFileColumn', $col, 'format', 'tsv', 'action', 'Submit');
52my @form = ('inputType', $type, 'inputTerms', $d, 'report', $resType,
53  'queryFile', '', 'format', 'tsv', 'action', 'Submit');
54if ($resType eq 'cgixns') { #only add if this type
55   push(@form, 'actionTypes', $actType);
56}
57my $ua = LWP::UserAgent->new;
58$ua->cookie_jar(HTTP::Cookies->new( () ));
59$ua->agent('Mozilla/5.0');
60my $page = $ua->post($url, \@form, 'Content_Type'=>'form-data');
61if ($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}
79exit;
80
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。