annotate VCF_to_VariantDB.pl @ 10:d5040a542e9d draft

Uploaded
author geert-vandeweyer
date Tue, 21 Oct 2014 05:11:23 -0400
parents 3b27cae9b359
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
1 #!/usr/bin/perl
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
2
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
3 # load modules
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
4 use Getopt::Std;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
5
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
6 ##########################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
7 # COMMAND LINE ARGUMENTS #
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
8 ##########################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
9 # v = (v)cf file to load
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
10 # V = (V)CF file encoded id
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
11 # u = (u)ser email from galaxy
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
12 # n = sample (n)ame
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
13 # a = sample (a)nnotation
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
14 # g = sample (g)ender
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
15 # o = (o)utput file (simple text file)
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
16 # b = (b)am file (optional)
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
17 # B = (B)am index , needed if b is specified
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
18 # c = encoded id of bam file (optional)
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
19 # C = encoded id of Bam index , needed if b is specified => NOT POSSIBLE YET, NEEDS INDEXING ON VARIANTDB SERVER !
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
20 # S = (S)erver addrress to send data to.
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
21 # R = (r)oot of galaxy web server (/home/galaxyuser/galaxy-dist)
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
22 # H = (H)ost of the galaxy web server (http://my.galaxy.server/galaxy/)
9
3b27cae9b359 New Version. VariantDB checks for Genome Build matching using the Galaxy dbkey variable.
geert-vandeweyer
parents: 8
diff changeset
23 # G = Genome build (dbkey)
7
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
24 # F = (F)ormat of input file
9
3b27cae9b359 New Version. VariantDB checks for Genome Build matching using the Galaxy dbkey variable.
geert-vandeweyer
parents: 8
diff changeset
25 getopts('v:u:n:a:g:o:b:B:V:c:S:R:H:G:F:', \%opts); # option are in %opts
2
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
26 $|++;
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
27 #################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
28 ## CHECK INPUT ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
29 #################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
30 if (!exists($opts{'v'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
31 die('No VCF File Specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
32 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
33 if (!-e $opts{'v'}) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
34 die('VCF File not found');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
35 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
36 if (!exists($opts{'u'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
37 die('No user specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
38 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
39 if (!exists($opts{'S'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
40 die('No VariantDB server specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
41 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
42 if (!exists($opts{'H'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
43 die('The Galaxy source-server is not specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
44 }
7
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
45 if (!exists($opts{'F'})) {
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
46 die('VCF format not specified.');
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
47 }
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
48
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
49 ################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
50 # open outfile #
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
51 ################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
52 open OUT, ">$opts{'o'}";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
53
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
54 ###############################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
55 ## TEST CONNECTION TO SERVER ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
56 ###############################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
57 use LWP::UserAgent;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
58 my $url = $opts{'S'}."/";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
59 $url =~ s/\/\/$/\//;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
60 $url .= "cgi-bin/galaxy_communication.cgi";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
61 my $conn = LWP::UserAgent->new();
2
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
62 $conn->timeout(1800);
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
63 my $response = $conn->post( $url, {'HelloWorld' => 1} );
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
64 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
65
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
66 if ($content eq 'HelloGalaxy') {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
67 print OUT "Testing connection to $opts{'S'} : OK.\n";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
68 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
69 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
70 die("Could not connect to the specified server : $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
71 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
72
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
73
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
74 ##################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
75 ## TEST USER ID ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
76 ##################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
77 $email = $opts{'u'};
9
3b27cae9b359 New Version. VariantDB checks for Genome Build matching using the Galaxy dbkey variable.
geert-vandeweyer
parents: 8
diff changeset
78 $dbkey = $opts{'G'};
3b27cae9b359 New Version. VariantDB checks for Genome Build matching using the Galaxy dbkey variable.
geert-vandeweyer
parents: 8
diff changeset
79 my $response = $conn->post( $url, {'CheckUser' => $email,'dbkey' => $dbkey} );
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
80 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
81
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
82 if ($content eq 'OK') {
9
3b27cae9b359 New Version. VariantDB checks for Genome Build matching using the Galaxy dbkey variable.
geert-vandeweyer
parents: 8
diff changeset
83 print OUT "Testing User-existence and Genome Build: OK.\n";
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
84 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
85 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
86 die("ERROR: $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
87 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
88
5
6ddc1c6472ef Macro corrections
geert-vandeweyer
parents: 2
diff changeset
89 print $opts{'H'}. " was specified as galaxy host\n";
6ddc1c6472ef Macro corrections
geert-vandeweyer
parents: 2
diff changeset
90
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
91 ###############################################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
92 ## SEND THE VCF AND BAM FILES FOR PROCESSING ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
93 ###############################################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
94 # filepaths
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
95 my $vcfpath = $opts{'v'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
96 my $bampath = $opts{'b'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
97 my $baipath = $opts{'B'};
7
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
98 # input VCF format
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
99 $format = $opts{'F'};
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
100 # make output directory in (galaxy/static/) working dir
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
101 my $rand = int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
102 our $wd = $opts{'R'}."/static/VCF_parser.".$rand; #int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
103 our $dd = $opts{'H'}."/static/VCF_parser.".$rand;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
104 while (-d $wd) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
105 my $rand = int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
106 $wd = $opts{'R'}."/static/VCF_parser.".$rand;#int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
107 $dd = $opts{'H'}."/static/VCF_parser.".$rand;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
108
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
109 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
110 $result = system("mkdir $wd");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
111
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
112
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
113 ## link files
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
114 $vcfurl = "$dd/data.vcf";
8
db44ff975de8 Corrected macro.xml handling of GALAXY_URL
geert-vandeweyer
parents: 7
diff changeset
115 $vcfurl =~ s/\s//g;
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
116 system ("ln -s $vcfpath $wd/data.vcf");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
117 if (exists($opts{'b'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
118 $bamurl = "$dd/data.bam";
8
db44ff975de8 Corrected macro.xml handling of GALAXY_URL
geert-vandeweyer
parents: 7
diff changeset
119 $bamurl =~ s/\s//g;
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
120 $bamidxurl = "$dd/data.bai";
8
db44ff975de8 Corrected macro.xml handling of GALAXY_URL
geert-vandeweyer
parents: 7
diff changeset
121 $bamidxurl =~ s/\s//g;
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
122 system ("ln -s $bampath $wd/data.bam");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
123 system ("ln -s $baipath $wd/data.bai");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
124 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
125 $sample = $opts{'n'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
126 $gender = $opts{'g'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
127 # post form to the variantDB host.
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
128 if (exists($opts{'b'})) {
7
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
129 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'BAMurl1' => "$bamurl", 'BAIurl1' => "$bamidxurl",'storedata1' => 1, 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email, 'GalaxyUpload' => 1,'Format1' => $format} );
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
130 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
131 else {
7
04e3bba317f4 Added selection to differentiate in VCF format
geert-vandeweyer
parents: 5
diff changeset
132 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email, 'GalaxyUpload' =>1, 'Format1' => $format } );
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
133 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
134 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
135 chomp($content);
2
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
136 ## check if upload went ok.
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
137 if (substr($content,0,2) ne 'OK') {
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
138 die("ERROR: $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
139 }
2
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
140 ## extract wd from content.
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
141 print OUT "Uploading datafiles to VariantDB : OK.\n";
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
142 $content =~ m/OK-(.+)$/;
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
143 $rwd = $1;
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
144 if ($rwd eq '') {
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
145 die("ERROR : No remote working directory provided to check status.");
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
146 }
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
147 ## now wait for the import to finish.
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
148 $status = 0;
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
149 while ($status == 0) {
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
150 my $response = $conn->post( $url, {'CheckStatus' => 1,'rwd' => $rwd}) ;
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
151 $content = $response->decoded_content();
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
152 chomp($content);
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
153 if (substr($content,0,2) ne 'OK') {
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
154 die("ERROR: $content");
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
155 }
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
156 $status = substr($content,3,1);
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
157 sleep 10;
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
158 }
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
159
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
160 ## Loading OK
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
161 # latest respons : OK-1-Content
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
162 $content = substr($content,5);
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
163 print OUT "Processing Datafiles : OK.\n";
d03a63a57e82 New version, better following configuration guidelines
geert-vandeweyer
parents: 1
diff changeset
164 print OUT "\n$content\n";
1
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
165 close OUT;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
166
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
167 # clean up
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
168 system("rm -Rf '$wd'");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
169