[Bio] / FigWebServices / cv.cgi Repository:
ViewVC logotype

Diff of /FigWebServices/cv.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Wed Oct 19 14:39:06 2005 UTC revision 1.15, Thu Nov 10 20:18:17 2005 UTC
# Line 18  Line 18 
18    
19  use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.  use LWP::Simple qw(!head); # see the caveat in perldoc LWP about importing two head methods.
20    
 #for testing  
21    
22  my $peg = "fig|9598.2.peg.1";  my $peg;
23    if ($cgi->param('prot') )
24    {
25        $peg = $cgi->param('prot');
26    }
27    else
28    {
29        $peg = $cgi->param('prot');
30        my(@html);
31        push(@html, $cgi->p("Parameter error- prot is required."));
32        &HTML::show_page($cgi, \@html, 1);
33        exit;
34    }
35    
36    # a global for the results of a search. overridden by an actual search
37    
38    my $search_results= [];
39    
40    my $error_message = "";
41    
42    
43    my $user = "";
44    if ($cgi->param('user') ) {
45        $user = $cgi->param('user');
46    }
47    
48  my $fig;  my $fig;
49  eval {  eval {
# Line 47  Line 70 
70  }  }
71    
72  my $html = [];  my $html = [];
 my $user = $cgi->param('user');  
   
 unshift(@$html, "<TITLE>Controlled Vocabulary Workbench</TITLE>\n");  
73    
74  my $ids;  my $ids;
75  my $tag_to_id;  my $tag_to_id;
# Line 57  Line 77 
77    
78  if ($cgi->param('request') eq "Delete Checked Terms")  if ($cgi->param('request') eq "Delete Checked Terms")
79  {  {
80        if (!$cgi->param('user'))
81        {
82                my(@html);
83                push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
84                &HTML::show_page($cgi, \@html, 1);
85                exit;
86        }
87        else
88        {
89      my %id_term_to_source;      my %id_term_to_source;
90      my @checked;      my @checked;
91      my @param_list = $cgi->param();      my @param_list = $cgi->param();
# Line 76  Line 105 
105    
106          for my $c (@checked)          for my $c (@checked)
107          {          {
108             @temp = split('\t',$c);                  @temp = split('split_here',$c);
109             $id_term_to_source{$temp[1]} = $temp[0];             $id_term_to_source{$temp[1]} = $temp[0];
110          }          }
111      }      }
112      &delete_terms($fig,$cgi,$html,$peg,\%id_term_to_source);      &delete_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
113  }  }
114    }
115  elsif ($cgi->param('request') eq "Search Selected Controlled Vocabulary")  elsif ($cgi->param('request') eq "Search Selected Controlled Vocabulary")
116  {  {
117      if ($cgi->param('search_term')) {$search_term=$cgi->param('search_term')}      if ( $cgi->param('search_term') && $cgi->param('select_cv') ) {
118      if ($cgi->param('select_cv')) {$cv=$cgi->param('select_cv')}          $search_term=$cgi->param('search_term');
119      &search($fig,$cgi,$html,$peg,$cv,$search_term);          $cv=$cgi->param('select_cv');
120            $search_results = $fig->search_cv_file($cv,$search_term);
121        }
122    }
123    elsif ($cgi->param('request') eq "Add New Terms")
124    {
125        if (!$cgi->param('user'))
126        {
127                my(@html);
128                push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
129                &HTML::show_page($cgi, \@html, 1);
130                exit;
131  }  }
132  elsif ($cgi->param('request') eq "Add Custom Term")      else
133  {  {
134      if ($cgi->param('custom_source')) {$custom_source=$cgi->param('custom_source')}          my %id_term_to_source;
135      if ($cgi->param('custom_id')) {$custom_id=$cgi->param('custom_id')}          my @checked;
136      if ($cgi->param('custom_term')) {$custom_term=$cgi->param('custom_term')}          my @param_list = $cgi->param();
137            if (@param_list)
138            {
139                foreach my $p (@param_list)
140                {
141                    if ( $p=~/add_checked/)
142                    {
143                        if($cgi->param($p))
144                        {
145                            $value = $cgi->param($p);
146                            push(@checked,$value)
147                            }
148                    }
149                }
150    
151      my $triple = [$custom_source,$custom_id,$custom_term];              for my $c (@checked)
152      &add_custom_term($fig,$cgi,$html,$peg,$triple);              {
153                    @temp = split("split_here",$c);
154                    $source = $temp[0];
155                    $id_term = $temp[1];
156                    $id_term_to_source{$id_term} =$source ;
157                }
158  }  }
159            &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
160    
161        }
162    }
163    
164    elsif ($cgi->param('request') eq "Add Term Manually")
165    {
166        if (!$cgi->param('user'))
167        {
168                my(@html);
169                push(@html, $cgi->p("You must be logged in as a user to edit controlled vocabulary terms."));
170                &HTML::show_page($cgi, \@html, 1);
171                exit;
172        }
173        else
174        {
175            my %id_term_to_source;
176            my $id_term;
177            if ( $cgi->param('manual_source') && $cgi->param('manual_id') && $cgi->param('manual_term') ) {
178                $manual_source=$cgi->param('manual_source');
179                $manual_id=$cgi->param('manual_id');
180                $manual_term=$cgi->param('manual_term');
181                $id_term = $manual_id."; ".$manual_term;
182                $id_term_to_source{$id_term} = $manual_source;
183                &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
184            }
185  else  else
186  {  {
187    &show_initial($fig,$cgi,$html,$peg);              $error_message = "Error in 'Add Terms Manually': supply all three items correctly.";
188            }
189        }
190    }
191    else
192    {
193        #no op.  Initial page display
194  }  }
195    
196    &build_page($fig,$cgi,$html,$peg,$search_results);
197  &HTML::show_page($cgi,$html,1);  &HTML::show_page($cgi,$html,1);
198  exit;  exit;
199    
# Line 110  Line 201 
201  {  {
202     my ($fig,$cgi,$html,$peg,$id_term_to_source) = @_;     my ($fig,$cgi,$html,$peg,$id_term_to_source) = @_;
203     my @id_term = keys(%{$id_term_to_source});     my @id_term = keys(%{$id_term_to_source});
204     foreach my $it (@id_term){$fig->delete_attribute($peg,$id_term_to_source->{$it},$it)}     foreach my $it (@id_term)
205     &show_initial($fig,$cgi,$html,$peg);     {
206           $fig->delete_attribute($peg,$id_term_to_source->{$it},$it)
207  }  }
208    }
209    
210    # moved to FIG.pm
211    #sub search_cv_file
212    #{
213    ##    my ($fig,$cgi,$html,$peg,$cv,$search_term) =@_;
214    #    my ($cv,$search_term) =@_;
215    #    $file = $FIG_Config::global."/CV/cv_search_".$cv.".txt";
216    #    if (! open(LOOKUP,"$file") ) {
217    #       print STDERR "Search could not find vocabulary file, $file";
218    #       return;
219    #    }
220    #    my @lines = <LOOKUP>;
221    #    my @grep_results = grep(/$search_term/i,@lines);
222    #     return [@grep_results];
223    #}
224    
225  sub search  sub add_terms
226  {  {
227      my ($fig,$cgi,$html,$peg,$cv,$search_term) =@_;      print STDERR "add_terms called!\n";
228      open(LOOKUP,"$FIG_config::global/$cv_lookup.txt");      my ($fig,$cgi,$html,$peg,$id_term_to_source) =@_ ;
229      my @lines = <LOOKUP>;      my @id_term = keys(%{$id_term_to_source});
230      my $search_results = grep(/$search_term/i,@lines);      #my %sources={};   #in case someday we allow adds from >1 vocab at once
231      &show_search_results($fig,$cgi,$html,$peg,$cv,$search_results);      my $source;
232  }      my $user = $cgi->param('user');
233    
234  sub add_custom_term      foreach my $it (@id_term)
235  {  {
236      my ($fig,$cgi,$html,$peg,$triple) =@_ ;         $source = $id_term_to_source->{$it};
237      my @input = @$triple;         my @temp = split("; ",$it);
238      my $key = $input[0];         my $id = $temp[0];
239      my $id = $input[1];         my $term = $temp[1];
240      my $term = $input[2];         my $status = $fig->add_cv_term( $user, $peg, $source, $id, $term);
241      $value = $id.": ".$term;         if (!$status) {
242      $fig->add_attribute($peg,$key,$value);             #print STDERR "$peg- Added ($source, $id, $term)\n";
243               #&HTML::show_page($cgi, \@html);
244           }
245           else
246           {
247               print STDERR "$peg- Error for ($source, $id, $term):\t$status\n";
248               my(@html);
249               push(@html, $cgi->p("$peg- Error for ($source, $id, $term):\t$status\n"));
250               &HTML::show_page($cgi, \@html, 1);
251               exit;
252  }  }
253    
254  sub show_search_results {  
255   my ($fig,$cgi,$html,$peg,$cv,$search_results)=@_;     }
256    
257        #$sources{$source}=1;   #build unique list of source names
258    
259    
260    
261        #my %key_info_hash;
262        #$key_info_hash{"is_cv"} = 1;
263        #$key_info_hash{"single"} = 0;
264        #$key_info_hash{"readonly"} = 1;
265    
266        #$fig->key_info($source,\%key_info_hash);
267    
268        #&show_initial($fig,$cgi,$html,$peg);
269    }
270    
271    
272    sub build_page {
273        my ($fig,$cgi,$html,$peg,$search_results)=@_;
274    
275    
276        unshift(@$html, "<TITLE>Controlled Vocabulary Workbench for $peg</TITLE>\n");
277    
278        # Build seach results table
279    
280   @sr = @$search_results;   @sr = @$search_results;
281   my $add_col_hdrs = ["Add","Source","ID: Term"];      my $add_col_hdrs = ["Add","Vocab. Name","ID; Term"];
282   my $add_table_rows;   my $add_table_rows;
283        my $counter = 0;
284   for my $r (@sr)   for my $r (@sr)
285   {   {
286       @temp = split("\t",$r);       @temp = split("\t",$r);
287       $row = [];       $row = [];
288            $cv=$cgi->param('select_cv');
289       $source = $cv;       $source = $cv;
290       $id_and_term = $temp[1];          $id= $temp[1];
291       $cb ="<input type=checkbox name=add_checked value=$id_and_term>" ;          $term = $temp[2];
292            $id_and_term = $id."; ".$term;
293            $cb_value = $cv."split_here".$id."; ".$term;
294            $cb ="<input type=checkbox name=add_checked_$counter value='$cb_value'>" ;
295       push(@$row,$cb);       push(@$row,$cb);
296       push(@$row,$source);       push(@$row,$source);
297       push(@$row,$id_and_term);       push(@$row,$id_and_term);
298       push(@$add_table_rows,$row);       push(@$add_table_rows,$row);
299            $counter = $counter + 1;
300   }   }
301    
302   my $delete_col_hdrs = ["Delete","Source","ID: Term"];      my $add_terms_button="";
303   my @results = $fig->get_attributes($peg,'GO');      if ($counter > 0) {
304            $add_terms_button= $cgi->submit(-name=>'request', -value=>'Add New Terms');
305        }
306    
307        # build term deletions stuff
308    
309        my $delete_col_hdrs = ["Delete","Vocab. Name","ID; Term"];
310        my @results = $fig->get_attributes($peg);
311   my $delete_table_rows;   my $delete_table_rows;
312   my $counter = 0;   my $counter = 0;
313   for my $r (@results)   for my $r (@results)
314   {   {
315       $row = [];       $row = [];
316       $source = $r->[1];       $source = $r->[1];
317            $cv_key_hash = $fig->key_info($source);
318            if($cv_key_hash->{"is_cv"} == 1)
319            {
320       $id_and_term = $r->[2];       $id_and_term = $r->[2];
321       $cb ="<input type=checkbox name=delete_checked_$counter value=$id_and_term>" ;              $value = $source."split_here".$id_and_term;
322                $cb ="<input type=checkbox name='delete_checked_$counter' value='$value'>" ;
323       push(@$row,$cb);       push(@$row,$cb);
324       push(@$row,$source);       push(@$row,$source);
325       push(@$row,$id_and_term);       push(@$row,$id_and_term);
326       push(@$delete_table_rows,$row);       push(@$delete_table_rows,$row);
327       $counter = $counter + 1;       $counter = $counter + 1;
328   }   }
329        }
330    
331    
332        # build the page
333        my $user = $cgi->param('user');
334        my $link = "protein.cgi?prot=$peg&user=$user";
335   push @$html,   push @$html,
336   $cgi->start_multipart_form(),      #$cgi->start_multipart_form(),
337   "<h2>Controlled Vocabulary Workbench</h2>\n",      $cgi->start_form(),
338        $cgi->hidden(-name=>'prot', -value=>'$peg'),
339        $cgi->hidden(-name=>'user', -value=>'$user'),
340        $cgi->br,
341        "<a href=$link> Back to protein page</a>",
342        $cgi->br,
343        "<h2>Controlled Vocabulary Workbench for $peg</h2>",
344        $cgi->hr,
345        "<h1>$error_message</h1>",
346   $cgi->hr,   $cgi->hr,
347   "<h4>Current Terms Assigned To Peg </h4>\n",      "<h4>Current Terms Assigned To $peg </h4>\n",
348   &HTML::make_table($delete_col_hdrs,$delete_table_rows),   &HTML::make_table($delete_col_hdrs,$delete_table_rows),
349   $cgi->br,   $cgi->br,
350   $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),   $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),
351        $cgi->end_form;
352    
353        push @$html,
354        $cgi->start_form(),
355        $cgi->hidden(-name=>'prot', -value=>'$peg'),
356        $cgi->hidden(-name=>'user', -value=>'$user'),
357   $cgi->hr,   $cgi->hr,
358   $cgi->br,   $cgi->br,
359   "<h4>Search for New Terms to Add </h4>\n",   "<h4>Search for New Terms to Add </h4>\n",
360   "<select name=select_cv>   "<select name=select_cv>
361          <option value=all >all CVs</option>          <option value=GO  >Gene Ontology</option>
362          <option value=go  >Gene Ontology</option>          <option value=HUGO  >HUGO Gene Nomenclature Committee</option>
         <option value=omim >OMIM</option>  
