Hello,

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>&nbsp - New value added to new reference list + &nbsp</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.


In reply to RegExpression fails to work by MonkPaul

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.