#!/usr/local/perl #we modified the main program by removing processing the likelihoods so we get faster program to count dif in two individuals from same population $chunk =$ARGV[1]*1000000 +1; $dir = 'PUR_Rare_April28'; mkdir "./$dir", 0750 unless -d "./$dir"; open(OUT1, ">./$dir/$ARGV[0]_$ARGV[1]_Aa")|| die "Can't open 1_1 output : $!\n"; # open(OUT2, ">./$dir/$ARGV[0]_$ARGV[2]_$ARGV[3]_B")|| die "Can't open 2_2 output : $!\n"; $str = localtime(); #print OUT1 "$str\n"; #@pair_id = (); open (FILE1, "zcat /home/ahmed/PUR_RareSNPs_Table.txt.gz |") || die "Can't open RareSNPs table file : $!\n"; $line_N = 0; while (){ $line_N++; if ($line_N == 1){ chop $_; @ID = split(/\t/, $_); $n = 1; # to test that we are getting the IDs line foreach (@ID) { print "$n\t$_\n";$n++; } last; } } #new edit to test for two individuals. #@pair_id = ('NA19328', 'NA19312');#TWo GBR individual to test for $x (0..$#ID) { for $y (0..$#ID) { if ($ID[$x] eq $ID[$y]) { push(@columns, $x); # #end of the edit. } } } for $n(0..$#columns){ print $columns[$n]."\n";} # # open (FILE, "zcat /home/ahmed/PUR_RareSNPs_Table.txt.gz |") || die "Can't open zipped file chr21 : $!\n"; $line_N = 0; #$w, $z two individuals from the analyzed population(e.g. GBR) @diff = (); while (){ $line_N++; if ($line_N >= $chunk + 1000000) {last;} if ($line_N > 1 && $line_N >= $chunk) { if ($line_N%1000 ==0 ) {print "$line_N PUR\n";} if ($line_N > 1){ # print "my god\n"; @e = split(/\t/, $_); # print $e[1]."\n"; for $w (0..$#columns){ for $z (0..$#columns){ if ($w < $z){ # @e = split(/\t/, $_); # 1.To calculate Differneces between each two individuals. if ($e[$columns[$w]] =~/^(\d)\|(\d)\:(.+)\:(.+)\,(.+)\,(.+)/){ $p1 = $1 + $2; # print $p1."\n"; } if ($e[$columns[$z]] =~/^(\d)\|(\d)\:(.+)\:(.+)\,(.+)\,(.+)/){ $p2 = $1 + $2; # print $p2."\n"; } #to calcualte total differences # $diff[$w][$z] += abs ($p1 - $p2); # $my = abs ($p1 - $p2); # print $my."\n"; # End of 1. # to calcualte shared rare SNPS. if ($p1 == 1 && $p2 == 1){$one_one_common[$w][$z]++; #print "found common \n"; } if ($p1 == 2 && $p2 == 2){$two_two_common[$w][$z]++;} if (($p1 == 2 && $p2 == 1) || ($p1 == 1 && $p2 == 2)){$two_one_common[$w][$z]++;} } } } } } } for $w (0..$#columns) { for $z (0..$#columns) { if ($w < $z) { #to print total differences : # print OUT1 "$columns[$w]\t$columns[$z]\t$diff[$w][$z]\n"; # to Print Shared rare SNPs.: $Total = $one_one_common[$w][$z] + ($two_two_common[$w][$z]* 2) + ($two_one_common[$w][$z]); print OUT1 "$columns[$w]\t$ID[$columns[$w]]\t$columns[$z]\t$ID[$columns[$z]]\tOne_One:\t$one_one_common[$w][$z]\tTwo_Two:\t$two_two_common[$w][$z]\tTwo_One:\t$two_one_common[$w][$z]\t $Total\n"; } } } $str2 = localtime(); print OUT1 "$str2\n";