Mercurial > repos > geert-vandeweyer > vcf_to_variantdb
annotate VCF_to_VariantDB.pl @ 3:f2525e35b8e9 draft
typo in macros file
author | geert-vandeweyer |
---|---|
date | Wed, 19 Feb 2014 06:47:41 -0500 |
parents | d03a63a57e82 |
children | 6ddc1c6472ef |
rev | line source |
---|---|
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 | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
25 $|++; |
1 | 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(); | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
58 $conn->timeout(1800); |
1 | 59 my $response = $conn->post( $url, {'HelloWorld' => 1} ); |
60 my $content = $response->decoded_content(); | |
61 | |
62 if ($content eq 'HelloGalaxy') { | |
63 print OUT "Testing connection to $opts{'S'} : OK.\n"; | |
64 } | |
65 else { | |
66 die("Could not connect to the specified server : $content"); | |
67 } | |
68 | |
69 | |
70 ################## | |
71 ## TEST USER ID ## | |
72 ################## | |
73 $email = $opts{'u'}; | |
74 my $response = $conn->post( $url, {'CheckUser' => $email} ); | |
75 my $content = $response->decoded_content(); | |
76 | |
77 if ($content eq 'OK') { | |
78 print OUT "Testing User-existence : OK.\n"; | |
79 } | |
80 else { | |
81 die("ERROR: $content"); | |
82 } | |
83 | |
84 ############################################### | |
85 ## SEND THE VCF AND BAM FILES FOR PROCESSING ## | |
86 ############################################### | |
87 # filepaths | |
88 my $vcfpath = $opts{'v'}; | |
89 my $bampath = $opts{'b'}; | |
90 my $baipath = $opts{'B'}; | |
91 # make output directory in (galaxy/static/) working dir | |
92 my $rand = int(rand(1000)); | |
93 our $wd = $opts{'R'}."/static/VCF_parser.".$rand; #int(rand(1000)); | |
94 our $dd = $opts{'H'}."/static/VCF_parser.".$rand; | |
95 while (-d $wd) { | |
96 my $rand = int(rand(1000)); | |
97 $wd = $opts{'R'}."/static/VCF_parser.".$rand;#int(rand(1000)); | |
98 $dd = $opts{'H'}."/static/VCF_parser.".$rand; | |
99 | |
100 } | |
101 $result = system("mkdir $wd"); | |
102 | |
103 | |
104 ## link files | |
105 $vcfurl = "$dd/data.vcf"; | |
106 system ("ln -s $vcfpath $wd/data.vcf"); | |
107 if (exists($opts{'b'})) { | |
108 $bamurl = "$dd/data.bam"; | |
109 $bamidxurl = "$dd/data.bai"; | |
110 system ("ln -s $bampath $wd/data.bam"); | |
111 system ("ln -s $baipath $wd/data.bai"); | |
112 } | |
113 $sample = $opts{'n'}; | |
114 $gender = $opts{'g'}; | |
115 # post form to the variantDB host. | |
116 if (exists($opts{'b'})) { | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
117 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'BAMurl1' => "$bamurl", 'BAIurl1' => "$bamidxurl",'storedata1' => 1, 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email, 'GalaxyUpload' => 1} ); |
1 | 118 } |
119 else { | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
120 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email, 'GalaxyUpload' =>1 } ); |
1 | 121 } |
122 my $content = $response->decoded_content(); | |
123 chomp($content); | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
124 ## check if upload went ok. |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
125 if (substr($content,0,2) ne 'OK') { |
1 | 126 die("ERROR: $content"); |
127 } | |
2
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
128 ## extract wd from content. |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
129 print OUT "Uploading datafiles to VariantDB : OK.\n"; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
130 $content =~ m/OK-(.+)$/; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
131 $rwd = $1; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
132 if ($rwd eq '') { |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
133 die("ERROR : No remote working directory provided to check status."); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
134 } |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
135 ## now wait for the import to finish. |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
136 $status = 0; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
137 while ($status == 0) { |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
138 my $response = $conn->post( $url, {'CheckStatus' => 1,'rwd' => $rwd}) ; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
139 $content = $response->decoded_content(); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
140 chomp($content); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
141 if (substr($content,0,2) ne 'OK') { |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
142 die("ERROR: $content"); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
143 } |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
144 $status = substr($content,3,1); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
145 sleep 10; |
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 |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
148 ## Loading OK |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
149 # latest respons : OK-1-Content |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
150 $content = substr($content,5); |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
151 print OUT "Processing Datafiles : OK.\n"; |
d03a63a57e82
New version, better following configuration guidelines
geert-vandeweyer
parents:
1
diff
changeset
|
152 print OUT "\n$content\n"; |
1 | 153 close OUT; |
154 | |
155 # clean up | |
156 system("rm -Rf '$wd'"); | |
157 |