[Bioperl-l] codon usage

subarna thakur bubli_thakur at rediffmail.com
Fri Apr 20 22:59:50 EDT 2012


I am writing a script for determining number of genes
containing a particular codon. The codons are mentioned in a separate file. The
output is coming all right for the first codon mentioned in the file but for
the other codons , the script is not working. Please suggest the error in the
script. The script is as follows ----

#!/usr/bin/perl -w

use Bio::SeqIO;

$file2="table.txt";

$codon=0;

open OUT, ">out-test.txt" or die $!;

$seqio_obj = Bio::SeqIO->new( -file =>
"gopi2.txt" , '-format' => 'Fasta');

open( my $fh2, $file2 ) or die "$!";

while( my $line = <$fh2> ){

$acc=$line;

chomp $acc;

while ($seq1= $seqio_obj->next_seq){

my @output = $seq1->id;

my $string = $seq1->seq;

$v=0;

$l= length($string);

$t=$l/3;

$k=0;

for ($i=1; $i <= $t; $i++){

@array2 = substr($string, $k, 3);

$k=$k+3;

foreach $value (@array2)

{

if ($value eq "$acc")

{

print OUT " The sequence id is @output\n";

print OUT "$acc codon found in position $i\n\n";

$v=$v+1;

}

}

}

if ($v==0)

{

$h=0;

}

else

{

$h=1;

}

$codon=$codon+$h;

}

print OUT "Total number of sequences with $acc
codon";

print OUT "\t";

print OUT $codon;

}

exit;


More information about the Bioperl-l mailing list