Question: perl compilation errors
gravatar for hsu
7 months ago by
hsu0 wrote:

I want to extract fpkm information and I used a perl script:

more PB_stressed_sample.txt | perl -ne 'BEGIN{my %F;my %G; my $C=0; @S=("gene","genename");}@a=split;push @S,$a[0];open(my       $fh, "<", " SRX3084$a[0]/genes.fpkm_tracking");$C++;<$fh>;while (my $row = <$fh>) {@b=split(/\s/,$row);push @{$F{$b[0]}}, $      b[9];$G{$b[0]}=$b[4]} END{print join("\t",@S),"\n";foreach my $key (keys %F) {$tt=join("\t",@{$F{$key}}[0..$C-1]);print "$k      ey\t$G{$key}\t$tt\n"}}' >fpkms_stressed.txt

there is a mistake :

syntax error at ./stressed line 4, near "-ne"
Execution of ./stressed aborted due to compilation errors.

What should i do about it ?

assembly • 256 views
ADD COMMENTlink modified 7 months ago by Michael Dondrup45k • written 7 months ago by hsu0

What does your file PB_stressed_sample.txt look like? It's hard for anyone to tell without looking at the file. You can post few lines of your file.

ADD REPLYlink written 7 months ago by Vijay Lakhujani3.6k
gravatar for Alex Reynolds
7 months ago by
Alex Reynolds27k
Seattle, WA USA
Alex Reynolds27k wrote:

Break up that Perl one-liner into something you can debug line by line.

ADD COMMENTlink written 7 months ago by Alex Reynolds27k
gravatar for Michael Dondrup
7 months ago by
Bergen, Norway
Michael Dondrup45k wrote:

What should you do about it?

I'd strongly recommend not to use so complex perl one-liners. while some might have a habit of using these to show off how smart a hacker they are, they are the opposite of smart. Using these for more than a few commands is definitely not a good idea, except for making unreadable unmaintainable code.

  1. Find out what the code is exactly supposed to do and check for alternative options (the code is possibly full of errors, so if you can find an easier option, don't use the complex one)

  2. I guess you inherited the code. To debug, format it as a proper perl program and edit in an editor with proper syntax highlighting and auto-formatting. I have tried to edit it for you and turn it into a proper perl program for you this time.

  3. Say the perl program is named, debug the syntax with perl -c until it is showing no more errors. The parser will now tell you the line where the errors occur.

  4. Run the program finally: PB_stressed_sample.txt, no need to use more, cat, etc.

    #!/usr/bin/env perl
    use strict;
    use warnings;
    # you will most likely have to fix more errors now

    BEGIN{ # there is no more need for a begin block
                     my %F = ();
                     my %G = (); 
                     my $C = 0; 
                     my @S = ("gene","genename");

     while (<>) { # this line is the only advantage what perl -n provides

                      my @a=split; 
                      push @S,$a[0]; 
                      open(my     $fh, "<", " SRX3084$a[0]/genes.fpkm_tracking");
                      while (my $row = <$fh>) {
                             my @b=split(/\s/,$row);
                             push @{$F{$b[0]}}, $b[9]; 
       END{ # there is no more need for an END block in a simple parser either
                        print join("\t",@S),"\n";
                        foreach my $key (keys %F) {
                            my $tt=join("\t",@{$F{$key}}[0..$C-1]);
                            print "$key\t$G{$key}\t$tt\n"

ADD COMMENTlink modified 7 months ago • written 7 months ago by Michael Dondrup45k
gravatar for Bastien Hervé
7 months ago by
Bastien Hervé3.3k
Limoges, CBRS, France
Bastien Hervé3.3k wrote:

Why not put this line in a perl script file and add some verbose to investigate your error ?

ADD COMMENTlink modified 7 months ago • written 7 months ago by Bastien Hervé3.3k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1242 users visited in the last hour