5 use Data
::Dump
qw(ddx);
7 my $Usage = "Usage: $0 <vcf.gz> <out prefix>\n";
8 die $Usage if @ARGV < 1;
10 my ($filename,$outp) = @ARGV;
11 my $cmd = "bcftools view -U -m2 -i '%QUAL>=40 & MIN(FMT/GQ)>20 & GT[2]=\"het\"' -v snps $filename |bcftools view -e 'FMT/DP=\".\"'| bcftools query -f '%CHROM\t%POS\t%REF,%ALT\t%QUAL[\t%TGT:%AD:%GQ]\n'";
13 open(SID
,'-|',"bcftools query -l $filename") or die "Error opening [$filename]: $!\n";
21 my $theKiller = 'T3C';
22 my $theVictim = 'T10C';
23 my @addedSID = qw(Rsin);
24 my @AllSID = (@SampleIDs,@addedSID);
26 open O
,'>',"$outp.tfam" or die "[$outp.tfam]:$!\n";
30 print O
join(' ',$FID,$IID,0,0,0,0),"\n";
31 # https://www.cog-genomics.org/plink/1.9/formats#fam
43 my @GTs = sort keys %{$hashref};
45 if (scalar @GTs ==1) {
48 return join(' ',@GTs);
51 open O
,'>',"$outp.tped" or die "[$outp.tped]:$!\n";
52 open(IN
,"-|",$cmd) or die "Error opening [$filename]: $!\n";
55 my ($Chrom,$Pos,$RefAlt,$Qual,@GTs) = split /\t/,$_;
56 next if $Chrom =~ /_/;
58 my (%GTs,%GTstr,%GTped);
59 @GTstr{@SampleIDs} = @GTs;
61 for my $k (keys %GTstr) {
62 my ($sGT,$sAD,$sGQ) = split /:/,$GTstr{$k};
63 my @aGT = split /[|\/]/,$sGT;
64 my @aAD = split /\,/,$sAD;
69 #my @result = sort(keys %counter);
72 $GTs{$addedSID[0]} = {%{$GTs{'mixed'}}};
73 #$GTs{$addedSID[1]} = {%{$GTs{'mixed'}}};
74 for (keys %{$GTs{$theVictim}}) {
75 if (exists $GTs{$addedSID[0]}{$_}) {
76 delete $GTs{$addedSID[0]}{$_};
79 for my $k (keys %GTs) {
80 $GTped{$k} = mergeGT
($GTs{$k});
82 if (length($GTped{$addedSID[0]})==0) {
86 if (length($RefAlt)>3) {
93 $ChrCode =~ s/^chr//i;
95 my $VarID = 'p'.$vCounter.$RefAlt;
97 print O
join("\t",$ChrCode,$VarID,0,$Pos);
99 print O
"\t",$GTped{$k};
104 # https://www.cog-genomics.org/plink/1.9/formats#tped
105 # https://www.cog-genomics.org/plink/1.9/formats#map
106 # Chromosome code. PLINK 1.9 also permits contig names here, but most older programs do not.
108 # Position in morgans or centimorgans (optional; also safe to use dummy value of '0')
109 # Base-pair coordinate
113 print "plink --noweb --tfile $outp --make-bed --out xxx\n";