This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Finding Gc And At Percentages In A Sequence

I have written this program to calculate GC and AT contents in a given sequence but am unable to ignore the case sensitiveness.

I would appreciate your help.

print"Enter the fasta file name \n";
$a=<>;
chomp($a);

unless(open(FH,$a)){
    print"Error";
}

@a=<FH>;
close FH;
$a=join('',@a);
$a=~s /\s//g;
$n=length($a);
print "$n";
$a1=0;
$t=0;
$g=0;
$c=0;
$a1=($a=~tr/A//ig);
$t=($a=~tr/T//ig);
$g=($a=~tr/G//ig);
$c=($a=~tr/C//ig);
#$e=$n-($a+$t+$g+$c);
print "The counts are\n";
print"A:$a1 \n";
print"T:$t \n";
print"G:$g \n";
print"C:$c \n";
#print"E:$e \n";
$op = (($a1+$t)/$n)*100;
$op1 = (($g+$c)/$n)*100;
print " GC%= $op\n";
print " AT% = $op1";
perl gc sequence

then also error is coming as bareword found where operatoe is expected at ~tr/T... lines

3 answers

There are syntax errors in the tr lines that prevent this working at all. Perhaps you mean, for example:

$a =~ s/A//ig

Your Fasta parser is broken because it reads the header line as is if it were sequence.

Also, if you are learning, you should put use strict at the top, until you understand when not to use strict.

Isn't your $op variable storing the AT content, and the $op1 storing the GC content? I think you are printing them reversely.

As a general advice, I would better choose the variable names, since $a for the data variable is slightly confusing and forces you to use $a1 for the A count (looking to $c, $g and $t that A count should be labeled as $a in order to humanly read through the code without any hassle), and also using numbers on variable names is definitely not advisable. I would change it for a simpler $data, and if case-sensitiveness matters I would lower-case or upper-case that $data variable to forget about the case through the entire code (using lc($data) or uc($data) as desired), not having to specify the i option for the pattern matching.

yeahh thanq Jorge

you don't need to post an answer to thank others' answers, but to add comments when clarifying is needed, give points to helpful answers, or accept a particular one when it solves your doubt ;)

Log in to answer this question.