annotate VCF_to_VariantDB.pl @ 1:355e491dbd0f draft

Uploaded
author geert-vandeweyer
date Wed, 08 May 2013 04:34:30 -0400
parents
children d03a63a57e82
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/)
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
23 getopts('v:u:n:a:g:o:b:B:V:c:S:R:H:', \%opts); # option are in %opts
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
24
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
25
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
26 #################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
27 ## CHECK INPUT ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
28 #################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
29 if (!exists($opts{'v'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
30 die('No VCF File Specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
31 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
32 if (!-e $opts{'v'}) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
33 die('VCF File not found');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
34 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
35 if (!exists($opts{'u'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
36 die('No user specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
37 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
38 if (!exists($opts{'S'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
39 die('No VariantDB server specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
40 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
41 if (!exists($opts{'H'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
42 die('The Galaxy source-server is not specified');
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
43 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
44
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
45 ################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
46 # open outfile #
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
47 ################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
48 open OUT, ">$opts{'o'}";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
49
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
50 ###############################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
51 ## TEST CONNECTION TO SERVER ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
52 ###############################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
53 use LWP::UserAgent;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
54 my $url = $opts{'S'}."/";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
55 $url =~ s/\/\/$/\//;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
56 $url .= "cgi-bin/galaxy_communication.cgi";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
57 my $conn = LWP::UserAgent->new();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
58 my $response = $conn->post( $url, {'HelloWorld' => 1} );
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
59 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
60
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
61 if ($content eq 'HelloGalaxy') {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
62 print OUT "Testing connection to $opts{'S'} : OK.\n";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
63 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
64 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
65 die("Could not connect to the specified server : $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
66 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
67
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
68
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
69 ##################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
70 ## TEST USER ID ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
71 ##################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
72 $email = $opts{'u'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
73 my $response = $conn->post( $url, {'CheckUser' => $email} );
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
74 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
75
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
76 if ($content eq 'OK') {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
77 print OUT "Testing User-existence : OK.\n";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
78 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
79 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
80 die("ERROR: $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
81 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
82
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
83 ###############################################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
84 ## SEND THE VCF AND BAM FILES FOR PROCESSING ##
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
85 ###############################################
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
86 # filepaths
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
87 my $vcfpath = $opts{'v'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
88 my $bampath = $opts{'b'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
89 my $baipath = $opts{'B'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
90 # make output directory in (galaxy/static/) working dir
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
91 my $rand = int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
92 our $wd = $opts{'R'}."/static/VCF_parser.".$rand; #int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
93 our $dd = $opts{'H'}."/static/VCF_parser.".$rand;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
94 while (-d $wd) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
95 my $rand = int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
96 $wd = $opts{'R'}."/static/VCF_parser.".$rand;#int(rand(1000));
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
97 $dd = $opts{'H'}."/static/VCF_parser.".$rand;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
98
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
99 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
100 $result = system("mkdir $wd");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
101
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
102
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
103 ## link files
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
104 $vcfurl = "$dd/data.vcf";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
105 system ("ln -s $vcfpath $wd/data.vcf");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
106 if (exists($opts{'b'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
107 $bamurl = "$dd/data.bam";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
108 $bamidxurl = "$dd/data.bai";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
109 system ("ln -s $bampath $wd/data.bam");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
110 system ("ln -s $baipath $wd/data.bai");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
111 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
112 $sample = $opts{'n'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
113 $gender = $opts{'g'};
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
114 # post form to the variantDB host.
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
115 if (exists($opts{'b'})) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
116 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'BAMurl1' => "$bamurl", 'BAIurl1' => "$bamidxurl",'storedata' => 1, 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email} );
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
117 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
118 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
119 $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'sample1' => "$sample", 'gender1' => "$gender", 'User' => $email} );
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
120 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
121 my $content = $response->decoded_content();
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
122 chomp($content);
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
123 if ($content =~ m/OK$/) {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
124 print OUT "Processing Datafiles : OK.\n";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
125 print OUT "\n$content\n";
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
126 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
127 else {
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
128 die("ERROR: $content");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
129 }
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
130 close OUT;
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
131
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
132 # clean up
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
133 system("rm -Rf '$wd'");
355e491dbd0f Uploaded
geert-vandeweyer
parents:
diff changeset
134