6810 |
|
|
6811 |
Finally, in the parsing of all files any line beginning with a pound sign is ignored as a comment. |
Finally, in the parsing of all files any line beginning with a pound sign is ignored as a comment. |
6812 |
|
|
6813 |
|
A method, read_attribute_transaction_log, is provided to read the transaction_logs and implement the changes therein. In each of the methods add_attribute, delete_attribute, and change_attribute there is an optional boolean that can be set to prevent writing of the transaction_log. The read_attribute_transaction_log reads the log and then adds/changes/deletes the records as appropriate. Without this boolean there is a circular reference. |
6814 |
|
|
6815 |
=head3 get_attributes |
=head3 get_attributes |
6816 |
|
|
6817 |
Get attributes requires one of four keys: |
Get attributes requires one of four keys: |
6911 |
key name. This is case sensitive and has the leading and trailing white space removed |
key name. This is case sensitive and has the leading and trailing white space removed |
6912 |
value |
value |
6913 |
optional URL to add |
optional URL to add |
6914 |
|
boolean to prevent writing to the transaction log. See above |
6915 |
|
|
6916 |
|
|
6917 |
=cut |
=cut |
6918 |
|
|
6919 |
sub add_attribute { |
sub add_attribute { |
6920 |
my($self,$peg,$k,$v, $url, $file) = @_; |
my($self,$peg,$k,$v, $url, $notl) = @_; |
6921 |
return unless ($peg && $k); # we must have at least a peg and a tag to add (though other things can be undef) |
return unless ($peg && $k); # we must have at least a peg and a tag to add (though other things can be undef) |
6922 |
$k =~ s/^\s+//; $k =~ s/\s+$//; |
$k =~ s/^\s+//; $k =~ s/\s+$//; |
6923 |
my $rdbH = $self->db_handle; |
my $rdbH = $self->db_handle; |
6924 |
$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')"); |
6925 |
my $location=$self->attribute_location($peg); |
my $location=$self->attribute_location($peg); |
6926 |
&verify_dir("$location"); |
&verify_dir("$location"); |
6927 |
if (open(TMPATTR,">>$location/transaction_log")) |
if (!$notl && open(TMPATTR,">>$location/transaction_log")) |
6928 |
{ |
{ |
6929 |
print TMPATTR "ADD\t$peg\t$k\t\t\t$v\t$url\n"; |
print TMPATTR "ADD\t$peg\t$k\t\t\t$v\t$url\n"; |
6930 |
close(TMPATTR); |
close(TMPATTR); |
6939 |
Arguments: |
Arguments: |
6940 |
feature id, this can be a peg, genome, etc, |
feature id, this can be a peg, genome, etc, |
6941 |
key name to delete |
key name to delete |
6942 |
value optional value of the key to be deleted |
optional value of the key to be deleted |
6943 |
|
optional url of the key to be deleted |
6944 |
|
don't write to transaction_log. This is usually false which means that the changes are written to the transaction log. It is set to true when parsing the transaction log. |
6945 |
|
|
6946 |
If the optional value is ommited all keys with this name for this feature will be deleted. Otherwise, only those keys with that value will be deleted. |
If the optional value is ommited all keys with this name for this feature will be deleted. Otherwise, only those keys with that value will be deleted. |
6947 |
|
|
6949 |
=cut |
=cut |
6950 |
|
|
6951 |
sub delete_attribute { |
sub delete_attribute { |
6952 |
my($self,$peg,$k, $oldval) = @_; |
my($self,$peg,$k, $oldval, $oldurl, $notl) = @_; |
6953 |
|
|
6954 |
# get the transaction log |
# get the transaction log |
6955 |
my $location=$self->attribute_location($peg); |
my $location=$self->attribute_location($peg); |
6956 |
&verify_dir("$location"); |
&verify_dir("$location"); |
6957 |
if (open(TMPATTR,">>$location/transaction_log")) |
if (!$notl && open(TMPATTR,">>$location/transaction_log")) |
6958 |
{ |
{ |
6959 |
print TMPATTR "DELETE\t$peg\t$k\t$oldval\n"; |
print TMPATTR "DELETE\t$peg\t$k\t$oldval\n"; |
6960 |
close(TMPATTR); |
close(TMPATTR); |
6961 |
} |
} |
6962 |
return $self->change_attribute($peg, $k, $oldval, undef, undef, undef); |
return $self->change_attribute($peg, $k, $oldval, $oldurl, undef, undef); |
6963 |
} |
} |
6964 |
|
|
6965 |
=head3 change_attribute |
=head3 change_attribute |
6973 |
URL of the original key (optional) |
URL of the original key (optional) |
6974 |
value to replace it with |
value to replace it with |
6975 |
optional URL to add |
optional URL to add |
6976 |
|
don't write to transaction_log. This is usually used when parsing the transaction log to avoid circular references |
6977 |
|
|
6978 |
Returns 1 on success. |
Returns 1 on success. |
6979 |
|
|
6980 |
=cut |
=cut |
6981 |
|
|
6982 |
sub change_attribute { |
sub change_attribute { |
6983 |
my($self,$peg,$k,$oldval, $oldurl, $newval, $newurl) = @_; |
my($self,$peg,$k,$oldval, $oldurl, $newval, $newurl, $notl) = @_; |
6984 |
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. |
6985 |
$k =~ s/^\s+//; $k =~ s/\s+$//; |
$k =~ s/^\s+//; $k =~ s/\s+$//; |
6986 |
my $rdbH = $self->db_handle; |
my $rdbH = $self->db_handle; |
6999 |
# write to the transaction log if we add a new value (writing deletes is handled above) |
# write to the transaction log if we add a new value (writing deletes is handled above) |
7000 |
my $location=$self->attribute_location($peg); |
my $location=$self->attribute_location($peg); |
7001 |
&verify_dir("$location"); |
&verify_dir("$location"); |
7002 |
if (open(TMPATTR,">>$location/transaction_log")) |
if (!$notl && open(TMPATTR,">>$location/transaction_log")) |
7003 |
{ |
{ |
7004 |
print TMPATTR "CHANGE\t$peg\t$oldval\t$oldurl\t$newval\t$newurl\n"; |
print TMPATTR "CHANGE\t$peg\t$oldval\t$oldurl\t$newval\t$newurl\n"; |
7005 |
close(TMPATTR); |
close(TMPATTR); |
7008 |
return 1; |
return 1; |
7009 |
} |
} |
7010 |
|
|
7011 |
|
=head3 read_attribute_transaction_log |
7012 |
|
|
7013 |
|
use: $fig->read_attribute_transaction_log($logfile); |
7014 |
|
|
7015 |
|
This method reads the transaction_log described in $logfile and enacts the changes described therein. The changes must be one of add, delete, or change. |
7016 |
|
|
7017 |
|
=cut |
7018 |
|
|
7019 |
|
sub read_attribute_transaction_log { |
7020 |
|
my ($self, $file)=@_; |
7021 |
|
return unless (-e $file); |
7022 |
|
open(IN, $file) || die "Can't open $file"; |
7023 |
|
while (<IN>) { |
7024 |
|
next if (/^\s*\#/); |
7025 |
|
chomp; |
7026 |
|
my @line=split /\t/; |
7027 |
|
my $type=shift @line; |
7028 |
|
if (uc($type) eq "DELETE") |
7029 |
|
{ |
7030 |
|
$line[4]=1; |
7031 |
|
$self->delete_attribute(@line); |
7032 |
|
} |
7033 |
|
elsif (uc($type) eq "ADD") |
7034 |
|
{ |
7035 |
|
$line[4]=1; |
7036 |
|
$self->add_attribute(@line); |
7037 |
|
} |
7038 |
|
elsif (uc($type) eq "CHANGE") |
7039 |
|
{ |
7040 |
|
$line[7]=1; |
7041 |
|
$self->change_attribute(@line); |
7042 |
|
} |
7043 |
|
else |
7044 |
|
{ |
7045 |
|
print STDERR "Do not understand this line from $file. It doesn't appear to be a transaction record:\n$_\n"; |
7046 |
|
} |
7047 |
|
} |
7048 |
|
} |
7049 |
|
|
7050 |
=head3 erase_attribute_entirely |
=head3 erase_attribute_entirely |
7051 |
|
|
7052 |
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! |
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! |