perl compilation errors
3
0
Entering edit mode
6.4 years ago
hsu ▴ 40

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 • 2.5k views
ADD COMMENT
0
Entering edit mode

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 REPLY
1
Entering edit mode
6.4 years ago

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

ADD COMMENT
1
Entering edit mode
6.4 years ago
Michael 55k

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 extract_fpkm.pl, debug the syntax with perl -c extract_fpkm.pl until it is showing no more errors. The parser will now tell you the line where the errors occur.

  4. Run the program finally: extract_fpkm.pl 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");
                      $C++; 
                      <$fh>;
                      while (my $row = <$fh>) {
                             my @b=split(/\s/,$row);
                             push @{$F{$b[0]}}, $b[9]; 
                             $G{$b[0]}=$b[4]
                      } 
      }
       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"
                        }
       }

      __END__
ADD COMMENT
0
Entering edit mode
6.4 years ago

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

ADD COMMENT

Login before adding your answer.

Traffic: 1677 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6