in reply to Re: Getting (famous) error during running perl script
in thread Getting (famous) error during running perl script

Of course, I updated my question with the code. This code is for replacing sequences of interest from one fasta file to another. Another thing that may be useful to know is that I can see sequence of interest before running the script, but after the running the script, the output file just showed the header of sequence not sequence itself, as if there isn't such a sequence at all. Please let me know if you need further information.Thanks for your help

.
  • Comment on Re^2: Getting (famous) error during running perl script

Replies are listed 'Best First'.
Re^3: Getting (famous) error during running perl script
by LanX (Saint) on Jul 04, 2015 at 20:41 UTC
    Are you sure that $hash1{$list{$1} } is defined?

    Cheers Rolf
    (addicted to the Perl Programming Language and ☆☆☆☆ :)
    Je suis Charlie!

      Hi, sorry, I'm not sure, honestly I'm so new here and I don't know what you mean! However, it sounds that script is correct because it works fine on short fasta file, say 5 sequences, but when I tried to run it on my original fasta file composed of about 150, 000 sequences, the error appeared

      .
        Sorry but it doesn't seem like you wrote this code.

        We could recommend you some good books to learn programming.

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re^3: Getting (famous) error during running perl script
by marinersk (Priest) on Jul 04, 2015 at 20:49 UTC

    In Re: Getting (famous) error during running perl script, BillKSmith suggests blank lines in your input file -- and there's a decent chance that's it.

    However, dissecting the line with the issue into digestible form:

    if (/>(.*)/) { if (defined $list{$1}) { print $_. "\n" . $hash1{$list{$1}} . "\n"; $x = 1 } else { $x = 0 } } #e print $_ . "\n" if $x == 0; #e

    I can't help but wonder: You check to see if $list{$1}is defined, but make no attempt to ascertain if $hash1{$list{$1}}is defined -- but that's what you're using there.

    Could it be that you need to change that line to:

    if (defined $hash1{$list{$1}})

    If it might help you a bit?

      thanks friend, I'm basically a biologist and really new in this field.Could you please let me know what should exactly I do, please tell me in simple language, if I add the code, which you wrote, to the script? Thanks for your kindness

      .

        Okay, one concept at a time.

        Consider these three statements:

        my $var1 = 0; my $var2 = ''; my $var3;

        These three variables have different values in them.

        1. The first is a numerical zero*
        2. The second is a text value (which happens to be blank)
        3. The third is undefined. Meaning, it's not zero, it's not spaces, it's not an empty text string -- a chunk of memory has been set aside for it but no value of any kind is associated with it.

        *The nuances of how the data is actually stored is not important right now, so for our purposes, calling it a numerical value is sufficient for the task at hand, even though it might not be technically accurate under the covers.

        This last one works reasonably well with both arithmetic operations (treated as zero) and text operations (treated as blank), but there are places where Perl cannot reasonably assume what you mean.

        Hash keys is one of those places; and you are using the variable in question as a hash key.

        So you get warnings when using uninitialized variables in certain circumstances, like print statements or when used as a hash key.

        So, to answer your question -- I don't know if my suggestion is the right thing to do. You know how you're a biology specialist but are new to Perl programming?

        Yeah, the opposite for me. Perl I understand; but I have no idea what a fasta file is, why it's different than a slowa file, or what would be in one.

        So -- just to help us along here, is there any chance you could put up maybe 5 lines of data from your fasta file, embedded in <code></code>tags?

        This won't necessarily identify the problem, but it will help us see how the file is being used by the Perl script -- and that could lead to some insight. Maybe even an Aha!/Eureka! moment.

        With that context, we might be able to answer your question in a more useful manner. There's just a few unknowns too many at the moment.