#! /usr/bin/perl open(FILE,$ARGV[0]) || die "Unable to open file"; %nhash = (); while() { @a = split; #HWI-ST674_0111:4:2207:13207:103630#0/3 $a[0] =~ s/\/3$//g; if(($a[1] == 161 || $a[1] == 97) && $a[4] >= 20) { $id[$i] = $a[0]; $chr[$i] = $a[2]; $pos[$i] = $a[3]; $str[$i] = "+"; $dist[$i] = $a[8]; $length[$i] = length($a[9]); $i++; $idhash{$a[0]} = "aaaa"; } if(($a[1] == 145 || $a[1] == 81) && $idhash{$a[0]} eq "aaaa") { $key = $a[0]; $length = length($a[9]); $val = "$a[2]\t$a[3]\t-\t$a[8]\t$length"; $nhash{$key} = $val; } } #print "$i \n"; $chr = $chr[$i-1]; for($j=0;$j<$i;$j++) { if(($pos[$j] - $pos[$j-1] > 300 ) || ($dist[$j] - $dist[$j-1] > 300 || $dist[$j-1] - $dist[$j] > 300)) { #print "$k $l\n"; if($k==1 && $l==1) { @parr = split(/\t/,$ll[0]); @narr = split(/\t/,$kk[0]); } if($k > 1 && $l > 1) { for($m=0;$m<$k;$m++) { @parr = split(/\t/,$ll[$m]); $ppos[$b] = $parr[2]; $pdist[$b] = $parr[4]; $plength[$b] = $parr[5]; $sum_pdist = $sum_pdist + $parr[4]; $b++; } for($n=0;$n<$l;$n++) { @narr = split(/\t/,$kk[$n]); $npos[$c] = $narr[2]; $ndist[$c] = $narr[4]; $nlength[$c] = $narr[5]; $c++; } @npos = sort(@npos); #print "@npos\n"; $pstart = $ppos[0]; $pend = $ppos[$b-1]; $prealend = $ppos[$b-1] + $plength[$b-1]; $nstart = $npos[0]; $nend = $npos[$c-1]; $del_length = $nstart - $prealend; $avg_dist = $sum_pdist / $b; $real_del_length = $avg_dist - 200; if($del_length > 0) { print "$chr\t$k\t$pstart\t$pend\t$prealend\t$nstart\t$nend\t$l\t$del_length\t$avg_dist\t$real_del_length\n"; } @ppos=(); @pdist =(); @plength = (); @npos = (); @ndist = (); @nlength =(); } $k=0;$l=0; $b=0;$c=0; $sum_pdist = 0; $#ll = -1; $#kk = -1; } $ll[$k] = "$id[$j]\t$chr[$j]\t$pos[$j]\t$str[$j]\t$dist[$j]\t$length[$j]"; $k++; $nhval = $nhash{$id[$j]}; $kk[$l] = "$id[$j]\t$nhval"; #print "$kk[$l]\n"; $l++; }