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