17h44 :
J’ai finalement décider de monter rapidement une petite base de donnée très simplifiée pour pourvoir acceder aux info sur les enzymes de restriction.
J’ai donc créer la table lorelei (pour Liste Of Restriction Enzyme with Location and Enzyme Information). cette table se trouve dans la base bab_el_oueb que je devrais renommé babel_oueb d’ailleurs, étant une sorte de fourre-tout pour mes tables.
j’y ai mis aussi une autre base, congel_location.
code pour creer ces bases
DROP TABLE lorelei;
DROP TABLE congel_location;
CREATE TABLE congel_location
(
cl_id serial NOT NULL,
cl_loc varchar(255),
CONSTRAINT congel_location_pkey PRIMARY KEY (cl_id)
)
WITHOUT OIDS;
ALTER TABLE congel_location OWNER TO fricard;
CREATE TABLE lorelei
(
lor_id serial NOT NULL,
lor_name varchar(20),
lor_link varchar(255),
lor__site varchar(50),
cl_id int4,
CONSTRAINT lorelei_pkey PRIMARY KEY (lor_id),
CONSTRAINT lorelei_cl_id_fkey FOREIGN KEY (cl_id)
REFERENCES congel_location (cl_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
WITHOUT OIDS;
ALTER TABLE lorelei OWNER TO fricard;
lorelei fait référence a congel_location
on stocke dans la base le nom de l’enzyme et le lieu ou est est stockée ainsi qu’un lien vers une base de données donnant les infos sur cette enzyme.
J’ai ensuite créé une interface en php très simplfiée pour voir les donnée, en ajouter et les effacer.
http://berthemorisot.gim.pasteur.fr/lorelei.php
code php
<?php
function add_enz($vals, $db){
$query = "select cl_id from congel_location where cl_loc='".$vals[1]."'";
$res = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
if (pg_numrows($res)==0){
$query="insert into congel_location (cl_loc) values ('".$vals[1]."')";
echo $query;
$res = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
}
$query = "select cl_id from congel_location where cl_loc='".$vals[1]."'";
$res = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
$cl= pg_fetch_row($res, 0);
$cl_id=$cl[0];
$query="insert into lorelei (lor_name, lor_link, cl_id) values ('".$vals[0]."','".$vals[2]."',".$cl_id.")";
$res = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
echo $vals[0]." added<br/>";
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Lorelei</title>
<style type="text/css">
body {
font-family: Arial,Helvetica,sans-serif;
font-size: 12px;
}
h1 {
font-size: 18px;
color: LightSeaGreen;
}
h2 {
font-size: 14px;
}
.initiale{
font-size: 16px;
color: LightSeaGreen;
}
a {
color:steelblue;
text-decoration:none;
}
a:hover{
color:white;
background-color:steelblue;
}
table {
font-size: 13px;
vertical-align:top;
}
td{
vertical-align:top;
}
td.head {
color:white;
background-color:steelblue;
}
td.add{
background-color:YellowGreen;
}
td.del{
background-color:IndianRed;
}
td.add_light{
background-color:#ccff99;
}
td.del_light{
background-color:#ff9999;
}
td.add_dark{
background-color:#003300;
color:white;
}
td.del_dark{
background-color:#330000;
color:white;
}
a.ancre{
color:DarkSlateBlue;
}
a.ancre:hover{
background-color:DarkSlateBlue;
color:white;
}
</style>
</head>
<body>
<table><tr><td rowspan=2>
<img src="lorelei_01.jpg" width=50 height=50 />
</td><td><h1>LORELEÏ</h1></td></tr>
<tr><td>
<h2><span class="initiale">L</span>iste <span class="initiale">O</span>f <span class="initiale">R</span>estriction <span class="initiale">E</span>nzyme with <span class="initiale">L</span>ocation and <span class="initiale">E</span>nzyme <span class="initiale">I</span>nformation</h2>
</td></tr>
</table>
<br/>
<a class="ancre" href="#update">Ajouter ou retirer des enzymes</a>
<balise id="top"></balise>
<br/>
<br/>
<?php
$HOST="berthemorisot.gim.pasteur.fr";
$PORT=5432;
$BASE="bab_el_oueb";
$USER="fricard";
$db = pg_connect("host=$HOST port=$PORT dbname=$BASE user=$USER") or die("impossible de se connecter à la base de données");
if (isset($_POST["add_data"])){
if ($_FILES["file_data"]['name']){
$fichier=$_FILES['file_data']['tmp_name'];
if (file_exists($fichier)) {
$fp2=fopen($fichier, "r");
while(!feof($fp2)){
$line[]=fgets($fp2, 4096);
}
fclose($fp2);
}
}
elseif($_POST["text_data"]){
$line=explode("\n",$_POST["text_data"]);
}
if (count($line)>0){
$sep_list=array("\t",",");
foreach($sep_list as $sep){
if (strpos($line[0],$sep)){
break;
}
}
foreach ($line as $items){
$vals=explode($sep, $items);
add_enz($vals, $db);
}
}
}
if (isset($_POST["del_data"])){
$data_array = $_POST['item_list'];
$in = implode( $data_array, ',');
$query="select lor_name from lorelei where lor_id in ($in)";
$res = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
$query="delete from lorelei where lor_id in ($in)";
$res2 = pg_query($db, $query) or die("La requète $query n'a pas pu aboutir");
for ($i=0;$i<pg_numrows($res);$i++){
$ligne= pg_fetch_row($res, $i);
$enz[]=$ligne[0];
}
if ($i>1){
echo implode( $enz, ', ')." ont été effacées";
}else{
echo implode( $enz, ', ')." a été effacée";
}
}
$query_all = "select lor_id, lor_name, cl_loc, lor_link from lorelei, congel_location where lorelei.cl_id = congel_location.cl_id order by lor_name";
?>
<table>
<tr>
<td> </td><td class="head">Enzyme </td><td class="head">Localisation </td><td class="head">Lien </td></tr>
<?php
$res = pg_query($db, $query_all) or die("La requète n'a pas pu aboutir");
for ($i=0;$i<pg_numrows($res);$i++){
$ligne= pg_fetch_row($res, $i);
echo "<tr>";
foreach($ligne as $val){
if ((strpos($val,"html")) || (strpos($val,"http")) || (strpos($val,"www")) || (strpos($val,"php"))){
echo '<td><a href="'.$val.'">'.$val.'</a></td>';
}
else{
echo "<td>$val</td>";
}
}
echo "</tr>\n";
}
echo "</table>";
?>
<br/>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<br/>
<a class="ancre" href="#top">Retourner au début de la page</a>
<balise id="update"> </balise>
<br/>
<table>
<tr>
<td class="add_dark">
Pour ajouter des enzymes à la liste
</td>
<td class="del_dark">
Pour effacer des enzymes de la liste
</td>
</tr>
<tr>
<td class="add">
<form name="add_item" method="POST" action="lorelei.php" ENCTYPE="multipart/form-data">
Copier-coller la liste des enzymes ci-dessous selon le format suivant :<br/>
nom localisation lien</br>
en séparant les colonnes par des tabulations ou des virgules<br/> (un copier-coller depuis excel par exemple)
</td>
<td class="del">
sélectionnez la ou les enzymes a effacer<br/>
</td>
</tr>
<tr>
<td class="add_light">
<form name="add_item" method="POST" action="lorelei.php" ENCTYPE="multipart/form-data">
<textarea name="text_data" cols="70" rows="10" wrap="physical" ></textarea>
<br/>
ou uploader un fichier au format décrit ci-dessus<br/>
<input type="file" name="file_data" />
<br/>
<input type="submit" name="add_data" value="Ajouter" />
</form>
</td>
<td class="del_light">
<form name="del_item" method="POST" action="lorelei.php" ENCTYPE="multipart/form-data">
<select name="item_list[]" multiple size=5>
<?php
for ($i=0;$i<pg_numrows($res);$i++){
$ligne= pg_fetch_row($res, $i);
$id=$ligne[0];
$nom=$ligne[1];
echo '<option value="'.$id.'">'.$nom.'</option>';
}
?>
</select>
<br/>
<input type="submit" name="del_data" value="Retirer" />
</form>
</td>
</tr>
</table>
</body>
</head>




