get_chr_CR.pl 941 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my $usage="perl $0 sample.cov/sample.pcov
  5. Chech chrX and SRY Copy Ratio. ";
  6. die $usage unless @ARGV;
  7. my $covf=shift;
  8. my (%dat,$tot,$num);
  9. open my $fhcov,'<', $covf or die "Cannot open file:$covf $!";
  10. while(<$fhcov>){
  11. next if /^contig/ or $.==1;
  12. my ($chr,$start,$cnt)=(split /\s+/)[0,1,4];
  13. $chr=~s/chr//;
  14. next if $chr=~/Y/ and $start> 2700000;
  15. $dat{$chr}{CNT}++;
  16. $dat{$chr}{VAL}+=$cnt;
  17. $tot+=$cnt;
  18. $num++;
  19. }
  20. close($fhcov);
  21. my $avg=$tot/$num;
  22. my @chrs=(1..22,'X','Y');
  23. print "#Chr\tCopy_Ratio\tCopy_Infer\n";
  24. for my $chr(@chrs){
  25. next unless exists $dat{$chr};
  26. my $chr_tot=$dat{$chr}{VAL};
  27. my $chr_num=$dat{$chr}{CNT};
  28. $chr="SRY" if $chr eq 'Y';
  29. my $chr_avg=sprintf("%.2f",$chr_tot/($chr_num*$avg));
  30. my $copy=2;
  31. if($chr_avg<0.1){
  32. $copy=0;
  33. }elsif($chr_avg<0.75){
  34. $copy=1;
  35. }
  36. print $chr,"\t",$chr_avg,"\t$copy\n";
  37. }