Debug this little perl program

From BITS wiki
Jump to: navigation, search
Go back to Perl introductionary training#Exercises

Debug following program

This is a small program in which errors are introduced. In real life, you often reuse code you have written, or even use code of colleagues. These may contain errors: reading the error codes and learning to look for the obvious errors first might benefit you to a great extent.

#!/usr/bin/perl -w

$|=1;

use strict;

################################################
# This program uses a sliding window
# to search local spots in an aminoacid sequence
# with large amounts of a specific amino acid.
#
# Can you correct the mistakes in this program?
# Some should be obvious by just looking at the
# syntax highlighting. For others, use the 
# warnings upon executing. In the end, you might
# check if the program does what it needs to do.
#
# joachim.jacob@vib.be
################################################

my $seq="MPYNFCLPSLSCRTSCSSRPCVPPSCHSCTLPGACNIPANVSNCNWFCEGSFNGSEKETM
QFLNDRLASYLEKVRQLERDNAELENLIRERSQQQEPLLCPSYQSYFKTIEELQQKILCT
KSENARLVVQIDNAKLAADDFRTKYQTELSLRQLVESDINGLRRILDELTLCKSDLEAQV
ESLKEELLCLKSNHEQEVNTLRCQLGDRNVEVDAAPTVDLNRVLNETRSQYEALVETNRLL
LLLLEVEQWFTTQTEELNKQVVSSSEQLQSYQAEIIELRRTVNALEIELQAQHNLRDSLENTL
TESEARYSSQLSQVQSLITNVESQLAEIRSDLERQNQEYQVLLDVRARLECEINTYRSLL
ESEDCNLPSNPCATTNACSKPIGPCLSNPCTSCVPPAPCTPCAPRPRCGPCNSFVR
";

my $windowlength=20;	# length sliding window (must be shorter than sequencelength)

my $AAoi="L";			# Aminoacid of interest

my $AAamount=0.38		# report cutoff of percentage within window (percentage)

my (%number,$window);

my $seqlen = length($seq);

for( my $mover=0;$mover<=($seqlen-$windowlength);$mover++){		# let window slide over sequence

	#print "\nOk\tMover=$mover\n";

	$window=substr($seq,$mover,$windowlength);			# getting sequence under window

	#print "\nSequence under window: $window\n";

	%number=();							# reset hash

	my $count=$window=~tr/$AAoi/$AAoi/g;						

	#print "Test counter: $count in $window\n";

	my $content=$count/$windowlength;

	#print "\n$AAoi content= $content\n";

	if ( $content > $AAamount){

		print "Found $window with $AAoi-content of $content at position $mover.\n;

	}

}

print "\nProgram finished succesfully!\n";

exit 0;


One solution