chomp @INFILE2 loop. You are right, I should have chomped the lines. Because I get that file by using another script where I add \n at the end. Thanks for pointing it out.
I revised the code in line with your suggestions, and get the following errors:
Possible unintended interpolation of @VariantList in string at PD.pl line 91.
I have no idea why I am getting this error. I thought I can safely use an array to print it out in this way.
Type of arg 1 to push must be array (not hash slice) at PD.pl line 33, near "$line;"
This is weird?!
Global symbol "@VariantList" requires explicit package name at PD.pl l +ine 91. Execution of PD.pl aborted due to compilation errors.
And here is the code. #!/usr/bin/perl -w use strict; use Data::Dumper; my %info = (); my $humangi; my $data = '/DATA/proteinfile.txt'; open INFILE, '<', $data or die "Failed at opening $data!\n"; # Construct the hash with GIs as keys and sequences as values while ( <INFILE> ) { my $line = $_; chomp($line); last if m!END!; if($line=~m/HUMAN/){ ($humangi) = ($line=~m/^\S+\|(\d+)/) } if($line=~m/^\S+\|(\d+)/) { if(defined($1)) { my $gi=$1; } } else { if (defined(my $gi)) { push (@info{$gi}, $line); } else { die "Badly formatted file. Failed at reading the GI!\n"; } } } #print Dumper (\%info); print "$humangi\n"; close(INFILE); my $data2 = '/DATA/variantlist.txt'; open INFILE2, '<', $data2 or die "Failed at opening $data2!\n"; my $data3 = '/DATA/VariantOutput.txt'; open OUTFILE, '>', $data3 or die "Failed at opening $data3!\n"; while ( <INFILE2>){ # Grab a variant from the file (in this example: P82L) my $line2 = $_; chomp($line2); my $Variant = $line2; # Split the variant into three parts my ($source, $position, $sink) = split(/(\d+)(\w)/, $Variant); print "$source , $ position , $sink\n"; # Check whether HS has the source (i.e., P) at the given position (i.e +., 82) my @temp = @info{$humangi}; if ( $temp[$position] eq $source) { print "Yep, $source has been confirmed!\n"; } else { print "There is something wrong!\n"; } # Scan the rest of the sequences to check what amino acid they have at + the given position for my $gi ( keys %info ) { my @value = @info{$gi}; my @VariantList = (); push ( @VariantList, $value[$position]); if ($value[$position] eq $sink){ # Note the cases where we obs +erve the sink (i.e., L) at this position print OUTFILE "A pathogenic deviation has been found at si +te $position - from $source to $sink !\n" . " And the corresponding g +i for this deviation is: $gi\n"; } } print OUTFILE "Variant list contains: @VariantList\n"; } close(INFILE2);
In reply to Re^2: Use of uninitialized value in string eq
by sophix
in thread Use of uninitialized value in string eq
by sophix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |