[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.2, Wed Oct 19 20:20:07 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 = $cgi->param('prot');  my $peg;
23  #my $peg = "fig|9598.2.peg.1";  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 48  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 58  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 77  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")  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        else
133        {
134      my %id_term_to_source;      my %id_term_to_source;
135      my @checked;      my @checked;
136      my @param_list = $cgi->param();      my @param_list = $cgi->param();
# Line 100  Line 140 
140          {          {
141            if ( $p=~/add_checked/)            if ( $p=~/add_checked/)
142            {            {
               print STDERR "checked_param:$p\n";  
143               if($cgi->param($p))               if($cgi->param($p))
144               {               {
145                   $value = $cgi->param($p);                   $value = $cgi->param($p);
# Line 115  Line 154 
154             $source = $temp[0];             $source = $temp[0];
155             $id_term = $temp[1];             $id_term = $temp[1];
156             $id_term_to_source{$id_term} =$source ;             $id_term_to_source{$id_term} =$source ;
            print STDERR "checked_source:$source\n";  
            print STDERR "checked_value:$c\n";  
157          }          }
158      }      }
159      &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);      &add_terms($fig,$cgi,$html,$peg,\%id_term_to_source);
160    
161  }  }
162    }
163    
164  elsif ($cgi->param('request') eq "Add Custom Term")  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;      my %id_term_to_source;
176      my $id_term;      my $id_term;
177      if ($cgi->param('custom_source')) {$custom_source=$cgi->param('custom_source')}          if ( $cgi->param('manual_source') && $cgi->param('manual_id') && $cgi->param('manual_term') ) {
178      if ($cgi->param('custom_id')) {$custom_id=$cgi->param('custom_id')}              $manual_source=$cgi->param('manual_source');
179      if ($cgi->param('custom_term')) {$custom_term=$cgi->param('custom_term')}              $manual_id=$cgi->param('manual_id');
180      $id_term = $custom_id.": ".$custom_term;              $manual_term=$cgi->param('manual_term');
181      $id_term_to_source{$id_term} = $custom_source;              $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);      &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 147  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)
    &show_initial($fig,$cgi,$html,$peg);  
 }  
   
 sub search  