363    </select> &nbsp;&nbsp",    </select> &nbsp;&nbsp",
364   $cgi->textfield(-name => "search_term", -size => 20),      $cgi->textfield(-name => 'search_term', -size => 20),
365   $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'),   $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'),
366   $cgi->br,   $cgi->br,
  &HTML::make_table($add_col_hdrs,$add_table_rows),  
  $cgi->hr,  
367   $cgi->br,   $cgi->br,
368   "<h4>Add Custom Terms </h4>\n",      &HTML::make_table($add_col_hdrs,$add_table_rows),
  "<h5>Source </h5>\n",  
  $cgi->textfield(-name => "custom_source", -size => 20),  
  "<h5>ID</h5>\n",  
  $cgi->textfield(-name => "custom_id", -size => 20),  
  "<h5>Term</h5>\n",  
  $cgi->textfield(-name => "custom_term", -size => 20),  
  $cgi->br,$cgi->br,  
  $cgi->submit(-name=>'request', -value=>'Add Custom Term'),  
369   $cgi->br,   $cgi->br,
370   $cgi->hr,      $add_terms_button,
371   $cgi->end_form;   $cgi->end_form;
372    
  return $html;  
 }  
   
 sub show_initial {  
  my ($fig,$cgi,$html,$peg)=@_;  
  # generate a blank page  
   
  my $col_hdrs = ["Delete","Source","ID: Term"];  
  my @results = $fig->get_attributes($peg,'GO');  
  my $table_rows;  
  for my $r (@results)  
  {  
      $row = [];  
      $source = $r->[1];  
      $id_and_term = $r->[2];  
      $cb ="<input type=checkbox name=delete_checked value=$source\t$id_and_term>" ;  
      push(@$row,$cb);  
      push(@$row,$source);  
      push(@$row,$id_and_term);  
      push(@$table_rows,$row);  
  }  
   
373    push @$html,    push @$html,
374   $cgi->start_multipart_form(),      $cgi->start_form(),
375   "<h2>Controlled Vocabulary Workbench</h2>\n",      $cgi->hidden(-name=>'prot', -value=>'$peg'),
376   $cgi->hr,      $cgi->hidden(-name=>'user', -value=>'$user'),
  "<h4>Current Terms Assigned To Peg </h4>\n",  
  &HTML::make_table($col_hdrs,$table_rows),  
  $cgi->br,  
  $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),  
