#!/usr/local/bin/perl use strict; use warnings; use Data::Dump qw(pp); use feature qw(switch say); my $path = "testSample.txt"; open(FH, $path) or die("error, $!\n"); my (%hetero, %homo, %unclassified); until(eof(FH)){ my ($file, $patientName, $panel, $snp, $allele1, $allele2, $size1, $size2)= split "\t", ; $snp ||='';$allele1 ||= ''; $allele2||=''; #if not initialized set to '' chomp($snp); $snp = 'missed' if $snp eq ''; given($allele1, $allele2){ when($allele1 ne '' && $allele2 ne ''){constructHetero($snp, $patientName, $allele1, $allele2)} when($allele1 ne '' && $allele2 eq ''){constructHomo('type1', $snp,$patientName, 'allele1', $allele1)} when($allele1 eq '' && $allele2 ne ''){constructHomo('type2', $snp,$patientName, 'allele2', $allele2)} when($allele1 eq '' && $allele2 eq ''){constructUnclassified($snp, $patientName)} } } sub constructHetero{ my ($snp, $patientName, $allele1, $allele2) = @_; $hetero{$snp}{$patientName}{'allele1'}=$allele1; $hetero{$snp}{$patientName}{'allele2'}=$allele2; $hetero{$snp}{$patientName}{'records'}++; $hetero{$snp}{'total_records'}++; }; sub constructHomo{ my ($type, $snp, $patientName, $alleleNumber,$allele)=@_; $homo{$type}{$snp}{$patientName}{$alleleNumber}=$allele; $homo{$type}{$snp}{$patientName}{'records'}++; $homo{$type}{$snp}{'total'}++; $homo{$type}{'total_records'}++; } sub constructUnclassified{ my($snp, $patientName)=@_; $unclassified{$snp}{$patientName}{'records'}++; $unclassified{$snp}{'total'}++; $unclassified{'total_records'}++; } #print pp(\%hetero); #print pp(\%homo); #print pp(\%unclassified); #### testSample.txt Sample File Sample Name Panel SNP Allele 1 Allele 2 Size 1 Size 2 011.fsa MS-039 Panel_3130 012.fsa MS-039 Panel_3130 31.76 014.fsa MS-291 Panel_3130 rs7577363 90.79 92.46 013.fsa MS-291 Panel_3130 rs7577363 006.fsa MS-290 Panel_3130 rs10735781 G 78.69 80.31 005.fsa MS-290 Panel_3130 rs10735781 G 78.85 80.32 011.fsa MS-039 Panel_3130 rs10735781 C 78.63 80.1 001.fsa MS-148 Panel_3130 rs10735781 C G 78.57 80.2 ####