blib/htdocs/example_scripts/gbrowse_upload_data.pl untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 56 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/bin/perl
2  
3 use strict;
4 use LWP::UserAgent;
5 use HTTP::Request::Common;
6 use File::Basename 'basename';
7 use JSON;
8  
9 @ARGV || $ARGV[0]=~ /^-?-h/ or die <<END;
10 usage: $0 <gbrowse_url> [session_id]
11 The data to be uploaded into GBrowse as a
12 new track will be read from STDIN.
13 END
14 ;
15 my $gbrowse = shift;
16 my $id = shift;
17  
18 print STDERR "Please enter data to be uploaded (BED, WIG, GFF3 format) on stdin: \n"
19 if -t STDIN;
20  
21 my $data = join ('',<>); # slurp all of stdin
22  
23 my $agent = LWP::UserAgent->new;
24 $agent->cookie_jar({file=>"$ENV{HOME}/.gbrowse_session",
25 autosave=>1
26 });
27 my $url = $gbrowse;
28 $url .= '/' unless $url =~ m!/$/!;
29  
30 my @id = (id => $id) if $id;
31 my $request = POST($url,
32 Content_Type => 'form-data',
33 Content => [
34 action => 'upload_file',
35 overwrite => 1,
36 data => $data,
37 @id
38 ]
39 );
40 my $response = $agent->request($request);
41 die $response->status_line unless $response->is_success;
42 my $content = $response->decoded_content;
43 my $cookie = $response->header('Set-cookie');
44 my ($used_id) = $cookie =~ /gbrowse_sess=([a-f0-9]+)/;
45  
46 my $struct = from_json($content);
47  
48 if ($struct->{success}) {
49 print <<END;
50 Tracks : @{$struct->{tracks}}
51 uploadName : $struct->{uploadName}
52 sessionID : $used_id
53 END
54 } else {
55 die $struct->{error_msg};
56 }