sreya has asked for the wisdom of the Perl Monks concerning the following question:
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. LikeID 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"; } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Listing occurence of all residues
by Anonymous Monk on Mar 01, 2015 at 13:23 UTC | |
by sreya (Initiate) on Mar 01, 2015 at 14:50 UTC | |
by pme (Monsignor) on Mar 01, 2015 at 15:06 UTC | |
by sreya (Initiate) on Mar 01, 2015 at 17:14 UTC | |
by pme (Monsignor) on Mar 01, 2015 at 18:57 UTC | |
|
Re: Listing occurence of all residues
by 2teez (Vicar) on Mar 01, 2015 at 15:07 UTC | |
|
Re: Listing occurence of all residues
by Anonymous Monk on Mar 01, 2015 at 15:48 UTC |