Dear Perl experts, I request a help from you. I have a list of fasta format sequences, like

>header1

aaaaabbbb

ccccddd

>header2

ggggg

jjj

kkkk

etc... I want to count the frequency of all residues corresponding to each protein id given in the header.ie I need to count occurrence of X(X ="not sure" residues) and unusual amino acids too.If the occurrence of any residue is zero,I just give a blank. Like

ID A B C D G U X J K

ID_1 5 4 4 3 - - - - -

ID_2 - - - - 5 - - 3 4

...........

I have tried.But my code doesn't print it in the required format nor count accordingly rather it continuously count each residue till end of the file.I am biology student and not very good in programming.I am in the learning phase.

I am giving my code here. Please tell me where I am wrong in my code what I need to get the exact output. Thank you all for considering and reading my doubt.

open(FILE1,"e.txt")or die "can't open file for reading\n"; while (<FILE1>) { chomp; next if(/^\s*$/); my $FastaLine= $_; if ( $FastaLine =~ /^>sp\|(\w+\S+)\|/ ) { $header = $FastaLine; } else #storing the sequences and appending the sequence lin +es that come after each header #and storing the sequence as values of $header { $Fasta_split{$header} .= $FastaLine; } if ( $header =~ /^>sp\|(\w+\S+)\|/ ) { my $name = $1; #print "$name\t"; } } while (($header,$Fasta_split{$header})=each(%Fasta_split +) ){ if ( $header =~ /^>sp\|(\w+\S+)\|/ ) { my $name = $1; #print "$name.txt\n"; #print"$name\n$Fasta_split{$header}\n"; my @words= split"", $Fasta_split{$header}; foreach my $w(@words){ $count{$w}++; } while (my($w,$c)=each(%count)){ print "$w:$c\t"; } print "\n"; } }

In reply to Listing occurence of all residues by sreya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.