This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Using Perl script including R script to retrive Go annotations for list of accesion number

Hi everyone,

I have wrote a perl script to retrieve Go annotations (Molecular Function especially with go id). To retrieve go annotation i use a chunck from R that can do this in few lines, and use Perl to format the output. But it's not working.

I have got this error:

Global symbol "$lines" requires explicit package name (did you forget to declare "my $lines"?) at GO_Perl_R line 21.
Global symbol "$lines" requires explicit package name (did you forget to declare "my $lines"?) at GO_Perl_R line 22.
Global symbol "$hits" requires explicit package name (did you forget to declare "my $hits"?) at GO_Perl_R line 22.
Global symbol "$go" requires explicit package name (did you forget to declare "my $go"?) at GO_Perl_R line 24.
Global symbol "@MF" requires explicit package name (did you forget to declare "my @MF"?) at GO_Perl_R line 24.
Global symbol "$id" requires explicit package name (did you forget to declare "my $id"?) at GO_Perl_R line 24.
Global symbol "$lines" requires explicit package name (did you forget to declare "my $lines"?) at GO_Perl_R line 25.
Global symbol "$go" requires explicit package name (did you forget to declare "my $go"?) at GO_Perl_R line 25.
Global symbol "@MF" requires explicit package name (did you forget to declare "my @MF"?) at GO_Perl_R line 25.
Global symbol "@id" requires explicit package name (did you forget to declare "my @id"?) at GO_Perl_R line 25.
Global symbol "$go" requires explicit package name (did you forget to declare "my $go"?) at GO_Perl_R line 25.
Global symbol "@MF" requires explicit package name (did you forget to declare "my @MF"?) at GO_Perl_R line 25.
Global symbol "@term" requires explicit package name (did you forget to declare "my @term"?) at GO_Perl_R line 25.
Execution of GO_Perl_R aborted due to compilation errors.

This is my code :

#! usr/bin/perl

use warnings;
use strict;
use Statistics::R;

my $R = Statistics::R->new();
my $i = 1;
# open the file containing uniprot accession numbers
open (ACC, "acc_numbers.txt") or die "Can't open acc_numbers.txt: $!\n";

while (my @lines=<ACC>) {
    chomp($_);
}

$R -> startR;
$R -> send('library(mygene);');
$R -> run (q`sink('GO_MF.txt')`);
$R -> run (q`sink()`);
$R -> run (
    qq`while($lines){
        res<-query($lines,fields='go')$hits,
        sink('GO_MF.txt', append=TRUE),
        while($i <= length(res$go$MF[[1]]$id) {
            print(paste($lines,"\n",res$go$MF[[1]]$id[$i],"\t",res$go$MF[[1]]$term[$i],"\n"),
        sink(),
        }
    }`
);

exit 0;

Any solution to reach my purpose using Perl script, R script or merging both should be useful.

The output file format is like :

P10214
    GO:xxxxxxx                    "aaaaaaaaaaaaaaaaaaaaa"
    GO:zzzzzzzz                    "bbbbbbbbbbbbbbbbbbbbb"
    ...................                   
Q34F56
    GO:fffffffffff                       "ccccccccccccccccccccccc"
    GO:gggggg                        "hhhhhhhhhhhhhhhhhhhh"
    ...................

Thanks you so much

perl r gene ontology

2 answers

Try this solution,

A: Returning gene functional annotations with gene symbols as input (using mygene B

If you google for perl global symbol requires explicit package name, there will be so many hits pointing to the correct answer I could not even choose one the link here.

The quickest (but not the best) solution is to remove the use strict; line.

Not using strict is not recommended for beginners as this leads to more issues and make these more difficult to track. The OP should just read the error messages in full. They give helpful hints.

Log in to answer this question.