#!/bin/env perl
$|=1;
use strict;
use warnings;

use HTTP::Request::Common;
use LWP::UserAgent;

MAIN: {
    my $ua=LWP::UserAgent->new;
    my $uri='http://db.systemsbiology.net/kaviar-beta/cgi-pub/Kaviar.pl';

    # using separate chromosome and coordinate fields
    # get variant information for four sample positions on chromosome 1  for hg38
    my $freeze = "hg38";
    my $coordinates = "1";  # 0 for 0-based, 1 for 1-based
    my $chr = "chr1";
    my $positions = "11794419, 11796321, 230710048, 236885200";

    # table, text, or json
    my $format = "json";

    my $req_args=[
                        frz => $freeze,
                        onebased => $coordinates,
                        chr => $chr,
                        pos => $positions,
                        format => $format
                 ];

    print "Retrieving information for genome build $freeze ".
          "with coordinate system $coordinates ".
	  "for chromosome $chr positions $positions\n";

    #sleep inserted for readability of print statement
    #do not use sleep statement in normal web service queries
    sleep 1;  


    my $res=$ua->request(POST $uri, $req_args);
    print $res->content;

    # using list field
    my $list = "chr1:11794419\nchr1:11796321\nchr1:230710048\nchr1:236885200";

    my $list_args = [
                        frz => $freeze,
                        onebased => $coordinates,
                        list => $list,
                        format => $format
                    ];

    my $list_res=$ua->request(POST $uri, $req_args);
    print $list_res->content;


}
