prep_FeBY2_plus.pl 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/perl
  2. use strict;
  3. use warnings;
  4. my $usage="\n\tperl $0 SampleName panel_type Ref_file\n\n";
  5. die $usage if @ARGV<3;
  6. my $sam=shift;
  7. my $panel=shift;
  8. my $ref_file=shift;
  9. my (%call,@cols);
  10. my $flag=0;
  11. my %hash=('FeBY2' => "Yesuan,Xueshuan",
  12. 'FeBY2_plus' => "Yesuan,Xueshuan,Zigong,Luanchao",
  13. 'IDT_WES' => "Yesuan,Xueshuan",
  14. 'MBY2' => "Yesuan"
  15. );
  16. unless( exists $hash{$panel}){
  17. print "NO Genotyping for $panel.\n";
  18. exit;
  19. }
  20. my $type=$hash{$panel};
  21. open my $call_fh, '<' , $sam.'.ye.norm.tab' or die "Cannot open $sam.ye.norm.tab\n$!";
  22. while(<$call_fh>){
  23. chomp;
  24. if(/^CHROM/){
  25. my @cont=split /\t/;
  26. for my $i(0..$#cont){
  27. push @cols,$i if $cont[$i] eq 'CHROM' or $cont[$i] eq 'POS'
  28. or $cont[$i] =~ /GT$/ or $cont[$i] =~ /GQ$/
  29. or $cont[$i] =~ /AD$/;
  30. }
  31. next;
  32. }
  33. my ($chr,$pos,$gt,$gq,$ad)=(split /\t/)[@cols];
  34. next if $gq eq 'NA' or $gq eq '.';
  35. my ($nref,$nalt)=split /,/,$ad;
  36. next if $nref+$nalt <7 ;
  37. $call{$chr.'_'.$pos}{$gt}=undef if $gq > 20;
  38. }
  39. close($call_fh);
  40. open my $reffh, ' <', $ref_file or die "Cannot open file:$ref_file \n$!";
  41. open my $wfh, ' >', $sam.'.GT.xls' or die "Cannot write file: \n$!";
  42. while(<$reffh>){
  43. s/\s+$//;
  44. if(/^##/){
  45. my ($key)=$_=~/^##(\w+)##\s*$/;
  46. $flag=1 if $type=~/$key/ ;
  47. print $wfh $_,"\n" if $flag;
  48. }elsif(/^_+\s*$/){
  49. print $wfh $_,"\n" if $flag;
  50. $flag=0;
  51. }else{
  52. next unless $flag;
  53. my ($chr,$pos, $gt, $strand, $info)=split /\t/,$_,5;
  54. if(/^#/){
  55. print $wfh '#'.$info,"\tResult\n";
  56. }else{
  57. my $res= exists $call{$chr.'_'.$pos}{$gt} ? '+' : '0';
  58. print $wfh $info,"\t", $res, "\n" if $res;
  59. }
  60. }
  61. }
  62. close($reffh);