#!/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/))
{
#@currentProtein= $_;
push (@currentProtein, $_);
}
if (/^>/)
{
$fastaLine = $_;
}
if ((($_ !~ /\w/) || (eof)) && (@currentProtein > 0))
{
$protSequence = join("", @currentProtein);
$protein{$fastaLine} = $protSequence;
@currentProtein = ();
}
}
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";
}
Problem description
I want to calculate the number of charges amino acids (acidic, basic and neutral) in each protein sequences which is present in fasta file.
Note: I have a fasta file which have numerous protein sequences
OUTPUT
This script is calculating all the amino acids throughout the file and show the result in last protein sequence entry.
Its something like that:
>gi|1064567454|ref|YP_67854|lipoprotein Myxococcous strain DK6476
Number of acidic amino acids: 312454
Number of basic amino acids: 313534
Number of neutral amino acids: 54454
It is not calculating charged amino acids sequence by sequence but as a whole |