-3

I needed to create a sliding window of size 15, go through a Fasta file and store all of the values of the sliding window into a hash. When I try to print I get the error

Global symbol "$sequence" requires explicit package name at ./findAllKmers.1.pl line 60.
Execution of ./findAllKmers.1.pl aborted due to compilation errors"

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

my %windowSeqScores = ();

my $sequenceRef = loadSequence("/scratch/Drosophila/dmel-2L-chromosome-r5.54.fasta");  
my $windowSize = 23;
my $stepSize = 1;
my $maxScore = 0;
my $sequence = @_; 
my $in_file = 'uniqueKmersEndingGG.fasta';

open (my $fh, '>', $in_file) or die "Could not open file 'filename' $!";

for (
    my $windowStart = 0;
    $windowStart <= (length($$sequenceRef) - $windowSize);
    $windowStart += $stepSize
)
{
    my $windowSeq = substr($$sequenceRef, $windowStart, $windowSize);
    sub loadSequence {
        my ($sequenceFile) = @_;
        my $sequence = "";
        my $counter = 0;
        unless (open(FASTA, "<", $sequenceFile)) {
            die $!;
        }

        while (<FASTA>) {
            my $line = $_;
            chomp($line);
            if ($line !~ /^>/) {
                my $sequence = $line;
                if (length($sequence) == 15) {
                $counter = $counter + 1;
                print $_;
            }
        }
        return \$sequence;
    }
}
print $sequence;
Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328

1 Answers1

0

I tried compiling your code. I got error "Missing right curly or square bracket at test.pl line 44, at end of line" I just added a close brace "}" after the last line and it compiled.

You are declaring a function inside a for() loop. That's quit unusual. I could most that outside the loop.

Yetti99
  • 326
  • 2
  • 11