[Ilugc] read and count only limited characters using php script

Mahalingam Subramaniam smal at ccmb.res.in
Sun Jan 31 22:40:48 IST 2010


Hi All
the aim is to read and count only 100 characters from input text file containing characters of A, G, C, T....of 500 or more.... The PHP script which I appended here reads all the 500 or whatever is present in the input file. The help which I expect from the forum is to find and correct the mistake by which it can read and count only the limited number of characters to be set as a condition.
<?php
$file="co3.txt";
$handle=fopen($file, 'r');
$A=0;
$G=0;
$C=0;
$T=0;
$contents[] = '';
    while(!feof($handle)) {
   $contents[] = fread($handle, 100);
}
#echo($contents);
 { $readchar=fgetc($handle);
  $readchar=strtoupper($readchar);
for ($i=0; $i<100; $i++)
{
#echo ($contents[$i]);
if($contents[$i] == 'A' )    # && ($A++ <=100))
 {
 
    $A++;
#   if ( $A++ <= 100 ) {
    imagefilledrectangle($img, $x1, $y1, $x2, $y2, $green);
/***to draw an image of thin vertical rectangular line for every characters read and counted which is secondary***/
    $x1=$x1+6;
    $x2=$x2+6;
}
    else
    if ($contents[$i] == 'G' )  # ($G++ <=100))
{
    $G++;
#   if ( $G++ <= 100 ) {
    imagefilledrectangle($img, $x1, $y1, $x2, $y2, $black);
    $x1=$x1+6;
    $x2=$x2+6;
}
    else
    if ($contents[$i] == 'C' )  #($C++ <=100))
{
    
    $C++;
#   if ( $C++ <= 100 ) {
    imagefilledrectangle($img, $x1, $y1, $x2, $y2, $blue);
    $x1=$x1+6;
    $x2=$x2+6;
}
    else
    if ($contents[$i] == 'T' )  #($T++ <=100))
{
    $T++;
#   if ( $T++ <= 100 ) {
    imagefilledrectangle($img, $x1, $y1, $x2, $y2, $red);
    $x1=$x1+6;
    $x2=$x2+6;
}
}
fclose($handle);
?>
I shall appreciate and honor your help.
with thanks & regards
s.mahalingam



More information about the ilugc mailing list