On Dec 4, 11:06 am, [EMAIL PROTECTED] (Minky Arora) wrote:
> I am quite new to perl so pls bear with me.I am trying to do some
> Bioinformatics Analysis.A part of my file looks like this:
>
> gene            410..1750
>                      /gene="dnaA"
>                      /db_xref="EMBL:2632267"
>      CDS             410..1750
>                      /gene="dnaA"
>                      /function="initiation of chromosome replication (DNA
>                      synthesis)"
>                      /note="alternate gene name: dnaH, dnaJ, dnaK"
>                      /codon_start=1
>                      /transl_table=11
>                      /protein_id="CAB11777.1"
>                      /db_xref="GI:2632268"
>
> I need to extract the range for gene as well as CDS and compare them.
>
> SO far this is where Ive reached:
> #!/usr/bin/perl
> use warnings;
> use strict;
> my $line;
> my @new;
> my $line1;
> open FILE,"/users/meenaksharora/bio.txt"or die"cannot open $!\n";
> foreach $line(<FILE>){
> if($line=~m/gene/)
>    [EMAIL PROTECTED];

This line most likely does not do what you think it does.  Are you
trying to add every line that matches 'gene' to the array?   That's
not what this does.  This overwrites the existing @new contents,
setting @new to be the last value of $line that matches 'gene'.  In
your example data, this is the second '/gene="dnaA"' line.

>     }}
>
> foreach $line1(@new){

So by the time you get to here, @new only has one element in it, and
you're iterating over that one element - '/gene="dnaA"'.  This line
obviously doesn't have any numbers in it, so the regexp fails.

>  if($line1=~m/(\d)+\.\./)
>   {   print $line1;print "hello";
>   }
>
> }
>
> I am not able to extract the lines with the digits.I am not sure
> why.IS there a better way to do this?? Can someone guide me how to go
> abt that?

You need better debugging skills, which will likely develop over
time.  You're assuming there's a problem with your regexp, when
there's actually a problem with your array.  If you'd printed the
contents of your array before the loop, you would have seen that.

change
@new = $line;
to
push @new, $line;
so that each matching value of $line gets added to the end of @new,
rather than overwriting the existing contents.

push @new, $line
means roughly the same thing as
@new = (@new, $line);
except it's more efficient.

Think of 'push' as the same sort of shortcut as the .= operator, so
you can write
$text .= $string;
rather than
$text = $text . $string;

perldoc -f push
for more information.

Paul Lalli


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to