3 Author: Hu Xuesong @ BIOPIC <galaxy001@gmail.com>
4 Version: 1.0.0 @ 20120720
8 use Data
::Dump
qw(ddx);
11 use List
::MoreUtils
'first_index';
13 die "Usage: $0 <plink model file> <bcgv bcf> <out>\n" if @ARGV<3;
19 open O
,'>',$outfs or die "Error opening $outfs: $!\n";
20 $t = "# In: [$plinkfs],[$bcfs], Out: [$outfs]\n";
24 my (%Plink,@PlinkS,%Vcf,$SortI,$TypeI,%Types);
25 open L
,'<',$plinkfs or die;
29 $SortI = first_index
{ $_ eq 'P' } (split /\s+/);
30 $TypeI = first_index
{ $_ eq 'TEST' } (split /\s+/);
31 #warn $SortI,(split /\s+/)[$SortI];
36 my @Dat = split /\s+/; # $chr,$markID,$min,$maj,$model,@other
39 #die '[',join('|',@Dat),"]\n";
40 $Plink{$t}{$Dat[$TypeI]} = \
@Dat;
46 my $th = openpipe
('bcftools view -I',$bcfs); # -I skip indels
47 my (@Samples,@Parents);
51 my @data = split /\t/;
52 if ($data[0] eq '#CHROM') {
53 @Samples = map {my $t=(split /\//)[-1];$t=~s/_cut
//g;$t=~s/-/./g; $_=join('_',(split /\./,$t)[-5,-6]);} splice @data,9;
54 # ../5.bam_0000210210_merged/d1_4_merged.D4.JHH001.XTU.sort.rmdup.bam
55 @Parents = grep(!/^GZXJ/,@Samples);
59 print O
"# Samples: [",join('],[',@Samples),"]\n# Parents: [",join('],[',@Parents),"]\n";
60 warn "Samples:\n[",join("]\n[",@Samples),"]\nParents: [",join('],[',@Parents),"]\n";
62 my ($VCF_In,%ChrPn,%ChrPs,%TypePsum);
69 #my ($CHROM, $POS, $ID, $REF, $ALT, $QUAL, $FILTER, $INFO, $FORMAT, @data) = split /\t/;
70 my @data = split /\t/;
71 ++$VCF_In; # also as rs#
72 if (exists $Plink{$VCF_In}) {
73 $Vcf{$VCF_In} = \
@data;
74 for (keys %{$Plink{$VCF_In}}) {
75 $t = $Plink{$VCF_In}{$_}->[$SortI];
76 $ChrPs{$_}{$data[0]} += $t;
80 #$ChrPs{$data[0]} += $Plink{$VCF_In}->[$SortI];
86 print O
'# ChrID Count: ',scalar(keys %ChrPn),"\n",'# SNP Count: ',scalar(keys %Plink),"\n";
92 for my $type (sort { $TypePsum{$a} <=> $TypePsum{$b} } keys %Types) {
93 for my $chr (keys %ChrPn) {
94 $ChrPs{$type}{$chr} /= $ChrPn{$chr};
96 @PlinkS = sort { $ChrPs{$type}{$Vcf{$a}->[0]} cmp $ChrPs{$type}{$Vcf{$b}->[0]} || $Plink{$a}{$type}->[$SortI] <=> $Plink{$b}{$type}->[$SortI] } keys %Plink;
98 print O
join("\t",@
{$Plink{$_}{$type}},@
{$Vcf{$_}}),"\n";
99 print "{$_}{$type},@{$Plink{$_}{$type}}\n";