CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Hashes, Bioinformatics, Counting Codons

 



anzdro
New User

Apr 13, 2013, 11:06 AM

Post #1 of 4 (519 views)
Hashes, Bioinformatics, Counting Codons Can't Post

Hi,
I'm just starting out with bioinformatics while using Perl. There's a certain problem I've been having in getting the data I want. There is a list of codons and it's my job to go through it and count how many times each specific codon observed throughout the data and print out the name of the codon and the number of times it was seen. I've written the following code:

while (<>) {
@codon = split;
%hash = @codon;
}
foreach $key (keys %hash) {
$tallyscore{$key}++;
print "$key $tally{$key}\n";
}

The code gives me the codon names that I want but does not give the numbers that I'm looking for. I'm just starting out with perl and any help would be greatly appreciated!


FishMonger
Veteran / Moderator

Apr 13, 2013, 11:20 AM

Post #2 of 4 (516 views)
Re: [anzdro] Hashes, Bioinformatics, Counting Codons [In reply to] Can't Post

Please post some sample lines of your data and what output you expect from that sample.


g4143
Novice

Apr 13, 2013, 11:20 AM

Post #3 of 4 (515 views)
Re: [anzdro] Hashes, Bioinformatics, Counting Codons [In reply to] Can't Post

Try something like below.


Code
#!/usr/bin/perl 

use warnings;
use strict;

my @codon;
my %hash;

while ( <> )
{
@codon = split;
++$hash{$_} foreach(@codon);
}

foreach(sort(keys(%hash)))
{
print "$_ has a value->$hash{$_}\n";
}



anzdro
New User

Apr 13, 2013, 11:46 AM

Post #4 of 4 (505 views)
Re: [g4143] Hashes, Bioinformatics, Counting Codons [In reply to] Can't Post

Wow, thank you! This really helped!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives