Mercurial > repos > geert-vandeweyer > vcf_to_variantdb
changeset 1:355e491dbd0f draft
Uploaded
author | geert-vandeweyer |
---|---|
date | Wed, 08 May 2013 04:34:30 -0400 |
parents | 156964ba18fc |
children | d03a63a57e82 |
files | VCF_to_VariantDB.pl |
diffstat | 1 files changed, 134 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/VCF_to_VariantDB.pl Wed May 08 04:34:30 2013 -0400 @@ -0,0 +1,134 @@ +#!/usr/bin/perl + +# load modules +use Getopt::Std; + +########################## +# COMMAND LINE ARGUMENTS # +########################## +# v = (v)cf file to load +# V = (V)CF file encoded id +# u = (u)ser email from galaxy +# n = sample (n)ame +# a = sample (a)nnotation +# g = sample (g)ender +# o = (o)utput file (simple text file) +# b = (b)am file (optional) +# B = (B)am index , needed if b is specified +# c = encoded id of bam file (optional) +# C = encoded id of Bam index , needed if b is specified => NOT POSSIBLE YET, NEEDS INDEXING ON VARIANTDB SERVER ! +# S = (S)erver addrress to send data to. +# R = (r)oot of galaxy web server (/home/galaxyuser/galaxy-dist) +# H = (H)ost of the galaxy web server (http://my.galaxy.server/galaxy/) +getopts('v:u:n:a:g:o:b:B:V:c:S:R:H:', \%opts); # option are in %opts + + +################# +## CHECK INPUT ## +################# +if (!exists($opts{'v'})) { + die('No VCF File Specified'); +} +if (!-e $opts{'v'}) { + die('VCF File not found'); +} +if (!exists($opts{'u'})) { + die('No user specified'); +} +if (!exists($opts{'S'})) { + die('No VariantDB server specified'); +} +if (!exists($opts{'H'})) { + die('The Galaxy source-server is not specified'); +} + +################ +# open outfile # +################ +open OUT, ">$opts{'o'}"; + +############################### +## TEST CONNECTION TO SERVER ## +############################### +use LWP::UserAgent; +my $url = $opts{'S'}."/"; +$url =~ s/\/\/$/\//; +$url .= "cgi-bin/galaxy_communication.cgi"; +my $conn = LWP::UserAgent->new(); +my $response = $conn->post( $url, {'HelloWorld' => 1} ); +my $content = $response->decoded_content(); + +if ($content eq 'HelloGalaxy') { + print OUT "Testing connection to $opts{'S'} : OK.\n"; +} +else { + die("Could not connect to the specified server : $content"); +} + + +################## +## TEST USER ID ## +################## +$email = $opts{'u'}; +my $response = $conn->post( $url, {'CheckUser' => $email} ); +my $content = $response->decoded_content(); + +if ($content eq 'OK') { + print OUT "Testing User-existence : OK.\n"; +} +else { + die("ERROR: $content"); +} + +############################################### +## SEND THE VCF AND BAM FILES FOR PROCESSING ## +############################################### +# filepaths +my $vcfpath = $opts{'v'}; +my $bampath = $opts{'b'}; +my $baipath = $opts{'B'}; +# make output directory in (galaxy/static/) working dir +my $rand = int(rand(1000)); +our $wd = $opts{'R'}."/static/VCF_parser.".$rand; #int(rand(1000)); +our $dd = $opts{'H'}."/static/VCF_parser.".$rand; +while (-d $wd) { + my $rand = int(rand(1000)); + $wd = $opts{'R'}."/static/VCF_parser.".$rand;#int(rand(1000)); + $dd = $opts{'H'}."/static/VCF_parser.".$rand; + +} +$result = system("mkdir $wd"); + + +## link files +$vcfurl = "$dd/data.vcf"; +system ("ln -s $vcfpath $wd/data.vcf"); +if (exists($opts{'b'})) { + $bamurl = "$dd/data.bam"; + $bamidxurl = "$dd/data.bai"; + system ("ln -s $bampath $wd/data.bam"); + system ("ln -s $baipath $wd/data.bai"); +} +$sample = $opts{'n'}; +$gender = $opts{'g'}; +# post form to the variantDB host. +if (exists($opts{'b'})) { + $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'BAMurl1' => "$bamurl", 'BAIurl1' => "$bamidxurl",'storedata' => 1, 'name1' => "$sample", 'gender1' => "$gender", 'User' => $email} ); +} +else { + $response = $conn->post( $url, {'VCFurl1' => "$vcfurl", 'sample1' => "$sample", 'gender1' => "$gender", 'User' => $email} ); +} +my $content = $response->decoded_content(); +chomp($content); +if ($content =~ m/OK$/) { + print OUT "Processing Datafiles : OK.\n"; + print OUT "\n$content\n"; +} +else { + die("ERROR: $content"); +} +close OUT; + +# clean up +system("rm -Rf '$wd'"); +