" && $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 ); } #-------------------------------------------------------- # Etract bank names from *.pal, *.nal files #-------------------------------------------------------- function expBankName( $basePath, $name, $ext ) { $fPal = fopen( "$basePath$name$ext", "r" ); $buf = fgets( $fPal, 1024 ); $buf = fgets( $fPal, 1024 ); $buf = fgets( $fPal, 1024 ); $nameList = split( "[ ]+", $buf, 2 ); fclose( $fPal ); return rtrim( $nameList[ 1 ] ); } #-------------------------------------------------------- # 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 ] != "spr" && $database[ $i ] != "swisstrembl" && $database[ $i ] != "nr" && $database[ $i ] != "tre" ) { $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;
      $parts0 = split( " ", $buf, 2 );   # VN 03-29-04
      $parts = split( "\|", $parts0[1], 3 );
      $subparts = split( " ", $parts[ 2 ], 2 );
      $parts1 = " ";
      for( $k = strlen($parts[1])+strlen($subparts[0]); $k < 25; $k++ )   {
         $parts1 = $parts1." ";
      }
      echo $parts[0]."|".$parts[1]."|"."".$subparts[0].""." ".$parts1.$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: nik@genebee.msu.su
"; 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" ); $basePath = "/HOME/sergeyk/blast/DB/"; for( $i = 0; $i < count( $database ); $i++ ) { if( $database[ $i ] == "nr" || $database[ $i ] == "nt" ) { fputs( $fbank, "$basePath".$database[ $i ]." 12\n" ); } elseif( $database[ $i ] == "spr" || $database[ $i ] == "tre" ) { $nameList = expBankName( $basePath, $database[ $i ], ".pal" ); fputs( $fbank, "$basePath$nameList 12\n" ); } elseif( $database[ $i ] == "swisstrembl" ) { $nameList = expBankName( $basePath, "spr", ".pal" ); fputs( $fbank, "$basePath$nameList 12\n" ); $nameList = expBankName( $basePath, "tre", ".pal" ); fputs( $fbank, "$basePath$nameList 12\n" ); } else { $nameList = expBankName( $basePath, $database[ $i ], ".nal" ); $arrName = split( "[ +]", $nameList ); for( $j = 0; $j < count( $arrName ); $j++ ) { # print $arrName[ $j ]."
"; fputs( $fbank, "$basePath".$arrName[ $j ]." 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 = "$fseqName C -s $matrix -b 100 -d 50"; else $callStr = "$fseqName C -b 100 -d 50"; # print "$fresName"; # echo $callStr."
"; $lokFile = "$fresName.lok"; $fA = fopen( $lokFile, "w" ); fputs( $fA, "This is lok-file for FASTA." ); fclose( $fA ); $ru = popen( "nohup ./run_fasta.pl -p $program -o \"$callStr\" -f $lokFile -r $fresName -l $fgdbName &", "r" ); $nRep = 0; $myColor = array( "red", "black", "blue" ); while( file_exists( $lokFile ) ) { sleep( 1 ); clearstatcache(); if( $nRep == 0 ) { echo "Progress bar:    "; } if( $nRep % 60 == 0 ) { print "o"; flush(); } $nRep++; } echo "
"; pclose( $ru ); # 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" ); } ?>