MonkPaul has asked for the wisdom of the Perl Monks concerning the following question:
Im working on a script at the moment that looks through a file and stores each line into an element for a given record. Say one array per record.
I know that in the last element of the array that their is information relating to an organisms species. I previously split the $line on a "|" and printed the elements to the screen, so i know that the array holds the right info.
What i now want to do is show in a web page only those that match e.g Homo sapiens. This value to filter by is chosen by the user on a web page and stored in a variable called $species_filter.
I have tried to just get the regex working for a simple case when it first failed but even that didnt work.
The example of the array stuff is
gi|2827179|gb|AF035737.1|AF035737 Homo sapiens general transcription factor 2-I (GTF2I) mRNA, complete.
The important parts of the code are below:
sub filter_by_Species() { print("New Blast File Opened<BR>"); open( NEWALIGN, "<blast_files/$newBlastFile") || die "$!"; print("Filtering Data........Please wait<P>"); #PARSE BLAST RESULT HERE.... #read results file one line at a time my @resultLine = <NEWALIGN>; # 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} = ""; #so I produce a hash with key = >gi line of report and value = all lin +es after until next >gi 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} means give value of $alignment when $current_subject is the + key } $alignment->{$current_subject} = $alignment->{$current_subject}.$r +esultLine[ $i ]; } my @elements; my $boolean; print("<TABLE BORDER=2>"); print("<th align=center><B>Status</B></th>"); print("<th align=center><B>Information on new hits</B></th>"); foreach my $z (@subjects) { chomp $z; @elements = split('\|', $z); if($elements[4] =~ /^$species_filter/) ##### filtering part here { $boolean = 0; print ("<TR><TD>Match to $species_filter"); show_Output($boolean, $z, @elements); } } print("</TABLE><BR><BR>"); #close files close NEWALIGN; } ###################################################################### +########## # Display the blast results to user in easy to view format sub show_Output() # HTML code { my ($boolean, $z, @elements_copy) = @_; $elements_copy[1] = '<a href="http://www.ncbi.nlm.nih.gov/entrez/v +iewer.fcgi?db=nucleotide&val='.$elements_copy[1].">Link</a>"; if($boolean == 0) { print("<TR><TD> $z </TD><TD>@elements_copy[1]</TD></TR>"); } else { print("<TD> $z <BR>  - New value added to new reference list +  </TD><TD>@elements_copy[1]</TD></TR>"); } }
The books i have for this sort of thing arent very good so im struggling a bit with the use of Regex.
Can anybody give me some pointers on why its failing to find $species_filter. (Oh and im not sure if i can use /^$species_filter/ as i think that it may just look for ^"$species_filter" and not its value.
Cheers
MonkPaul.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegExpression fails to work
by jeffa (Bishop) on Jun 14, 2005 at 13:31 UTC | |
by MonkPaul (Friar) on Jun 14, 2005 at 15:22 UTC | |
|
Re: RegExpression fails to work
by tlm (Prior) on Jun 14, 2005 at 13:24 UTC | |
|
Re: RegExpression fails to work
by thundergnat (Deacon) on Jun 14, 2005 at 14:15 UTC | |
by MonkPaul (Friar) on Jun 14, 2005 at 15:04 UTC |