" && $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 "
"; } ?>
Homepage

Belozersky Institute

GeneBee

Russian EMBnet Node


Basic Fasta 3.4
Help YOUR EMAIL
Dr. W.R. Pearson
documentation
PROGRAM
DataBases including EST
MATRIX

Enter or Paste here your sequence in FASTA format


Any comments or suggestions are welcomed at: [email protected]
"; echo "
Processing your request...
"; flush(); #........add to database......... //require("/www/db/connect.php3"); $TaskID=13; $SenderMail=$emailaddress; //insert_message_to_db($TaskID, $SenderMail); #............................... # 1. --------------------------------------------------------- # Check correspondence between bank & program choises. if( ( ( $program == "tfastx" || $program == "tfasty" || $program == "tfasts" || $program == "tfastf" ) && bankProt( $database, $errBank ) == 0 ) || ( ( $program == "fastf" || $program == "fasts" || $program == "fastx" || $program == "fasty" ) && bankProt( $database, $errBank ) != 0 ) ) { echo "
Dear Fasta user!
You select incompatible combination:
database $errBank and program $program
Please look at the description
"; } # 2a. -------------------------------------------------------- # Create file with list of choosen banks. $fBankName = tempnam( "/tmp/", "fas" ).".nam"; $fbank = fopen( $fBankName, "w" ); for($i = 0; $i < count( $database ); $i++ ) { if( $database[ $i ] == "swiss" ) fputs( $fbank, "/HOME/molbio/DB/blast/".$database[ $i ]."-".$sproRel." 12\n" ); else { if( $database[ $i ] != "swisstreml" ) { $arrName = split( "[ +]", $database[ $i ] ); for( $j = 0; $j < count( $arrName ); $j++ ) { fputs( $fbank, "/HOME/molbio/DB/blast/".$arrName[ $j ]."-".$emblRel." 12\n" ); # fputs( $fbank, "/HOME/molbio/DB/blast/".$database[ $i ]."-".$emblRel." 12\n" ); } } } } fclose( $fbank ); # 2a. -------------------------------------------------------- # Create 'fastgdb' file. $fgdbName = tempnam( "/tmp/", "fas" ); $fgdb = fopen( $fgdbName, "w" ); # MUST be 0 - protein, 1 - nucleotide. $sign = bankProt( $database, $errBank ); $str = "BANK$".$sign."C@".$fBankName." 12"; fputs( $fgdb, $str ); fclose( $fgdb ); # 3. --------------------------------------------------------- # Call the chosen program. # 3a. -------------------------------------------------------- # Write sequence to temporary file. $fseqName = tempnam( "/tmp/", "fas" ); $fseq = fopen( $fseqName, "w" ); fputs( $fseq, $seq ); fclose( $fseq ); # 3b. -------------------------------------------------------- # Proper call the program. $fresName = tempnam( "/tmp/", "fas" ); #$fresName = "/tmp/ccc"; $program .= "34"; if( $sign != 1 && $program != "fasty34" && $program != "tfasty34" ) $callStr = "./$program $fseqName C -l $fgdbName -s $matrix > $fresName"; else $callStr = "./$program $fseqName C -l $fgdbName > $fresName"; #echo "Call string: ".$callStr."
"; system( $callStr ); # 4. --------------------------------------------------------- # Show results. if( $emailaddress != "" ) { $callMail = "cat $fresName | mail -s \"Fasta34 Results from GeneBee\" $emailaddress"; #echo $callMail."
"; system( $callMail ); } echo "
Fasta34 Results

"; echo "Reference
"; echo "Graphical alignment
"; echo "Best scores
"; echo "Alignments

"; echo "

Reference

"; echo "W.R. Pearson & D.J. Lipman PNAS (1988) 85:2444-2448
"; echo "

Query sequence:

"; $seqStr = split( "\n", $seq ); echo "
";
   for( $i = 0; $i < count( $seqStr ); $i++ )  {
      $lseqStr = ltrim( $seqStr[ $i ] );
      if( $i == 0 )
         echo "".$lseqStr."
"; else echo $lseqStr."
"; } echo "

"; #echo $seq."
"; getMotFast( $iSup, $beg, $len, $maxLen, $zscore, $strArr, $fresName ); #getMotFast( $iSup, $beg, $len, $maxLen, $zscore, $strArr, "aaa2" ); $size = 3; $bor = 5; $wid = 600; $key_size = 33; #$gif_file = "../trash/ddd2.gif"; $gif_file = tempnam( "../trash/", "fas" ); makeGrapAli( $iSup, $beg, $len, $maxLen, $zscore, $gif_file, $bor, $size, $key_size, $wid, &$hei ); echo "

Graphic Alignment

"; echo ""; $up = 4*$bor + $key_size; $down = $up + 2*$size; for( $i = 0; $i < $iSup; $i++ ) { $idx = $i + 1; $a = "#a".$idx; $rig = $wid-$bor; $curStr = $strArr[ $i ]; echo ""; #echo ""; $up += 2*$size; $down += 2*$size; } echo ""; echo "
"; echo "
"; echo "

"; showBest( $fresName ); # 5. --------------------------------------------------------- # Delete all temporary files. system( "rm $fBankName" ); system( "rm $fgdbName" ); system( "rm $fseqName" ); } ?>