some variables declared before the method calls and the correct syntax for a CGI script.
###############################################################################
sub get_Input()
{
$html = new CGI; # create a new instance of CGI to upload file
$blastFile = $html->param('blast_Upload'); # upload file
$refFile = $html->param('ref_Upload'); # upload file
$blastSeq = param("blast_Seq");
chomp($refFile);
@dir = split(/\\/, $refFile);
pop(@dir);
$pathName = join('\\', @dir);
print("
$pathName is the location files will be saved to
");
print("
$blastFile
");
print("
$refFile
");
}
###############################################################################
sub get_Results()
{
#my $referenceFile;
#my $blastFile;
#if using this WITHOUT an reference file as input, cmdline must be as follows
# --blastresult result.txt --reffile file.txt (even if it's an empty file)
#GetOptions( "blastresult=s" => \$blastFile, "reffile=s" => \$refFile);
my $ref_File = "<" . $refFile;
my $blast_File = "<" . $blastFile;
print("
$blast_File
");
print("
$ref_File
");
## open file handles.############## PROBLEM HERE ##########
open( BLAST_FILE, $blast_File ) || die "$!";
open( REF_FILE, $ref_File ) || die "$!";
print("Blast File Opened
");
print("Reference File Opened
");
## output files - open them
my $newRefFile = "$pathName\\newRefFile.txt";
my $newBlastFile = "$pathName\\newBlastFile.txt";
open( NEW_ACC, ">$newRefFile" ) || die "$!";
open( NEW_ALIGN, ">$newBlastFile") || die "$!";
print("New files created
");
## put list of reference accessions into a structure so we can parse it...
my $refList = {}; # reference to empty hash
while ()
{
chomp; # removes newline character
$refList->{$_} = ""; # $_ is whatever line is currently open, thus creating a hash with key = accession, value = " "(.: defined)
}
#PARSE BLAST RESULT HERE....
#read results file one line at a time
my @resultLine = ;
my $alignment = {}; # reference to an empty hash
my @subjects = []; # reference to empty array
my $current_subject = "front_matter";
$alignment->{$current_subject} = "";
#so I produce a hash with key = >gi line of report and value = all lines after until next >gi
for (my $i = 0 ; $i/)
{
$current_subject = $resultLine[ $i ];
chomp ($current_subject);
push (@subjects, $current_subject);
$alignment->{$current_subject} = ""; #$alignment->{$current_subject} means give value of $alignment when $current_subject is the key
}
$alignment->{$current_subject} = $alignment->{$current_subject} . $resultLine[ $i ];
}
my @elements;
foreach my $z (@subjects)
{
chomp $z;
print "$z\n";
@elements = split('\|', $z);
if ( ! defined $elements[ 3 ] )
{
print "
Parsing Error
";
print "
Line $z
";
}
if (defined $elements[ 3 ] && defined $refList->{$elements[3]})
{
print "
Match
";
}
else
{
print "
No match
";
print NEW_ALIGN $alignment->{$z} . "
";
print NEW_ACC $elements[3]."
";
print $alignment->{$z} . "
";
print $elements[3]."
";
}
}
#close files
close REF_FILE;
close BLAST_FILE;
close NEW_ALIGN;
close NEW_ACC;
}