/plugins/ -> gb_plugin.php
1 <?php
2
3 // plugin_inc.php - skeleton file for plugin codes
4 // plugin_inc.php - author: Nico Stuurman
5
6 /*
7 Copyright 2002, Nico Stuurman
8
9 This is a skeleton file to code your own plugins.
10 To use it, rename this file to something meaningfull,
11 add the path and name to this file (relative to the phplabware root)
12 in the column 'plugin_code' of 'tableoftables', and code away.
13 And, when you make something nice, please send us a copy!
14
15 This program is free software: you can redistribute it and/ormodify it under
16 the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
17
18 */
19
20
21 ////
22 // !This function is called after a record has been added
23 // As an example, it is used to write some data concerning the
24 // new record to a file for inclusion in a webpage
25 /*
26 function plugin_add ($db,$tableid,$id)
27 {
28 }
29 */
30
31
32 ////
33 // !Change/calculate/check values just before they are added/modified
34 // $fieldvalues is an array with the column names as key.
35 // Any changes you make in the values of $fieldvalues will result in
36 // changes in the database.
37 // You could, for instance, calculate a value of a field based on other fields
38 // make sure this function returns true (or does not exist), or additions/modification
39 // will fail!
40 function plugin_check_data($db,&$fieldvalues,$table_desc,$modify=false)
41 {
42 global $HTTP_POST_VARS, $HTTP_POST_FILES;
43
44
45 # Genbank entry parsing constants
46 # (may need to adjust!)
47 $KEYCOL=0;
48 $VALUECOL=12;
49 $FEATURECOL=5;
50 $FEATUREVALCOL=21;
51
52 // we can not demand a file to be there since this might be a modify
53 if (is_readable($HTTP_POST_FILES["gbfile"]["tmp_name"][0])) {
54 // force the mime-type to be pdb compliant
55 $HTTP_POST_FILES["gbfile"]["type"][0]="chemical/seq-na-genbank";
56
57 $lines = file($HTTP_POST_FILES["gbfile"]["tmp_name"][0]);
58 $feature_section=FALSE;
59 $sequence_section=FALSE;
60
61 #parse file
62 foreach ($lines as $line) {
63
64 #Accession?
65 if (preg_match("/^ACCESSION\s+(.+)/", $line, $matches)) {
66 $accessions=preg_split("/\s+/",$matches[1]);
67 continue;
68 }
69
70 #VERSION?
71 if (preg_match("/^VERSION/", $line)) {
72 $vernid = preg_split("/\s+/", $line);
73 list($junk,$tmp)=preg_split("/:/",$vernid[3]);
74 $vernid[3]='g'.$tmp;
75 $version=$vernid[2];
76 $Nid=$vernid[3];
77 continue ;
78 }
79
80 #COMMENT? - We need to check for VNTI info in here.
81 if (preg_match("/^COMMENT\s+(.+)/", $line, $matches)) {
82 $comment_text=$matches[1];
83
84 if (preg_match("/This file is created by Vector NTI/",$comment_text)) {
85 $VNTI_file=TRUE;
86 }
87 if (preg_match("/VNTNAME\|(.*)\|/",$comment_text,$matches)) {
88 $name=$matches[1];
89 }
90 if (preg_match("/VNTAUTHORNAME\|(.*)\|/",$comment_text,$matches)) {
91 $auth=$matches[1];
92 }
93
94 #Done with comment checking - most of the rest of the VNTI stuff looks like
95 #drawing info
96 continue ;
97 }
98 # special case for the features table
99 # features section is all text from ^FEATURES to ^ORIGIN
100 if (preg_match("/^FEATURES/",$line)){
101 unset($keyword);
102 $feature_section=TRUE;
103 }
104 if ($feature_section){
105 if (preg_match("/^FEATURES/", $line)) {
106 unset ($features);
107 continue;
108 }
109
110 if (preg_match("/^(BASE COUNT|ORIGIN)/", $line)) {
111 if (isset($feature))
112 $features[]=$feature;
113 unset ($feature);
114 if (preg_match("/^BASE COUNT/", $line))
115 continue;
116
117 #special case for the sequence itself
118 if (preg_match("/^ORIGIN/", $line)) {
119 $feature_section=FALSE;
120 $sequence_section=TRUE;
121 continue;
122 }
123 }
124 $featurelabel = trim(substr($line,$FEATURECOL,$FEATUREVALCOL-$FEATURECOL));
125 $featurevalue = trim(substr($line,$FEATUREVALCOL));
126 if (isset($featurelabel)) {
127 if (isset($feature))
128 $features[]=$feature;
129 $feature = array('label'=>$featurelabel,'value'=>$featurevalue);
130 } else {
131 $feature['value'] .= $featurevalue;
132 }
133 continue;
134 }
135
136
137 #For now, don't parse any other keys
138
139 #just scoop up sequence into one big string; we'll clean it up later.
140 #assumes sequence is last thing in file
141 if($sequence_section) {
142 if (preg_match("/^\/\//",$line))
143 continue;
144 $sequence.=$line;
145 }
146 }
147
148 # remove leading numbers and whitespace
149 $sequence = preg_replace("/^(.{9,10})/m", "", $sequence); #strip leader
150 $sequence = preg_replace("/(.{10}) /m", "$1", $sequence); # remove spacers
151 $sequence = preg_replace("/\s/", "", $sequence); #strip newlines and whitespace
152
153 #set table values appropriately
154 $fieldvalues["fullname"]=$name;
155 $fieldvalues["author"]=$auth;
156 }
157 return true;
158 }
159
160 ////
161 // !Overrides the standard 'show record'function
162 function plugin_show($db,$tableinfo,$id,$USER,$system_settings,$backbutton=true)
163 {
164 }
165
166
167 ////
168 // !Extends the search query
169 // $query is the complete query that you can change and must return
170 // $fieldvalues is an array with the column names as key.
171 // if there is an $existing_clause (boolean) you should prepend your additions
172 // with ' AND' or ' OR', otherwise you should not
173 function plugin_search($query,$fieldvalues,$existing_clause)
174 {
175 return $query;
176 }
177
178
179 ////
180 // !Extends function getvalues
181 // $allfields is a 2-D array containing the field names of the table in the first dimension
182 // and name,columnid,label,datatype,display_table,display_record,ass_t,ass_column,
183 // ass_local_key,required,modifiable,text,values in the 2nd D
184 function plugin_getvalues($db,&$allfields,$id,$tableid)
185 {
186 }
187
188 ////
189 // !Extends function display_add
190 // This lets you add information to every specific item
191 function plugin_display_add ($db,$tableid,$nowfield)
192 {
193 if ($nowfield["name"]=="gbfile") {
194 echo "<br>If a Vector NTI file is uploaded (above), the fields Name and Author will be extracted from the file.";
195 }
196
197 }
198
199
200 ?>