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