There may be simpler solutions but give this a shot :
$y=0
while(( ($contents=fread( $handle, 100 )) != '' )) {
//$A etc. should be set to 0 at the beginning of while loop.
$A=0;
$G=0;
$C=0;
$T=0;
for ($i=0; $i<100; $i++)
{if($contents[$i] == 'A' )
{
$A++;
}
else
if($contents[$i] == 'G' )
{
$G++
}
etc...
}
//picture is drawn at the end of for loop but inside while loop.
$imageyel = imagecreate($A,10);
$imageblu = imagecreate($G,10);
$imagegre = imagecreate($C,10);
$imagered = imagecreate($T,10);
$back = ImageColorAllocate($imageyel,255,255,255);
ImageFilledRectangle($imageyel,$y,0,110,$y+10,$back);
$yel = ImageColorAllocate($imageyel,255,255,0);
ImageFilledRectangle($imageyel,1,$y+1,1+$A,$y+10,$yel);
$red = ImageColorAllocate($image,255,0,0);
ImageFilledRectangle($imagered,1+$A,$y+1,1+$A+$G,$y+10,$red);
$green = ImageColorAllocate($image,0,255,0);
ImageFilledRectangle($imagegre,1+$A+$G,$y+1,1+$A+$G+$C,$y+10,$green);
$blue = ImageColorAllocate($image,0,0,255);
ImageFilledRectangle($imageblu,1+$A+$G+$C,$y+1,1+$A+$G+$C+$T,$y+10,$blue);
$y=$y+10;
}
> To: [email protected]
> From: [email protected]
> Date: Sun, 7 Feb 2010 16:40:20 +0530
> Subject: Re: RE: [TwinCLinG] read and count only limited charactersusingphp
> script
>
> -- Original Message --
> From: shinoj vg <[email protected]>
> To: <[email protected]>
> Date: Fri, 5 Feb 2010 07:44:56 +0530
> Subject: RE: [TwinCLinG] read and count only limited characters usingphp
> script
> Please clarify your requirements. Is it:
> 1. Read a file that has no fixed size in chunks of 100 characters.
> 2. Count the occurance & recurrance of A,G,C,T in the above 100 characters.
> 3. Draw a bargraph for the above - 1 bargraph in a line for each 100 chars
> and every subsequent drawn for every set
> of 100 should be appended one below other.
> 4. Stop when count of A,G,C,T, reached the last character.
> Please state your specs in simple statements like above.
> Yes, it is true and the requirement is as stated above.
> with thansk & regards
> s.mahalingam
> > To: <ilughyd%40yahoogroups.com>[email protected]
> > From: <smal%40ccmb.res.in>[email protected]
> > Date: Wed, 3 Feb 2010 17:37:02 +0530
> > Subject: Re: RE: [TwinCLinG] read and count only limited characters
> > usingphp script
> >
> > -- Original Message --
> > From: shinoj vg <<shinoj%40hotmail.com>[email protected]>
> > To: <<ilughyd%40yahoogroups.com>[email protected]>
> > Date: Mon, 1 Feb 2010 20:55:11 +0530
> > Subject: RE: [TwinCLinG] read and count only limited characters using php
> > script
> > I dont understand your requirements but you can try this:
> > while(( ($contents=fread( $handle, 100 )) != '' )) {
> > for ($i=0; $i<100; $i++)
> > {if
> > {
> > ...
> > }
> > else
> > if{
> > ..
> > }
> > }
> > }
> > There may be a problem in the last read above.
> > If you are trying to count the occurance of A,G,C,T in the file using
> > preg_grep may be easier.
> > Regards,
> > Shinoj.
> > still, it reads & counts all entire characters present in the input file
> > instead of limited number of characters as I desire. The aim is to draw a
> > barcode of series of thin vertical lines with respect to its recurrence in
> > the input file. The preg_grep function is to search & filter the pattern
> > from an array which may not be exactly what I am looking for.
> > with regards
> > s.mahalingam
> > > To: <ilughyd%40yahoogroups.com>[email protected]
> > > From: <smal%40ccmb.res.in>[email protected]
> > > Date: Sun, 31 Jan 2010 22:44:00 +0530
> > > Subject: [TwinCLinG] read and count only limited characters using php
> > > script
> > >
> > >
> > >
> > >
> > > 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 regards
> > > s.mahalingam
> > >
> > >
> > >
> > > [Non-text portions of this message have been removed]
> > >
> > >
> > >
> > > ------------------------------------
> > >
> > > -----------------------------------------------
> > > Next Meeting as on our Website:
> > > <http://ilughyd.org.in>http://ilughyd.org.in
> > > -----------------------------------------------Yahoo! Groups Links
> > >
> > >
> > >
> >
> > __________________________________________________________
> > Hotmail: Trusted email with Microsofts powerful SPAM protection.
> > <https://signup.live.com/signup.aspx?id=60969>https://signup.live.com/signup.aspx?id=60969
> > [Non-text portions of this message have been removed]
> > ------------------------------------
> > -----------------------------------------------
> > Next Meeting as on our Website: <http://ilughyd.org.in>http://ilughyd.org.in
> > -----------------------------------------------Yahoo! Groups Links
> > Individual Email | Traditional
> http://docs.yahoo.com/info/terms/
> >
> >
> >
> > [Non-text portions of this message have been removed]
> >
> >
> >
> > ------------------------------------
> >
> > -----------------------------------------------
> > Next Meeting as on our Website: <http://ilughyd.org.in>http://ilughyd.org.in
> > -----------------------------------------------Yahoo! Groups Links
> >
> >
> >
> __________________________________________________________
> Hotmail: Powerful Free email with security by Microsoft.
> <https://signup.live.com/signup.aspx?id=60969>https://signup.live.com/signup.aspx?id=60969
> [Non-text portions of this message have been removed]
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> ------------------------------------
>
> -----------------------------------------------
> Next Meeting as on our Website: http://ilughyd.org.in
> -----------------------------------------------Yahoo! Groups Links
>
>
>
_________________________________________________________________
Hotmail: Powerful Free email with security by Microsoft.
https://signup.live.com/signup.aspx?id=60969
[Non-text portions of this message have been removed]