As marto said, I've already posted the code, and the example, and it works for me. Unless you tell me what results you're getting, I'm afraid I won't know how to alter the code. Contrary to popular belief, I'm not psychic.
The only thing I can think of is that your fasta file might not have spaces between the entries. If that is the issue then this should work:
#!/usr/bin/perl -w
use strict;
use warnings;
my $file = $ARGV[0];
my @currentProtein;
my %protein;
open (FASTA, "<", $file) || die "Can't open $file\n";
my $fastaLine;
my $protSequence;
while (<FASTA>)
{
#print STDERR "$_";
chomp;
if (($_ !~ /^>/) && ($_ =~ /\w/))
{
push (@currentProtein, $_);
}
if ((/^>/) || (eof))
{
if ((@currentProtein > 0) || (eof))
{
$protSequence = join("", @currentProtein);
$protein{$fastaLine} = $protSequence;
@currentProtein = ();
}
$fastaLine = $_ if $_ =~ /\w/;
}
}
close FASTA;
foreach my $key (sort(keys %protein))
{
my $count_of_acidic = 0;
my $count_of_basic = 0;
my $count_of_neutral = 0;
my $aa;
my $sequence = "$protein{$key}";
$sequence =~ s/\s//g;
my @prot=split("",$sequence); #splits string into an array
#print " \nThe original PROTEIN file is:\n$sequence \n";
while(@prot)
{
$aa = shift (@prot);
if($aa =~/[DNEQ]/ig)
{
$count_of_acidic++;
}
if($aa=~/[KRH]/ig)
{
$count_of_basic++;
}
if($aa=~/[DNEQKRH]/ig)
{
$count_of_neutral++;
}
}
print "\nName: $key\n";
print "Number of acidic amino acids:".$count_of_acidic."\n";
print "Number of basic amino acids:".$count_of_basic."\n";
print "Number of neutral amino acids:".$count_of_neutral."\n";
}
Apart from that, as much as I might like to help you, I simply can't unless I know what the problem is, not just that there is a problem. | [reply] [d/l] |
| [reply] |
| [reply] |