CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Substring Issue

 



alkawi
New User

Mar 26, 2015, 1:05 PM

Post #1 of 2 (6342 views)
Substring Issue Can't Post

Hello,
Every time I run the commands below, I get a "Global symbol "$substring" requires explicit package name at Line 62"..

I am searching for the number of sequences (within the hash), but for some reason, my "$substring" function keeps giving me an error.

Here is the entire Perl script:

Code
#!/usr/bin/perl 
use strict;
use warnings;

my %codon; # hash to store amino acid residues, keyed by codons

# open the codon file and read in the lines, to store them in a hash
open (CODON, "<" . $ARGV[1]) or die $!;
while (<CODON>) {
chomp($_);

my @line= split(/,/, $_); # split the line on commas
$codon {$line[0]} = $line[1];
}
close (CODON);


open (GENES, "<" . $ARGV[0]) or die $!;

# start the offset at 0 and the length of a codon is 3 letters long
my $offset= 0;
my $length= 3;
my $geneID= "";
my $hello;

while (<GENES>) {
chomp($_);

# check if we are in a gene ID or sequence line using a regular expression
if ($_ =~ /AT(C|M|\d)G\d+/){
$geneID = $_;
print $_ . "\n";
} else {
# keep translating as long as there are codons remaining AND
# we have not encountered a stop codon
my $stopped= "no";
while ($offset <= (length ($_) - $length) and $stopped eq "no") {
my $substring = substr($_, $offset , $length);
print $codon{$substring};

if ($codon{$substring} eq "*") {
$stopped= "yes";
}

$offset = $offset + 3; # move to the next "codon"
#add substrings (amino acids) together
$hello = $_ . $codon{$substring};
}

$offset= 0; #reset

print "\n";

}
}
close (GENES);


# Make a hash table (with geneID in one column, and the gene codon in the other),
# then search the translated ORFs (genes) for the presence of the (ordered) motifs
my %protein;
$protein{$geneID} = $codon{$substring};
{
if ($protein{$geneID} =~ /motif...not shown/) {
my $count_1++;
print $count_1;
}

if ($protein{$geneID} =~ /[motif...not shown]/) {
my $count_2++;
print $count_2;
}

if ($protein{$geneID} =~ /motif...not shown/) {
my $count_3++;
print $count_3;
}

if ($protein{$geneID} =~ /motif...not shown/) {
my $count_4++;
print $count_4;
}

if ($protein{$geneID} =~ /motif...not shown/) {
my $count_5++;
print $count_5;
}
}



Thank you very much in advance!!
Alkawi


(This post was edited by alkawi on Mar 26, 2015, 2:10 PM)


FishMonger
Veteran / Moderator

Mar 26, 2015, 1:43 PM

Post #2 of 2 (6338 views)
Re: [alkawi] Substring Issue [In reply to] Can't Post

$substring was declared in the while loop and after that while loop finishes, that var is no longer available. If you need to use that var outside of the while loop, then you'll need to declare it prior to the loop so you can use it in line 62.

I have not looked over your code logic, so I can't say exactly what other changes you need to make to get your script working correctly.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives