Graphical representation of genomes
and oligonucleotide frequencies

?CGR">Chaos Game Representation (CGR)
as described by Jeffrey (1990).
Represents DNA primary sequence organization.

 

?FCGR">Chaos Game Representation of Frequencies (FCGR)
as described by Deschavanne at al. (1999).
Represents frequencies of oligonucleotides.

 


This script has been extracted from online tools at insilico.ehu.es/.
CGR images for all sequenced bacterial genomes are available here
To understand how CGR images are generated, check here

Source code is available at BioPHP.org

>Home

Computation of Chaos Game Representation (CGR) images

?CGR" method="post">
Sequence name
Size of image (pixel)
Sequence code (< bp; all digits, spaces and other non-coding characters will be removed)

When size of CGR image is not specified (Auto), the following image sizes are used:

  256x256 images for sequences up to 100,000 bp,
  512x512 images for sequences up to 1,000,000 bp,
  1024x1024 images for sequences up to 5,000,000 bp.

Home

\n"; print "
\n

Chaos Game Representation of DNA sequences

\n"; // GET POSTED DATA if ($_POST["seq_name"]){$seq_name=$_POST["seq_name"];}else{ $seq_name="No name";} $seq=strtoupper ($_POST["seq"]); $seq = preg_replace ("/\W|\d/", "", $seq); $seq_len=strlen($seq); // add limits to length of imput sequence if ($seq_len>$input_max){die("

Sequence is longer than $input_max bp.

At this moment we can not provide this service to such a long sequences.");} if ($seq_len<$input_min){die("

Minumum sequence length: $input_min bp");} if($_POST["size"]=="auto"){ $size=256; if ($seq_len>1000000){$size=1024;} if ($seq_len>100000){$size=512;} }else{ $size=$_POST["size"]; } create_CGR_image($seq_name,$seq,$size); print "\n"; print "

\n"; } //######################################################## function print_FCGR_form($input_max){ ?>

>Home

Computation of
Chaos Game Representation of frequencies (FCGR)

?FCGR" method="post">
Sequence name
Compute data for
Search oligos of length
Sequence code (< bp; all digits, spaces and other non-coding characters will be removed)


Show as image map (not recomemded for long oligonuclotides)
Show oligonuclotide frequencies

Home

\n"; print "Computing...(time depends on sequence length and power of the server)

";flush(); // GET DATA if ($_POST["seq_name"]){$seq_name=$_POST["seq_name"];}else{ $seq_name="No name";} $seq=strtoupper ($_POST["seq"]); $seq = preg_replace ("/\W|\d/", "", $seq); $seq_len=strlen($seq); // limits for length of sequence if ($seq_len>$input_max){die("

Sequence is longer than $input_max bp.

At this moment we can not provide this service to such a long sequences.");} if ($seq_len<$input_min){die("

Minumum sequence length: $input_min bp");} $oligo_len=$_POST["len"]; // If double strand is requested to be computed... if ($_POST["s"]==2){$seq.=" ".RevComp($seq); } // compute nucleotide frequencies $A=substr_count($seq,"A"); $C=substr_count($seq,"C"); $G=substr_count($seq,"G"); $T=substr_count($seq,"T"); // COMPUTE OLIGONUCLEOTIDE FREQUENCIES // frequencies are saved to an array named $oligos $oligos=find_oligos($seq,$oligo_len); // CREATE CHAOS GAME REPRESENTATION OF FREQUENCIES IMAGE // check the function for more info on parameters // $data contains a string with the data to be used to create the image map $for_map=create_FCGR_image($oligos,$seq_name,$A,$C,$G,$T,$seq_len,$_POST["s"],$oligo_len); // PRINT THE IMAGE, WHICH WILL BE A IMAGE MAP WHEN REQUESTED // to avoid submission of a huge amount of data throught the net if ($_POST["map"]==1){ // image map is requested print "
\n$for_map\n\n 
\n"; }else{ print "
"; } // PRINT TEXTAREA WITH OLIGONUCLEOTIDE FREQUENCIES WHEN REQUESTED if ($_POST["freq"]==1){ // oligonucleotide frequencies are requested print "

Raw data used to generate images above:
"; } } //######################################################## function create_CGR_image($seq_name,$seq,$size,$ip2){ $im = @imagecreatetruecolor($size, $size+20) or die("Cannot initialize image"); $white =imagecolorallocate($im, 255, 255, 255); $black =imagecolorallocate($im, 0, 0, 0); imagefilledrectangle($im,0,0,$size,$size+20,$white); $x=round ($size/2);$y=$x; for($i=0;$i $val_a){ foreach($base_b as $key_b => $val_b){ if ($oligos_1step[$val_a.$val_b]){ $oligos[$val_a.$val_b] = $oligos_1step[$val_a.$val_b]; }else{ $oligos[$val_a.$val_b] = 0; } }} } //for oligos 3 bases long if ($oligo_len==3){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ if ($oligos_1step[$val_a.$val_b.$val_c]){ $oligos[$val_a.$val_b.$val_c] = $oligos_1step[$val_a.$val_b.$val_c]; }else{ $oligos[$val_a.$val_b.$val_c] = 0; } }}} } //for oligos 4 bases long if ($oligo_len==4){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ foreach($base_d as $key_d => $val_d){ if ($oligos_1step[$val_a.$val_b.$val_c.$val_d]){ $oligos[$val_a.$val_b.$val_c.$val_d] = $oligos_1step[$val_a.$val_b.$val_c.$val_d]; }else{ $oligos[$val_a.$val_b.$val_c.$val_d] = 0; } }}}} } //for oligos 5 bases long if ($oligo_len==5){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ foreach($base_d as $key_d => $val_d){ foreach($base_e as $key_e => $val_e){ if ($oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e]){ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e] = $oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e]; }else{ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e] = 0; } }}}}} } //for oligos 6 bases long if ($oligo_len==6){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ foreach($base_d as $key_d => $val_d){ foreach($base_e as $key_e => $val_e){ foreach($base_f as $key_f => $val_f){ if ($oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f]){ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f] = $oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f]; }else{ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f] = 0; } }}}}}} } //for oligos 7 bases long if ($oligo_len==7){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ foreach($base_d as $key_d => $val_d){ foreach($base_e as $key_e => $val_e){ foreach($base_f as $key_f => $val_f){ foreach($base_g as $key_g => $val_g){ if ($oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g]){ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g] = $oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g]; }else{ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g] = 0; } }}}}}}} } //for oligos 8 bases long if ($oligo_len==8){ foreach($base_a as $key_a => $val_a){ foreach($base_b as $key_b => $val_b){ foreach($base_c as $key_c => $val_c){ foreach($base_d as $key_d => $val_d){ foreach($base_e as $key_e => $val_e){ foreach($base_f as $key_f => $val_f){ foreach($base_g as $key_g => $val_g){ foreach($base_h as $key_h => $val_h){ if ($oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g.$val_h]){ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g.$val_h] = $oligos_1step[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g.$val_h]; }else{ $oligos[$val_a.$val_b.$val_c.$val_d.$val_e.$val_f.$val_g.$val_h] = 0; } }}}}}}}} } return $oligos; } //######################################################## // CREATE CHAOS GAME REPRESENTATION OF FREQUENCIES // The FCGR image will be save to a file, and an string is returned which contains data to be create a image map // $oligos is the array containing the oligonucleotides and their frequencies // $seq_name name of the sequence // $A,$C,$G,$T frequencies of nucleotides // $seq_len length of sequence // $n number of strands used to compute the figure // $oligo_len length of oligonucleotides studied function create_FCGR_image($oligos,$seq_name,$A,$C,$G,$T,$seq_len,$n,$oligo_len){ $max_val=max($oligos); $min_val=min($oligos); foreach ($oligos as $key => $val){ $ratio[$key]= floor(255-((255*($val-$min_val))/($max_val-$min_val))); } $im = @imagecreatetruecolor(552, 370) or die("Cannot initialize image"); for($c=0;$c<256;$c++){ $thecolor[$c]=ImageColorAllocate($im, $c, $c, $c); } $background_color =imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im,0,0,552,700,$background_color); $black =imagecolorallocate($im, 0, 0, 0); $red =imagecolorallocate($im, 255, 0, 0); $blue =imagecolorallocate($im, 0, 0, 255); imagestring($im, 4, 10, 10, "Over or under-representation of oligonucleotides", $blue); imagestring($im, 3, 20, 30, "Chaos Game Representation of frequencies (FCGR)", $black); imageline ($im, 10, 50, 350, 50, $black); $seq_name=substr($seq_name,0,15); imagestring($im, 3, 20, 55, "Sequence name: $seq_name ($seq_len bp)", $black); if ($n==1){imagestring($im, 3, 20, 73, "Results for only one strand", $black);} if ($n==2){imagestring($im, 3, 20, 73, "Results for both strands", $black);} $thecolor[255]=ImageColorAllocate($im, 255, 255, 255); $for_map=""; foreach($ratio as $seq => $val){ $len=strlen($seq); if ($len==7){$len_cuadro=1;} if ($len==6){$len_cuadro=3;} if ($len==5){$len_cuadro=7;} if ($len==4){$len_cuadro=15;} if ($len==3){$len_cuadro=31;} if ($len==2){$len_cuadro=63;} $mas_x=10;$mas_y=90; // para posicion $x=0; $y=0; $tt=0; $len2=$len; while ($len2>0){ $len2--; $ttt=pow(2,$tt);$tt++; $subseq1=substr($seq,$len2,1); if($subseq1=="A" or $subseq1=="T"){$y+=128/$ttt;} if($subseq1=="G" or $subseq1=="T"){$x+=128/$ttt;} } $x+=$mas_x;$x2=$x+$len_cuadro; $y+=$mas_y;$y2=$y+$len_cuadro; imagefilledrectangle($im,$x,$y,$x2,$y2,$thecolor[$val]); $for_map.=" ".$oligos[$seq]."');\" onMouseout=\"a('');\" COORDS=\"$x,$y,$x2,$y2\" SHAPE=RECT>\n"; } imagestring($im, 3, 420, 10, "A: $A", $black); imagestring($im, 3, 420, 30, "C: $C", $black); imagestring($im, 3, 420, 50, "G: $G", $black); imagestring($im, 3, 420, 70, "T: $T", $black); // lines imageline ($im, 10, 90, 10, 346, $black); imageline ($im, 266, 90, 266, 346, $black); imageline ($im, 10, 90, 266, 90, $black); imageline ($im, 10, 346, 266, 346, $black); if ($oligo_len==2){ // lines imageline ($im, 10, 154, 266, 154, $black); imageline ($im, 10, 218, 266, 218, $black); imageline ($im, 10, 282, 266, 282, $black); imageline ($im, 74, 90, 74, 346, $black); imageline ($im, 138, 90, 138, 346, $black); imageline ($im, 202, 90, 202, 346, $black); // dimers in their place $h_pos=24; $v_pos=26; imagestring($im, 3, 10+$h_pos, 90+$v_pos, "CC", $black); imagestring($im, 3, 74+$h_pos, 90+$v_pos, "GC", $black); imagestring($im, 3, 138+$h_pos, 90+$v_pos, "CG", $black); imagestring($im, 3, 202+$h_pos, 90+$v_pos, "GG", $black); imagestring($im, 3, 10+$h_pos, 154+$v_pos, "AC", $black); imagestring($im, 3, 74+$h_pos, 154+$v_pos, "TC", $black); imagestring($im, 3, 138+$h_pos, 154+$v_pos, "AG", $black); imagestring($im, 3, 202+$h_pos, 154+$v_pos, "TG", $black); imagestring($im, 3, 10+$h_pos, 218+$v_pos, "CA", $black); imagestring($im, 3, 74+$h_pos, 218+$v_pos, "GA", $black); imagestring($im, 3, 138+$h_pos, 218+$v_pos, "CT", $black); imagestring($im, 3, 202+$h_pos, 218+$v_pos, "GT", $black); imagestring($im, 3, 10+$h_pos, 282+$v_pos, "AA", $black); imagestring($im, 3, 74+$h_pos, 282+$v_pos, "TA", $black); imagestring($im, 3, 138+$h_pos, 282+$v_pos, "AT", $black); imagestring($im, 3, 202+$h_pos, 282+$v_pos, "TT", $black); } if ($oligo_len==3){ // lines imageline ($im, 10, 122, 266, 122, $black); imageline ($im, 10, 154, 266, 154, $black); imageline ($im, 10, 186, 266, 186, $black); imageline ($im, 10, 218, 266, 218, $black); imageline ($im, 10, 250, 266, 250, $black); imageline ($im, 10, 282, 266, 282, $black); imageline ($im, 10, 314, 266, 314, $black); imageline ($im, 42, 90, 42, 346, $black); imageline ($im, 74, 90, 74, 346, $black); imageline ($im, 106, 90, 106, 346, $black); imageline ($im, 138, 90, 138, 346, $black); imageline ($im, 170, 90, 170, 346, $black); imageline ($im, 202, 90, 202, 346, $black); imageline ($im, 234, 90, 234, 346, $black); // trinucleotides in their place $h_pos=8; $v_pos=10; imagestring($im, 2, 10+$h_pos, 90+$v_pos, "CCC", $black); imagestring($im, 2, 42+$h_pos, 90+$v_pos, "GCC", $black); imagestring($im, 2, 74+$h_pos, 90+$v_pos, "CGC", $black); imagestring($im, 2, 106+$h_pos, 90+$v_pos, "GGC", $black); imagestring($im, 2, 138+$h_pos, 90+$v_pos, "CCG", $black); imagestring($im, 2, 170+$h_pos, 90+$v_pos, "GCG", $black); imagestring($im, 2, 202+$h_pos, 90+$v_pos, "CGG", $black); imagestring($im, 2, 234+$h_pos, 90+$v_pos, "GGG", $black); imagestring($im, 2, 10+$h_pos, 122+$v_pos, "ACC", $black); imagestring($im, 2, 42+$h_pos, 122+$v_pos, "TCC", $black); imagestring($im, 2, 74+$h_pos, 122+$v_pos, "AGC", $black); imagestring($im, 2, 106+$h_pos, 122+$v_pos, "TGC", $black); imagestring($im, 2, 138+$h_pos, 122+$v_pos, "ACG", $black); imagestring($im, 2, 170+$h_pos, 122+$v_pos, "TCG", $black); imagestring($im, 2, 202+$h_pos, 122+$v_pos, "AGG", $black); imagestring($im, 2, 234+$h_pos, 122+$v_pos, "TGG", $black); imagestring($im, 2, 10+$h_pos, 154+$v_pos, "CAC", $black); imagestring($im, 2, 42+$h_pos, 154+$v_pos, "GAC", $black); imagestring($im, 2, 74+$h_pos, 154+$v_pos, "ATC", $black); imagestring($im, 2, 106+$h_pos, 154+$v_pos, "CTC", $black); imagestring($im, 2, 138+$h_pos, 154+$v_pos, "CAG", $black); imagestring($im, 2, 170+$h_pos, 154+$v_pos, "GAG", $black); imagestring($im, 2, 202+$h_pos, 154+$v_pos, "CTG", $black); imagestring($im, 2, 234+$h_pos, 154+$v_pos, "GTG", $black); imagestring($im, 2, 10+$h_pos, 186+$v_pos, "AAC", $black); imagestring($im, 2, 42+$h_pos, 186+$v_pos, "TAC", $black); imagestring($im, 2, 74+$h_pos, 186+$v_pos, "GTC", $black); imagestring($im, 2, 106+$h_pos, 186+$v_pos, "TTC", $black); imagestring($im, 2, 138+$h_pos, 186+$v_pos, "AAG", $black); imagestring($im, 2, 170+$h_pos, 186+$v_pos, "TAG", $black); imagestring($im, 2, 202+$h_pos, 186+$v_pos, "ATG", $black); imagestring($im, 2, 234+$h_pos, 186+$v_pos, "TTG", $black); imagestring($im, 2, 10+$h_pos, 218+$v_pos, "CCA", $black); imagestring($im, 2, 42+$h_pos, 218+$v_pos, "GCA", $black); imagestring($im, 2, 74+$h_pos, 218+$v_pos, "CGA", $black); imagestring($im, 2, 106+$h_pos, 218+$v_pos, "GGA", $black); imagestring($im, 2, 138+$h_pos, 218+$v_pos, "CCT", $black); imagestring($im, 2, 170+$h_pos, 218+$v_pos, "GCT", $black); imagestring($im, 2, 202+$h_pos, 218+$v_pos, "CGT", $black); imagestring($im, 2, 234+$h_pos, 218+$v_pos, "GGT", $black); imagestring($im, 2, 10+$h_pos, 250+$v_pos, "ACA", $black); imagestring($im, 2, 42+$h_pos, 250+$v_pos, "TCA", $black); imagestring($im, 2, 74+$h_pos, 250+$v_pos, "AGA", $black); imagestring($im, 2, 106+$h_pos, 250+$v_pos, "TGA", $black); imagestring($im, 2, 138+$h_pos, 250+$v_pos, "ACT", $black); imagestring($im, 2, 170+$h_pos, 250+$v_pos, "TCT", $black); imagestring($im, 2, 202+$h_pos, 250+$v_pos, "AGT", $black); imagestring($im, 2, 234+$h_pos, 250+$v_pos, "TGT", $black); imagestring($im, 2, 10+$h_pos, 282+$v_pos, "CAA", $black); imagestring($im, 2, 42+$h_pos, 282+$v_pos, "GAA", $black); imagestring($im, 2, 74+$h_pos, 282+$v_pos, "CTA", $black); imagestring($im, 2, 106+$h_pos, 282+$v_pos, "GTA", $black); imagestring($im, 2, 138+$h_pos, 282+$v_pos, "CAT", $black); imagestring($im, 2, 170+$h_pos, 282+$v_pos, "GAT", $black); imagestring($im, 2, 202+$h_pos, 282+$v_pos, "CTT", $black); imagestring($im, 2, 234+$h_pos, 282+$v_pos, "GTT", $black); imagestring($im, 2, 10+$h_pos, 314+$v_pos, "AAA", $black); imagestring($im, 2, 42+$h_pos, 314+$v_pos, "TAA", $black); imagestring($im, 2, 74+$h_pos, 314+$v_pos, "ATA", $black); imagestring($im, 2, 106+$h_pos, 314+$v_pos, "TTA", $black); imagestring($im, 2, 138+$h_pos, 314+$v_pos, "AAT", $black); imagestring($im, 2, 170+$h_pos, 314+$v_pos, "TAT", $black); imagestring($im, 2, 202+$h_pos, 314+$v_pos, "ATT", $black); imagestring($im, 2, 234+$h_pos, 314+$v_pos, "TTT", $black); } // show length of oligonucleotides imagestring($im, 3, 50, 350, "Oligonucleotide length: $oligo_len", $black); $cent=286; imagestring($im, 2, 6+$cent, 228, "Frequency", $black); imagefilledrectangle($im,6+$cent,208,16+$cent,218,$thecolor[255]); imagefilledrectangle($im,19+$cent,208,29+$cent,218,$thecolor[240]); imagefilledrectangle($im,32+$cent,208,42+$cent,218,$thecolor[225]); imagefilledrectangle($im,45+$cent,208,55+$cent,218,$thecolor[210]); imagefilledrectangle($im,58+$cent,208,68+$cent,218,$thecolor[195]); imagefilledrectangle($im,71+$cent,208,81+$cent,218,$thecolor[180]); imagefilledrectangle($im,84+$cent,208,94+$cent,218,$thecolor[165]); imagefilledrectangle($im,97+$cent,208,107+$cent,218,$thecolor[150]); imagefilledrectangle($im,110+$cent,208,120+$cent,218,$thecolor[135]); imagefilledrectangle($im,123+$cent,208,133+$cent,218,$thecolor[135]); imagefilledrectangle($im,136+$cent,208,146+$cent,218,$thecolor[120]); imagefilledrectangle($im,149+$cent,208,159+$cent,218,$thecolor[105]); imagefilledrectangle($im,162+$cent,208,172+$cent,218,$thecolor[90]); imagefilledrectangle($im,175+$cent,208,185+$cent,218,$thecolor[75]); imagefilledrectangle($im,188+$cent,208,198+$cent,218,$thecolor[60]); imagefilledrectangle($im,201+$cent,208,211+$cent,218,$thecolor[45]); imagefilledrectangle($im,214+$cent,208,224+$cent,218,$thecolor[30]); imagefilledrectangle($im,227+$cent,208,237+$cent,218,$thecolor[15]); imagefilledrectangle($im,240+$cent,208,250+$cent,218,$thecolor[0]); imagepng($im,"FCGR.png"); imagedestroy($im); return $for_map; } //######################################################## // REVERSE_COMPLEMENT DNA function RevComp($code){ $code=strrev($code); $code=str_replace("A", "t", $code); $code=str_replace("T", "a", $code); $code=str_replace("G", "c", $code); $code=str_replace("C", "g", $code); $code = strtoupper ($code); return $code; } ?>