#!/usr/bin/perl use strict; use warnings; my $usage="perl $0 sample.cov/sample.pcov Chech chrX and SRY Copy Ratio. "; die $usage unless @ARGV; my $covf=shift; my (%dat,$tot,$num); open my $fhcov,'<', $covf or die "Cannot open file:$covf $!"; while(<$fhcov>){ next if /^contig/ or $.==1; my ($chr,$start,$cnt)=(split /\s+/)[0,1,4]; $chr=~s/chr//; next if $chr=~/Y/ and $start> 2700000; $dat{$chr}{CNT}++; $dat{$chr}{VAL}+=$cnt; $tot+=$cnt; $num++; } close($fhcov); my $avg=$tot/$num; my @chrs=(1..22,'X','Y'); print "#Chr\tCopy_Ratio\tCopy_Infer\n"; for my $chr(@chrs){ next unless exists $dat{$chr}; my $chr_tot=$dat{$chr}{VAL}; my $chr_num=$dat{$chr}{CNT}; $chr="SRY" if $chr eq 'Y'; my $chr_avg=sprintf("%.2f",$chr_tot/($chr_num*$avg)); my $copy=2; if($chr_avg<0.1){ $copy=0; }elsif($chr_avg<0.75){ $copy=1; } print $chr,"\t",$chr_avg,"\t$copy\n"; }