$bound){ return 0; } } } return 1; } function get_lbound_attr ($line, $lbound){ for ($i=0; $i= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start'] ) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); # $strand = substr(strchr ($line, 'strand='), 7, 1); # if ( $strand == '+' xor $req['start'] >= $req['end']) { # for($i = $startpos; $i < $endpos-10; $i+=10){ # imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); # imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); # } # }else if ( $strand == '-' xor $req['start'] >= $req['end']) { # for($i = $startpos; $i < $endpos -10; $i+=10){ # imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); # imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); # } # } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ if ($exon_end < $req['start']) continue; if ($exon_start > $req['end']) continue; $startpos = $req['width'] * ($exon_start - $req['start'] ) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { if ($exon_end < $req['end']) continue; if ($exon_start > $req['start']) continue; $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_style_full($genes, $req, $colorD, $h1, $hgene){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start'] ) + 1; $h2 = 0; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $num; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if ($startpos < 0) $startpos = 0; if ($endpos >$req['width'] ) $endpos = $req['width']; imageline($image, $startpos, $h, $endpos, $h, $color); $strand = substr(strchr ($line, 'strand='), 7, 1); if ( $strand == '+' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos-10; $i+=10){ imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); } }else if ( $strand == '-' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos -10; $i+=10){ imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); } } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end ) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if ($startpos < 0) $startpos = 0; if ($endpos >$req['width'] ) $endpos = $req['width']; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function get_pack_height ($genes, $req, &$gene_height, $h1, $distance){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start'] + 1); if ($num_genes == 0) return 5; $base_end = array(); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } $height = sizeof ($base_end); $flag = 0; for($i=0; $i < $height; $i++){ if($base_end[$i] <= ($startpos - $distance)){ $base_end[$i] = $endpos; array_push ($gene_height, $i); $flag = 1; break; } } if ($flag == 0){ array_push ($base_end, $endpos); array_push ($gene_height, $height); } } return sizeof ($base_end) * $h1; } function draw_gene_style_pack($genes, $req, $colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start']) + 1; $size = 8; $fontfile = $utgb_font_Abadi_file; # $h1 = 10; # $hgene = 3; # 20 # $h2 = 5; # $h2 = 1; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); // イメージの作成 # for($i=50; $i < $req['width']; $i = $i +50){ # imageline($image, $i, 0, $i, $height, $black); # } draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); $strand = substr(strchr ($line, 'strand='), 7, 1); if ( $strand == '+' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos-10; $i+=10){ imageline($image, $i, $h-$hgene, $i+$hgene, $h, $color); imageline($image, $i, $h+$hgene, $i+$hgene, $h, $color); } }else if ( $strand == '-' xor $req['start'] >= $req['end']) { for($i = $startpos; $i < $endpos -10; $i+=10){ imageline($image, $i, $h, $i+$hgene, $h-$hgene, $color); imageline($image, $i, $h, $i+$hgene, $h+$hgene, $color); } } if($startpos > 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, $startpos-$strbox[2]+$strbox[0]- 10, $h + (- $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_style_small($genes, $req, $colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start']) + 1; $size = 8; $fontfile = $utgb_font_Abadi_file; # $h1 = 10; # $hgene = 3; # 20 # $h2 = 5; # $h2 = 1; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1,10); $image = imagecreatetruecolor( $req['width'], $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $req['width']-1,$height-1, $white); // イメージの作成 # for($i=50; $i < $req['width']; $i = $i +50){ # imageline($image, $i, 0, $i, $height, $black); # } draw_ruler($image, $req, $height); for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } // 色の取得 $colorRGB = $colorD; if(array_key_exists('usecolor', $req)) { if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imageline($image, $startpos, $h, $endpos, $h, $color); $exon_line = $line; for(;;){ if(($exon = strchr ($exon_line, 'exon=')) == FALSE) break; $exon_line = substr($exon, 5); list($exon_start, $exon_end, $remain) = split("[, \t]", $exon_line); if($exon_start > $exon_end) { $tmp = $exon_start; $exon_start = $exon_end; $exon_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($exon_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($exon_end - $req['start'] + 1) / $basewidth; }else { $endpos = $req['width'] * ($req['start'] - $exon_start + 1) / $basewidth; $startpos = $req['width'] * ($req['start'] - $exon_end) / $basewidth; } if (($endpos < 0) || ($startpos >$req['width'] )) continue; if($startpos < 0) $startpos = 0; if($endpos > $req['width']) $endpos = $req['width']-1; imagefilledrectangle($image, $startpos, $h-$hgene, $endpos, $h+$hgene, $color); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene($file,$first_line){ $first_line = trim (substr($first_line, 9)); $colorD = get_defaultcolor($first_line); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ draw_gene_style_full($genes,$req,$colorD,9,3); }else if ($style == 'dense'){ draw_gene_style_dense($genes,$req,$colorD,9); }else if ($style == 'pack'){ draw_gene_style_pack($genes,$req,$colorD, 9,3); }else if ($style == 'small'){ draw_gene_style_small($genes,$req,$colorD, 4,1); } } function draw_gene_index_style_full($genes,$req,$colorD, $h1, $hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); // イメージの生成 # $h1 = 10; # $hgene = 5; # 20 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの作成 for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 * $num; if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, ($width-$strbox[2]+$strbox[0])/2, $h + ($h1 + $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_dense($genes,$req,$colorD,$height){ $num_genes = sizeof($genes); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_pack($genes,$req,$colorD, $h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); // イメージの生成 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの作成 for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } // 色の取得 $colorRGB = $colorD; if(preg_match("/^(\w+)\-color$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_color($colorD, $line, $at[1], $req['color']); }else if(preg_match("/^(\w+)\-gradation$/",$req['usecolor'],$at)){ $colorRGB = get_genecolor_by_gradation($colorD, $line, $at[1], $req['gradation']); } if (array_key_exists ('foundGene', $req) ){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); if ($name == $req['foundGene']){ $colorRGB = array(230,159,0); } } } $color = imagecolorallocate( $image, $colorRGB[0], $colorRGB[1], $colorRGB[2] ); $h = $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } if($startpos <= 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); #imagestring($image, 1, 10, $h-20, $name, $black); // Replace path by your own font path $strbox = imagettfbbox( $size, 0, $fontfile, $name ); imagettftext( $image, $size, 0, ($width-$strbox[2]+$strbox[0])/2, $h + ($h1 + $h2 + $strbox[3]-$strbox[5])/2, $color, $fontfile, $name); } } } // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index_style_small($genes,$req,$colorD,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); // イメージの生成 $h2 = 0; $size = 8; $fontfile = $utgb_font_Abadi_file; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 10); $width = 100; $image = imagecreatetruecolor( $width, $height ); $white = imagecolorallocate( $image, 0xFF, 0xFF, 0xFF ); $black = imagecolorallocate( $image, 0x00, 0x00, 0x00 ); // imagefill( $image, 0, 0, $white); imagefilledrectangle($image, 0, 0, $width-1,$height-1, $white); // イメージの出力 header( 'Content-type: image/png' ); imagepng( $image ); imagedestroy( $image ); } function draw_gene_index($file, $first_line){ $first_line = trim (substr($first_line, 9)); $colorD = get_defaultcolor($first_line); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ draw_gene_index_style_full($genes,$req,$colorD,9,3); }else if ($style == 'dense'){ draw_gene_index_style_dense($genes,$req,$colorD,9); }else if ($style == 'pack'){ draw_gene_index_style_pack($genes,$req,$colorD,9,3); }else if ($style == 'small'){ draw_gene_index_style_small($genes,$req,$colorD,4,1); } } function def_gene_operation_style_full($genes,$req,$h1,$hgene){ $num_genes = sizeof($genes); $basewidth = abs ($req['end'] - $req['start']) + 1; // 共通パラメータ $h2 = 0; $height = $num_genes * $h1 + $h2; if ($num_genes == 0) $height = 5; // xml出力 header('Content-Type: text/xml'); print"\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } $h = $h1 / 2 + $h2 + $h1 * $num; $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_operation_style_dense($genes,$req,$h1){ // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; print ""; } function def_gene_operation_style_pack($genes, $req,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); $size = 8; $fontfile = $utgb_font_Abadi_file; # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } if($startpos > 100){ if(($name_pos = strpos($line, 'name=')) !== FALSE) { $name_line = substr($line, $name_pos + 5); list($name, $remain) = split("[ \t]", $name_line); $strbox = imagettfbbox( $size, 0, $fontfile, $name ); $startpos = $startpos - $strbox[2] + $strbox[0] - 10; } } $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_operation_style_small($genes, $req,$h1,$hgene){ global $utgb_font_Abadi_file; $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); $size = 8; $fontfile = $utgb_font_Abadi_file; # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 10); // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start'] + 1) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start + 1) / $basewidth; } # if($startpos > 100){ # if(($name_pos = strpos($line, 'name=')) !== FALSE) { # $name_line = substr($line, $name_pos + 5); # list($name, $remain) = split("[ \t]", $name_line); # $strbox = imagettfbbox( $size, 0, $fontfile, $name ); # $startpos = $startpos - $strbox[2] + $strbox[0] - 10; # } # } $y1 = $h-$hgene; $y2 = $h+$hgene+1; if ($startpos < 0) { $x1 = 0; }else { $x1 = floor ($startpos); // 0; } if ($endpos >= $req['width']) { $x2 = $req['width']-1; }else { $x2 = ceil($endpos) ; // $req['width']-1; } // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_operation($file, $first_line){ // イメージサイズの取得 $first_line = trim (substr($first_line, 9)); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ def_gene_operation_style_full($genes,$req,9,3); }else if ($style == 'dense'){ def_gene_operation_style_dense($genes,$req,9); }else if ($style == 'pack'){ def_gene_operation_style_pack($genes,$req,9,3); }else if ($style == 'small'){ def_gene_operation_style_small($genes,$req,4,1); } } function def_gene_index_operation_style_full($genes,$req,$h1, $hgene){ $num_genes = sizeof($genes); // 共通パラメータ $h2 = 0; $height = $num_genes * $h1 + $h2; if($num_genes == 0) $height = 5; $width = 100; // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $h = $h1 / 2 + $h2 + $h1 * $num; $y1 = $h-$hgene; $y2 = $h+$hgene+1; $x1 = 0; $x2 = $width-1; // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } print ""; } function def_gene_index_operation_style_dense($genes,$req,$height){ // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; print ""; } function def_gene_index_operation_style_pack($genes, $req,$h1,$hgene){ $num_genes = sizeof($genes); if ($req['start'] > $req['end']){ usort ($genes, "cmp_genes_rev"); } $basewidth = abs ($req['end'] - $req['start'] + 1); # $h2 = 5; $h2 = 0; $gene_height = array(); $height = get_pack_height ($genes, $req, $gene_height, $h1, 100); $width = 100; // xml出力 header('Content-Type: text/xml'); print "\n"; print "\n"; for($num=0; $num < $num_genes; $num++){ $line = $genes[$num]; $range_line = substr(strchr ($line, 'range='), 6); list($range_start, $range_end, $remain) = split("[, \t]", $range_line); if($range_start > $range_end) { $tmp = $range_start; $range_start = $range_end; $range_end = $tmp; } $h = $h1 / 2 + $h2 + $h1 * $gene_height[$num]; if($req['end'] >= $req['start']){ $startpos = $req['width'] * ($range_start - $req['start']) / $basewidth; $endpos = $req['width'] * ($range_end - $req['start']) / $basewidth; } else { $startpos = $req['width'] * ($req['start'] - $range_end) / $basewidth; $endpos = $req['width'] * ($req['start'] - $range_start) / $basewidth; } if($startpos <= 100){ $y1 = $h-$hgene; $y2 = $h+$hgene+1; $x1 = 0; $x2 = $width-1; // URLの取得 if (preg_match("/url=\"(\S+)\"/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; }else if (preg_match("/url=(\S+)/",$line, $url)){ $url[1] = preg_replace('/&/', "&" , $url[1]); print " \n" ; print " \n"; print " \n"; print " \n" ; print " \n" ; } } } print ""; } function def_gene_index_operation($file, $first_line){ $first_line = trim (substr($first_line, 9)); $opattrs = get_optional_attribute($first_line); $req = get_request($_REQUEST, $opattrs, $colorD); $genes = get_display_genes($file,$req); // style の検索 $style = $req['style']; if ($style == 'full'){ def_gene_index_operation_style_full($genes,$req,9,3); }else if ($style == 'dense'){ def_gene_index_operation_style_dense($genes,$req,10); }else if ($style == 'pack'){ def_gene_index_operation_style_pack($genes,$req,9,3); }else if ($style == 'small'){ def_gene_index_operation_style_dense($genes,$req,10); } } ?>