I'm stuck.

So, I'm trying to make a program which looks at fasta formated data, and counts the number of words with X length. Say, I'm looking for two words, it will count all two words it can find in each of the sequences. This counting part, kinda works so far, thanks to @toolic who answered my previous post, but it's not really that accurate since it's not actually looking for X length words, it's just splitting the sequence in X parts (ATGCAT -> AT GC AT) and counts all of the different parts it gets...

Anyway, here is an example data of what I want my program to work with:

>ENSCAPT00000000001.1 cdna (...) CACTCCGCCGGCAAGGCCACCAAGTATCTGAAGGATGTCACGTTAAAGAAGCAATGTGTG CCATTCCGGCGTTACAATGGTGGAGTTGGAAGGTGTGCCCAGGCCAAACAATGGGGCTGG ACCCAGGGTCGGTGGCCCAAAAAGAGTGCTGAATTTTTGCTGCAC >ENSCAPT00000000002.1 cdna (...) CAGCTGCTGAAGACGGAGCTGGGGTCCTTCTTCACCGAGTACCTGCAGAACCAGCTGCTG ACCAAAGGCATGGTGATCCTTCGGGACAAGATCCGCTTCTATGAGGGACAGAAACTGCTG GACTCGCTGGCAGAGACCTGGGACTTCTTCTTCAGCGACGTGCTGCCCACGCTGCAGGCC ATCTTCTACCC >ENSCAPT00000000004.1 cdna (...) ATGATGCTGGGAGAAGATGATGAGGAGTTCGTGGTGAAGGTGCGGGGTTTGCCTTGGTCC TGCTCGGCTGACGAGGTGCAGCGGTTCTTCTCCGACTGCAAAATTCAAAATGGTGCTCAA GGTATTTGTTTCATCTACACCAGAGAAGGCAGACCGAGTGGCGAGGCTTTTGTTGAACTT GAATCCGAAGATGAAGTCAAACTATCAAACAACGTTGAAATGGATTGGGTGTTGAAGCAT ACTGGTCCAAATAGTCCTGACACGGCCAATGATGGCTTTGTACGGCTTAGAGAACTCCCC TTTGGATGTAGCA

And my counting-part of my code so far:

#Open data file; chomp($paths[1]); my ($sfile) = $paths[1].$ARGV[0]; open my $fain,'<', $sfile or die "Unable to open $sfile\nError: $!\n"; my $length = $paths[3]; my $line = 0; my %count; while (my $fasta = <$fain>){ if ($fasta !~ m/^>/){ while ($fasta =~ /(.{$length})/g) { $count{$1}++; } } if ($fasta =~ m/^>/){ #Print ID line print "$_ $count{$_}\n" for sort keys %count; %count = (); $line++; chomp($fasta); print "$line|$fasta\n"; } } print "$_ $count{$_}\n" for sort keys %count;

It's weird, I know. But I'm trying... I guess I should count them in a different way, but the main thing that bothers me now, is that I want to get more data, from the data. See, I want to know how long (how many characters) each sequence is. And I also want to manipulate the hash data. I want to detect anomalies. If the data was random, you would expect to find an equal amount of all words. So in a 100 character long sequence, AA is expected to be seen 6.25 (I think) times. But if I count a 100 character sequence, and I find 25 AA's then I could do something like 1-(6.25/25) = 0.75 more AA than expected. Since it really doesn't make sense to compare amount of AA's found in a 50c.long. seq. with AA's found in a 500c.long.seq.

I feel my main obstacle here is that the sequence is on more than one line.

Thanks for any answers!


In reply to Counting & manipulating hashes by bisimen

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.