[Bio] / FigKernelPackages / FIG.pm Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIG.pm

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

revision 1.379, Thu Oct 20 10:22:04 2005 UTC revision 1.380, Sat Oct 22 17:43:49 2005 UTC
# Line 8279  Line 8279 
8279    
8280  =head3 key_info  =head3 key_info
8281    
8282  Access a reference to an array of [single, explanation]  Access a hash of key information. The data that are returned are:
8283    
8284    hash key name           what is it                      data type
8285    single                                                  [boolean]
8286    description             Explanation of key              [free text]
8287    readonly                whether to allow read/write     [boolean]
8288    is_cv                   attribute is a cv term          [boolean]
8289    
8290  Single is a boolean, if it is true only the last value returned should be used. Note that the other methods willl still return all the values, it is upto the implementer to ensure that only the last value is used.  Single is a boolean, if it is true only the last value returned should be used. Note that the other methods willl still return all the values, it is upto the implementer to ensure that only the last value is used.
8291    
8292  Explanation is a user-derived explanation that can be defined.  Explanation is a user-derived explanation that can be free text
8293    
8294    If a reference to a hash is provided, along with the key, those values will be set to the attribute_keys file
8295    
8296  if a reference to an array is provided, along with the key, those values will be set.  Returns an empty hash if the key is not provieded or doesn't exist
8297    
8298  e.g.  e.g.
8299  $fig->key_info($key, \@data); # set the data  $fig->key_info($key, \%data); # set the data
8300  $data=$fig->key_info($key); # get the data  $data=$fig->key_info($key); # get the data
8301    
8302  =cut  =cut
8303    
8304  sub key_info {  sub key_info {
8305   my ($self, $key, $data)=@_;   my ($self, $key, $data)=@_;
8306   return [] unless ($key);   return {} unless ($key);
8307   $key =  $self->clean_attribute_key($key);   $key =  $self->clean_attribute_key($key);
8308   my %attr;   return $self->{'key_info'}->{$key} if (!$data && $self->{'key_info'}->{$key});
8309    
8310     my $version=1;
8311     my $attr;
8312   if (-e "$FIG_Config::global/Attributes/attribute_keys") {   if (-e "$FIG_Config::global/Attributes/attribute_keys") {
8313    open(IN, "$FIG_Config::global/Attributes/attribute_keys") || die "Can't open $FIG_Config::global/Attributes/attribute_keys although it exists";    open(IN, "$FIG_Config::global/Attributes/attribute_keys") || die "Can't open $FIG_Config::global/Attributes/attribute_keys although it exists";
8314    while (<IN>) {    while (<IN>) {
8315      if (/^\#\s*Version\s*(\d+)/) {$version=$1}
8316     next if (/^\s*\#/);     next if (/^\s*\#/);
8317     chomp;     chomp;
8318     next unless ($_);     next unless ($_);
8319     my @a=split /\t/;     my @a=split /\t/;
8320     my $k=shift @a;     # fix old versions of attribute_keys
8321     $attr{$k}=\@a;     if ($version==1) {$attr->{$a[0]}->{'single'}=$a[1]; $attr->{$a[0]}->{'description'}=$a[2]; next}
8322    
8323       $attr->{$a[0]}->{$a[1]}=$a[2];
8324    }    }
8325    close IN;    close IN;
8326   }   }
8327   $attr{$key}->[1]=$data->[1] if ($data);  
8328   return [] unless ($attr{$key}); # no use writing it if we didn't add anything   if ($data)
8329     {
8330      $attr->{$key}=$data;
8331   open(OUT, ">$FIG_Config::global/Attributes/attribute_keys") || die "Can't open $FIG_Config::global/Attributes/attribute_keys for writing";   open(OUT, ">$FIG_Config::global/Attributes/attribute_keys") || die "Can't open $FIG_Config::global/Attributes/attribute_keys for writing";
8332   print OUT map {"$_\t".(join "\t", @{$attr{$_}})."\n"} keys %attr;    if ($version==1)
8333      {
8334       print OUT "# Version 2\n# This file contains information about the attribute keys in this database. The columns are:\n";
8335       print OUT "# attribute key\n# tag associated for that key\n# value of that tag\n";
8336       print OUT "# Each attribute key can have as many of these as you want. The last one in the file will be used. This is used to store data applicable to\n";
8337       print OUT "# every key in the attributes\n";
8338      }
8339    
8340      map {my $k=$_; map {print OUT "$k\t$_\t", $attr->{$k}->{$_}, "\n"} keys %{$attr->{$k}}} keys %$attr;
8341   close OUT;   close OUT;
8342   if (exists $attr{$key}) {return $attr{$key}} else {return []}   }
8343    
8344     $self->{'key_info'}=$attr;
8345     if (exists $attr->{$key}) {return $attr->{$key}} else {return {}}
8346  }  }
8347    
8348  =head3 get_key_value  =head3 get_key_value

Legend:
Removed from v.1.379  
changed lines
  Added in v.1.380

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3