Question: perl compilation errors
0
gravatar for hsu
5 days ago by
hsu0
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 • 95 views
ADD COMMENTlink modified 5 days ago by Michael Dondrup44k • written 5 days 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 5 days ago by Vijay Lakhujani2.7k
1
gravatar for Alex Reynolds
5 days ago by
Alex Reynolds24k
Seattle, WA USA
Alex Reynolds24k wrote:

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

ADD COMMENTlink written 5 days ago by Alex Reynolds24k
1
gravatar for Michael Dondrup
5 days ago by
Bergen, Norway
Michael Dondrup44k 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 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 COMMENTlink modified 5 days ago • written 5 days ago by Michael Dondrup44k
0
gravatar for Bastien Hervé
5 days ago by
Bastien Hervé1.5k
Limoges, CBRS, France
Bastien Hervé1.5k wrote:

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

ADD COMMENTlink modified 5 days ago • written 5 days ago by Bastien Hervé1.5k
Please log in to add an answer.

Help
Access

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