annotate SVDetect_compare.pl @ 7:c8744c56e979 draft

Uploaded
author bzeitouni
date Mon, 11 Jun 2012 12:31:50 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
1 #!/usr/bin/perl -w
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
2
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
3 =pod
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
4
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
5 =head1 NAME
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
6
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
7 SVDetect Compare for Galaxy
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
8
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
9 Version: 0.8 for Galaxy
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
10
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
11 =head1 SYNOPSIS
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
12
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
13 SVDetect_compare.pl links2compare -conf <configuration_file> [-help] [-man]
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
14
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
15 =cut
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
16
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
17 # -------------------------------------------------------------------
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
18
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
19 use strict;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
20 use warnings;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
21
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
22 use Pod::Usage;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
23 use Getopt::Long;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
24
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
25 use Config::General;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
26 use Tie::IxHash;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
27
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
28 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
29 #PARSE THE COMMAND LINE
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
30 my %OPT;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
31 GetOptions(\%OPT,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
32 'conf=s',
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
33 'out1=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
34 'out2=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
35 'out3=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
36 'out4=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
37 'out5=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
38 'out6=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
39 'out7=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
40 'out8=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
41 'out9=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
42 'l=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
43 'N=s', #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
44 'help',
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
45 'man'
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
46 );
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
47
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
48 pod2usage() if $OPT{help};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
49 pod2usage(-verbose=>2) if $OPT{man};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
50 pod2usage(-message=> "$!", -exitval => 2) if (!defined $OPT{conf});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
51
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
52
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
53 pod2usage() if(@ARGV<1);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
54
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
55 tie (my %func, 'Tie::IxHash',links2compare=>\&links2compare);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
56
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
57 foreach my $command (@ARGV){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
58 pod2usage(-message=> "Unknown command \"$command\"", -exitval => 2) if (!defined($func{$command}));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
59 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
60 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
61
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
62 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
63 #READ THE CONFIGURATION FILE
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
64 my $conf=Config::General->new( -ConfigFile => $OPT{conf},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
65 -Tie => "Tie::IxHash",
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
66 -AllowMultiOptions => 1,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
67 -LowerCaseNames => 1,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
68 -AutoTrue => 1);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
69 my %CONF= $conf->getall;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
70 validateconfiguration(\%CONF); #validation of the configuration parameters
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
71
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
72
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
73 my $SAMTOOLS_BIN_DIR="/bioinfo/local/samtools"; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
74 my $BEDTOOLS_BIN_DIR="/bioinfo/local/BEDTools/bin"; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
75
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
76 my $pt_log_file=$OPT{l}; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
77 my $log_file=$CONF{general}{output_dir}.$OPT{N}.".svdetect_compare.log"; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
78 open LOG,">$log_file" or die "$0: can't open ".$log_file.":$!\n";#GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
79
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
80 my @pt_sv_file=($OPT{out1},$OPT{out2},$OPT{out3}) if($OPT{out1}); #GALAXY common,sample,reference
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
81 my @pt_circos_file=($OPT{out4},$OPT{out5},$OPT{out6}) if($OPT{out4}); #GALAXY common,sample,reference
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
82 my @pt_bed_file=($OPT{out7},$OPT{out8},$OPT{out9}) if($OPT{out7}); #GALAXY common,sample,reference
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
83
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
84 $CONF{compare}{sample_link_file}=readlink($CONF{compare}{sample_link_file});#GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
85 $CONF{compare}{sample_link_file}=~s/.sv.txt//; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
86
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
87 $CONF{compare}{reference_link_file}=readlink($CONF{compare}{reference_link_file});#GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
88 $CONF{compare}{reference_link_file}=~s/.sv.txt//; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
89
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
90 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
91
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
92 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
93 #COMMAND EXECUTION
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
94 foreach my $command (@ARGV){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
95 &{$func{$command}}();
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
96 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
97 print LOG "-- end\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
98
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
99 close LOG;#GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
100 system "rm $pt_log_file ; ln -s $log_file $pt_log_file"; #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
101
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
102 exit(0);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
103 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
104
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
105 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
106 #FUNCTIONS
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
107
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
108 # -----------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
109 #MAIN FUNCTION number 5:Comparison between samples, common or specific links
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
110 sub links2compare{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
111
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
112 my @compare_files;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
113
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
114 compareSamples($CONF{general}{output_dir},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
115 $CONF{compare}{list_samples},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
116 $CONF{compare}{sample_link_file},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
117 $CONF{compare}{reference_link_file},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
118 $CONF{compare}{min_overlap},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
119 $CONF{compare}{same_sv_type},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
120 \@compare_files);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
121
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
122 my $pt_ind=0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
123
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
124 for my $input_file (@compare_files){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
125
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
126 $input_file=$CONF{general}{output_dir}.$input_file;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
127
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
128 my $output_file=$input_file;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
129 $output_file=~s/unique$/compared/;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
130
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
131 sortLinks($input_file, $output_file,1);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
132
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
133 if($CONF{compare}{circos_output}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
134 links2segdup($CONF{circos}{organism_id},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
135 $CONF{circos}{colorcode},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
136 $output_file,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
137 $output_file.".segdup.txt");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
138 system "rm $pt_circos_file[$pt_ind]; ln -s $output_file.segdup.txt $pt_circos_file[$pt_ind]" if (defined $pt_circos_file[$pt_ind]); #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
139 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
140
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
141 if($CONF{compare}{bed_output}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
142 links2bedfile($CONF{compare}{read_lengths},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
143 $CONF{bed}{colorcode},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
144 $output_file,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
145 $output_file.".bed");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
146 system "rm $pt_bed_file[$pt_ind]; ln -s $output_file.bed $pt_bed_file[$pt_ind]" if (defined $pt_bed_file[$pt_ind]); #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
147 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
148
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
149 if($CONF{compare}{sv_output}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
150
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
151 links2SVfile ($output_file, $output_file.".sv.txt");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
152 system "rm $pt_sv_file[$pt_ind]; ln -s $output_file.sv.txt $pt_sv_file[$pt_ind]" if (defined $pt_sv_file[$pt_ind]); #GALAXY
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
153 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
154 $pt_ind++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
155
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
156 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
157 unlink(@compare_files);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
158
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
159 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
160 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
161 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
162 sub compareSamples{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
163
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
164 my ($dir,$list_samples,$sample_file,$reference_file,$min_overlap,$same_sv_type,$file_names)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
165
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
166 my @bedpefiles;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
167 my @list=split(",",$list_samples);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
168 my @list_files=($sample_file,$reference_file);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
169
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
170 print LOG "\# Comparison procedure...\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
171 print LOG "-- samples=$list_samples\n".
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
172 "-- minimum overlap=$min_overlap\n".
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
173 "-- same SV type=$same_sv_type\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
174
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
175 #conversion of links to bedPE format file
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
176 print LOG "-- Conversion of links.filtered files to bedPE format\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
177 for my $s (0..$#list) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
178
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
179 links2bedPElinksfile($list[$s],$list_files[$s],$list_files[$s].".bedpe.txt");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
180 push(@bedpefiles,$list_files[$s].".bedpe.txt");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
181
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
182 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
183
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
184 #get common links between all samples compared
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
185 print LOG "-- Getting common links between all samples with BEDTools\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
186 my $common_name=join(".",@list);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
187
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
188 my $nb=scalar @list;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
189 my $command="";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
190 my $prompt=">";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
191
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
192 while ($nb>0){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
193
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
194 for my $i (0..$#list_files){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
195
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
196 $command.="$BEDTOOLS_BIN_DIR/pairToPair -type both -f $min_overlap -a ".$list_files[$i].".bedpe.txt";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
197 my $pipe=0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
198
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
199 for my $j ($i+1..$#list_files){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
200
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
201 $command.="| $BEDTOOLS_BIN_DIR/pairToPair -type both -f $min_overlap -a stdin" if($pipe);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
202 $command.=" -b ".$list_files[$j].".bedpe.txt";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
203 $pipe=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
204
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
205 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
206
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
207 $command.=$prompt.$dir.$common_name.".bedpe.tmp;";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
208 $prompt=">>";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
209
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
210 my $first=shift(@list_files); push(@list_files,$first);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
211 last;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
212 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
213 $nb--;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
214 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
215
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
216 system ($command);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
217
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
218 push(@bedpefiles,$dir.$common_name.".bedpe.tmp");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
219
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
220 #Post comparison to get common links if same type only (as an option)
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
221 open( FILE, "<".$dir.$common_name.".bedpe.tmp") or die "Can't open".$dir.$common_name.".bedpe.tmp : $!";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
222 open( OUT, ">".$dir.$common_name.".bedpe.unique") or die "Can't write in ".$dir.$common_name.".bedpe.unique : $!";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
223
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
224 while(<FILE>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
225 my @t=split("\t",$_);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
226 my $s=(split("_",$t[6]))[0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
227 my ($sv1,$sv2)=($t[7],$t[18]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
228 splice(@t,11,$#t);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
229
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
230 if($same_sv_type){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
231 print OUT join("\t",@t)."\n" if($sv1 eq $sv2);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
232 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
233 print OUT join("\t",@t)."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
234 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
235 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
236 close FILE;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
237 close OUT;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
238
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
239 bedPElinks2linksfile($dir.$common_name.".bedpe.unique", $dir.$common_name.".unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
240 push(@bedpefiles,$dir.$common_name.".bedpe.unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
241 push(@$file_names,$common_name.".unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
242 print LOG "-- output created: ".$dir.$common_name.".compared\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
243
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
244 #get specific links for each sample
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
245 print LOG "-- Getting specific links for each sample\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
246 for my $s (0..$#list) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
247 system("grep -Fxv -f ".$dir.$common_name.".bedpe.unique ".$list_files[$s].".bedpe.txt >".$dir.$list[$s].".bedpe.unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
248 bedPElinks2linksfile($dir.$list[$s].".bedpe.unique",$dir.$list[$s].".unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
249 push(@bedpefiles,$dir.$list[$s].".bedpe.unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
250 push(@$file_names,$list[$s].".unique");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
251 print LOG "-- output created: ".$dir.$list[$s].".compared\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
252 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
253
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
254 unlink(@bedpefiles);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
255
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
256 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
257 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
258 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
259 #convert the links file to the circos format
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
260 sub links2segdup{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
261
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
262 my($id,$color_code,$links_file,$segdup_file)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
263
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
264 print LOG "\# Converting to the circos format...\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
265
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
266 tie (my %hcolor,'Tie::IxHash'); #color-code hash table
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
267 foreach my $col (keys %{$color_code}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
268 my ($min_links,$max_links)=split(",",$color_code->{$col});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
269 $hcolor{$col}=[$min_links,$max_links];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
270 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
271
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
272 open LINKS, "<$links_file" or die "$0: can't open $links_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
273 open SEGDUP, ">$segdup_file" or die "$0: can't write in the output: $segdup_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
274
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
275 my $index=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
276 while(<LINKS>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
277
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
278 my ($chr1,$start1,$end1,$chr2,$start2,$end2,$count)=(split)[0,1,2,3,4,5,6];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
279
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
280 my $color=getColor($count,\%hcolor,"circos"); #get the color-code according the number of links
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
281
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
282 print SEGDUP "$index\t$id$chr1\t$start1\t$end1\tcolor=$color\n". #circos output
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
283 "$index\t$id$chr2\t$start2\t$end2\tcolor=$color\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
284 $index++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
285 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
286
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
287 close LINKS;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
288 close SEGDUP;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
289 print LOG "-- output created: $segdup_file\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
290 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
291 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
292 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
293 #convert the links file to the bedPE format for BEDTools usage
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
294 sub links2bedPElinksfile{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
295
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
296 my ($sample,$links_file,$bedpe_file)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
297
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
298 open LINKS, "<$links_file" or die "$0: can't open $links_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
299 open BEDPE, ">$bedpe_file" or die "$0: can't write in the output: $bedpe_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
300
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
301 my $nb_links=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
302
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
303 while(<LINKS>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
304
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
305 chomp;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
306 my @t=split("\t",$_);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
307 my ($chr1,$start1,$end1,$chr2,$start2,$end2)=splice(@t,0,6);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
308 my $type=($chr1 eq $chr2)? "INTRA":"INTER";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
309 $type.="_".$t[10];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
310
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
311 $start1--; $start2--;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
312
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
313 print BEDPE "$chr1\t$start1\t$end1\t$chr2\t$start2\t$end2".
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
314 "\t$sample"."_link$nb_links\t$type\t.\t.".
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
315 "\t".join("|",@t)."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
316
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
317 $nb_links++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
318 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
319
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
320 close LINKS;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
321 close BEDPE;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
322
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
323 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
324 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
325 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
326 sub bedPElinks2linksfile{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
327
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
328 my ($bedpe_file,$links_file)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
329
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
330 open BEDPE, "<$bedpe_file" or die "$0: can't open: $bedpe_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
331 open LINKS, ">$links_file" or die "$0: can't write in the output $links_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
332
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
333 while(<BEDPE>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
334
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
335 chomp;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
336 my $sample=(split("_",(split("\t",$_))[6]))[0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
337 my @t1=(split("\t",$_))[0,1,2,3,4,5];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
338 my @t2=split(/\|/,(split("\t",$_))[10]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
339 push(@t2,$sample);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
340
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
341 print LINKS join("\t",@t1)."\t".join("\t",@t2)."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
342
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
343 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
344 close BEDPE;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
345 close LINKS;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
346
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
347 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
348 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
349 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
350 #convert the links file to the bed format
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
351 sub links2bedfile{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
352
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
353 my ($tag_length,$color_code,$links_file,$bed_file)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
354
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
355 print LOG "\# Converting to the bed format...\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
356
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
357 my $compare=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
358 if($links_file!~/compared$/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
359 $compare=0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
360 $tag_length->{none}->{1}=$tag_length->{1};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
361 $tag_length->{none}->{2}=$tag_length->{2};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
362 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
363
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
364 #color-code hash table
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
365 tie (my %hcolor,'Tie::IxHash');
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
366 my %color_order;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
367 $color_order{"255,255,255"}=0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
368 my $n=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
369 foreach my $col (keys %{$color_code}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
370 my ($min_links,$max_links)=split(",",$color_code->{$col});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
371 $hcolor{$col}=[$min_links,$max_links];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
372 $color_order{$col}=$n;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
373 $n++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
374 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
375
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
376 my %pair;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
377 my %pt;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
378 $n=1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
379 open LINKS, "<$links_file" or die "$0: can't open $links_file:$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
380
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
381 my %str=( "F"=>"+", "R"=>"-" );
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
382
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
383 while(<LINKS>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
384
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
385 my @t=split;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
386 my $sample=($compare)? pop(@t):"none";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
387
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
388 my $chr1=$t[0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
389 my $chr2=$t[3];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
390 $chr1 = "chr".$chr1 unless ($chr1 =~ m/chr/i);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
391 $chr2 = "chr".$chr2 unless ($chr2 =~ m/chr/i);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
392 my $same_chr=($chr1 eq $chr2)? 1:0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
393
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
394 my $count=$t[6];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
395 my $color=getColor($count,\%hcolor,"bed");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
396
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
397 my @pairs=deleteBadOrderSensePairs(split(",",$t[7]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
398 my @strand1=deleteBadOrderSensePairs(split(",",$t[8]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
399 my @strand2=deleteBadOrderSensePairs(split(",",$t[9]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
400 my @ends_order1=deleteBadOrderSensePairs(split(",",$t[10]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
401 my @ends_order2=deleteBadOrderSensePairs(split(",",$t[11]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
402 my @position1=deleteBadOrderSensePairs(split(",",$t[14]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
403 my @position2=deleteBadOrderSensePairs(split(",",$t[15]));
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
404 my @start1; my @end1; getCoordswithLeftMost(\@start1,\@end1,\@position1,\@strand1,\@ends_order1,$tag_length->{$sample});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
405 my @start2; my @end2; getCoordswithLeftMost(\@start2,\@end2,\@position2,\@strand2,\@ends_order2,$tag_length->{$sample});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
406
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
407
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
408 for my $p (0..$#pairs){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
409
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
410 if (!exists $pair{$pairs[$p]}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
411
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
412 if($same_chr){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
413
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
414 $pair{$pairs[$p]}->{0}=[ $chr1, $start1[$p]-1, $end2[$p], $pairs[$p], 0, $str{$strand1[$p]},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
415 $start1[$p]-1, $end2[$p], $color,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
416 2, $tag_length->{$sample}->{$ends_order1[$p]}.",".$tag_length->{$sample}->{$ends_order2[$p]}, "0,".($start2[$p]-$start1[$p]) ];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
417 $pt{$n}=$pair{$pairs[$p]}->{0};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
418 $n++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
419
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
420 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
421
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
422 $pair{$pairs[$p]}->{1}=[ $chr1, $start1[$p]-1, $end1[$p] , $pairs[$p]."/1", 0, $str{$strand1[$p]},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
423 $start1[$p]-1, $end1[$p], $color,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
424 1, $tag_length->{$sample}->{$ends_order1[$p]}, 0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
425 $pt{$n}=$pair{$pairs[$p]}->{1};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
426 $n++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
427
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
428
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
429 $pair{$pairs[$p]}->{2}=[ $chr2, $start2[$p]-1, $end2[$p], $pairs[$p]."/2", 0, $str{$strand2[$p]},
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
430 $start2[$p]-1, $end2[$p], $color,
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
431 1, $tag_length->{$sample}->{$ends_order2[$p]}, 0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
432 $pt{$n}=$pair{$pairs[$p]}->{2};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
433 $n++;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
434 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
435 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
436
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
437 if($same_chr){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
438 ${$pair{$pairs[$p]}->{0}}[8]=$color if($color_order{$color}>$color_order{${$pair{$pairs[$p]}->{0}}[8]});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
439 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
440 ${$pair{$pairs[$p]}->{1}}[8]=$color if($color_order{$color}>$color_order{${$pair{$pairs[$p]}->{1}}[8]});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
441 ${$pair{$pairs[$p]}->{2}}[8]=$color if($color_order{$color}>$color_order{${$pair{$pairs[$p]}->{2}}[8]});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
442 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
443 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
444 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
445 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
446 close LINKS;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
447
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
448 my $nb_pairs=$n-1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
449
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
450 open BED, ">$bed_file" or die "$0: can't write in the output: $bed_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
451 print BED "track name=\"$bed_file\" description=\"mate pairs involved in links\" ".
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
452 "visibility=2 itemRgb=\"On\"\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
453
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
454 for my $i (1..$nb_pairs){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
455 print BED join("\t",@{$pt{$i}})."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
456 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
457
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
458 close BED;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
459
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
460 print LOG "-- output created: $bed_file\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
461
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
462 undef %pair;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
463 undef %pt;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
464
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
465 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
466 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
467 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
468 sub links2SVfile{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
469
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
470 my($links_file,$sv_file)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
471
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
472 print LOG "\# Converting to the sv output table...\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
473 open LINKS, "<$links_file" or die "$0: can't open $links_file:$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
474 open SV, ">$sv_file" or die "$0: can't write in the output: $sv_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
475
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
476 my @header=qw(chr_type SV_type BAL_type chromosome1 start1-end1 average_dist
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
477 chromosome2 start2-end2 nb_pairs score_strand_filtering score_order_filtering score_insert_size_filtering
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
478 final_score breakpoint1_start1-end1 breakpoint2_start2-end2);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
479
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
480 my $nb_links=0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
481
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
482 while (<LINKS>){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
483
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
484 my @t=split;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
485 my @sv=();
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
486 my $sv_type="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
487 my $strand_ratio="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
488 my $eq_ratio="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
489 my $eq_type="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
490 my $insert_ratio="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
491 my $link="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
492 my ($bk1, $bk2)=("-","-");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
493 my $score="-";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
494
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
495 my ($chr1,$start1,$end1)=($t[0],$t[1],$t[2]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
496 my ($chr2,$start2,$end2)=($t[3],$t[4],$t[5]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
497 my $nb_pairs=$t[6];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
498 $chr1 = "chr".$chr1 unless ($chr1 =~ m/chr/i);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
499 $chr2 = "chr".$chr2 unless ($chr2 =~ m/chr/i);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
500 my $chr_type=($chr1 eq $chr2)? "INTRA":"INTER";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
501
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
502 #if strand filtering
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
503 if (defined $t[16]){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
504 #if inter-chr link
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
505 $sv_type=$t[16];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
506 if(defined $t[17] && $t[17]=~/^(\d+)\/(\d+)$/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
507 $strand_ratio=floor($1/$2*100)."%";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
508 $score=$t[18];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
509 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
510 if(defined $t[18] && $t[18]=~/^(\d+)\/(\d+)$/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
511 #if intra-chr link with insert size filtering
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
512 $strand_ratio=floor($1/$2*100)."%";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
513 $link=floor($t[17]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
514 if($sv_type!~/^INV/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
515 $insert_ratio=floor($1/$2*100)."%" if($t[19]=~/^(\d+)\/(\d+)$/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
516 $score=$t[20];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
517 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
518 $score=$t[19];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
519 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
520 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
521 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
522
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
523 if(defined $t[18] && ($t[18] eq "UNBAL" || $t[18] eq "BAL")){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
524
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
525 #if strand and order filtering only and/or interchr link
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
526 $eq_type=$t[18];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
527 $eq_ratio=floor($1/$2*100)."%" if($t[19]=~/^(\d+)\/(\d+)$/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
528 ($bk1, $bk2)=($t[20],$t[21]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
529 foreach my $bk ($bk1, $bk2){$bk=~s/\),\(/ /g; $bk=~s/(\(|\))//g; $bk=~s/,/-/g;}
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
530 $score=$t[22];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
531
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
532 }elsif(defined $t[19] && ($t[19] eq "UNBAL" || $t[19] eq "BAL")){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
533
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
534 #if all three filtering
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
535 $link=floor($t[17]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
536 $eq_type=$t[19];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
537 $eq_ratio=floor($1/$2*100)."%" if($t[20]=~/^(\d+)\/(\d+)$/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
538
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
539 if(defined $t[21] && $t[21]=~/^(\d+)\/(\d+)$/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
540 $insert_ratio=floor($1/$2*100)."%";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
541 ($bk1, $bk2)=($t[22],$t[23]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
542 $score=$t[24];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
543
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
544 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
545 ($bk1, $bk2)=($t[21],$t[22]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
546 $score=$t[23];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
547 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
548 foreach my $bk ($bk1, $bk2){$bk=~s/\),\(/ /g; $bk=~s/(\(|\))//g; $bk=~s/,/-/g;}
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
549
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
550 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
551
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
552
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
553 push(@sv, $chr_type, $sv_type,$eq_type);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
554 push(@sv,"$chr1\t$start1-$end1");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
555 push(@sv, $link);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
556 push(@sv,"$chr2\t$start2-$end2",
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
557 $nb_pairs,$strand_ratio,$eq_ratio,$insert_ratio, decimal($score,4), $bk1, $bk2);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
558
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
559
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
560 print SV join("\t",@sv)."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
561 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
562
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
563 close LINKS;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
564 close SV;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
565
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
566 system "sort -k 9,9nr -k 13,13nr $sv_file > $sv_file.sorted";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
567
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
568 open SV, "<".$sv_file.".sorted" or die "$0: can't open in the output: $sv_file".".sorted :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
569 my @links=<SV>;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
570 close SV;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
571
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
572 open SV, ">$sv_file" or die "$0: can't write in the output: $sv_file :$!\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
573
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
574 print SV join("\t",@header)."\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
575 print SV @links;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
576 close SV;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
577
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
578 unlink($sv_file.".sorted");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
579
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
580 print LOG "-- output created: $sv_file\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
581
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
582 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
583 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
584 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
585 sub deleteBadOrderSensePairs{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
586
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
587 my (@tab)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
588 my @tab2;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
589
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
590 foreach my $v (@tab){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
591
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
592 $v=~s/[\(\)]//g;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
593 push(@tab2,$v) if($v!~/[\$\*\@]$/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
594 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
595 return @tab2;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
596 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
597 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
598 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
599 #gets starts and ends Coords when start=leftmost given positions, directions and orders
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
600 sub getCoordswithLeftMost {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
601
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
602 my ($starts,$ends,$positions,$strand,$end_order,$tag_length) = @_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
603
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
604 for my $i (0..scalar(@{$positions})-1) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
605
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
606 if($strand->[$i] eq 'F'){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
607 $starts->[$i]=$positions->[$i];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
608 $ends->[$i]=$positions->[$i]+$tag_length->{$end_order->[$i]}-1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
609 }else{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
610 $starts->[$i]=$positions->[$i]-$tag_length->{$end_order->[$i]}+1;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
611 $ends->[$i]=$positions->[$i];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
612 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
613 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
614 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
615 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
616 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
617 sub floor {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
618 my $nb = $_[0];
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
619 $nb=~ s/\..*//;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
620 return $nb;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
621 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
622 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
623 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
624 sub decimal{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
625
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
626 my $num=shift;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
627 my $digs_to_cut=shift;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
628
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
629 $num=sprintf("%.".($digs_to_cut-1)."f", $num) if ($num=~/\d+\.(\d){$digs_to_cut,}/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
630
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
631 return $num;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
632 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
633
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
634 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
635 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
636 #Sort links according the concerned chromosomes and their coordinates
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
637 sub sortLinks{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
638
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
639 my ($links_file,$sortedlinks_file,$unique)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
640
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
641 print LOG "# Sorting links...\n";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
642
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
643 my $pipe=($unique)? "| sort -u":"";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
644 system "sort -k 1,1 -k 4,4 -k 2,2n -k 5,5n -k 8,8n $links_file $pipe > $sortedlinks_file";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
645
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
646 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
647 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
648 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
649 sub getColor{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
650
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
651 my($count,$hcolor,$format)=@_;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
652 for my $col ( keys % { $hcolor} ) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
653 return $col if($count>=$hcolor->{$col}->[0] && $count<=$hcolor->{$col}->[1]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
654 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
655 return "white" if($format eq "circos");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
656 return "255,255,255" if($format eq "bed");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
657 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
658 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
659 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
660 #check if the configuration file is correct
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
661 sub validateconfiguration{
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
662
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
663 my %conf=%{$_[0]};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
664 my $list_prgs="@ARGV";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
665
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
666 my @circos_params=qw(organism_id colorcode);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
667 my @bed_params=qw(colorcode);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
668 my @compare_params=qw(list_samples list_read_lengths sample_link_file reference_link_file);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
669
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
670 unless (defined($conf{general}{output_dir})) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
671 $conf{general}{output_dir} = ".";
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
672 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
673 unless (-d $conf{general}{output_dir}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
674 mkdir $conf{general}{output_dir} or die;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
675 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
676 $conf{general}{output_dir}.="/" if($conf{general}{output_dir}!~/\/$/);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
677
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
678
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
679 if($list_prgs=~/links2compare/){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
680 foreach my $p (@compare_params) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
681 die("Error Config : The compare parameter \"$p\" is not defined\n") if (!defined $conf{compare}{$p});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
682 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
683
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
684 unless (defined($conf{compare}{same_sv_type})) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
685 $conf{compare}{same_sv_type} = 0;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
686 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
687
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
688 unless (defined($conf{compare}{min_overlap})) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
689 $conf{compare}{min_overlap} = 1E-9;
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
690 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
691
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
692 if($conf{compare}{circos_output}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
693 foreach my $p (@circos_params) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
694 next if($list_prgs=~/^ratio/ && $p eq "colorcode");
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
695 die("Error Config : The circos parameter \"$p\" is not defined\n") if (!defined $conf{circos}{$p});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
696 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
697 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
698 if($conf{compare}{bed_output}){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
699 foreach my $p (@bed_params) {
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
700 die("Error Config : The bed parameter \"$p\" is not defined\n") if (!defined $conf{bed}{$p});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
701 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
702 die("Error Config : The compare parameter \"list_read_lengths\" is not defined\n") if (!defined $conf{compare}{list_read_lengths});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
703
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
704 my @samples=split(",",$conf{compare}{list_samples});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
705 my @read_lengths=split(",",$conf{compare}{list_read_lengths});
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
706 for my $i (0..$#samples){
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
707 my @l=split("-",$read_lengths[$i]);
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
708 $conf{compare}{read_lengths}{$samples[$i]}={ 1=> $l[0], 2=> $l[1]};
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
709 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
710 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
711 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
712
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
713
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
714 }
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
715 #------------------------------------------------------------------------------#
c8744c56e979 Uploaded
bzeitouni
parents:
diff changeset
716 #::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::#