I tried this. There might be an easier BioPerl solution, but I don't know BioPerl.

open my $IN, '<', 'domain.txt' or die $!; while (<$IN>) { my ($id, $from, $to) = split /[;\s]+/; print "$id; $from $to\n"; for my $pos (0 .. length($hash1{$id})) { print join ' ', $pos, substr($hash1{$id}, $pos, 1), substr($hash2{$id}, $pos * 3, 3), $from <= $pos && $pos <= $to ? 'YES' : 'NOT', "\n"; } }

Update: The output is now almost the same as yours. The problem was caused by wrong formatting of the post - please use code tags for data, too.

Update 2: This is how I populated the hashes. Again, no BioPerl.

#!/usr/bin/perl use warnings; use strict; sub load_fasta { my ($file) = @_; open my $IN, '<', $file or die $!; my ($seq, $id, %hash) = q(); my $store = sub { $hash{$id} = $seq if $id; ($id) = shift =~ /\|(.*)/; $seq = q(); }; while (<$IN>) { chomp; if (/^>/) { $store->($_); } else { $seq .= $_; } } $store->(q()); return %hash } my %hash1 = load_fasta('acids.txt'); my %hash2 = load_fasta('nucleotides.txt');

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

In reply to Re: Find codon usage in domain based on domain's position from a file by choroba
in thread Find codon usage in domain based on domain's position from a file by 345qwerty

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.