Skip to content

Commit

Permalink
Merge pull request #9 from EMBL-EBI-GCA/dr_faang_seed
Browse files Browse the repository at this point in the history
FAANG seeding changes
  • Loading branch information
davidrichardson committed Jun 29, 2016
2 parents f770110 + b3d0195 commit f8ae446
Show file tree
Hide file tree
Showing 12 changed files with 250 additions and 110 deletions.
12 changes: 10 additions & 2 deletions modules/ReseqTrack/Attribute.pm
Expand Up @@ -15,12 +15,13 @@ sub new{
my ($class, @args) = @_;
my $self = $class->SUPER::new(@args);

my ($table_name, $other_id, $attribute_name, $attribute_value ) =
rearrange([qw(TABLE_NAME OTHER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE ) ], @args);
my ($table_name, $other_id, $attribute_name, $attribute_value, $attribute_units ) =
rearrange([qw(TABLE_NAME OTHER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE ATTRIBUTE_UNITS) ], @args);
$self->table_name($table_name);
$self->other_id($other_id);
$self->attribute_name($attribute_name);
$self->attribute_value($attribute_value);
$self->attribute_units($attribute_units);
return $self;
}

Expand Down Expand Up @@ -69,6 +70,13 @@ sub attribute_value{
return $self->{attribute_value};
}

sub attribute_units{
my ($self, $arg) = @_;
if(defined $arg){
$self->{attribute_units} = $arg;
}
return $self->{attribute_units};
}



Expand Down
14 changes: 10 additions & 4 deletions modules/ReseqTrack/DBSQL/AttributeAdaptor.pm
Expand Up @@ -21,7 +21,7 @@ sub new {

sub columns{
return "attribute.attribute_id, attribute.other_id, attribute.table_name, ".
"attribute.attribute_name, attribute.attribute_value";
"attribute.attribute_name, attribute.attribute_value, attribute.attribute_units";
}

sub table_name{
Expand Down Expand Up @@ -89,7 +89,8 @@ sub store{
$attribute->dbID($exists->dbID);
$attribute->adaptor($self);

if($update && $exists->attribute_value ne $attribute->attribute_value){
if($update &&
($exists->attribute_value ne $attribute->attribute_value || $exists->attribute_units // '' ne $attribute->attribute_units // '')){
$attribute->dbID($exists->dbID);
# print "existing stats id is " . $exists->dbID . "\n";
# print "reassigned stats id is: " . $attribute->dbID . "\n";
Expand All @@ -101,12 +102,13 @@ sub store{


my $sql = "insert into attribute (other_id, table_name, attribute_name, ".
"attribute_value) values(?, ?, ?, ?)";
"attribute_value, attribute_units) values(?, ?, ?, ?, ?)";
my $sth = $self->prepare($sql);
$sth->bind_param(1, $attribute->other_id);
$sth->bind_param(2, $attribute->table_name);
$sth->bind_param(3, $attribute->attribute_name);
$sth->bind_param(4, $attribute->attribute_value);
$sth->bind_param(5, $attribute->attribute_units);
$sth->execute;

my $dbID = $sth->{'mysql_insertid'};
Expand All @@ -125,16 +127,19 @@ sub update{
", other_id = ? ".
", attribute_name = ? ".
", attribute_value = ? ".
", attribute_units = ? ".
"where attribute_id = ? ";
my $sth = $self->prepare($sql);

$sth->bind_param(1, $attribute->table_name);
$sth->bind_param(2, $attribute->other_id);
$sth->bind_param(3, $attribute->attribute_name);
$sth->bind_param(4, $attribute->attribute_value);
$sth->bind_param(5, $attribute->dbID);
$sth->bind_param(5, $attribute->attribute_units);
$sth->bind_param(6, $attribute->dbID);
$sth->execute;
$sth->finish;

return $attribute;
}

Expand All @@ -149,6 +154,7 @@ sub object_from_hashref{
-table_name => $hashref->{table_name},
-attribute_name => $hashref->{attribute_name},
-attribute_value => $hashref->{attribute_value},
-attribute_units => $hashref->{attribute_units},
);
return $attribute;
}
Expand Down
10 changes: 5 additions & 5 deletions modules/ReseqTrack/DBSQL/BaseAdaptor.pm
Expand Up @@ -198,12 +198,12 @@ sub store_attributes{
my ($self, $object, $update) = @_;
throw("Can't store attributes for ".$object." that isnt a ReseqTrack::HasHistory ") unless($object->isa("ReseqTrack::HasHistory"));
my $attr_a = $self->db->get_AttributeAdaptor();

if($object->attributes){
foreach my $statistics(@{$object->attributes}){
$statistics->other_id($object->dbID);
$statistics->table_name($object->object_table_name);
$attr_a->store($statistics, $update);
foreach my $attribute(@{$object->attributes}){
$attribute->other_id($object->dbID);
$attribute->table_name($object->object_table_name);
$attr_a->store($attribute, $update);
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion modules/ReseqTrack/DBSQL/ERA/BaseEraAdaptor.pm
Expand Up @@ -65,14 +65,15 @@ sub attach_attributes_from_xml {

my $key = uc( $element->first_child_text('TAG') );
my $value = $element->first_child_text('VALUE');
my $units = $element->first_child_text('UNITS');

for ( $key, $value ) {
s/^\s+|\s+$//g;
}

if ($value) {
push @attributes,
create_attribute_for_object( $object, $key, $value );
create_attribute_for_object( $object, $key, $value, $units );
}
}
}
Expand Down

0 comments on commit f8ae446

Please sign in to comment.