205  {  {
206      my ($fig,$cgi,$html,$peg,$cv,$search_term) =@_;         $fig->delete_attribute($peg,$id_term_to_source->{$it},$it)
     $file = $FIG_Config::global."/".$cv."_lookup.txt";  
     open(LOOKUP,"$file");  
     my @lines = <LOOKUP>;  
     my @grep_results = grep(/$search_term/i,@lines);  
     print STDERR "$grep_results[0]\n";  
     my $search_results = [@grep_results];  
     &show_search_results($fig,$cgi,$html,$peg,$cv,$search_results);  
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 add_terms  sub add_terms
226  {  {
227        print STDERR "add_terms called!\n";
228      my ($fig,$cgi,$html,$peg,$id_term_to_source) =@_ ;      my ($fig,$cgi,$html,$peg,$id_term_to_source) =@_ ;
229      my @id_term = keys(%{$id_term_to_source});      my @id_term = keys(%{$id_term_to_source});
230        #my %sources={};   #in case someday we allow adds from >1 vocab at once
231        my $source;
232        my $user = $cgi->param('user');
233    
234      foreach my $it (@id_term)      foreach my $it (@id_term)
235      {      {
236          print STDERR "added_source:$id_term_to_source->{$it}\n";         $source = $id_term_to_source->{$it};
237          print STDERR "added_value:$it\n";         my @temp = split("; ",$it);
238           my $id = $temp[0];
239           my $term = $temp[1];
240           my $status = $fig->add_cv_term( $user, $peg, $source, $id, $term);
241           if (!$status) {
242               #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    
         $fig->add_attribute($peg,$id_term_to_source->{$it},$it);  
254    
255      }      }
256      &show_initial($fig,$cgi,$html,$peg);  
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  sub show_search_results {  
272   my ($fig,$cgi,$html,$peg,$cv,$search_results)=@_;  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;   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= $temp[1];       $id= $temp[1];
      print STDERR "id:$id\n";  
291       $term = $temp[2];       $term = $temp[2];
292       print STDERR "term:$term\n";          $id_and_term = $id."; ".$term;
293       $id_and_term = $id.": ".$term;          $cb_value = $cv."split_here".$id."; ".$term;
      $cb_value = $cv."split_here".$id.": ".$term;  
      print STDERR "iandt:$id_and_term\n";  
294       $cb ="<input type=checkbox name=add_checked_$counter value='$cb_value'>" ;       $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);
# Line 204  Line 299 
299       $counter = $counter + 1;       $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   my $delete_table_rows;          $add_terms_button= $cgi->submit(-name=>'request', -value=>'Add New Terms');
  $counter = 0;  
  for my $r (@results)  
  {  
      $row = [];  
      $source = $r->[1];  
   
      $id_and_term = $r->[2];  
      $cb ="<input type=checkbox name=delete_checked_$counter value=$id_and_term>" ;  
      push(@$row,$cb);  
      push(@$row,$source);  
      push(@$row,$id_and_term);  
      push(@$delete_table_rows,$row);  
      $counter = $counter + 1;  
  }  
   
  push @$html,  
  $cgi->start_multipart_form(),  
  "<h2>Controlled Vocabulary Workbench</h2>\n",  
  $cgi->hr,  
  "<h4>Current Terms Assigned To Peg </h4>\n",  
  &HTML::make_table($delete_col_hdrs,$delete_table_rows),  
  $cgi->br,  
  $cgi->submit(-name=>'request', -value=>'Delete Checked Terms'),  
  $cgi->hr,  
  $cgi->br,  
  "<h4>Search for New Terms to Add </h4>\n",  
  "<select name=select_cv>  
         <option value=go  >Gene Ontology</option>  
   </select> &nbsp;&nbsp",  
  $cgi->textfield(-name => "search_term", -size => 20),  
  $cgi->submit(-name=>'request', -value=>'Search Selected Controlled Vocabulary'),  
  $cgi->br,  
  &HTML::make_table($add_col_hdrs,$add_table_rows),  
  $cgi->br,  
  $cgi->submit(-name=>'request', -value=>'Add New Terms'),  
  $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),  
  $cgi->br,$cgi->br,  
  $cgi->submit(-name=>'request', -value=>'Add Custom Term'),  
  $cgi->br,  
  $cgi->hr,  
  $cgi->end_form;  
   
  return $html;  
305  }  }
306    
307  sub show_initial {      # build term deletions stuff
  my ($fig,$cgi,$html,$peg)=@_;  
  # generate a blank page  
308    
309   my $delete_col_hdrs = ["Delete","Source","ID: Term"];      my $delete_col_hdrs = ["Delete","Vocab. Name","ID; Term"];
310   my @results = $fig->get_attributes($peg);   my @results = $fig->get_attributes($peg);
  print STDERR "@results\n";  
  print STDERR "peg:$peg\n";  
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       print STDERR "source:$source\n";          $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=$source\t$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   my $link = "protein.cgi?prot=$peg";      }
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        $cgi->start_form(),
338        $cgi->hidden(-name=>'prot', -value=>'$peg'),
339        $cgi->hidden(-name=>'user', -value=>'$user'),
340   $cgi->br,   $cgi->br,
341   "<a href=$link>Back to protein page</a>",   "<a href=$link>Back to protein page</a>",
342   $cgi->br,   $cgi->br,
343   "<h2>Controlled Vocabulary Workbench</h2>\n",      "<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=GO  >Gene Ontology</option>          <option value=GO  >Gene Ontology</option>
362            <option value=HUGO  >HUGO Gene Nomenclature Committee</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'),
  $cgi->hr,  
366   $cgi->br,   $cgi->br,
367   "<h4>Add Custom Terms </h4>\n",      $cgi->br,
368   "<h5>Source </h5>\n",      &HTML::make_table($add_col_hdrs,$add_table_rows),
369   $cgi->textfield(-name => 'custom_source', -size => 20),      $cgi->br,
370   "<h5>ID</h5>\n",      $add_terms_button,
371   $cgi->textfield(-name => 'custom_id', -size => 20),      $cgi->end_form;
372   "<h5>Term</h5>\n",  
373   $cgi->textfield(-name => 'custom_term', -size => 20),      push @$html,
374        $cgi->start_form(),
375        $cgi->hidden(-name=>'prot', -value=>'$peg'),
376        $cgi->hidden(-name=>'user', -value=>'$user'),
377        $cgi->hr,
378        "<h4>Add Term Manually (WARNING: This is strongly discouraged to avoid data entry errors.)</h5>",
379        "<h5>Vocabulary Name (single word, no spaces or punctuation), e.g., MyVocab </h5>\n",
380        $cgi->textfield(-name => 'manual_source', -size => 48, -default=>'', -override=>1 ),
381        "<h5>Term ID (single word, no spaces or punctuation), e.g., A147</h5>\n",
382        $cgi->textfield(-name => 'manual_id', -size => 32, -default=>'', -override=>1),
383        "<h5>Term text, e.g., catalytic activity</h5>\n",
384        $cgi->textfield(-name => 'manual_term', -size => 70, -default=>'', -override=>1 ),
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.2  
changed lines
  Added in v.1.15

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3