biohisham has asked for the wisdom of the Perl Monks concerning the following question:
So fellow monks, I present before you the code after having become spent for my efforts with some records from the tab-delimited dataset, the combination of the code conditionals reflect whether or not some entries in the columns SNP, Allele1 and Allele2 are missing, and seeking your explanation on why this error arises and how to go about resolving it I afford you my appreciations and the kindest of gratitude ..
#!/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, $siz +e1, $size2)= split "\t", <FH>; $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 ''){constructUnclas +sified($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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
by TomDLux (Vicar) on Oct 18, 2010 at 13:56 UTC | |
by biohisham (Priest) on Oct 18, 2010 at 14:09 UTC | |
by biohisham (Priest) on Oct 18, 2010 at 17:15 UTC | |
by TomDLux (Vicar) on Oct 18, 2010 at 19:05 UTC | |
|
Re: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
by AnomalousMonk (Archbishop) on Oct 18, 2010 at 17:25 UTC | |
|
Re: Text Analysis: given(){when(){}} block throws a 'useless use of private variable...etc' error
by kcott (Archbishop) on Oct 18, 2010 at 14:19 UTC |