<html>
<head>
<title>ANISEED - Interpro domain results (Ciona intestinalis, Halocynthia roretzi)</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="description" content="Interproscan was performed for each Ciona intestinalis protein. This page will list Ciona genes model with the Interpro terms you have clicked.">
<meta name="keywords" content="Tassy, Lemaire, Daian, Dauga, Ciona intestinalis, Halocynthia roretzi, ascidian database, ciona intestinalis database, ciona intestinalis protein, functional annotation, Interpro domain, Interproscan, protein domain, functionnal motif.">
<meta name = "robots" content = "index, follow, all">
<META HTTP-EQUIV="Content-Language" CONTENT="EN">
<style type="text/css">
</style>
</head>

<?php
/*
    ANISEED, NISEED System and Database
    Copyright (C) 2007 Olivier Tassy, Fabrice Daian, Patrick Lemaire

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*/
include("connection.php");
include("frames_header.php");
?>


<?php
	//connection
	
	
		$species="";
		$words="";
		$genelist="";
	
		if(isset($_POST["species"]))
			$species=$_POST["species"];
		if(isset($_POST["ip"]))
			{
			$words=$_POST["ip"];
			$wordslist=implode("@",$words);
			}

		if(isset($_POST["genelist"]))
			{
			$genelist=$_POST["genelist"];

		///// Conversion de la genelist pour utiliser les ANISEED GM ////////////

			$tmp=explode(":",$genelist);
			$new=(array) null;
			for ($i=0;$i<count($tmp);$i++)
			{
			$requete="select \"NAME\" from \"MOL_ENTITY\" where \"MOL_ID\" in (SELECT \"GENE_MODEL_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='".str_replace("aniseedV3_","cluster",$tmp[$i])."')";
			$stmt=pg_query($c,$requete);
			if (pg_num_rows($stmt)!=0)
			{
			while ($row=pg_fetch_array($stmt))
				{
				$new[count($new)]=$row["NAME"];
				}
			}
			}
			if (count($new)!=0) $genelist=implode(":",$new);
			////////////////// fin de la conversion ///////////////////////////////////


			}
			

		if (isset($_POST["notin"]))
			$notin=$_POST["notin"];

//////		//molecular weight parameters
/*
		if($_GET["mwc"]==0)
			$mwc=">";
		else
			$mwc="<";
		$mw=$_GET["mw"];
*/
		
		
        if(count($words)<=0){
	        print "<br><br><center><strong>Please select an Interpro id to search for.</strong></center><br><br>";
	        include("frames_footer.php");
			return;
//////
/*		}else if((! is_numeric($mw))or($mw<0)){
			print '<center><h2><strong>Wrong MW parameter.</strong></h2></center>';
			include("frames_footer.php");
			return;
*/
		}else{
			if(strlen($genelist)>0)
				print "<center><H2><font color=\"#FF6600\">Refining subset mode</font></H2></center>";
		
		        print "query: ";
		if ($notin=='y') print "NOT ( ";
		else print "&nbsp;&nbsp;<strong>";
		    for($a=0; $a<count($words); ++$a)
			    print $words[$a]." &nbsp;";
		if ($notin=='y') print ")";
		}

		/*$query="'$words[0]'";
		for($a=1; $a<count($words); ++$a)
		    $query.=", '$words[$a]'";*/
		
		
		//recherche des termes enfants a inclure dans la requete suivante
		/*$requete="SELECT DISTINCT IP_ID FROM CIONA_DESIGN.IP_CHILD_OF CONNECT BY CHILD_OF = PRIOR IP_ID START WITH IP_ID in (".$query.")";
		$stmt = OCIParse($connection, $requete);
		OCIExecute($stmt);
		while( OCIFetch($stmt) ){
			$query.=", '".OCIResult($stmt,"IP_ID")."'";
		}*/









/* SIMULATION D'UNE REQUETE SUR HIERARCHIE PAR UNE PROCEDURE DE REQUETES RECURSIVES */


