[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.262, Sat Apr 2 11:56:12 2005 UTC revision 1.263, Sun Apr 3 19:11:11 2005 UTC
# Line 5217  Line 5217 
5217  The attributes methods have now been rewritten for handling all kinds of attributes. The tag/value pairs can be associated with a feature like a peg, rna, or prophage, or a genome.  The attributes methods have now been rewritten for handling all kinds of attributes. The tag/value pairs can be associated with a feature like a peg, rna, or prophage, or a genome.
5218    
5219  There are several base attribute methods:  There are several base attribute methods:
5220    
5221   get_attributes   get_attributes
5222   add_attribute   add_attribute
5223   delete_attribute   delete_attribute
5224   change_attribute   change_attribute
5225    
5226  There are also methods for more complex things:  There are also methods for more complex things:
5227    
5228   get_tags   get_tags
5229   get_values   get_values
5230   guess_value_format   guess_value_format
# Line 5316  Line 5318 
5318  Add a new tag/value pair to something. Something can be a genome id, a peg, an rna, prophage, whatever.  Add a new tag/value pair to something. Something can be a genome id, a peg, an rna, prophage, whatever.
5319    
5320  Arguments:  Arguments:
5321    
5322          feature id, this can be a peg, genome, etc,          feature id, this can be a peg, genome, etc,
5323          tag name to replace          tag name
5324          value to replace it with          value
5325          optional URL to add          optional URL to add
5326          optional file to store the attributes in.          optional file to store the attributes in.
5327    
5328  A note on files, at the moment Attributes is a directory, and we are using load attributes to load everything. I think we should switch to this method which is a lot cleaner, so I added the option of defining the file here. The default is to use assigned_attributes and load_attributes loads this file last so anything in that file will replace anthing in the other files.  A note on file names. At the moment the file assigned_attributes is used to store new attributes by default, and load_attributes loads that file last so any changes will overwrite existing tags. However this is not quite true since we can now have multiple tag/values for a single peg. Using this method you can define a filename to store the attributes in. The directory structure will be figured out for you, so you can use something like "pirsf" as the file name.
5329    
5330  =cut  =cut
5331    
# Line 5395  Line 5398 
5398      return 1;      return 1;
5399  }  }
5400    
5401    =head1 erase_attribute_entirely
5402    
5403    This method will remove any notion of the attribute that you give it. It is different from delete as that just removes a single attribute associated with a peg. This will remove the files and uninstall the attributes from the database so there is no memory of that type of attribute. All of the attribute files are moved to FIG_Tmp/Attributes/deleted_attributes, and so you can recover the data for a while. Still, you should probably use this carefully!
5404    
5405    I use this to clean out old PIR superfamily attributes immediately before installing the new correspondence table.
5406    
5407    e.g. my $status=$fig->erase_attribute_entirely("pirsf");
5408    
5409    This will return the number of files that were moved to the new location
5410    
5411    =cut
5412    
5413    sub erase_attribute_entirely {
5414     my ($self, $attr)=@_;
5415     return 0 unless ($attr);
5416    
5417     my %path_to_files; # this hash has the path as the key and the genome id as the value
5418    
5419     # get all the tags we know about
5420     my $tags=$self->get_tags();
5421     foreach my $type (keys %$tags)
5422     {
5423      foreach my $label (keys %{$tags->{$type}})
5424      {
5425       next unless (uc($label) eq uc($attr));
5426       foreach my $peg (@{$tags->{$type}->{$label}})
5427       {
5428        # delete the attribute from the database
5429        my $rdbH = $self->db_handle;
5430        $rdbH->SQL("DELETE FROM attribute WHERE fid = \'$peg\' and tag = \'$label\'");
5431        # make a hash of all files that we should delete, and then when we are done we can go move them
5432        $path_to_files{$self->attribute_location($peg)}=$self->genome_of($peg);
5433       }
5434      }
5435     }
5436    
5437     # now we need to check that we have the files to delete
5438     # we are going to see if there are files to delete, and then we will make temp dirs and move them. If there are no files
5439     # to do we don't need to make the dir
5440     my @files;
5441     foreach my $path (keys %path_to_files)
5442     {
5443      if (-e "$path/$attr") {push @files, $path}
5444     }
5445    
5446     return 1 unless (scalar @files); # don't continue if there are no files to move
5447    
5448     mkdir "$FIG_Config::temp/Attributes/deleted_attributes", 0755 unless (-e "$FIG_Config::temp/Attributes/deleted_attributes");
5449    
5450     foreach my $path (@files)
5451     {
5452      my $genome=$path_to_files{$path};
5453      unless ($genome) {$genome='unknown'}
5454      my $dest="$FIG_Config::temp/Attributes/deleted_attributes/$genome";
5455      mkdir "$FIG_Config::temp/Attributes/deleted_attributes/$genome", 0755 unless (-e "$FIG_Config::temp/Attributes/deleted_attributes/$genome");
5456      $dest .= $attr;
5457      if (-e $dest)
5458      {
5459       # don't overwrite the file
5460       my $count=1;
5461       while (-e "$dest.$count") {$count++}
5462       $dest .= ".$count";
5463      }
5464    
5465      system("mv $path/$attr $dest");
5466     }
5467    
5468     return scalar @files;
5469    }
5470    
5471    
5472  =head1 get_tags  =head1 get_tags
5473    
# Line 5402  Line 5475 
5475    
5476  Without any arguments:  Without any arguments:
5477    
5478  Returns a reference to a hash, where the key is the type of feature (peg, genome, rna, prophage, etc), and the value is a reference to a hash where the key is the tag name and the value is the number of occurences  Returns a reference to a hash, where the key is the type of feature (peg, genome, rna, prophage, etc), and the value is a reference to a hash where the key is the tag name and the value is a reference to an array of all features with that id.
5479    
5480    e.g.
5481    
5482  e.g. print "There are  " , {$fig->get_tags}->{'peg'}->{'PIRSF'}, " PIRSF tags in the database\n";  print "There are  " , scalar @{{$fig->get_tags}->{'peg'}->{'PIRSF'}}, " PIRSF tags in the database\n";
5483    
5484    my $tags=$fig->get_tags;
5485    foreach my $type (keys %$tags)
5486    {
5487     foreach my $label (keys %{$tags->{$type}})
5488     {
5489      foreach my $peg (@{$tags->{$type}->{$label}})
5490      {
5491        .. do something to each peg and genome here
5492      }
5493     }
5494    }
5495    
5496  With an argument (that should be a recognized type like peg, rna, genome, etc):  With an argument (that should be a recognized type like peg, rna, genome, etc):
5497    
5498  Returns a reference to a hash where the key is the tag name and the value is the count. This should use less memory than above.  Returns a reference to a hash where the key is the tag name and the value is the reference to the array. This should use less memory than above.
5499  The argument should be (currently) peg, rna, pp, genome, or any other recognized feature type (generally defined as the .peg. in the fid). The default is to return all tags, and this can also be specified with all  The argument should be (currently) peg, rna, pp, genome, or any other recognized feature type (generally defined as the .peg. in the fid). The default is to return all tags, and this can also be specified with all
5500    
5501  =cut  =cut
# Line 5424  Line 5511 
5511    $tag =~ s/^\s+//; $tag =~ s/\s+$//; $tag=uc($tag);    $tag =~ s/^\s+//; $tag =~ s/\s+$//; $tag=uc($tag);
5512    my $type=$self->ftype($fid);    my $type=$self->ftype($fid);
5513    if ($type && ($want eq $type || $want eq "all")) {    if ($type && ($want eq $type || $want eq "all")) {
5514     $tags->{$type}->{$tag}++;     push (@{$tags->{$type}->{$tag}}, $fid);
5515    } elsif (($fid =~ /^\d+\.\d+$/) && (lc($want) eq "genome" || $want eq "all")) {    } elsif (($fid =~ /^\d+\.\d+$/) && (lc($want) eq "genome" || $want eq "all")) {
5516     $tags->{'genome'}->{$tag}++;     push (@{$tags->{'genome'}->{$tag}}, $fid);
5517    }    }
5518   }   }
5519   if ($want eq "all") {return $tags} else {return $tags->{$want}}   if ($want eq "all") {return $tags} else {return $tags->{$want}}
# Line 5492  Line 5579 
5579  =head1 get_tag_value  =head1 get_tag_value
5580    
5581  Given a tag and a value will return anything that has both  Given a tag and a value will return anything that has both
5582    
5583  E.g.  E.g.
5584    
5585          my @nonmotile_genomes = $fig->get_tag_value('motile', 'non-motile');          my @nonmotile_genomes = $fig->get_tag_value('motile', 'non-motile');
5586          my @bluepegs          = $fig->get_tag_value('color', 'blue');          my @bluepegs          = $fig->get_tag_value('color', 'blue');
5587    

Legend:
Removed from v.1.262  
changed lines
  Added in v.1.263

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3