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

error calling variables? Going insane...

by lecb (Acolyte)
on Jun 25, 2014 at 20:40 UTC ( #1091247=perlquestion: print w/replies, xml ) Need Help??
lecb has asked for the wisdom of the Perl Monks concerning the following question:

Hi again, I'm back.. much further in my program - but stuck again - 8 hours of solid playing around and still nothing.

my ($left_of_boundary, $intron_from_boundary, $new_left, $seq, $col7, +$col_alt, $matchID); my $i = 0; open (INTRONS_five, '>fasta_introns_five_non'); open (INTRONS_three, '>fasta_introns_three_non'); foreach $col7(@col7) { ##50bp seq in var file $seq = ''; $col7[$i] =~ s/\[[ACTG]\]/$col_ref[$i]/i; if ($intron_from_boundary[$i] =~ m/\-/) { &three_prime; } elsif ($intron_from_boundary[$i] =~ m/\+/) { &five_prime; } my $length = length($seq); if ($length == 9) { print INTRONS_five (">" . "$match{$col_NM[$i]}" . "\n", lc +($seq),"\n"); } elsif ($length != '') { print INTRONS_three (">" . "$col_NM[$i]" . "\n", lc($seq), +"\n"); } ++$i; } close (INTRONS_five); close (INTRONS_three); sub three_prime { if ($strands{$ID[$i]} =~ m/\+/) { ## !!!PROBLEM!!! - $seq prints to file INTRONS_three when $strands{$ID[$i]} = + or - ### ### BUT if I print out $ID[$i] here, it only pulls out + (shows the hash is working) ### $left_of_boundary = 20; ##$right_of_boundary = 3; $left_of_boundary = $left_of_boundary + $intron_from_bound +ary[$i]; $new_left = 51 - $left_of_boundary; $seq = substr( $col7[$i], $new_left, 23); } elsif ($strands{$ID[$i]} =~ m/\-/) { if ($intron_from_boundary[$i] >= -6) { $left_of_boundary = 3; #$right_of_boundary = 6; $left_of_boundary = $left_of_boundary - $intron_from_bound +ary[$i]; $new_left = 51 - $left_of_boundary; $seq = substr( $col7[$i], $new_left, 9); $matchID = $ID[$i] . "\t" . $intron_from_boundary[$i] +. "\t" . "on the negative strand"; } } }

I know this is a lot of code (and not all of it), but I have commented out "problem" where the issue lies. My %strands works, but when I open the INTRONS_three file it is printing out sequences for both when $ID[$i] is + or -. I thought maybe it was to do with when I am calling my variables i.e. my $seq? I've tried using/not using a subroutine, data::dumping, hitting the keyboard, prayer.. but still to no avail...

Replies are listed 'Best First'.
Re: error calling variables? Going insane...
by toolic (Bishop) on Jun 25, 2014 at 21:06 UTC

      I'm sorry you feel that my question was inappropriate. I'm not too sure how I can ask the question without context though? I don't understand how $seq is not meeting the if condition when everything else is.

        "I'm sorry you feel that my question was inappropriate."

        What precisely is your question? A long time ago Ovid wrote this reply: Clean your room. If you take the time to make your question easy to read, then others will give the time to help you find the solution.

        For starters, please consider formatting your code with Perl Tidy as your indention is extremely inconsistent and makes your code extremely hard to read.


        (the triplet paradiddle with high-hat)

        Since this is a question regarding why your if condition is unexpectedly true, collect some sample cases where it is not behaving as expected.

        Since you are doing a simple regex test against a single value, your question likely boils down to "Why does this string get matched by this regex?"

        if ($strands{$ID[$i]} =~ m/\+/) { That regex matches any string containing a '+' anywhere in it. In the case where you think it should NOT match but is matching, print out the string $strands{$ID[$i]} (not just $ID[$i] as your comment implies) and see what it contains.


        I notice at the top you are checking if '-', elsif '+', but at the bottom of your code, you are checking if '+' elsif '-'. If you have a string that contains both a + and a -, that may be causing some confusion.

        Forgive me if this is nonsense but if all your output is going to INTRONS_three then presumably the length of $seq is not 9. So does that mean that this block is not entered ?
        if ($intron_from_boundary[$i] >= -6) { $left_of_boundary = 3; #$right_of_boundary = 6; $left_of_boundary = $left_of_boundary - intron_from_bound +ary[$i]; $new_left = 51 - $left_of_boundary; $seq = substr( $col7[$i], $new_left, 9); $matchID = $ID[$i] . "\t" . $intron_from_boundary[$i] +. "\t" . "on the negative strand"; }
        Is which case is this $intron_from_boundary[$i] >= -6 the correct test, any number greater or equal to -6 ie. -5, -4, -3 etc or should it be less or equal to -6 ie -7,-8,9 etc

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1091247]
Approved by GrandFather
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2018-06-21 09:22 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.