function select_recursif_descendant($conn,$start,$res)
{
$res.=$start.",";
/*ON ECRIT SA REQUETE*/
$requete="SELECT distinct * FROM \"IP_CHILD_OF\" WHERE \"CHILD_OF\"=".$start." ";


$stmt=pg_query($conn,$requete);
while ($row=pg_fetch_array($stmt))
	{
	$res=select_recursif_descendant($conn,"'".$row["IP_ID"]."'",$res);
	}
return $res;
}

$result="";
for ($a=0;$a<count($words);$a++)
{
$words[$a]="'".$words[$a]."'";
$result=select_recursif_descendant($c,$words[$a],$result);
$query.=$result;
}
$query=substr($query,0,strlen($query)-1);

/* FIN DE LA SIMULATION */











		
		
if ($notin!='y')
{
		
		$requete="SELECT distinct B.\"NAME\", B.\"GENE_ID\", C.\"SPECIES\" FROM \"IP_DESCRIPTION\" A, \"GENE\" B, \"MOL_ENTITY\" C WHERE (A.\"MOL_ID\"=B.\"GENE_ID\") and (A.\"MOL_ID\"=C.\"MOL_ID\") and (A.\"IP_ID\" in (".$query.") )";
		
		if( strlen($species)>1 )
		    $requete.=" AND (C.\"SPECIES\" ='$species')";
		//////if( $mw>0 )
		//////	$requete.=" AND (B.MW".$mwc.$mw.")";
		
		if( strlen($genelist)>0){
		    $genelist = substr($genelist, 0, strlen($genelist)-1);
		    $genelist = ereg_replace(":","','",$genelist);

			$requete.=" AND (B.\"NAME\" in('".$genelist."'))";
		}

}
else
{
$requete="SELECT distinct B.\"NAME\", B.\"GENE_ID\", C.\"SPECIES\" FROM \"IP_DESCRIPTION\" A, \"GENE\" B, \"MOL_ENTITY\" C WHERE (A.\"MOL_ID\"=B.\"GENE_ID\") and (A.\"MOL_ID\"=C.\"MOL_ID\") and (A.\"IP_ID\" not in (".$query.") )";
		
		if( strlen($species)>1 )
		    $requete.=" AND (C.\"SPECIES\" ='$species')";
		//////if( $mw>0 )
		//////	$requete.=" AND (B.MW".$mwc.$mw.")";
		
		if( strlen($genelist)>0){
		    $genelist = substr($genelist, 0, strlen($genelist)-1);
		    $genelist = ereg_replace(":","','",$genelist);

			$requete.=" AND (B.\"NAME\" in('".$genelist."'))";
		}
$requete.="EXCEPT SELECT distinct B.\"NAME\", B.\"GENE_ID\", C.\"SPECIES\" FROM \"IP_DESCRIPTION\" A, \"GENE\" B, \"MOL_ENTITY\" C WHERE (A.\"MOL_ID\"=B.\"GENE_ID\") and (A.\"MOL_ID\"=C.\"MOL_ID\") and (A.\"IP_ID\" in (".$query.") )";
		
		if( strlen($species)>1 )
		    $requete.=" AND (C.\"SPECIES\" ='$species')";
		//////if( $mw>0 )
		//////	$requete.=" AND (B.MW".$mwc.$mw.")";
		
		if( strlen($genelist)>0){
		  	$requete.=" AND (B.\"NAME\" in('".$genelist."'))";
		}
}









		
		
		$stmt = pg_query($c,$requete);
		
		print "<center><font color=\"#D64242\" size=\"3\"><b>Matching genes:</b></font><br><br>";
		print '<table width="99%" border="0" cellspacing="0" cellpadding="0">';
		//////print '<tr align="center" valign="middle" bgcolor="#990000"><td>Gene ID</td><td width="65%">Possible names</td><td>MW(Da)</td><td background="pictures/barre-red.jpg">Species</td></tr>';
		print '<tr align="center" valign="middle"><td><font color="#456898" size="2"><b>Gene ID</b></font></td><td width="65%"><font color="#456898" size="2"><b>Possible names</b></font></td><td><font color="#456898" size="2"><b>Species</b></font></td></tr>';

		print "<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>";

        
		$count=0;
		$genelist="";
		while( $row=pg_fetch_array($stmt) ){

		//print $row["NAME"]."<br>";
		$requete0="select \"GENE_CLUSTER_ID\" from \"GENE_CONCEPT\" where \"GENE_MODEL_ID\"=(
		SELECT \"GENE_ID\" from \"GENE\" where \"NAME\"='".$row["NAME"]."')";
		$stmt0=pg_query($c,$requete0);
		$row0=pg_fetch_array($stmt0);

		$table[$row0["GENE_CLUSTER_ID"]]++;




		/*


		    //recherche des noms du gene
			$requete="SELECT \"SYNO\", \"ORIGIN\" FROM \"SYNO\" WHERE \"GENE_ID\"=".$row["GENE_ID"]." order by \"ORIGIN\" DESC";
			$stmt2 = pg_query($c,$requete);
			$names=""; $a=0;
		    while( $row2=pg_fetch_array($stmt2) ){
			    
			    if($row2["SYNO"]==$row["NAME"])
				    continue;
				
				if(++$a>1)
				    $names.=' <strong><font color="000000">/</font></strong> ';
			    $names.=$row2["SYNO"];
				if($row2["ORIGIN"]=="user-JGI")
				    $names.="*";
					
				
                //la chaine affichee ne doit pas depasser 100 char.
                //on ne prend en compte que l'affichage et pas le code html dans la mesure
				if( strlen($names)-(($a-1)*48) > 100 ){
				    $names.=" <strong><font color=\"000000\">/</font></strong>...";
					break;
				}
				
			}
			if($a==0){
				$requete="select \"DESCRIPTION\", \"EVALUE\" from \"BLAST\" where \"MOL_ID\"='".$row["GENE_ID"]."' and \"SCORE\"=(select max(\"SCORE\") from \"BLAST\" where \"MOL_ID\"='".$row["GENE_ID"]."')";
				$stmt2 = pg_query($c,$requete);
				if($row2=pg_fetch_array($stmt2)){
					
					$eval = $row2["EVALUE"];
					if( $eval <= 1e-10)
						$names.= "HIGHLY ";
					else if( ($eval >= 1e-4) and ($eval <= 1e-3) )
						$names.= "WEAKLY ";
					if($eval <= 1e-3)
						$names.= "SIMILAR TO ".$row2["DESCRIPTION"]." (Eval: $eval)";
				}
			}
			
			
			
			
		    ++$count;
			
			print "<tr align=\"center\" valign=\"top\" >"."<td><a href=\"molecule-gene.php?name=".$row["NAME"]."\"><font color=\"#000000\" size=\"-1\">".$row["NAME"]."</font></a></td><td><font color=\"#656565\" size=\"-1\">$names</font></td><td><font color=\"#656565\" size=\"-1\">".$row["SPECIES"]."</font></td></tr>";
		    print '<tr valign="top"><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td><td><hr size="1"></td></tr>';
		    $genelist.=$row["NAME"].":";  //liste les gene id pour rechercher les in situs.

		*/
		}

////// AJOUT ICI
//print_r($table);
//return;
		foreach ($table as $key => $val)
		{
		$gene_name="";
		$requete0="SELECT \"GENE_CLUSTER_NAME\" from \"GENE_CONCEPT_NAME\" where \"GENE_CLUSTER_ID\"='$key'";
		$stmt0=pg_query($c,$requete0);
		while ($row0=pg_fetch_array($stmt0)) 
			{
			if (strlen($gene_name)==0) $gene_name=$row0["GENE_CLUSTER_NAME"];
			else $gene_name.=" / ".$row0["GENE_CLUSTER_NAME"];
			}

		$requete0="SELECT \"SPECIES\" from \"MOL_ENTITY\" where \"MOL_ID\" in(
		select \"GENE_MODEL_ID\" from \"GENE_CONCEPT\" where \"GENE_CLUSTER_ID\"='$key')";
		$stmt0=pg_query($c,$requete0);
		$row0=pg_fetch_array($stmt0);

		$species=$row0["SPECIES"];


		if (strlen($gene_name)==0) 
			{
			$requete0="SELECT \"GENE_CLUSTER_NAME_BLAST\" from \"GENE_CONCEPT_NAME_BLAST\" where \"GENE_CLUSTER_ID\"='$key'";
			$stmt0=pg_query($c,$requete0);
			$row0=pg_fetch_array($stmt0);
			$gene_name=$row0["GENE_CLUSTER_NAME_BLAST"];


			}

		print "<tr align=\"center\" valign=\"top\" ><td><a href=\"gene-card.php?clusterid=$key\"><font color=\"#000000\" size=\"-1\">".(str_replace("cluster","aniseedV3_",$key))."</font></a></td><td><font color=\"#656565\" size=\"-1\">$gene_name</font></td><td><font color=\"#656565\" size=\"-1\">$species</font></td></tr>";


		////AJOUT
		if (strlen($key)!=0) $genelist.=str_replace("cluster","aniseedV3_",$key).":";



		}


		///// AJOUT
		$count=count($table);


		print '</table>';
		
		if($count==0){
		    print "<br><br><center><h2><strong>No match</strong></h2></center><br><br>";
		}else{
		    print "<br><br>$count results";
			print "</center><br><br>* Manual annotation<center>";
		}


/*
print '<form name="formulaire2" action="AllGenesFASTA.php" method="post">';
print '<input type="hidden" value="'.$genelist.'" name="id">';
print '&nbsp;&nbsp;&nbsp;<input name="submit" type="image" src="pictures/button-sequence.jpg" onClick="submit">';
print '</form>';
*/

if(substr_count($genelist,":")<1000){
	print '<form name="formulaire3" action="" method="post">';
	print '<input type="hidden" value="'.$genelist.'" name="genelist">';
	print'&nbsp;&nbsp;&nbsp;
	
	<input name="submit" type="image" src="pictures/button-subset.jpg" onClick="javascript: window.document.formulaire3.action= window.document.formulaire3.redirect.value; submit;">';
	
	print '<br>
		   <select name="redirect" size="1">
			   <option value="GO-search.php">Gene ontology</option>
			   <option value="IP-search.php">Interpro</option>
			   <option value="insitu-search.php">In situ</option>
			   <option value="DDD-search.php">Digital Differential Display</option>
			   <option value="MW-search.php">Molecular weight</option>
			   <option value="ID.php">Batch Query</option>
		   </select>';
		   
	print '</form>';
}else{print '<font size="-1" color="#999999">Refine mode not available for set > 1000</font>';}

print '</center>';

//Pour l'affichage fichier plat par la methode POST
$css="text-decoration:underline; color:black; font-size:15; text-align:center; background-color:transparent; padding:5px border-width:0px;border-style:none;border-color:blue";
print '<form name="formu" action="FLATexport-IP.php" method="POST">';

print '<input type="hidden" value="'.$_POST["species"].'" name="species">';
print '<input type="hidden" value="'.$wordslist.'" name="ip">';
print '<input type="hidden" value="'.$_POST["genelist"].'" name="genelist">';
print '<input type="hidden" value="'.$_POST["notin"].'" name="notin">';

//print '<input type="submit" style="'.$css.'" value="Display entry in raw text format">';
print '</form>';
//Fin




?>


<?php
    include("frames_footer.php");
?>