[Bio] / FigKernelScripts / match_dna_to_aligned_prots.pl Repository:
ViewVC logotype

View of /FigKernelScripts/match_dna_to_aligned_prots.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (download) (as text) (annotate)
Mon Jan 17 01:27:44 2005 UTC (15 years ago) by overbeek
Branch: MAIN
add start prediction code

$usage = "match_dna_to_aligned_prots dna_filename aligned_prot_filename";

(($dna_filename = shift @ARGV) && ($aligned_prot_filename = shift @ARGV)) ||
    die $usage;

open(DNA,"<$dna_filename") or die "failed to open dna";
open(PROT,"<$aligned_prot_filename") or die "failed to open prot";
while (defined($line = <DNA>))
{
    $line =~ />(\S+)/;
    $id = $1;
    $seq = <DNA>;
    chomp $seq;
    $dnaseqs{$id} = $seq;
}

while (defined($line = <PROT>))
{
    $line =~ />(\S+)/;
    $id = $1;
    $seq = <PROT>;
    chomp $seq;
    $protseqs{$id} = $seq;
}

# for $id (keys(%protseqs)) { print "$id $protseqs{$id}\n"; }
# for $id (keys(%protseqs)) { print "$id $protseqs{$id}\n"  if ($id =~ /1048/); }
## for $id (keys(%protseqs))
## { 
    ## $protseqs{$id} =~ /(\-+)/;
    ## $subseq=$1;
    ## # print "$id NUM ", length($subseq), $subseq, "\n"  if ($id =~ /155920.*1503/);
    ## print "$id NUM=", length($subseq), "\n";
## }

for $id (keys(%protseqs))
{
    $protseq = $protseqs{$id};
    @protseq = split('',$protseq);
    $newprotseq = '';
    for ($i=0; $i < @protseq; $i++)
    {
        $newprotseq .= "$protseq[$i]  ";
    }
    @newprotseq = split('',$newprotseq);
    $protseqs{$id} = $newprotseq;
    # print "$id $newprotseq\n"  if ($id =~ /1048/);
    $dnaseq = $dnaseqs{$id};
    $dnaidx = 0;
    $newdnaseq = '';
    for ($i=0; $i < @protseq; $i++)
    {
        $c = $protseq[$i];
        if ($c =~ /[A-Z]/)
        {
            $newdnaseq .= substr($dnaseq,$dnaidx,3);
            $dnaidx += 3;
        }
        elsif ($c eq '-')
        {
            $newdnaseq .= "---";
        }
        else
        {
            print STDERR "unrecognized char $c\n";
        }
    }
    $dnaseqs{$id} = $newdnaseq;
    # print "$id $newdnaseq\n"  if ($id =~ /1048/);
    # sanity check
    if (length($newdnaseq) != length($newprotseq))
    {
        print STDERR  "BAD LEN $id ", length($newdnaseq), " ", length($newprotseq), "\n";
    }
    $id =~ /^ORF_(\S+)/;
    $dnaid = "DNA_" . $1;
    $proid = "PRO_" . $1;
    print ">$dnaid\n$newdnaseq\n";
    print ">$proid\n$newprotseq\n";
}

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3