Repository 'svdetect'
hg clone https://toolshed.g2.bx.psu.edu/repos/bzeitouni/svdetect

Changeset 7:c8744c56e979 (2012-06-11)
Previous changeset 6:f6ccaaed3654 (2012-06-11) Next changeset 8:3d3d0052443d (2012-06-11)
Commit message:
Uploaded
added:
SVDetect_compare.pl
b
diff -r f6ccaaed3654 -r c8744c56e979 SVDetect_compare.pl
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/SVDetect_compare.pl Mon Jun 11 12:31:50 2012 -0400
[
b'@@ -0,0 +1,716 @@\n+#!/usr/bin/perl -w\n+\n+=pod\n+\n+=head1 NAME\n+\n+SVDetect Compare for Galaxy\n+\n+Version: 0.8 for Galaxy\n+\n+=head1 SYNOPSIS\n+\n+SVDetect_compare.pl links2compare -conf <configuration_file> [-help] [-man]\n+\n+=cut\n+\n+# -------------------------------------------------------------------\n+\n+use strict;\n+use warnings;\n+\n+use Pod::Usage;\n+use Getopt::Long;\n+\n+use Config::General;\n+use Tie::IxHash;\n+\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+#PARSE THE COMMAND LINE\n+my %OPT;\n+GetOptions(\\%OPT,\n+\t   \'conf=s\',\n+\t   \'out1=s\', #GALAXY\n+\t   \'out2=s\', #GALAXY\n+\t   \'out3=s\', #GALAXY\n+\t   \'out4=s\', #GALAXY\n+\t   \'out5=s\', #GALAXY\n+\t   \'out6=s\', #GALAXY\n+\t   \'out7=s\', #GALAXY\n+\t   \'out8=s\', #GALAXY\n+\t   \'out9=s\', #GALAXY\n+\t   \'l=s\', #GALAXY\n+\t   \'N=s\', #GALAXY\n+\t   \'help\',\n+           \'man\'\n+\t  );\n+\n+pod2usage() if $OPT{help};\n+pod2usage(-verbose=>2) if $OPT{man};\n+pod2usage(-message=> "$!", -exitval => 2) if (!defined $OPT{conf});\n+\n+\n+pod2usage() if(@ARGV<1);\n+\n+tie (my %func, \'Tie::IxHash\',links2compare=>\\&links2compare);\n+\n+foreach my $command (@ARGV){\n+    pod2usage(-message=> "Unknown command \\"$command\\"", -exitval => 2) if (!defined($func{$command}));\n+}\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+#READ THE CONFIGURATION FILE\n+my $conf=Config::General->new(    -ConfigFile        => $OPT{conf},\n+                                  -Tie => "Tie::IxHash",\n+                                  -AllowMultiOptions => 1,\n+\t\t\t\t  -LowerCaseNames    => 1,\n+\t\t\t\t  -AutoTrue => 1);\n+my %CONF= $conf->getall;\n+validateconfiguration(\\%CONF);\t\t\t\t\t\t\t#validation of the configuration parameters\n+\n+\n+my $SAMTOOLS_BIN_DIR="/bioinfo/local/samtools"; #GALAXY\n+my $BEDTOOLS_BIN_DIR="/bioinfo/local/BEDTools/bin"; #GALAXY\n+\n+my $pt_log_file=$OPT{l}; #GALAXY\n+my $log_file=$CONF{general}{output_dir}.$OPT{N}.".svdetect_compare.log"; #GALAXY\n+open LOG,">$log_file" or die "$0: can\'t open ".$log_file.":$!\\n";#GALAXY\n+\n+my @pt_sv_file=($OPT{out1},$OPT{out2},$OPT{out3}) if($OPT{out1}); #GALAXY common,sample,reference\n+my @pt_circos_file=($OPT{out4},$OPT{out5},$OPT{out6}) if($OPT{out4}); #GALAXY common,sample,reference\n+my @pt_bed_file=($OPT{out7},$OPT{out8},$OPT{out9}) if($OPT{out7}); #GALAXY common,sample,reference\n+\n+$CONF{compare}{sample_link_file}=readlink($CONF{compare}{sample_link_file});#GALAXY\n+$CONF{compare}{sample_link_file}=~s/.sv.txt//; #GALAXY\n+\n+$CONF{compare}{reference_link_file}=readlink($CONF{compare}{reference_link_file});#GALAXY\n+$CONF{compare}{reference_link_file}=~s/.sv.txt//; #GALAXY\n+\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+#COMMAND EXECUTION\n+foreach my $command (@ARGV){\n+    &{$func{$command}}();\n+}\n+print LOG "-- end\\n";\n+\n+close LOG;#GALAXY\n+system "rm $pt_log_file ; ln -s $log_file $pt_log_file"; #GALAXY\n+\n+exit(0);\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n+#FUNCTIONS\n+\n+# -----------------------------------------------------------------------------#\n+#MAIN FUNCTION number 5:Comparison between samples, common or specific links\n+sub links2compare{\n+    \n+    my @compare_files;\n+    \n+    compareSamples($CONF{general}{output_dir},\n+\t\t   $CONF{compare}{list_samples},\n+\t\t   $CONF{compare}{sample_link_file},\n+\t\t   $CONF{compare}{reference_link_file},\n+\t\t   $CONF{compare}{min_overlap},\n+\t\t   $CONF{compare}{same_sv_type},\n+\t\t   \\@compare_files);\n+\n+    my $pt_ind=0;\n+ \n+    for my $input_file (@compa'..b'->[$i] eq \'F\'){\n+\t    $starts->[$i]=$positions->[$i];\n+\t    $ends->[$i]=$positions->[$i]+$tag_length->{$end_order->[$i]}-1;\n+\t}else{\n+\t    $starts->[$i]=$positions->[$i]-$tag_length->{$end_order->[$i]}+1;\n+\t    $ends->[$i]=$positions->[$i];\n+\t}\n+    }    \n+}\n+#------------------------------------------------------------------------------#\n+#------------------------------------------------------------------------------#\n+sub floor {\n+    my $nb = $_[0];\n+    $nb=~ s/\\..*//;\n+    return $nb;\n+}\n+#------------------------------------------------------------------------------#\n+#------------------------------------------------------------------------------#\n+sub decimal{\n+    \n+  my $num=shift;\n+  my $digs_to_cut=shift;\n+\n+  $num=sprintf("%.".($digs_to_cut-1)."f", $num) if ($num=~/\\d+\\.(\\d){$digs_to_cut,}/);\n+\n+  return $num;\n+}\n+\n+#------------------------------------------------------------------------------#\n+#------------------------------------------------------------------------------#\n+#Sort links according the concerned chromosomes and their coordinates\n+sub sortLinks{\n+    \n+    my ($links_file,$sortedlinks_file,$unique)=@_;\n+    \n+    print LOG "# Sorting links...\\n";\n+    \n+    my $pipe=($unique)? "| sort -u":"";\n+    system "sort -k 1,1 -k 4,4 -k 2,2n -k 5,5n -k 8,8n $links_file $pipe > $sortedlinks_file";\n+\n+}\n+#------------------------------------------------------------------------------#\n+#------------------------------------------------------------------------------#\n+sub getColor{\n+\n+    my($count,$hcolor,$format)=@_;\n+    for my $col ( keys % { $hcolor} ) {\n+       return $col if($count>=$hcolor->{$col}->[0] && $count<=$hcolor->{$col}->[1]);\n+    }\n+    return "white" if($format eq "circos");\n+    return "255,255,255" if($format eq "bed");\n+}\n+#------------------------------------------------------------------------------#\n+#------------------------------------------------------------------------------#\n+#check if the configuration file is correct\n+sub validateconfiguration{\n+    \n+    my %conf=%{$_[0]};\n+    my $list_prgs="@ARGV";\n+    \n+    my @circos_params=qw(organism_id colorcode);\n+    my @bed_params=qw(colorcode);\n+    my @compare_params=qw(list_samples list_read_lengths sample_link_file reference_link_file);\n+    \n+    unless (defined($conf{general}{output_dir})) {\n+\t$conf{general}{output_dir} = ".";\n+    }\n+    unless (-d $conf{general}{output_dir}){\n+\tmkdir $conf{general}{output_dir} or die;\n+    }\n+    $conf{general}{output_dir}.="/" if($conf{general}{output_dir}!~/\\/$/);\n+\n+    \n+    if($list_prgs=~/links2compare/){\n+\tforeach my $p (@compare_params) {\n+\t    die("Error Config : The compare parameter \\"$p\\" is not defined\\n") if (!defined $conf{compare}{$p});\n+\t}\n+\t\n+\tunless (defined($conf{compare}{same_sv_type})) {\n+\t    $conf{compare}{same_sv_type} = 0;\n+\t}\n+\t\n+\tunless (defined($conf{compare}{min_overlap})) {\n+\t    $conf{compare}{min_overlap} = 1E-9;\n+\t}\n+\t\n+\tif($conf{compare}{circos_output}){\n+\t    foreach my $p (@circos_params) {\n+\t\tnext if($list_prgs=~/^ratio/ && $p eq "colorcode");\n+\t\tdie("Error Config : The circos parameter \\"$p\\" is not defined\\n") if (!defined $conf{circos}{$p});\n+\t    }\n+\t}\n+\tif($conf{compare}{bed_output}){\n+\t    foreach my $p (@bed_params) {\n+\t\tdie("Error Config : The bed parameter \\"$p\\" is not defined\\n") if (!defined $conf{bed}{$p});\n+\t    }\n+\t    die("Error Config : The compare parameter \\"list_read_lengths\\" is not defined\\n") if (!defined $conf{compare}{list_read_lengths});\n+\n+\t    my @samples=split(",",$conf{compare}{list_samples});\n+\t    my @read_lengths=split(",",$conf{compare}{list_read_lengths});\n+\t    for my $i (0..$#samples){\n+\t\tmy @l=split("-",$read_lengths[$i]);\n+\t\t$conf{compare}{read_lengths}{$samples[$i]}={ 1=> $l[0], 2=> $l[1]};\n+\t    }\n+\t}\n+    }\n+   \n+    \n+}\n+#------------------------------------------------------------------------------#\n+#::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#\n'