$emblRel = "69";
$sproRel = "40";
function getMotFast( &$iSup, &$beg, &$len, &$maxLen, &$zscore, &$strArr, $mot_file ) {
$f = fopen( $mot_file, "r" );
$prev = 0;
$buf = fgets( $f, 1024 );
$iSup = 0;
while( $buf ) {
#__________________ Sign '#' means that new alignment is begun
if( $buf[0] == ">" && $buf[1] == ">" ) {
# Create string "U49145 [unidentified soil organism]Uniden (650 nt)"
# >>unc|U49145|USU49145 [unidentified soil organism]Uniden (650 nt)
$arr1 = split( "\|", $buf, 3 );
$arr2 = split( "[ +]", $arr1[ 2 ], 2 );
$strArr[ $iSup ] = $arr1[ 1 ]." ".Chop( $arr2[ 1 ] );
# Skip string "initn: 282 init1: 282 opt: 299 Z-score: 305.1 bits: 63.4 E(): 6.6e-11"
#_______________________________________________________________________________________
$buf = fgets( $f, 1024 );
$arr = split( "[ +]", trim( strstr( $buf, "Z-score:" ) ) );
$zscore[ $iSup ] = $arr[ 1 ];
# Get string "75.652% identity in 115 nt overlap (244-357:3-116)"
#_______________________________________________________________________________________
$buf = fgets( $f, 1024 );
if( strchr( $buf, ";" ) ) {
$buf = substr( strchr( $buf, ";" ), 1 );
}
$arr = split( "[%(:)-]", trim( $buf ) );
$Perc = $arr[ 0 ]; # Perc = 75.652
if( $arr[ 2 ] < $arr[ 3 ] ) {
$Beg = $arr[ 2 ]; # Beg = 244
$End = $arr[ 3 ]; # End = 357
}
else {
$Beg = $arr[ 3 ]; # Beg = 244
$End = $arr[ 2 ]; # End = 357
}
#echo "Perc ".$Perc." Beg ".$Beg." End ".$End."
";
# Skip empty string
#--------------------
$buf = fgets( $f, 1024 );
# String with numbers of query sequence " 220 ..."
#---------------------------------------------------
$buf = fgets( $f, 1024 );
#echo $buf."
";
# shf1 - first position of the first number, here shf1 = 11
# 220 230
#<- shf1 -->
#-----------------------------------------------------------
$shf1 = strspn( $buf, " " );
# shf2 - number of digit in the first number, here shf2 = 3
#-----------------------------------------------------------
$shf2 = strcspn( substr( $buf, $shf1 ), " " );
$arr = split( "[ +]", trim( $buf ) );
# Beg2 - the first number, here 220
#------------------------------------
$Beg2 = $arr[ 0 ];
#echo "shf1 ".$shf1." shf2 ".$shf2." Beg2 ".$Beg2."
";
$buf = fgets( $f, 1024 );
# querName - name of the query sequence
#---------------------------------
$querName = split( "[ +]", $buf );
# querSeq - first part of the query sequence
#---------------------------------------
$querSeq = trim( substr( $buf, $shf1+$shf2+( $Beg - $Beg2 ) - 1 ) );
$buf = fgets( $f, 1024 );
# part bank sequence is in the buf
#---------------------------------
$buf = fgets( $f, 1024 );
# bankName - name of the bank sequence
#---------------------------------
$bankName = split( "[ +]", $buf );
# bankSeq - first part of the bank sequence
#---------------------------------------
$bankSeq = trim( substr( $buf, $shf1+$shf2+( $Beg - $Beg2 ) - 1 ) );
while( $buf = fgets( $f, 1024 ) ) {
if( $buf[0] == ">" && $buf[1] == ">" )
break;
if( !strcmp( substr( $buf, 0, strlen( $querName[ 0 ] ) ), $querName[ 0 ] ) ) {
$arr = split( "[ +]", trim( $buf ) );
$querSeq .= $arr[ 1 ];
}
if( !strcmp( substr( $buf, 0, strlen( $bankName[ 0 ] ) ), $bankName[ 0 ] ) ) {
$arr = split( "[ +]", trim( $buf ) );
$bankSeq .= $arr[ 1 ];
}
}
#echo $querSeq."
";
#echo $bankSeq."
";
$beg[ $iSup ][ 0 ] = 0;
$len[ $iSup ][ 0 ] = 0;
$i = 0;
$idx = 0;
$inMotif = 1;
if( strlen( $bankSeq ) < strlen( $querSeq ) )
$minLen = strlen( $bankSeq );
else
$minLen = strlen( $querSeq );
while( $idx < $minLen ) {
#echo "idx ".$idx."quer ".$querSeq[ $idx ]."bank ".$bankSeq[ $idx ];
if( $inMotif ) {
if( $bankSeq[ $idx ] != '-' ) {
#echo " not equal
";
if( $querSeq[ $idx ] != '-' )
$len[ $iSup ][ $i ]++;
}
else {
#echo " equal
";
$inMotif = 0;
$i++;
$beg[ $iSup ][ $i ] = $beg[ $iSup ][ $i-1 ] + $len[ $iSup ][ $i-1 ] + 1;
}
}
else {
if( $bankSeq[ $idx ] == '-' )
$beg[ $iSup ][ $i ]++;
else {
$inMotif = 1;
$len[ $iSup ][ $i ] = 1;
}
}
$idx++;
}
for( $i = 0; $i < count( $beg[ $iSup ] ); $i++ ) {
$beg[ $iSup ][ $i ] += $Beg;
if( $i == ( count( $beg[ $iSup ] ) - 1 ) )
$len[ $iSup ][ $i ] = $End - $beg[ $iSup ][ $i ];
}
for( $i = 0; $i < count( $beg[ $iSup ] ); $i++ ) {
#echo "iSup ".$iSup."i ".$i."beg ".$beg[ $iSup ][ $i ]." len ".$len[ $iSup ][ $i ];
if( $i == ( count( $beg[ $iSup ] ) - 1 ) )
$len[ $iSup ][ $i ] = $End - $beg[ $iSup ][ $i ];
}
$iSup++;
}
else {
$buf = fgets( $f, 1024 );
}
}
$maxLen = 0;
for( $i=0; $i < $iSup; $i++) {
for( $j=0; $j < count( $beg[ $i ] ); $j++) {
$maxLen = max( $maxLen, ( $beg[ $i ][ $j ] + $len[ $i ][ $j ] ) );
}
}
#echo "maxLen ".$maxLen."
";
fclose( $f );
}
#--------------------------------------------------------
# Create Graphic Alignment GIF-file
#--------------------------------------------------------
function makeGrapAli( $iSup, $beg, $len, $maxLen, $power, $gif_file, $bor, $size, $key_size, $wid, &$hei ) {
$hei = $size*( 2*$iSup ) + 5*$bor + $key_size;
# Header("Content-type: image/gif");
$k = imagecreate( $wid, $hei );
imagefilledrectangle( $k, 0, 0, $wid, $hei, $white );
$key = imagecreatefromPng( "/www/fast_key.png" );
imagecopyresized( $k, $key, 0, 0, 0, 0, $wid, $key_size, $wid, $key_size );
$white = imagecolorallocate($k,255,255,255);
$red = imagecolorallocate($k,255,0,0);
$green = imagecolorallocate($k,0,128,0);
$magen = imagecolorallocate($k,128,0,128);
$blue = imagecolorallocate($k,0,0,255);
$black = imagecolorallocate($k,0,0,0);
$x = 2*$bor + $key_size;
imagefilledrectangle( $k, $bor, $x, $wid - $bor, $x+$size, $red );
$x += $size + 2*$bor;
for( $i=0; $i < $iSup; $i++) {
if( $power[ $i ] > 200.0 ) {
$color = $red;
}
else if( $power[ $i ] > 80.0 ) {
$color = $green;
}
else if( $power[ $i ] > 50.0 ) {
$color = $magen;
}
else if( $power[ $i ] > 40.0 ) {
$color = $blue;
}
else
$color = $black;
for( $j=0; $j < count( $beg[ $i ] ); $j++) {
$b = intval( $bor+$beg[ $i ][ $j ]*( $wid - 2*$bor )/$maxLen );
$e = intval( $bor+($beg[ $i ][ $j ]+$len[ $i ][ $j ])*( $wid - 2*$bor )/$maxLen );
#echo "beg ".$beg[ $i ][ $j ]." len".$len[ $i ][ $j ]." b ".$b." e ".$e." power ".$power[ $i ]." color ".$color."
";
imagefilledrectangle( $k, $b-1, $x, $e, $x+$size-1, $color );
}
$x += 2*$size;
}
#$er = imagegif( $k, $gif_file );
$er = imagePng( $k, $gif_file );
}
# -------------------------------------------------------------------
# Returns 0 if all chosen banks are protein, otherwise - return 1.
function bankProt( $database, &$name ) {
for( $i=0; $i < count( $database ); $i++) {
if( $database[ $i ] != "swiss" && $database[ $i ] != "swisstrembl" ) {
$name .= $database[ $i ];
return 1;
}
}
return 0;
}
# -------------------------------------------------------------------
# Show all best scores.
function showBest( $fileName ) {
# 1. ----------------------------------------
# Skip all string up to contaning 'Best score'
echo "Best Scores
";
echo "";
$fileIO = fopen( $fileName, "r" );
while( $buf = fgets( $fileIO, 128 ) ) {
if( ereg( "The best", $buf ) ) {
echo "".$buf."";
break;
}
}
# 2. ----------------------------------------
# Create best scores strings.
$i = 1;
while( $buf = fgets( $fileIO, 128 ) ) {
if( strlen( $buf ) <= 2 )
break;
$parts = split( "\|", $buf, 3 );
$subparts = split( " ", $parts[ 2 ], 2 );
echo $parts[0]."|".$parts[1]."|"."".$subparts[0].""." ".$subparts[1];
$i += 1;
}
echo "
";
# 3. ----------------------------------------
# Create Alignments list.
echo "
Alignments
";
echo "";
$i = 0;
while( $buf = fgets( $fileIO, 128 ) ) {
if( $buf[0] == ">" ) {
if( !$i )
echo "
";
$i += 1;
echo "Alignment $i
";
$parts = split( "\|", $buf, 3 );
echo $parts[0]."|".$parts[1]."|".$parts[2];
}
else
echo $buf;
}
echo "
";
}
?>
if ($init == 0)
{
?>