perlquestion
MonkPaul
Hello,
<P>
Further to my problems i posted yesterday i cannot seem to get the program to recognise information stored in one file and compare it to another file.
<P>
This is some of the code a colleague gave me to get it to recognise an Accession number in one file and compare it to an element in an array, obtained from a second file.
<P>
The $ref_filehandle holds the data from the reference file that contains only a list of Accession numbers, i.e. <BR>
<code>
AB014570.2
AB055861.1
AB067522.1
AB073617.1
AC004166.12
AC004851.2
AC004867.5
AC004883.3
AC005077.5
AC005080.2
</code>
Where as the @subjects holds in each element :
<BR>gi|14670349|ref|NM_032999.1| Homo sapiens general transcription factor II, i (GTF2I), transcript .... or a derivetive of.
<P>
The problem i have is that the hash %refList holds all the accession numbers in KEY = Accession VALUE = Accession, so both accession values are stored in key and value - should be an array i know but i need speed when searching through for each element of @subjects, hence the use of "defined" function.
<BR>
The only problem is that the " if " statement highlighted always equates to false....WHY?<P>
I have found, using print statements, that the hash does have the right values stored in it, but when searched for <code>$elements[3]</code> element it cant find it, so i tried "! defined" - and guess what, it equates to true. Knowing that the values are stored in the hash i can only assume the problem lies with the if statement.
<readmore>
<code>
sub get_Results()
{
open( NEWACC, ">ref_files/$newRefFile" ) || die "$!";
open( NEWALIGN, ">blast_files/$newBlastFile") || die "$!";
## put list of reference accessions into a structure so we can parse it...
my %refList = ();
while (<$ref_filehandle>) # used instead of REFFILE
{
chomp; # removes newline character
my $key = $_;
$refList{ $key } = "$_";
}
#PARSE BLAST RESULT HERE....
#read results file one line at a time
my @resultLine = <$blast_filehandle>; # used instead of BLASTFILE
my $alignment = {}; # reference to an empty hash
my @subjects; # reference to empty array
my $current_subject = "front_matter";
$alignment->{$current_subject} = "";
for (my $i = 0 ; $i<scalar @resultLine; $i++)
{
if ($resultLine[$i] =~ /^>/)
{
$current_subject = $resultLine[ $i ];
chomp ($current_subject);
push (@subjects, $current_subject);
$alignment->{$current_subject} = "";
}
$alignment->{$current_subject} = $alignment->{$current_subject}.$resultLine[ $i ];
}
my @elements;
foreach my $z (@subjects)
{
chomp $z;
@elements = split('\|', $z);
if ( ! defined $elements[ 3 ] )
{
print ("Parsing Error<BR>");
print ("Line $z");
}
##### PROBLEM LIES HERE WITH IF STATEMENT
if (defined $elements[3] && defined $refList{$elements[3]} )
{
print ("Already Present in file");
}
else
{
print "No match in reference file";
print (NEWALIGN $alignment->{$z}."\n");
print (NEWACC $elements[3]."\n");
}
}
#close files
close NEWALIGN;
close NEWACC;
}
</code>
</readmore>
<P>
Any help is really appreciated - including any critical appraisal as its not my handy work.
<P>
Cheers people
<BR>
MonkPaul.