root / src / plasmids.MVC.php @ d072e29c
Historique | Voir | Annoter | Télécharger (4,46 ko)
1 |
<?php
|
---|---|
2 |
|
3 |
|
4 |
require_once("lib/seq.lib.php"); |
5 |
// a Trigger to display plsmid map image
|
6 |
$all = $this->myQuery("SELECT * FROM " . $this->tb . " WHERE id=" . $this->rec); |
7 |
// reach the plasmid displayed
|
8 |
$plasmid = mysql_fetch_object($all); |
9 |
|
10 |
if ($plasmid) { |
11 |
|
12 |
if ($_REQUEST["action"] == "REMOVE_FILE_SEQ") { |
13 |
if ($plasmid->Link_to_file != "") { |
14 |
$to_rem_file = "plasmid_files/" . $plasmid->Link_to_file; |
15 |
if (file_exists($to_rem_file)) { |
16 |
unlink($to_rem_file); |
17 |
} |
18 |
} |
19 |
$reqsql = "UPDATE plasmids SET sequence='', Link_to_file='' WHERE id = $this->rec"; |
20 |
mysql_query($reqsql);
|
21 |
$all = $this->myQuery("SELECT * FROM " . $this->tb . " WHERE id=" . $this->rec); |
22 |
$plasmid = mysql_fetch_object($all); |
23 |
} |
24 |
|
25 |
if ($_REQUEST["action"] == "ADD_GB_GZ_FILE") { |
26 |
$userfile = $_FILES["userfile"]["tmp_name"]; |
27 |
$userfile_name = $_FILES["userfile"]["name"]; |
28 |
if (stristr($userfile_name, ".gb.gz")) { |
29 |
$ext=".gb.gz"; |
30 |
} else {
|
31 |
if(file_exists($userfile)) { |
32 |
unlink($userfile); |
33 |
} |
34 |
exit("ERROR 1, your file MUST have the extension .gb.gz (lowercase)). <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
35 |
} |
36 |
$dest_filename = str_replace(" ","_",substr($userfile_name, 0, strlen($userfile_name)-6)) . $ext; |
37 |
$dest_filepath = "plasmid_files/" . $dest_filename; |
38 |
if (file_exists($dest_filepath)) { |
39 |
if (file_exists($userfile)) { |
40 |
unlink($userfile); |
41 |
} |
42 |
exit("ERROR 2, this .gb.gz filename is already used. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
43 |
} |
44 |
if (!copy($userfile, $dest_filepath)){ |
45 |
if (file_exists($userfile)) { |
46 |
unlink($userfile); |
47 |
} |
48 |
exit("ERROR 3, problem copying file. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
49 |
} |
50 |
if(file_exists($userfile)) { |
51 |
unlink($userfile); |
52 |
} |
53 |
|
54 |
$url = "/var/www/labstocks/plasmid_files/" . $dest_filename; |
55 |
$handle = gzopen($url, 'r'); |
56 |
if ($handle) { |
57 |
$content = ""; |
58 |
while (!gzeof($handle)) { |
59 |
$buffer = gzgets($handle, 4096); |
60 |
$content .= $buffer; |
61 |
} |
62 |
gzclose($handle); |
63 |
preg_match('#ORIGIN(.*)//#sm', $content, $matches); |
64 |
$seq = $matches[0]; |
65 |
$seq = preg_replace("#ORIGIN#", "", $seq); |
66 |
$seq = preg_replace("#[^a-zA-Z]#ms", "", $seq); |
67 |
$reqsql = "UPDATE plasmids SET sequence='$seq', Link_to_file='$dest_filename' WHERE id = $this->rec"; |
68 |
mysql_query($reqsql);
|
69 |
$all = $this->myQuery("SELECT * FROM " . $this->tb . " WHERE id=" . $this->rec); |
70 |
$plasmid = mysql_fetch_object($all); |
71 |
} |
72 |
} |
73 |
|
74 |
|
75 |
/*
|
76 |
* VIEW
|
77 |
*/
|
78 |
|
79 |
$in_edit_mode = $_REQUEST["PME_sys_operation"] == "Change" || $_REQUEST["PME_sys_operation"] == "PME_op_Change"; |
80 |
|
81 |
if ($plasmid->sequence) { |
82 |
if ($in_edit_mode) { |
83 |
$remove_gbgz_form = <<<EOD |
84 |
<form action='' method='post'>
|
85 |
Remove file, filename and sequence for this plasmid:
|
86 |
<input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
|
87 |
<input type='hidden' name='PME_sys_rec' value='$this->rec'/>
|
88 |
<input type='hidden' name='action' value='REMOVE_FILE_SEQ'/>
|
89 |
<input type='button' name='send' value='Remove' onclick='if(confirm("Are you sure that you want to remove file, filename and sequence for this plasmid?")){this.form.submit()}else{return false;}'/>
|
90 |
</form>
|
91 |
EOD;
|
92 |
} |
93 |
$imgurl = seq2png($plasmid->sequence, PLASMAPPER_SERVER); |
94 |
$plasmapper_output = <<<EOD |
95 |
<img src="$imgurl"><br/>
|
96 |
<textarea readonly rows="10" cols="100">$plasmid->sequence</textarea>
|
97 |
EOD;
|
98 |
|
99 |
$wwwblast_url = WWWBLAST_SERVER . "blast.cgi?DATALIB=plfeatstock_db&PROGRAM=blastn&EXPECT=10&OOF_ALIGN=0&OVERVIEW=on&ALIGNMENT_VIEW=0&DESCRIPTIONS=100&ALIGNMENTS=50&COLOR_SCHEMA=0&SEQUENCE=$plasmid->sequence"; |
100 |
$fp = fopen($wwwblast_url, 'r', false); |
101 |
$resp = stream_get_contents($fp); |
102 |
$blast_output = preg_replace("/nph-viewgif.cgi/", WWWBLAST_SERVER . "nph-viewgif.cgi", $resp); |
103 |
|
104 |
} else {
|
105 |
if ($in_edit_mode) { |
106 |
$add_gbgz_form = <<<EOD |
107 |
<form action='' method='post' enctype='multipart/form-data'>
|
108 |
Add a .gb.gz file to this plasmid:
|
109 |
<input type='hidden' name='action' value='ADD_GB_GZ_FILE'/>
|
110 |
<input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
|
111 |
<input type='hidden' name='PME_sys_rec' value='$this->rec'/>
|
112 |
<input name='userfile' type='file' size='10'/>
|
113 |
<input type='button' name='send' value='Upload' onclick='return this.form.submit();'/>
|
114 |
</form>
|
115 |
EOD;
|
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
$to_be_post_list_content .= <<<EOD |
121 |
$remove_gbgz_form
|
122 |
$add_gbgz_form
|
123 |
$plasmapper_output
|
124 |
<hr/>
|
125 |
$blast_output
|
126 |
<hr/>
|
127 |
EOD;
|
128 |
|
129 |
?>
|