377   $cgi->hr,   $cgi->hr,
378   $cgi->br,      "<h4>Add Term Manually (WARNING: This is strongly discouraged to avoid data entry errors.)</h5>",
379   "<h4>Search for New Terms to Add </h4>\n",      "<h5>Vocabulary Name (single word, no spaces or punctuation), e.g., MyVocab </h5>\n",
380   "<select name=select_cv>      $cgi->textfield(-name => 'manual_source', -size => 48, -default=>'', -override=>1 ),
381          <option value=all >all CVs</option>      "<h5>Term ID (single word, no spaces or punctuation), e.g., A147</h5>\n",
382          <option value=go  >Gene Ontology</option>      $cgi->textfield(-name => 'manual_id', -size => 32, -default=>'', -override=>1),
383          <option value=omim >OMIM</option>      "<h5>Term text, e.g., catalytic activity</h5>\n",
384    </select> &nbsp;&nbsp",      $cgi->textfield(-name => 'manual_term', -size => 70, -default=>'', -override=>1 ),
  $cgi->textfield(-name => 'search_term', -size => 20),  
  $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'),  
  $cgi->hr,  
  $cgi->br,  
  "<h4>Add Custom Terms </h4>\n",  
  "<h5>Source </h5>\n",  
  $cgi->textfield(-name => 'custom_source', -size => 20),  
  "<h5>ID</h5>\n",  
  $cgi->textfield(-name => 'custom_id', -size => 20),  
  "<h5>Term</h5>\n",  
   $cgi->textfield(-name => 'custom_term', -size => 20),  
385   $cgi->br,$cgi->br,   $cgi->br,$cgi->br,
386   $cgi->submit(-name=>'request', -value=>'Add Custom Term'),      $cgi->submit(-name=>'request', -value=>'Add Term Manually'),
387   $cgi->br,   $cgi->br,
388   $cgi->hr,   $cgi->hr,
389   $cgi->end_form;   $cgi->end_form;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3