1
|
1 #!/usr/bin/perl
|
|
2
|
|
3 # load modules
|
|
4 use Getopt::Std;
|
|
5
|
|
6 ##########################
|
|
7 # COMMAND LINE ARGUMENTS #
|
|
8 ##########################
|
|
9 # v = (v)cf file to load
|
|
10 # V = (V)CF file encoded id
|
|
11 # u = (u)ser email from galaxy
|
|
12 # n = sample (n)ame
|
|
13 # a = sample (a)nnotation
|
|
14 # g = sample (g)ender
|
|
15 # o = (o)utput file (simple text file)
|
|
16 # b = (b)am file (optional)
|
|
17 # B = (B)am index , needed if b is specified
|
|
18 # c = encoded id of bam file (optional)
|
|
19 # C = encoded id of Bam index , needed if b is specified => NOT POSSIBLE YET, NEEDS INDEXING ON VARIANTDB SERVER !
|
|
20 # S = (S)erver addrress to send data to.
|
|
21 # R = (r)oot of galaxy web server (/home/galaxyuser/galaxy-dist)
|
|
22 # H = (H)ost of the galaxy web server (http://my.galaxy.server/galaxy/)
|
|
23 getopts('v:u:n:a:g:o:b:B:V:c:S:R:H:', \%opts); # option are in %opts
|
|
24
|
|
25
|
|
26 #################
|
|
27 ## CHECK INPUT ##
|
|
28 #################
|
|
29 if (!exists($opts{'v'})) {
|
|
30 die('No VCF File Specified');
|
|
31 }
|
|
32 if (!-e $opts{'v'}) {
|
|
33 die('VCF File not found');
|
|
34 }
|
|
35 if (!exists($opts{'u'})) {
|
|
36 die('No user specified');
|
|
37 }
|
|
38 if (!exists($opts{'S'})) {
|
|
39 die('No VariantDB server specified');
|
|
40 }
|
|
41 if (!exists($opts{'H'})) {
|
|
42 die('The Galaxy source-server is not specified');
|
|
43 }
|
|
44
|
|
45 ################
|
|
46 # open outfile #
|
|
47 ################
|
|
48 open OUT, ">$opts{'o'}";
|
|
49
|
|
50 ###############################
|
|
51 ## TEST CONNECTION TO SERVER ##
|
|
52 ###############################
|
|
53 use LWP::UserAgent;
|
|
54 my $url = $opts{'S'}."/";
|
|
55 $url =~ s/\/\/$/\//;
|
|
56 $url .= "cgi-bin/galaxy_communication.cgi";
|
|
57 my $conn = LWP::UserAgent->new();
|
|
58 my $response = $conn->post( $url, {'HelloWorld' => 1} );
|
|
59 my $content = $response->decoded_content();
|
|
60
|
|
61 if ($content eq 'HelloGalaxy') {
|
|
62 print OUT "Testing connection to $opts{'S'} : OK.\n";
|
|
63 }
|
|
64 else {
|
|
65 die("Could not connect to the specified server : $content");
|
|
66 }
|
|
67
|
|
68
|
|
69 ##################
|
|
70 ## TEST USER ID ##
|
|
71 ##################
|
|
72 $email = $opts{'u'};
|
|
73 my $response = $conn->post( $url, {'CheckUser' => $email} );
|
|
74 my $content = $response->decoded_content();
|
|
75
|
|
76 if ($content eq 'OK') {
|
|
77 print OUT "Testing User-existence : OK.\n";
|
|
78 }
|
|
79 else {
|
|
80 die("ERROR: $content");
|
|
81 }
|
|
82
|
|
83 ###############################################
|
|
84 ## SEND THE VCF AND BAM FILES FOR PROCESSING ##
|
|
85 ###############################################
|
|
86 # filepaths
|
|
87 my $vcfpath = $opts{'v'};
|
|
88 my $bampath = $opts{'b'};
|
|
89 my $baipath = $opts{'B'};
|
|
90 # make output directory in (galaxy/static/) working dir
|
|
91 my $rand = int(rand(1000));
|
|
92 our $wd = $opts{'R'}."/static/VCF_parser.".$rand; #int(rand(1000));
|
|
93 our $dd = $opts{'H'}."/static/VCF_parser.".$rand;
|
|
94 while (-d $wd) {
|
|
95 my $rand = int(rand(1000));
|
|
96 $wd = $opts{'R'}."/static/VCF_parser.".$rand;#int(rand(1000));
|
|
97 $dd = $opts{'H'}."/static/VCF_parser.".$rand;
|
|
98
|
|
99 }
|
|
100 $result = system("mkdir $wd");
|
|
101
|
|
102
|
|
103 ## link files
|
|
104 $vcfurl = "$dd/data.vcf";
|
|
105 system ("ln -s $vcfpath $wd/data.vcf");
|
|
106 if (exists($opts{'b'})) {
|
|
107 $bamurl = "$dd/data.bam";
|
|
108 $bamidxurl = "$dd/data.bai";
|
|
109 system ("ln -s $bampath $wd/data.bam");
|
|
110 system ("ln -s $baipath $wd/data.bai");
|
|
111 }
|
|
112 $sample = $opts{'n'};
|
|
113 $gender = $opts{'g'};
|
|
114 # post form to the variantDB host.
|
|
115 if (exists($opts{'b'})) {
|
|
116 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'BAMurl1' => "$bamurl", 'BAIurl1' => "$bamidxurl",'storedata' => 1, 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email} );
|
|
117 }
|
|
118 else {
|
|
119 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'sample1' => "$sample", 'gender1' => "$gender", 'User' => $email} );
|
|
120 }
|
|
121 my $content = $response->decoded_content();
|
|
122 chomp($content);
|
|
123 if ($content =~ m/OK$/) {
|
|
124 print OUT "Processing Datafiles : OK.\n";
|
|
125 print OUT "\n$content\n";
|
|
126 }
|
|
127 else {
|
|
128 die("ERROR: $content");
|
|
129 }
|
|
130 close OUT;
|
|
131
|
|
132 # clean up
|
|
133 system("rm -Rf '$wd'");
|
|
134
|