in reply to Re^2: Listing occurence of all residues
in thread Listing occurence of all residues

Hi sreya, could you attach a sample 'e.txt'?
  • Comment on Re^3: Listing occurence of all residues

Replies are listed 'Best First'.
Re^4: Listing occurence of all residues
by sreya (Initiate) on Mar 01, 2015 at 17:14 UTC
    Here is a sample file. I have used shebang line and declarations of varibles.But since I am posing the question to experts I just avoided them. Thank you for considering my question.

    >sp|P05100|3MG1_ECOLI DNA-3-methyladenine glycosylase 1

    MERCGWVSQDPLYIAYHDNEWGVPETDSKKLFEMICLEGQQAGLSWITVLKKRENYRACF

    HQFDPVKVAAMQEEDVERLVQDAGIIRHRGKIQAIIGNARAYLQMEQNGEPFVDFVWSUV

    >sp|P30871|3PASE_ECOLI Inorganic triphosphatase

    MAQEIELKFIVNHSAVEALRDHLNTLGGEHHDPVQLLNIYYETPDNWLRGHDMGLRI

    RGE NGRYEMTMKVAGRVTGGLHQRPEYNVALSEPTLDLAQLPTEVWPNGELPADLASRVQPLF

      I hope this little piece of code help. I supposed that the residues are marked with letters A-Z.
      #!/usr/bin/perl -w use strict; open FILE1, "<e.txt" or die "can't open file for reading: $!\n"; my %Fasta_split; my $id; while (<FILE1>) { chomp; next if(/^\s*$/); my $FastaLine = $_; if ( $FastaLine =~ /^>sp\|(\w+\S+)\|/ ) { $id = $1; } else { $Fasta_split{$id} .= $FastaLine; } } # print header my @header = qw/A B C D E F G H I J K L M N O P Q R S T U V W X Y Z/; print "ID " . join(' ', @header) . "\n"; # print data foreach my $id (sort keys %Fasta_split) { my %words; # count letters $words{$_}++ for split('', $Fasta_split{$id}); printf "%8s ", $id; # print counts foreach my $w (@header) { if (defined $words{$w}) { printf "%2d ", $words{$w}; } else { print ' - '; } } print "\n"; }