root / src / plasmids.MVC.php @ master
Historique | Voir | Annoter | Télécharger (5,58 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 |
// echo"<pre>";
|
27 |
// print_r($_FILES);
|
28 |
// echo"</pre>";
|
29 |
if ($_FILES["userfile"]["error"]) { |
30 |
exit("ERROR, your file is probably too big, maximum upload file size is " . ini_get('upload_max_filesize') . ". <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
31 |
} |
32 |
$userfile = $_FILES["userfile"]["tmp_name"]; |
33 |
$userfile_name = $_FILES["userfile"]["name"]; |
34 |
if (stristr($userfile_name, ".gb.gz")) { |
35 |
$ext=".gb.gz"; |
36 |
} else if (stristr($userfile_name, ".gb")) { |
37 |
$fp = fopen($userfile, "r"); |
38 |
$data = fread ($fp, filesize($userfile)); |
39 |
fclose($fp); |
40 |
$zp = gzopen($userfile, "w9"); |
41 |
gzwrite($zp, $data); |
42 |
gzclose($zp); |
43 |
$userfile_name = $userfile_name . ".gz"; |
44 |
$ext=".gb.gz"; |
45 |
} else {
|
46 |
if(file_exists($userfile)) { |
47 |
unlink($userfile); |
48 |
} |
49 |
exit("ERROR 1, your file MUST have the extension .gb.gz (lowercase)). <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
50 |
} |
51 |
$dest_filename = str_replace(" ","_",substr($userfile_name, 0, strlen($userfile_name)-6)) . $ext; |
52 |
$dest_filepath = "plasmid_files/" . $dest_filename; |
53 |
if (file_exists($dest_filepath)) { |
54 |
if (file_exists($userfile)) { |
55 |
unlink($userfile); |
56 |
} |
57 |
exit("ERROR 2, this .gb.gz filename is already used. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
58 |
} |
59 |
echo "<pre>$userfile $dest_filepath</pre>"; |
60 |
if (!copy($userfile, $dest_filepath)){ |
61 |
if (file_exists($userfile)) { |
62 |
unlink($userfile); |
63 |
} |
64 |
exit("ERROR 3, problem copying file. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
65 |
} |
66 |
if(file_exists($userfile)) { |
67 |
unlink($userfile); |
68 |
} |
69 |
|
70 |
$url = "/var/www/labstocks/plasmid_files/" . $dest_filename; |
71 |
$handle = gzopen($url, 'r'); |
72 |
if ($handle) { |
73 |
$content = ""; |
74 |
while (!gzeof($handle)) { |
75 |
$buffer = gzgets($handle, 4096); |
76 |
$content .= $buffer; |
77 |
} |
78 |
gzclose($handle); |
79 |
preg_match('#ORIGIN(.*)//#sm', $content, $matches); |
80 |
$seq = $matches[0]; |
81 |
$seq = preg_replace("#ORIGIN#", "", $seq); |
82 |
$seq = preg_replace("#[^a-zA-Z]#ms", "", $seq); |
83 |
$reqsql = "UPDATE plasmids SET sequence='$seq', Link_to_file='$dest_filename' WHERE id = $this->rec"; |
84 |
mysql_query($reqsql);
|
85 |
$all = $this->myQuery("SELECT * FROM " . $this->tb . " WHERE id=" . $this->rec); |
86 |
$plasmid = mysql_fetch_object($all); |
87 |
} |
88 |
} |
89 |
|
90 |
|
91 |
/*
|
92 |
* VIEW
|
93 |
*/
|
94 |
|
95 |
$in_edit_mode = $_REQUEST["PME_sys_operation"] == "Change" || $_REQUEST["PME_sys_operation"] == "PME_op_Change"; |
96 |
|
97 |
if ($plasmid->sequence) { |
98 |
if ($in_edit_mode) { |
99 |
$remove_gbgz_form = <<<EOD |
100 |
<form action='' method='post'>
|
101 |
Remove file, filename and sequence for this plasmid:
|
102 |
<input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
|
103 |
<input type='hidden' name='PME_sys_rec' value='$this->rec'/>
|
104 |
<input type='hidden' name='action' value='REMOVE_FILE_SEQ'/>
|
105 |
<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;}'/>
|
106 |
</form>
|
107 |
EOD;
|
108 |
} |
109 |
$imgurl = seq2png($plasmid->sequence, PLASMAPPER_SERVER); |
110 |
$plasmapper_output = <<<EOD |
111 |
<center>
|
112 |
<img src="$imgurl">
|
113 |
<br/>
|
114 |
<textarea readonly rows="10" cols="100">$plasmid->sequence</textarea></center>
|
115 |
</center>
|
116 |
EOD;
|
117 |
|
118 |
$wwwblast_url = WWWBLAST_SERVER . "blast.cgi"; |
119 |
$resp = post_vars($wwwblast_url, array( |
120 |
"DATALIB" => "plfeatstock_db", |
121 |
"PROGRAM" => "blastn", |
122 |
"EXPECT" => 10, |
123 |
"OOF_ALIGN" => 0, |
124 |
"OVERVIEW" => "on", |
125 |
"ALIGNMENT_VIEW" => 0, |
126 |
"DESCRIPTIONS" => 100, |
127 |
"ALIGNMENTS" => 50, |
128 |
"COLOR_SCHEMA" => 0, |
129 |
"SEQUENCE" => $plasmid->sequence |
130 |
)); |
131 |
|
132 |
$blast_output = preg_replace("/nph-viewgif.cgi/", WWWBLAST_SERVER . "nph-viewgif.cgi", $resp); |
133 |
|
134 |
} else {
|
135 |
if ($in_edit_mode) { |
136 |
$add_gbgz_form = <<<EOD |
137 |
<div class="centered_form">
|
138 |
<i>Add a <b>.gb</b> or a <b>.gb.gz</b> file to this plasmid</i>
|
139 |
<br/>
|
140 |
<br/>
|
141 |
<form action='' method='post' enctype='multipart/form-data'>
|
142 |
<fieldset>
|
143 |
<legend>Upload .gb File</legend>
|
144 |
<input type='hidden' name='action' value='ADD_GB_GZ_FILE'/>
|
145 |
<input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
|
146 |
<input type='hidden' name='PME_sys_rec' value='$this->rec'/>
|
147 |
<input name='userfile' type='file' size='10'/>
|
148 |
<input type='button' name='send' value='Upload' onclick='return this.form.submit();'/>
|
149 |
</fieldset>
|
150 |
</form>
|
151 |
</div>
|
152 |
EOD;
|
153 |
} |
154 |
} |
155 |
} |
156 |
|
157 |
|
158 |
$to_be_post_list_content .= <<<EOD |
159 |
<div class="sheet">
|
160 |
$remove_gbgz_form
|
161 |
$add_gbgz_form
|
162 |
$plasmapper_output
|
163 |
</div>
|
164 |
EOD;
|
165 |
|
166 |
if ($blast_output != "") { |
167 |
$to_be_post_list_content .= <<<EOD |
168 |
<div class="sheet">
|
169 |
$blast_output
|
170 |
</div>
|
171 |
EOD;
|
172 |
} |
173 |
|
174 |
?>
|