Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Why does this happen?

by Marinegirl (Initiate)
on Aug 17, 2005 at 19:35 UTC ( #484553=note: print w/replies, xml ) Need Help??

in reply to Why does this happen?

Your monklynesses

I have a similar problem ....

I get the warning message "Argument "n" isn't numeric in array element at line 356."

My code looks like this:

foreach $qbase (@query_sequence [$q_start .. $q_end]) { if ($qbase eq ("n"||"N") && $subj_sequence[$qbase] ne ("n"||"N +")) { ++$ncount; } } foreach $sbase (@subj_sequence [$s_start .. $s_end]) { if ($sbase eq ("n"||"N") && $query_sequence[$sbase] ne ("n"||" +N")) { ++$ncount; } }

My code is intended to mean:
for each position between a start and end position in an array, if the element at that position is an 'n', and the element at the same position in another array is not an n, ++count. $q_start, $q_end, $s_start, $s_end are numbers. @query_sequence and @subj_sequence are arrays of letters. It works ok apart from the warning! Why does this happen and how do I fix it?

Many thanks for your help

Marinegirl x

Replies are listed 'Best First'.
Re^2: Why does this happen?
by poj (Abbot) on Aug 17, 2005 at 20:17 UTC
    Because $qbase is a letter, $query_sequence[$qbase] is not valid. To fix it change to this
    foreach $qbase ($q_start .. $q_end) # qbase is now a number { if ( ($query_sequence[$qbase] =~ /[nN]/) && ($subj_sequence[$qbase] +!~ /[nN]/) ) { ++$ncount; } }
      I'd keep them separate in case ($#qbase != $#sbase), and since you're not doing anything else with the index, just loop through them all...
      foreach $qbase ( @qbase ) { if ( uc($qbase) eq 'N' ) { ++$ncount; } } foreach $sbase ( @sbase ) { if ( uc($sbase) eq 'N' ) { ++$ncount; } }
      or more concisely...
      do { $ncount++ if /n/i } foreach ( @qbase, @sbase );
      Update: disregard, read the OP wrong

      Update: re-read, and the answer doesn't take into account if subj_sequence is n and query is not...
      foreach my $idx ( 1..$#query_sequence ) { if ( $query_sequence[$idx] =~ /n/i && $subj_sequence[$idx] !~ /n/i ) + { $ncount++; } elsif ( $subj_sequence[$idx] =~ /n/i && $query_sequence[$idx] !~ / +n/i ) { $ncount++; } }
      (Note that it is assumed that $#query_sequence = $#subj_sequence)

      Update: again..
      $ncount = grep { ($qbase[$_] =~ /n/i && $sbase[$_] !~ /n/i) || ($qbase +[$_] !~ /n/i && $sbase[$_] =~ /n/i) } 1..$#qbase;
        Wow .... I never thought I'd get this much help this fast. Thankyou both very much.

        "(Note that it is assumed that $#query_sequence = $#subj_sequence)"
        The problem is that they aren't equal - it's a bioinformaticological alignment problem - so I have 2 sequences, each with an alignment start and end position, which aren't necessarily at the start and end of the sequence.

        Poj's thing seems to work - thankyou.

        Marinegirl x

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://484553]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (1)
As of 2022-01-28 05:52 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (73 votes). Check out past polls.