5237 |
|
|
5238 |
With one argument (the id): |
With one argument (the id): |
5239 |
|
|
5240 |
Get an array of attributes for a feature. Each attribute is a tag, a value, and (optionally) a URL This method will return an array where each element is a tag, a val, and it's url. |
Get an array of attributes for a feature. Each attribute is a tag, a value, and (optionally) a URL This method will return an array where each element is a reference to an array that contains the tag, a value, and it's url. |
5241 |
eg. my @attributes=$fig->get_attributes($peg); |
eg. my @attributes=$fig->get_attributes($peg); |
5242 |
|
foreach my $attr (@attributes) { |
5243 |
|
($tag, $val)=@$attr; |
5244 |
|
... |
5245 |
|
} |
5246 |
|
|
5247 |
Note that attributes are not just for pegs, hence you can get attributes for genomes: |
Note that attributes are not just for pegs, hence you can get attributes for genomes: |
5248 |
e.g. my @attributes=$fig->get_attributes($genome) |
e.g. my @attributes=$fig->get_attributes($genome) |
5249 |
|
|
5250 |
With two arguments (the id and the tag): |
With two arguments (the id and the tag): |
5251 |
|
|
5252 |
Will return the value and url for just that attribute |
Will return the value and urls for just that attribute |
5253 |
e.g. my ($value, $url)=$fig->get_attributes($genome, 'motility'); |
e.g. my @attributes=$fig->get_attributes($genome, 'motility'); |
5254 |
|
|
5255 |
NOTE: If there are no attributes an empty array will be returned. You need to check for this and not assume that it will be undef. |
NOTE: If there are no attributes an empty array will be returned. You need to check for this and not assume that it will be undef. |
5256 |
|
|
5283 |
if ($tag && ($relational_db_response = $rdbH->SQL("SELECT val,url FROM attribute WHERE ( fid = \'$fid\' and tag = \'$tag\' )")) && |
if ($tag && ($relational_db_response = $rdbH->SQL("SELECT val,url FROM attribute WHERE ( fid = \'$fid\' and tag = \'$tag\' )")) && |
5284 |
(@$relational_db_response > 0)) |
(@$relational_db_response > 0)) |
5285 |
{ |
{ |
5286 |
my @arr=@$relational_db_response; |
#my @arr=@$relational_db_response; |
5287 |
my $lastarray=$arr[$#arr]; # if we have several values for this tag, we just want the last one! |
#my $lastarray=$arr[$#arr]; # if we have several values for this tag, we just want the last one! |
5288 |
return @$lastarray; |
#return @$lastarray; |
5289 |
#return @$relational_db_response; |
return @$relational_db_response; |
5290 |
} |
} |
5291 |
elsif (!$tag && ($relational_db_response = $rdbH->SQL("SELECT tag,val,url FROM attribute WHERE ( fid = \'$fid\' )")) && |
elsif (!$tag && ($relational_db_response = $rdbH->SQL("SELECT tag,val,url FROM attribute WHERE ( fid = \'$fid\' )")) && |
5292 |
(@$relational_db_response > 0)) |
(@$relational_db_response > 0)) |
5357 |
Arguments: |
Arguments: |
5358 |
feature id, this can be a peg, genome, etc, |
feature id, this can be a peg, genome, etc, |
5359 |
tag name to delete |
tag name to delete |
5360 |
|
|
5361 |
|
Deleted attributes are stored in global/deleted_attributes |
5362 |
|
|
5363 |
=cut |
=cut |
5364 |
|
|
5365 |
sub delete_attribute { |
sub delete_attribute { |
5366 |
my($self,$peg,$k) = @_; |
my($self,$peg,$k) = @_; |
5367 |
|
# I wonder if we should read/write this file each time so that it is not growing exponentially. |
5368 |
|
if (open(TMPATTR,">>$FIG_Config::global/deleted_attributes")) |
5369 |
|
{ |
5370 |
|
print TMPATTR "$peg\t$k\n"; |
5371 |
|
close(TMPATTR); |
5372 |
|
} |
5373 |
return $self->change_attribute($peg, $k, undef, undef, undef); |
return $self->change_attribute($peg, $k, undef, undef, undef); |
5374 |
} |
} |
5375 |
|
|
5392 |
|
|
5393 |
sub change_attribute { |
sub change_attribute { |
5394 |
my($self,$peg,$k,$v, $url, $file) = @_; |
my($self,$peg,$k,$v, $url, $file) = @_; |
5395 |
unless ($file) {$file="assigned_attributes"} |
if ($v && !$file) {$file="assigned_attributes"} # only use assigned_attributes for changed values, not deleted values |
5396 |
return (0) unless ($peg && $k); # we must have at least a peg and a key. |
return (0) unless ($peg && $k); # we must have at least a peg and a key. |
5397 |
$k =~ s/^\s+//; $k =~ s/\s+$//; $k=uc($k); |
$k =~ s/^\s+//; $k =~ s/\s+$//; $k=uc($k); |
5398 |
my $rdbH = $self->db_handle; |
my $rdbH = $self->db_handle; |
5401 |
# now we can use this to delete things too |
# now we can use this to delete things too |
5402 |
$rdbH->SQL("INSERT INTO attribute ( fid,tag,val,url ) VALUES ( '$peg','$k','$v', '$url')"); |
$rdbH->SQL("INSERT INTO attribute ( fid,tag,val,url ) VALUES ( '$peg','$k','$v', '$url')"); |
5403 |
} |
} |
5404 |
|
if ($file) { |
5405 |
my $location=$self->attribute_location($peg); |
my $location=$self->attribute_location($peg); |
5406 |
&verify_dir("$location"); |
&verify_dir("$location"); |
5407 |
if (open(TMPATTR,">>$location/$file")) |
if (open(TMPATTR,">>$location/$file")) |
5409 |
print TMPATTR "$peg\t$k\t$v\t$url\n"; |
print TMPATTR "$peg\t$k\t$v\t$url\n"; |
5410 |
close(TMPATTR); |
close(TMPATTR); |
5411 |
} |
} |
5412 |
|
} |
5413 |
return 1; |
return 1; |
5414 |
} |
} |
5415 |
|
|