3 package CXGN
::GEM
::Platform
;
8 use base qw
| CXGN
::DB
::Object
|;
9 use Bio
::Chado
::Schema
;
10 use CXGN
::Biosource
::Schema
;
11 use CXGN
::Biosource
::Sample
;
12 use CXGN
::Metadata
::Metadbdata
;
13 use CXGN
::GEM
::TechnologyType
;
14 use CXGN
::GEM
::Template
;
16 use Carp qw
| croak cluck carp
|;
27 a class to manipulate a platform data from the gem schema.
31 our $VERSION = '0.01';
32 $VERSION = eval $VERSION;
36 use CXGN::GEM::Platform;
40 my $platform = CXGN::GEM::Platform->new($schema, $platform_id);
41 my $platform = CXGN::GEM::Platform->new_by_name($schema, $name);
43 ## Simple accessors (platform_name, technology_type_id, description and contact_id)
45 my $platform_name = $platform->get_platform_name();
46 $platform->set_platform_name($platform_name);
48 ## Advance accessors (platform_design, pub and dbxref)
50 $platform->add_platform_design( $sample_name );
51 my @sample_id_list = $platform->get_design_list();
53 $platform->add_dbxref($dbxref_id);
54 my @dbxref_list_id = $platform->get_publication_list();
56 $platform->add_publication($pub_id);
57 my @pub_id_list = $platform->get_publication_list();
59 ## Metadata objects (also for, platform_design, platform_dbxref and platform_pub)
61 my $metadbdata = $platform->get_platform_metadbdata();
62 unless ($platform->is_experiment_obsolete()) {
68 $platform->store($metadbdata);
70 ## Obsolete (also for platform_design, platform_dbxref and platform_pub)
72 $platform->obsolete_platform($metadata, $note, 'REVERT');
78 This object manage the target information of the database
82 + gem.ge_platform_design
83 + gem.ge_platform_dbxref
86 This data is stored inside this object as dbic rows objects with the
91 ge_platform_row => GePlatform_row,
93 ge_plaform_design => [ @GePlatformDesign_rows ],
95 ge_platform_dbxref_row => [ @GePlatformDbxref_rows ],
97 ge_platform_pub_row => [ @GePlatformPub_rows ],
104 Aureliano Bombarely <ab782@cornell.edu>
109 The following class methods are implemented:
116 ############################
117 ### GENERAL CONSTRUCTORS ###
118 ############################
120 =head2 constructor new
122 Usage: my $platform = CXGN::GEM::Platform->new($schema, $platform_id);
124 Desc: Create a new platform object
126 Ret: a CXGN::GEM::Platform object
128 Args: a $schema a schema object, preferentially created using:
129 CXGN::GEM::Schema->connect(
130 sub{ CXGN::DB::Connection->new()->get_actual_dbh()},
132 A $platform_id, a scalar.
133 If $platform_id is omitted, an empty platform object is created.
135 Side_Effects: access to database, check if exists the database columns that
136 this object use. die if the id is not an integer.
138 Example: my $platform = CXGN::GEM::Platform->new($schema, $platform_id);
144 my $schema = shift ||
145 croak
("PARAMETER ERROR: No schema object was supplied to the $class->new() function.\n");
148 ### First, bless the class to create the object and set the schema into the object
149 ### (set_schema comes from CXGN::DB::Object).
151 my $self = $class->SUPER::new
($schema);
152 $self->set_schema($schema);
154 ### Second, check that ID is an integer. If it is right go and get all the data for
155 ### this row in the database and after that get the data for platform
156 ### If don't find any, create an empty oject.
157 ### If it is not an integer, die
160 my @platform_design_rows = ();
161 my @platform_dbxrefs = ();
162 my @platform_pubs = ();
165 unless ($id =~ m/^\d+$/) { ## The id can be only an integer... so it is better if we detect this fail before.
167 croak
("\nDATA TYPE ERROR: The platform_id ($id) for $class->new() IS NOT AN INTEGER.\n\n");
170 ## Get the ge_platform_row object using a search based in the platform_id
172 ($platform) = $schema->resultset('GePlatform')
173 ->search( { platform_id
=> $id } );
175 if (defined $platform) {
176 ## Search also the platform elements associated to this platform
178 @platform_design_rows = $schema->resultset('GePlatformDesign')
179 ->search( { platform_id
=> $id } );
181 ## Search platform_dbxref associations
183 @platform_dbxrefs = $schema->resultset('GePlatformDbxref')
184 ->search( { platform_id
=> $id } );
186 @platform_pubs = $schema->resultset('GePlatformPub')
187 ->search( { platform_id
=> $id });
190 $platform = $schema->resultset('GePlatform')
191 ->new({}); ### Create an empty object;
195 $platform = $schema->resultset('GePlatform')
196 ->new({}); ### Create an empty object;
199 ## Finally it will load the rows into the object.
200 $self->set_geplatform_row($platform);
201 $self->set_geplatformdesign_rows(\
@platform_design_rows);
202 $self->set_geplatformdbxref_rows(\
@platform_dbxrefs);
203 $self->set_geplatformpub_rows(\
@platform_pubs);
208 =head2 constructor new_by_name
210 Usage: my $platform = CXGN::GEM::Platform->new_by_name($schema, $name);
212 Desc: Create a new Experiment object using platform_name
214 Ret: a CXGN::GEM::Platform object
216 Args: a $schema a schema object, preferentially created using:
217 CXGN::GEM::Schema->connect(
218 sub{ CXGN::DB::Connection->new()->get_actual_dbh()},
220 a $platform_name, a scalar
222 Side_Effects: accesses the database,
223 return a warning if the experiment name do not exists
226 Example: my $platform = CXGN::GEM::Platform->new_by_name($schema, $name);
232 my $schema = shift ||
233 croak
("PARAMETER ERROR: None schema object was supplied to the $class->new_by_name() function.\n");
236 ### It will search the platform_id for this name and it will get the platform_id for that using the new
237 ### method to create a new object. If the name don't exists into the database it will create a empty object and
238 ### it will set the platform_name for it
243 my ($platform_row) = $schema->resultset('GePlatform')
244 ->search({ platform_name
=> $name });
246 unless (defined $platform_row) {
247 warn("DATABASE OUTPUT WARNING: platform_name ($name) for $class->new_by_name() DON'T EXISTS INTO THE DB.\n");
249 ## If do not exists any platform with this name, it will return a warning and it will create an empty
250 ## object with the platform name set in it.
252 $platform = $class->new($schema);
253 $platform->set_platform_name($name);
257 ## if exists it will take the platform_id to create the object with the new constructor
258 $platform = $class->new( $schema, $platform_row->get_column('platform_id') );
262 $platform = $class->new($schema); ### Create an empty object;
268 =head2 constructor new_by_design
270 Usage: my $platform = CXGN::GEM::Platform->new_by_design($schema,
273 Desc: Create a new Platform object using a list of a sample_name used
274 in the design of the platform
276 Ret: a CXGN::GEM::Platform object
278 Args: a $schema a schema object, preferentially created using:
279 CXGN::GEM::Schema->connect(
280 sub{ CXGN::DB::Connection->new()->get_actual_dbh()},
282 a \@sample_names, an array reference with a list of sample
285 Side_Effects: accesses the database,
286 return a warning if the platform name do not exists into the db
288 Example: my $platform = CXGN::GEM::Platform->new_by_design( $schema,
295 my $schema = shift ||
296 croak
("PARAMETER ERROR: None schema object was supplied to the $class->new_by_name() function.\n");
297 my $elements_aref = shift;
299 ### It will search the platform_id for the list of these elements. If find a platform_id it will create a new object with it.
300 ### if not, it will create an empty object and it will add all the elements over the empty object using the add_element_by_name
301 ### function (it will search a element in the database and it will add it to the platform)
305 if (defined $elements_aref) {
306 if (ref($elements_aref) ne 'ARRAY') {
307 croak
("PARAMETER ERROR: The element array reference supplied to $class->new_by_design() method IS NOT AN ARRAY REF.\n");
310 my $elements_n = scalar(@
{$elements_aref});
312 ## First it will change sample_names by sample_ids
316 foreach my $sample_name ( @
{$elements_aref} ) {
317 my $sample_id = CXGN
::Biosource
::Sample
->new_by_name($schema, $sample_name)
319 unless (defined $sample_id) {
320 croak
("DATABASE OUTPUT WARNING: The sample_name=$sample_name do not exists into the biosource.bs_sample_table.");
323 push @sample_ids, $sample_id;
327 ## Dbix::Class search to get an id in a group using the elements of the group
329 my @geplatform_design_row = $schema->resultset('GePlatformDesign')
332 columns
=> ['platform_id'],
333 where
=> { sample_id
=> { -in => \
@sample_ids } },
334 group_by
=> [ qw
/platform_id/ ],
335 having
=> { 'count(platform_design_id)' => { '=', $elements_n } }
339 ## This search will return all the platform_design that contains the elements specified, it will filter
340 ## by the number of element to take only the rows where have all these elements
342 my $geplatform_design_row;
343 foreach my $row (@geplatform_design_row) {
344 my $count = $schema->resultset('GePlatformDesign')
345 ->search( platform_id
=> $row->get_column('platform_id') )
347 if ($count == $elements_n) {
348 $geplatform_design_row = $row;
352 unless (defined $geplatform_design_row) {
354 ## If platform_id don't exists into the db, it will warning with carp and create an empty object
355 warn("DATABASE OUTPUT WARNING: Elements specified haven't a Platform. It'll be created an empty platform object.\n");
356 $platform = $class->new($schema);
358 foreach my $element_name (@
{$elements_aref}) {
359 $platform->add_platform_design($element_name);
363 $platform = $class->new( $schema, $geplatform_design_row->get_column('platform_id') );
369 $platform = $class->new($schema); ### Create an empty object;
376 ##################################
377 ### DBIX::CLASS ROWS ACCESSORS ###
378 ##################################
380 =head2 accessors get_geplatform_row, set_geplatform_row
382 Usage: my $geplatform_row = $self->get_geplatform_row();
383 $self->set_geplatform_row($geplatform_row_object);
385 Desc: Get or set a geplatform row object into a platform
388 Ret: Get => $geplatform_row_object, a row object
389 (CXGN::GEM::Schema::GePlatform).
393 Set => $geplatform_row_object, a row object
394 (CXGN::GEM::Schema::GePlatform).
396 Side_Effects: With set check if the argument is a row object. If fail, dies.
398 Example: my $geplatform_row = $self->get_geplatform_row();
399 $self->set_geplatform_row($geplatform_row);
403 sub get_geplatform_row
{
406 return $self->{geplatform_row
};
409 sub set_geplatform_row
{
411 my $geplatform_row = shift
412 || croak
("FUNCTION PARAMETER ERROR: None geplatform_row object was supplied for $self->set_geplatform_row function.\n");
414 if (ref($geplatform_row) ne 'CXGN::GEM::Schema::GePlatform') {
415 croak
("SET ARGUMENT ERROR: $geplatform_row isn't a geplatform_row obj. (CXGN::GEM::Schema::GePlatform).\n");
417 $self->{geplatform_row
} = $geplatform_row;
420 =head2 accessors get_geplatformdesign_rows, set_geplatformdesign_rows
422 Usage: my @geplatformdesign_rows = $self->get_geplatformdesign_rows();
423 $self->set_geplatformdesign_rows(\@geplatformdesign_rows);
425 Desc: Get or set a geplatformdesign row object into a platform object
426 as hash reference where keys = name and value = row object
428 Ret: Get => An array reference with GePlatformDesign object
432 Set => An array with GePlatformDesign row objects
433 (CXGN::GEM::Schema::GePlatformDesign).
435 Side_Effects: With set check if the argument is a row object. If fail, dies.
437 Example: my @geplatformdesign_rows = $self->get_geplatformdesign_rows();
438 $self->set_geplatformdesign_rows(\@geplatformdesign_rows);
442 sub get_geplatformdesign_rows
{
445 return @
{$self->{geplatformdesign_rows
}};
448 sub set_geplatformdesign_rows
{
450 my $geplatformdesign_aref = shift
451 || croak
("FUNCTION PARAMETER ERROR: None ge_platform_design_row hash ref. was supplied for set_geplatformdesign_row function.\n");
453 if (ref($geplatformdesign_aref) ne 'ARRAY') {
454 croak
("SET ARGUMENT ERROR: array ref. = $geplatformdesign_aref isn't an array reference.\n");
457 my @geplatformdesign = @
{$geplatformdesign_aref};
459 foreach my $element_row (@geplatformdesign) {
460 unless (ref($element_row) eq 'CXGN::GEM::Schema::GePlatformDesign') {
461 croak
("SET ARGUMENT ERROR: row obj = $element_row isn't a row obj. (GePlatformDesign).\n");
465 $self->{geplatformdesign_rows
} = $geplatformdesign_aref;
469 =head2 accessors get_geplatformdbxref_rows, set_geplatformdbxref_rows
471 Usage: my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
472 $self->set_geplatformdbxref_rows(\@geplatformdbxref_rows);
474 Desc: Get or set a list of geplatformdbxref rows object into an
477 Ret: Get => @geplatformdbxref_row_object, a list of row objects
478 (CXGN::GEM::Schema::GePlatformDbxref).
482 Set => \@geplatformdbxref_row_object, an array ref of row objects
483 (CXGN::GEM::Schema::GePlatformDbxref).
485 Side_Effects: With set check if the argument is a row object. If fail, dies.
487 Example: my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
488 $self->set_geplatformdbxref_rows(\@geplatformdbxref_rows);
492 sub get_geplatformdbxref_rows
{
495 return @
{$self->{geplatformdbxref_rows
}};
498 sub set_geplatformdbxref_rows
{
500 my $geplatformdbxref_row_aref = shift
501 || croak
("FUNCTION PARAMETER ERROR:None geplatformdbxref_row array ref was supplied for $self->set_geplatformdbxref_rows().\n");
503 if (ref($geplatformdbxref_row_aref) ne 'ARRAY') {
504 croak
("SET ARGUMENT ERROR: $geplatformdbxref_row_aref isn't an array reference for $self->set_geplatformdbxref_rows().\n");
507 foreach my $geplatformdbxref_row (@
{$geplatformdbxref_row_aref}) {
508 if (ref($geplatformdbxref_row) ne 'CXGN::GEM::Schema::GePlatformDbxref') {
509 croak
("SET ARGUMENT ERROR:$geplatformdbxref_row isn't geplatformdbxref_row obj.\n");
513 $self->{geplatformdbxref_rows
} = $geplatformdbxref_row_aref;
516 =head2 accessors get_geplatformpub_rows, set_geplatformpub_rows
518 Usage: my @geplatformpub_rows = $self->get_geplatformpub_rows();
519 $self->set_geplatformpub_rows(\@geplatformpub_rows);
521 Desc: Get or set a list of geplatformpub rows object into an
524 Ret: Get => @geplatformpub_row_object, a list of row objects
525 (CXGN::GEM::Schema::GePlatformPub).
529 Set => \@geplatformpub_row_object, an array ref of row objects
530 (CXGN::GEM::Schema::GePlatformPub).
532 Side_Effects: With set check if the argument is a row object. If fail, dies.
534 Example: my @geplatformpub_rows = $self->get_geplatformpub_rows();
535 $self->set_geplatformpub_rows(\@geplatformpub_rows);
539 sub get_geplatformpub_rows
{
542 return @
{$self->{geplatformpub_rows
}};
545 sub set_geplatformpub_rows
{
547 my $geplatformpub_row_aref = shift
548 || croak
("FUNCTION PARAMETER ERROR:None geplatformpub_row array ref was supplied for $self->set_geplatformpub_rows().\n");
550 if (ref($geplatformpub_row_aref) ne 'ARRAY') {
551 croak
("SET ARGUMENT ERROR: $geplatformpub_row_aref isn't an array reference for $self->set_geplatformpub_rows().\n");
554 foreach my $geplatformpub_row (@
{$geplatformpub_row_aref}) {
555 if (ref($geplatformpub_row) ne 'CXGN::GEM::Schema::GePlatformPub') {
556 croak
("SET ARGUMENT ERROR:$geplatformpub_row isn't geplatformpub_row obj.\n");
560 $self->{geplatformpub_rows
} = $geplatformpub_row_aref;
563 ###################################
564 ### DATA ACCESSORS FOR PLATFORM ###
565 ###################################
567 =head2 get_platform_id, force_set_platform_id
569 Usage: my $platform_id = $platform->get_platform_id();
570 $platform->force_set_platform_id($platform_id);
572 Desc: get or set a platform_id in a platform object.
573 set method should be USED WITH PRECAUTION
574 If you want set a platform_id that do not exists into the
575 database you should consider that when you store this object you
576 CAN STORE a experiment_id that do not follow the
577 gem.ge_platform_platform_id_seq
579 Ret: get=> $platform_id, a scalar.
583 set=> $platform_id, a scalar (constraint: it must be an integer)
587 Example: my $platform_id = $platform->get_platform_id();
591 sub get_platform_id
{
593 return $self->get_geplatform_row->get_column('platform_id');
596 sub force_set_platform_id
{
599 croak
("FUNCTION PARAMETER ERROR: None platform_id was supplied for force_set_platform_id function");
601 unless ($data =~ m/^\d+$/) {
602 croak
("DATA TYPE ERROR: The platform_id ($data) for $self->force_set_platform_id() ISN'T AN INTEGER.\n");
605 $self->get_geplatform_row()
606 ->set_column( platform_id
=> $data );
610 =head2 accessors get_platform_name, set_platform_name
612 Usage: my $platform_name = $platform->get_platform_name();
613 $platform->set_platform_name($platform_name);
615 Desc: Get or set the platform_name from platform object.
617 Ret: get=> $platform_name, a scalar
621 set=> $platform_name, a scalar
625 Example: my $platform_name = $platform->get_platform_name();
626 $platform->set_platform_name($new_name);
629 sub get_platform_name
{
631 return $self->get_geplatform_row->get_column('platform_name');
634 sub set_platform_name
{
637 || croak
("FUNCTION PARAMETER ERROR: None data was supplied for $self->set_platform_name function.\n");
639 $self->get_geplatform_row()
640 ->set_column( platform_name
=> $data );
643 =head2 accessors get_technology_type_id, set_technology_type_id
645 Usage: my $technology_type_id = $platform->get_technology_type_id();
646 $platform->set_technology_type_id($technology_type_id);
648 Desc: Get or set technology_type_id from a platform object.
650 Ret: get=> $technology_type_id, a scalar
654 set=> $technology_type_id, a scalar
656 Side_Effects: For the set accessor, die if the technology_type_id don't
657 exists into the database
659 Example: my $technology_type_id = $platform->get_technology_type_id();
660 $platform->set_technology_type_id($technology_type_id);
663 sub get_technology_type_id
{
665 return $self->get_geplatform_row->get_column('technology_type_id');
668 sub set_technology_type_id
{
671 || croak
("FUNCTION PARAMETER ERROR: None data was supplied for $self->set_technology_type function.\n");
673 unless ($data =~ m/^\d+$/) {
674 croak
("DATA TYPE ERROR: The technology_type_id ($data) for $self->set_technology_type_id() ISN'T AN INTEGER.\n");
677 $self->get_geplatform_row()
678 ->set_column( technology_type_id
=> $data );
681 =head2 accessors get_description, set_description
683 Usage: my $description = $platform->get_description();
684 $platform->set_description($description);
686 Desc: Get or set description from a platform object.
688 Ret: get=> $description, a scalar
692 set=> $description, a scalar
696 Example: my $description = $platform->get_description();
697 $platform->set_description($description);
700 sub get_description
{
702 return $self->get_geplatform_row->get_column('description');
705 sub set_description
{
709 $self->get_geplatform_row()
710 ->set_column( description
=> $data );
713 =head2 get_contact_id, set_contact_id
715 Usage: my $contact_id = $platform->get_contact_id();
716 $platform->set_contact_id($contact_id);
718 Desc: get or set a contact_id in a platform object.
720 Ret: get=> $contact_id, a scalar.
724 set=> $contact_id, a scalar (constraint: it must be an integer)
726 Side_Effects: die if the argument supplied is not an integer
728 Example: my $contact_id = $platform->get_contact_id();
734 return $self->get_geplatform_row->get_column('contact_id');
741 unless ($data =~ m/^\d+$/) {
742 croak
("DATA TYPE ERROR: The contact_id ($data) for $self->set_contact_id() ISN'T AN INTEGER.\n");
745 $self->get_geplatform_row()
746 ->set_column( contact_id
=> $data );
750 =head2 get_contact_by_username, set_contact_by_username
752 Usage: my $contact_username = $platform->get_contact_by_username();
753 $platform->set_contact_by_username($contact_username);
755 Desc: get or set a contact_id in a platform object using username
757 Ret: get=> $contact_username, a scalar.
761 set=> $contact_username, a scalar (constraint: it must be an integer)
763 Side_Effects: die if the argument supplied is not an integer
765 Example: my $contact = $platform->get_contact_by_username();
769 sub get_contact_by_username
{
772 my $contact_id = $self->get_geplatform_row
773 ->get_column('contact_id');
775 if (defined $contact_id) {
777 ## This is a temp simple SQL query. It should be replaced by DBIx::Class search when the person module will be developed
779 my $query = "SELECT username FROM sgn_people.sp_person WHERE sp_person_id = ?";
780 my ($username) = $self->get_schema()
783 ->selectrow_array($query, undef, $contact_id);
785 unless (defined $username) {
786 croak
("DATABASE INTEGRITY ERROR: sp_person_id=$contact_id defined in gem.ge_platform don't exists in sp_person table.\n")
794 sub set_contact_by_username
{
797 croak
("SET ARGUMENT ERROR: None argument was supplied to the $self->set_contact_by_username function.\n");
799 my $query = "SELECT sp_person_id FROM sgn_people.sp_person WHERE username = ?";
800 my ($contact_id) = $self->get_schema()
803 ->selectrow_array($query, undef, $data);
805 unless (defined $contact_id) {
806 croak
("DATABASE COHERENCE ERROR: username=$data supplied to function set_contact_by_username don't exists in sp_person table.\n");
809 $self->get_geplatform_row()
810 ->set_column( contact_id
=> $contact_id );
818 ##########################################
819 ### DATA ACCESSORS FOR PLATFORM DESIGN ###
820 ##########################################
822 =head2 add_platform_design
824 Usage: $platform->add_platform_design( $sample_name );
826 Desc: Add a new platform design element to the platform object
830 Args: A scalar with the sample_name
832 Side_Effects: Die if the sample_name don't exists into the database
834 Example: $platform->add_platform_design('tomato_unigene_dataset');
838 sub add_platform_design
{
840 my $scalar = shift ||
841 croak
("FUNCTION PARAMETER ERROR: None data was supplied for $self->add_platform_design function.\n");
843 my $platformdesign_row;
845 ## Search in the database a sample name (biosource tables) and get the sample_id. Die if don't find anything.
847 my ($sample_row) = $self->get_schema()
848 ->resultset('BsSample')
849 ->search( { sample_name
=> $scalar } );
850 if (defined $sample_row) {
851 my $sample_id = $sample_row->get_column('sample_id');
853 $platformdesign_row = $self->get_schema()
854 ->resultset('GePlatformDesign')
855 ->new({ sample_id
=> $sample_id});
857 if (defined $self->get_platform_id() ) {
858 $platformdesign_row->set_column( platform_id
=> $self->get_platform_id() );
862 croak
("DATABASE COHERENCE ERROR for add_platform_design: Sample_name ($scalar) don't exists in database.\n");
865 my @platformdesign_rows = $self->get_geplatformdesign_rows();
866 push @platformdesign_rows, $platformdesign_row;
867 $self->set_geplatformdesign_rows(\
@platformdesign_rows);
870 =head2 get_design_list
872 Usage: my @design_list_id = $platform->get_design_list();
874 Desc: Get a list of sample_names associated to this platform.
876 Ret: An array of scalars (sample_id by default)
878 Args: None or a column to get ('sample_name').
882 Example: my @sample_id_list = $platform->get_design_list();
883 my @sample_name_list = $platform->get_design_list('sample_name');
887 sub get_design_list
{
891 my @design_list = ();
893 my @platformdesign_rows = $self->get_geplatformdesign_rows();
894 foreach my $platformdesign_row (@platformdesign_rows) {
895 my $sample_id = $platformdesign_row->get_column('sample_id');
897 if (defined $field && $field =~ m/sample_name/i) {
898 my ($sample_row) = $self->get_schema()
899 ->resultset('BsSample')
900 ->search( { sample_id
=> $sample_id } );
901 if (defined $sample_row) {
902 my $sample_name = $sample_row->get_column('sample_name');
903 push @design_list, $sample_name;
907 push @design_list, $sample_id;
915 ##########################################
916 ### DATA ACCESSORS FOR PLATFORM DBXREF ###
917 ##########################################
921 Usage: $platform->add_dbxref($dbxref_id);
923 Desc: Add a dbxref to the dbxref_ids associated to sample
924 object using dbxref_id or accesion + database_name
928 Args: $dbxref_id, a dbxref id.
929 To use with accession and dbxname:
930 $platform->add_dbxref(
932 accession => $accesssion,
937 Side_Effects: die if the parameter is not an hash reference
939 Example: $platform->add_dbxref($dbxref_id);
940 $platform->add_dbxref(
942 accession => 'GSE3380',
943 dbxname => 'GEO Accession Display',
950 my $dbxref = shift ||
951 croak
("FUNCTION PARAMETER ERROR: None dbxref data was supplied for $self->add_dbxref function.\n");
955 ## If the imput parameter is an integer, treat it as id, if not do it as hash reference
957 if ($dbxref =~ m/^\d+$/) {
958 $dbxref_id = $dbxref;
960 elsif (ref($dbxref) eq 'HASH') {
961 if (exists $dbxref->{'dbxname'}) {
962 my ($db_row) = $self->get_schema()
963 ->resultset('General::Db')
964 ->search( { name
=> $dbxref->{'dbxname'} });
965 if (defined $db_row) {
966 my $db_id = $db_row->get_column('db_id');
968 my ($dbxref_row) = $self->get_schema()
969 ->resultset('General::Dbxref')
972 accession
=> $dbxref->{'accession'},
976 if (defined $dbxref_row) {
977 $dbxref_id = $dbxref_row->get_column('dbxref_id');
980 croak
("DATABASE ARGUMENT ERROR: accession specified as argument in function $self->add_dbxref dont exists in db.\n");
984 croak
("DATABASE ARGUMENT ERROR: dbxname specified as argument in function $self->add_dbxref dont exists in db.\n");
988 croak
("INPUT ARGUMENT ERROR: None dbxname was supplied as hash ref. argument in the function $self->add_dbxref.\n ");
992 croak
("SET ARGUMENT ERROR: The dbxref ($dbxref) isn't a dbxref_id, or hash ref. with accession and dbxname keys.\n");
995 my $platformdbxref_row = $self->get_schema()
996 ->resultset('GePlatformDbxref')
997 ->new({ dbxref_id
=> $dbxref_id});
999 if (defined $self->get_platform_id() ) {
1000 $platformdbxref_row->set_column( platform_id
=> $self->get_platform_id() );
1003 my @platformdbxref_rows = $self->get_geplatformdbxref_rows();
1004 push @platformdbxref_rows, $platformdbxref_row;
1005 $self->set_geplatformdbxref_rows(\
@platformdbxref_rows);
1008 =head2 get_dbxref_list
1010 Usage: my @dbxref_list_id = $platform->get_publication_list();
1012 Desc: Get a list of dbxref_id associated to this platform.
1014 Ret: An array of dbxref_id
1016 Args: None or a column to get.
1018 Side_Effects: die if the parameter is not an object
1020 Example: my @dbxref_id_list = $platform->get_dbxref_list();
1024 sub get_dbxref_list
{
1027 my @dbxref_list = ();
1029 my @platformdbxref_rows = $self->get_geplatformdbxref_rows();
1030 foreach my $platformdbxref_row (@platformdbxref_rows) {
1031 my $dbxref_id = $platformdbxref_row->get_column('dbxref_id');
1032 push @dbxref_list, $dbxref_id;
1035 return @dbxref_list;
1038 #########################################
1039 ### DATA ACCESSORS FOR PLATFORMS PUBS ###
1040 #########################################
1042 =head2 add_publication
1044 Usage: $platform->add_publication($pub_id);
1046 Desc: Add a publication to the pub_ids associated to platform
1047 object using different arguments as pub_id, title or dbxref_accession
1051 Args: $pub_id, a publication id.
1052 To use with $pub_id:
1053 $platform->add_publication($pub_id);
1054 To use with $pub_title
1055 $platform->add_publication({ title => $pub_title } );
1056 To use with pubmed accession
1057 $platform->add_publication({ dbxref_accession => $accesssion});
1059 Side_Effects: die if the parameter is not an object
1061 Example: $platform->add_publication($pub_id);
1065 sub add_publication
{
1068 croak
("FUNCTION PARAMETER ERROR: None pub was supplied for $self->add_publication function.\n");
1071 if ($pub =~ m/^\d+$/) {
1074 elsif (ref($pub) eq 'HASH') {
1076 if (exists $pub->{'title'}) {
1077 ($pub_row) = $self->get_schema()
1078 ->resultset('Pub::Pub')
1079 ->search( {title
=> { 'ilike', '%' . $pub->{'title'} . '%' } });
1081 elsif (exists $pub->{'dbxref_accession'}) {
1082 ($pub_row) = $self->get_schema()
1083 ->resultset('Pub::Pub')
1085 { 'dbxref.accession' => $pub->{'dbxref_accession'} },
1086 { join => { 'pub_dbxrefs' => 'dbxref' } },
1091 unless (defined $pub_row) {
1092 croak
("DATABASE ARGUMENT ERROR: Publication data used as argument for $self->add_publication function don't exists in DB.\n");
1094 $pub_id = $pub_row->get_column('pub_id');
1098 croak
("SET ARGUMENT ERROR: The publication ($pub) isn't a pub_id, or hash with title or dbxref_accession keys.\n");
1100 my $geplatformpub_row = $self->get_schema()
1101 ->resultset('GePlatformPub')
1102 ->new({ pub_id
=> $pub_id});
1104 if (defined $self->get_platform_id() ) {
1105 $geplatformpub_row->set_column( platform_id
=> $self->get_platform_id() );
1108 my @geplatformpub_rows = $self->get_geplatformpub_rows();
1109 push @geplatformpub_rows, $geplatformpub_row;
1110 $self->set_geplatformpub_rows(\
@geplatformpub_rows);
1113 =head2 get_publication_list
1115 Usage: my @pub_list = $platform->get_publication_list();
1117 Desc: Get a list of publications associated to this experimental design.
1119 Ret: An array of pub_ids by default, but can be titles
1120 or accessions using an argument 'title' or 'dbxref.accession'
1122 Args: None or a column to get.
1124 Side_Effects: die if the parameter is not an object
1126 Example: my @pub_id_list = $platform->get_publication_list();
1127 my @pub_title_list = $platform->get_publication_list('title');
1128 my @pub_title_accs = $platform->get_publication_list('dbxref.accession');
1133 sub get_publication_list
{
1139 my @platformpub_rows = $self->get_geplatformpub_rows();
1140 foreach my $platformpub_row (@platformpub_rows) {
1141 my $pub_id = $platformpub_row->get_column('pub_id');
1142 my ($pub_row) = $self->get_schema()
1143 ->resultset('Pub::Pub')
1145 { 'me.pub_id' => $pub_id },
1147 '+select' => ['dbxref.accession'],
1148 '+as' => ['accession'],
1149 join => { 'pub_dbxrefs' => 'dbxref' },
1153 if (defined $field) {
1154 push @pub_list, $pub_row->get_column($field);
1157 push @pub_list, $pub_row->get_column('pub_id');
1165 #####################################
1166 ### METADBDATA ASSOCIATED METHODS ###
1167 #####################################
1169 =head2 accessors get_platform_metadbdata
1171 Usage: my $metadbdata = $platform->get_platform_metadbdata();
1173 Desc: Get metadata object associated to platform data
1174 (see CXGN::Metadata::Metadbdata).
1176 Ret: A metadbdata object (CXGN::Metadata::Metadbdata)
1178 Args: Optional, a metadbdata object to transfer metadata creation variables
1182 Example: my $metadbdata = $platform->get_platform_metadbdata();
1183 my $metadbdata = $platform->get_platform_metadbdata($metadbdata);
1187 sub get_platform_metadbdata
{
1189 my $metadata_obj_base = shift;
1192 my $metadata_id = $self->get_geplatform_row
1193 ->get_column('metadata_id');
1195 if (defined $metadata_id) {
1196 $metadbdata = CXGN
::Metadata
::Metadbdata
->new($self->get_schema(), undef, $metadata_id);
1197 if (defined $metadata_obj_base) {
1199 ## This will transfer the creation data from the base object to the new one
1200 $metadbdata->set_object_creation_date($metadata_obj_base->get_object_creation_date());
1201 $metadbdata->set_object_creation_user($metadata_obj_base->get_object_creation_user());
1206 ## If do not exists the metadata_id, check the possible reasons.
1207 my $platform_id = $self->get_platform_id();
1208 if (defined $platform_id) {
1209 croak
("DATABASE INTEGRITY ERROR: The metadata_id for the platform_id=$platform_id is undefined.\n");
1212 croak
("OBJECT MANAGEMENT ERROR: Object haven't defined any platform_id. Probably it hasn't been stored yet.\n");
1219 =head2 is_platform_obsolete
1221 Usage: $platform->is_platform_obsolete();
1223 Desc: Get obsolete field form metadata object associated to
1224 protocol data (see CXGN::Metadata::Metadbdata).
1226 Ret: 0 -> false (it is not obsolete) or 1 -> true (it is obsolete)
1232 Example: unless ($platform->is_experiment_obsolete()) {
1238 sub is_platform_obsolete
{
1241 my $metadbdata = $self->get_platform_metadbdata();
1242 my $obsolete = $metadbdata->get_obsolete();
1244 if (defined $obsolete) {
1252 =head2 accessors get_platform_design_metadbdata
1254 Usage: my %metadbdata = $platform->get_platform_design_metadbdata();
1256 Desc: Get metadata object associated to platform row
1257 (see CXGN::Metadata::Metadbdata).
1259 Ret: A hash with key=sample_name and value=metadbdata object
1260 (CXGN::Metadata::Metadbdata)
1262 Args: Optional, a metadbdata object to transfer metadata creation variables
1266 Example: my %metadbdata = $platform->get_platform_design_metadbdata();
1267 my %metadbdata = $platform->get_platform_design_metadbdata($metadbdata);
1268 my $metadbdata_1 = $metadbdata{'sample_name1'};
1272 sub get_platform_design_metadbdata
{
1274 my $metadata_obj_base = shift;
1277 my @platformdesign_rows = $self->get_geplatformdesign_rows();
1279 my $platform_id = $self->get_platform_id();
1280 unless (defined $platform_id) {
1281 croak
("OBJECT MANIPULATION ERROR: The object $self haven't any platform_id associated. Probably it hasn't been stored\n");
1284 foreach my $platformdesign_row (@platformdesign_rows) {
1286 my $metadata_id = $platformdesign_row->get_column('metadata_id');
1287 my $sample_id = $platformdesign_row->get_column('sample_id');
1289 unless (defined $sample_id) {
1290 croak
("OBJECT COHERENCE ERROR: The GePlatformDesign row for the get_platform_design_metadbdata() haven't any sample_id.\n");
1295 my ($sample) = $self->get_schema()
1296 ->resultset('BsSample')
1297 ->search({ sample_id
=> $sample_id });
1300 if (defined $sample) {
1301 $sample_name = $sample->get_column('sample_name');
1304 croak
("DATABASE COHERENCE ERROR: The sample_id=$sample_id from the platform_design row doesn't exists into the database.");
1307 if (defined $metadata_id) {
1308 $metadbdata = CXGN
::Metadata
::Metadbdata
->new($self->get_schema(), undef, $metadata_id);
1309 if (defined $metadata_obj_base) {
1311 ## This will transfer the creation data from the base object to the new one
1312 $metadbdata->set_object_creation_date($metadata_obj_base->get_object_creation_date());
1313 $metadbdata->set_object_creation_user($metadata_obj_base->get_object_creation_user());
1315 $metadbdata{$sample_name} = $metadbdata;
1318 croak
("DATABASE INTEGRITY ERROR: metadata_id for sample_name=$sample_name (sample_id=$sample_id) is undefined.\n");
1325 =head2 is_platform_design_obsolete
1327 Usage: $platform->is_platform_design_obsolete($element_name);
1329 Desc: Get obsolete field form metadata object associated to
1330 platform data (see CXGN::Metadata::Metadbdata).
1332 Ret: 0 -> false (it is not obsolete) or 1 -> true (it is obsolete)
1334 Args: $element_name, a scalar, the name for the platform element in the
1339 Example: unless ($platform->is_platform_design_obsolete($element_name)) {
1345 sub is_platform_design_obsolete
{
1347 my $element_name = shift;
1350 if (defined $element_name) {
1351 my %metadbdata = $self->get_platform_design_metadbdata();
1352 my $obsolete = $metadbdata{$element_name}->get_obsolete();
1354 if (defined $obsolete) {
1366 =head2 accessors get_platform_dbxref_metadbdata
1368 Usage: my %metadbdata = $platform->get_platform_dbxref_metadbdata();
1370 Desc: Get metadata object associated to tool data
1371 (see CXGN::Metadata::Metadbdata).
1373 Ret: A hash with keys=dbxref_id and values=metadbdata object
1374 (CXGN::Metadata::Metadbdata) for dbxref relation
1376 Args: Optional, a metadbdata object to transfer metadata creation variables
1380 Example: my %metadbdata = $platform->get_platform_dbxref_metadbdata();
1382 $platform->get_platform_dbxref_metadbdata($metadbdata);
1386 sub get_platform_dbxref_metadbdata
{
1388 my $metadata_obj_base = shift;
1391 my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
1393 foreach my $geplatformdbxref_row (@geplatformdbxref_rows) {
1394 my $dbxref_id = $geplatformdbxref_row->get_column('dbxref_id');
1395 my $metadata_id = $geplatformdbxref_row->get_column('metadata_id');
1397 if (defined $metadata_id) {
1398 my $metadbdata = CXGN
::Metadata
::Metadbdata
->new($self->get_schema(), undef, $metadata_id);
1399 if (defined $metadata_obj_base) {
1401 ## This will transfer the creation data from the base object to the new one
1402 $metadbdata->set_object_creation_date($metadata_obj_base->get_object_creation_date());
1403 $metadbdata->set_object_creation_user($metadata_obj_base->get_object_creation_user());
1405 $metadbdata{$dbxref_id} = $metadbdata;
1408 my $platform_dbxref_id = $geplatformdbxref_row->get_column('platform_dbxref_id');
1409 unless (defined $platform_dbxref_id) {
1410 croak
("OBJECT MANIPULATION ERROR: Object $self haven't any platform_dbxref_id. Probably it hasn't been stored\n");
1413 croak
("DATABASE INTEGRITY ERROR: metadata_id for the platform_dbxref_id=$platform_dbxref_id is undefined.\n");
1420 =head2 is_platform_dbxref_obsolete
1422 Usage: $platform->is_platform_dbxref_obsolete($dbxref_id);
1424 Desc: Get obsolete field form metadata object associated to
1425 protocol data (see CXGN::Metadata::Metadbdata).
1427 Ret: 0 -> false (it is not obsolete) or 1 -> true (it is obsolete)
1429 Args: $dbxref_id, a dbxref_id
1433 Example: unless ($platform->is_platform_dbxref_obsolete($dbxref_id)){
1439 sub is_platform_dbxref_obsolete
{
1441 my $dbxref_id = shift;
1443 my %metadbdata = $self->get_platform_dbxref_metadbdata();
1444 my $metadbdata = $metadbdata{$dbxref_id};
1447 if (defined $metadbdata) {
1448 $obsolete = $metadbdata->get_obsolete() || 0;
1453 =head2 accessors get_platform_pub_metadbdata
1455 Usage: my %metadbdata = $platform->get_platform_pub_metadbdata();
1457 Desc: Get metadata object associated to tool data
1458 (see CXGN::Metadata::Metadbdata).
1460 Ret: A hash with keys=pub_id and values=metadbdata object
1461 (CXGN::Metadata::Metadbdata) for dbxref relation
1463 Args: Optional, a metadbdata object to transfer metadata creation variables
1467 Example: my %metadbdata = $platform->get_platform_pub_metadbdata();
1468 my %metadbdata = $platform->get_platform_pub_metadbdata($metadbdata);
1472 sub get_platform_pub_metadbdata
{
1474 my $metadata_obj_base = shift;
1477 my @geplatformpub_rows = $self->get_geplatformpub_rows();
1479 foreach my $geplatformpub_row (@geplatformpub_rows) {
1480 my $pub_id = $geplatformpub_row->get_column('pub_id');
1481 my $metadata_id = $geplatformpub_row->get_column('metadata_id');
1483 if (defined $metadata_id) {
1484 my $metadbdata = CXGN
::Metadata
::Metadbdata
->new($self->get_schema(), undef, $metadata_id);
1485 if (defined $metadata_obj_base) {
1487 ## This will transfer the creation data from the base object to the new one
1488 $metadbdata->set_object_creation_date($metadata_obj_base->get_object_creation_date());
1489 $metadbdata->set_object_creation_user($metadata_obj_base->get_object_creation_user());
1491 $metadbdata{$pub_id} = $metadbdata;
1494 my $platform_pub_id = $geplatformpub_row->get_column('platform_pub_id');
1495 unless (defined $platform_pub_id) {
1496 croak
("OBJECT MANIPULATION ERROR: Object $self haven't any platform_pub_id. Probably it hasn't been stored\n");
1499 croak
("DATABASE INTEGRITY ERROR: metadata_id for the platform_pub_id=$platform_pub_id is undefined.\n");
1506 =head2 is_platform_pub_obsolete
1508 Usage: $platform->is_platform_dbxref_obsolete($pub_id);
1510 Desc: Get obsolete field form metadata object associated to
1511 protocol data (see CXGN::Metadata::Metadbdata).
1513 Ret: 0 -> false (it is not obsolete) or 1 -> true (it is obsolete)
1515 Args: $pub_id, a pub_id
1519 Example: unless ($platform->is_platform_pub_obsolete($pub_id)){
1525 sub is_platform_pub_obsolete
{
1529 my %metadbdata = $self->get_platform_pub_metadbdata();
1530 my $metadbdata = $metadbdata{$pub_id};
1533 if (defined $metadbdata) {
1534 $obsolete = $metadbdata->get_obsolete() || 0;
1541 #######################
1542 ### STORING METHODS ###
1543 #######################
1548 Usage: $platform->store($metadbdata);
1550 Desc: Store in the database the all platform data for the
1552 See the methods store_platform, store_platform_design,
1553 store_dbxref_associations and store_pub_associations for more details
1557 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1559 Side_Effects: Die if:
1560 1- None metadata object is supplied.
1561 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1564 Example: $platform->store($metadata);
1571 ## FIRST, check the metadata_id supplied as parameter
1572 my $metadata = shift
1573 || croak
("STORE ERROR: None metadbdata object was supplied to $self->store().\n");
1575 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1576 croak
("STORE ERROR: Metadbdata supplied to $self->store() is not CXGN::Metadata::Metadbdata object.\n");
1579 ## SECOND, the store functions return the updated object, so it will chain the different store functions
1581 $self->store_platform($metadata);
1582 $self->store_platform_designs($metadata);
1583 $self->store_dbxref_associations($metadata);
1584 $self->store_pub_associations($metadata);
1588 =head2 store_platform
1590 Usage: $platform->store_platform($metadata);
1592 Desc: Store in the database the platform data for the platform
1593 object (Only the geplatform row, don't store any
1594 platform_dbxref or platform_design data)
1598 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1600 Side_Effects: Die if:
1601 1- None metadata object is supplied.
1602 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1605 Example: $platform->store_platform($metadata);
1609 sub store_platform
{
1612 ## FIRST, check the metadata_id supplied as parameter
1613 my $metadata = shift
1614 || croak
("STORE ERROR: None metadbdata object was supplied to $self->store_platform().\n");
1616 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1617 croak
("STORE ERROR: Metadbdata supplied to $self->store_platform() is not CXGN::Metadata::Metadbdata object.\n");
1620 ## It is not necessary check the current user used to store the data because should be the same than the used
1621 ## to create a metadata_id. In the medadbdata object, it is checked.
1623 ## SECOND, check if exists or not platform_id.
1624 ## if exists platform_id => update
1625 ## if do not exists platform_id => insert
1627 my $geplatform_row = $self->get_geplatform_row();
1628 my $platform_id = $geplatform_row->get_column('platform_id');
1630 unless (defined $platform_id) { ## NEW INSERT and DISCARD CHANGES
1633 my $metadata_id = $metadata->get_metadata_id();
1635 $geplatform_row->set_column( metadata_id
=> $metadata_id ); ## Set the metadata_id column
1637 $geplatform_row->insert()
1638 ->discard_changes(); ## It will set the row with the updated row
1640 ## Now we set the platform_id value for all the rows that depends of it
1642 my @geplatformdesign_rows = $self->get_geplatformdesign_rows();
1643 foreach my $geplatformdesign_row (@geplatformdesign_rows) {
1644 $geplatformdesign_row->set_column( platform_id
=> $geplatform_row->get_column('platform_id'));
1647 my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
1648 foreach my $geplatformdbxref_row (@geplatformdbxref_rows) {
1649 $geplatformdbxref_row->set_column( platform_id
=> $geplatform_row->get_column('platform_id'));
1652 my @geplatformpub_rows = $self->get_geplatformpub_rows();
1653 foreach my $geplatformpub_row (@geplatformpub_rows) {
1654 $geplatformpub_row->set_column( platform_id
=> $geplatform_row->get_column('platform_id'));
1659 else { ## UPDATE IF SOMETHING has change
1661 my @columns_changed = $geplatform_row->is_changed();
1663 if (scalar(@columns_changed) > 0) { ## ...something has change, it will take
1665 my @modification_note_list; ## the changes and the old metadata object for
1666 foreach my $col_changed (@columns_changed) { ## this dbiref and it will create a new row
1667 push @modification_note_list, "set value in $col_changed column";
1670 my $modification_note = join ', ', @modification_note_list;
1672 my $mod_metadata = $self->get_platform_metadbdata($metadata);
1673 $mod_metadata->store({ modification_note
=> $modification_note });
1674 my $mod_metadata_id = $mod_metadata->get_metadata_id();
1676 $geplatform_row->set_column( metadata_id
=> $mod_metadata_id );
1678 $geplatform_row->update()
1679 ->discard_changes();
1685 =head2 obsolete_platform
1687 Usage: $platform->obsolete_platform($metadata, $note, 'REVERT');
1689 Desc: Change the status of a data to obsolete.
1690 If revert tag is used the obsolete status will be reverted to 0 (false)
1694 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1695 $note, a note to explain the cause of make this data obsolete
1698 Side_Effects: Die if:
1699 1- None metadata object is supplied.
1700 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1702 Example: $platform->obsolete_platform($metadata, 'change to obsolete test');
1706 sub obsolete_platform
{
1709 ## FIRST, check the metadata_id supplied as parameter
1711 my $metadata = shift
1712 || croak
("OBSOLETE ERROR: None metadbdata object was supplied to $self->obsolete_platform().\n");
1714 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1715 croak
("OBSOLETE ERROR: Metadbdata obj. supplied to $self->obsolete_platform isn't CXGN::Metadata::Metadbdata obj.\n");
1718 my $obsolete_note = shift
1719 || croak
("OBSOLETE ERROR: None obsolete note was supplied to $self->obsolete_platform().\n");
1721 my $revert_tag = shift;
1724 ## If exists the tag revert change obsolete to 0
1727 my $modification_note = 'change to obsolete';
1728 if (defined $revert_tag && $revert_tag =~ m/REVERT/i) {
1730 $modification_note = 'revert obsolete';
1733 ## Create a new metadata with the obsolete tag
1735 my $mod_metadata = $self->get_platform_metadbdata($metadata);
1736 $mod_metadata->store( { modification_note
=> $modification_note,
1737 obsolete
=> $obsolete,
1738 obsolete_note
=> $obsolete_note } );
1739 my $mod_metadata_id = $mod_metadata->get_metadata_id();
1741 ## Modify the group row in the database
1743 my $geplatform_row = $self->get_geplatform_row();
1745 $geplatform_row->set_column( metadata_id
=> $mod_metadata_id );
1747 $geplatform_row->update()
1748 ->discard_changes();
1751 =head2 store_platform_designs
1753 Usage: my $platform = $platform->store_platform_designs($metadata);
1755 Desc: Store in the database platform_designs associated to a platform
1759 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1761 Side_Effects: Die if:
1762 1- None metadata object is supplied.
1763 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1766 Example: my $platform = $platform->store_platform_designs($metadata);
1770 sub store_platform_designs
{
1773 ## FIRST, check the metadata_id supplied as parameter
1774 my $metadata = shift
1775 || croak
("STORE ERROR: None metadbdata object was supplied to $self->store_platform_designs().\n");
1777 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1778 croak
("STORE ERROR: Metadbdata supplied to $self->store_platform_designs() is not CXGN::Metadata::Metadbdata object.\n");
1781 ## It is not necessary check the current user used to store the data because should be the same than the used
1782 ## to create a metadata_id. In the medadbdata object, it is checked.
1784 ## SECOND, check if exists or not platform_designs_id.
1785 ## if exists platform_designs_id => update
1786 ## if do not exists platform_designs_id => insert
1788 my $platform_id = $self->get_platform_id();
1790 unless (defined $platform_id) {
1791 croak
("STORE ERROR: Don't exist platform_id associated to this step.Use store_platform before use store_platform_designs.\n");
1794 my @geplatformdesigns_rows = $self->get_geplatformdesign_rows();
1796 foreach my $geplatformdesign_row (@geplatformdesigns_rows) {
1797 my $platform_design_id = $geplatformdesign_row->get_column('platform_design_id');
1799 unless (defined $platform_design_id) { ## NEW INSERT and DISCARD CHANGES
1801 my $metadata_id = $metadata->store()
1802 ->get_metadata_id();
1804 $geplatformdesign_row->set_column( metadata_id
=> $metadata_id ); ## Set the metadata_id column
1806 $geplatformdesign_row->insert()
1807 ->discard_changes(); ## It will set the row with the updated row
1809 else { ## UPDATE IF SOMETHING has change
1811 my @columns_changed = $geplatformdesign_row->is_changed();
1813 if (scalar(@columns_changed) > 0) { ## ...something has change, it will take
1815 my @modification_note_list; ## the changes and the old metadata object for
1816 foreach my $col_changed (@columns_changed) { ## this dbiref and it will create a new row
1817 push @modification_note_list, "set value in $col_changed column";
1820 my $modification_note = join ', ', @modification_note_list;
1822 my %se_metadata = $self->get_platform_design_metadbdata($metadata);
1823 my $element_name = $geplatformdesign_row->get_column('platform_design_name');
1824 my $mod_metadata_id = $se_metadata{$element_name}->store({ modification_note
=> $modification_note })
1825 ->get_metadata_id();
1827 $geplatformdesign_row->set_column( metadata_id
=> $mod_metadata_id );
1829 $geplatformdesign_row->update()
1830 ->discard_changes();
1836 =head2 obsolete_platform_design
1838 Usage: my $platform = $platform->obsolete_platform_design( $metadata,
1844 Desc: Change the status of a data to obsolete.
1845 If revert tag is used the obsolete status will
1846 be reverted to 0 (false)
1850 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1851 $note, a note to explain the cause of make this data obsolete
1852 $element_name, the sample_element_name that identify this sample_element
1855 Side_Effects: Die if:
1856 1- None metadata object is supplied.
1857 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1859 Example: my $platform = $platform->obsolete_platform_design( $metadata,
1860 change to obsolete',
1865 sub obsolete_platform_design
{
1868 ## FIRST, check the metadata_id supplied as parameter
1870 my $metadata = shift
1871 || croak
("OBSOLETE ERROR: None metadbdata object was supplied to $self->obsolete_platform_design().\n");
1873 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1874 croak
("OBSOLETE ERROR: Metadbdata object supplied to $self->obsolete_platform_design is not CXGN::Metadata::Metadbdata obj.\n");
1877 my $obsolete_note = shift
1878 || croak
("OBSOLETE ERROR: None obsolete note was supplied to $self->obsolete_platform_design().\n");
1880 my $element_name = shift
1881 || croak
("OBSOLETE ERROR: None platform_design_name was supplied to $self->obsolete_platform_design().\n");
1883 my $revert_tag = shift;
1886 ## If exists the tag revert change obsolete to 0
1889 my $modification_note = 'change to obsolete';
1890 if (defined $revert_tag && $revert_tag =~ m/REVERT/i) {
1892 $modification_note = 'revert obsolete';
1895 ## Create a new metadata with the obsolete tag
1897 my %platform_design_metadata = $self->get_platform_design_metadbdata($metadata);
1898 my $mod_metadata_id = $platform_design_metadata{$element_name}->store( {
1899 modification_note
=> $modification_note,
1900 obsolete
=> $obsolete,
1901 obsolete_note
=> $obsolete_note
1903 ->get_metadata_id();
1905 ## Modify the group row in the database
1907 my @geplatformdesign_rows = $self->get_geplatformdesign_rows();
1909 foreach my $geplatformdesign_row (@geplatformdesign_rows) {
1911 my $sample_id = $geplatformdesign_row->get_column('sample_id');
1912 if (defined $sample_id) {
1913 my ($sample) = $self->get_schema()
1914 ->resultset('BsSample')
1915 ->search({ sample_id
=> $sample_id });
1917 if (defined $sample) {
1918 $sample_name = $sample->get_column('sample_name');
1921 if ($sample_name eq $element_name) {
1922 $geplatformdesign_row->set_column( metadata_id
=> $mod_metadata_id );
1923 $geplatformdesign_row->update()
1924 ->discard_changes();
1930 =head2 store_dbxref_associations
1932 Usage: $platform->store_dbxref_associations($metadata);
1934 Desc: Store in the database the dbxref association for the platform
1939 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
1941 Side_Effects: Die if:
1942 1- None metadata object is supplied.
1943 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
1946 Example: $platform->store_dbxref_associations($metadata);
1950 sub store_dbxref_associations
{
1953 ## FIRST, check the metadata_id supplied as parameter
1954 my $metadata = shift
1955 || croak
("STORE ERROR: None metadbdata object was supplied to $self->store_dbxref_associations().\n");
1957 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
1958 croak
("STORE ERROR: Metadbdata supplied to $self->store_dbxref_associations() is not CXGN::Metadata::Metadbdata object.\n");
1961 ## It is not necessary check the current user used to store the data because should be the same than the used
1962 ## to create a metadata_id. In the medadbdata object, it is checked.
1964 ## SECOND, check if exists or not platform_dbxref_id.
1965 ## if exists platform_dbxref_id => update
1966 ## if do not exists platform_dbxref_id => insert
1968 my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
1970 foreach my $geplatformdbxref_row (@geplatformdbxref_rows) {
1972 my $platform_dbxref_id = $geplatformdbxref_row->get_column('platform_dbxref_id');
1973 my $dbxref_id = $geplatformdbxref_row->get_column('dbxref_id');
1975 unless (defined $platform_dbxref_id) { ## NEW INSERT and DISCARD CHANGES
1978 my $metadata_id = $metadata->get_metadata_id();
1980 $geplatformdbxref_row->set_column( metadata_id
=> $metadata_id ); ## Set the metadata_id column
1982 $geplatformdbxref_row->insert()
1983 ->discard_changes(); ## It will set the row with the updated row
1986 else { ## UPDATE IF SOMETHING has change
1988 my @columns_changed = $geplatformdbxref_row->is_changed();
1990 if (scalar(@columns_changed) > 0) { ## ...something has change, it will take
1992 my @modification_note_list; ## the changes and the old metadata object for
1993 foreach my $col_changed (@columns_changed) { ## this dbiref and it will create a new row
1994 push @modification_note_list, "set value in $col_changed column";
1997 my $modification_note = join ', ', @modification_note_list;
1999 my %asdbxref_metadata = $self->get_platform_dbxref_metadbdata($metadata);
2000 my $mod_metadata = $asdbxref_metadata{$dbxref_id}->store({ modification_note
=> $modification_note });
2001 my $mod_metadata_id = $mod_metadata->get_metadata_id();
2003 $geplatformdbxref_row->set_column( metadata_id
=> $mod_metadata_id );
2005 $geplatformdbxref_row->update()
2006 ->discard_changes();
2012 =head2 obsolete_dbxref_association
2014 Usage: $platform->obsolete_dbxref_association($metadata, $note, $dbxref_id, 'REVERT');
2016 Desc: Change the status of a data to obsolete.
2017 If revert tag is used the obsolete status will be reverted to 0 (false)
2021 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
2022 $note, a note to explain the cause of make this data obsolete
2023 $dbxref_id, a dbxref id
2026 Side_Effects: Die if:
2027 1- None metadata object is supplied.
2028 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
2030 Example: $platform->obsolete_dbxref_association($metadata,
2031 'change to obsolete test',
2036 sub obsolete_dbxref_association
{
2039 ## FIRST, check the metadata_id supplied as parameter
2041 my $metadata = shift
2042 || croak
("OBSOLETE ERROR: None metadbdata object was supplied to $self->obsolete_dbxref_association().\n");
2044 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
2045 croak
("OBSOLETE ERROR: Metadbdata obj. supplied to $self->obsolete_dbxref_association is not CXGN::Metadata::Metadbdata obj.\n");
2048 my $obsolete_note = shift
2049 || croak
("OBSOLETE ERROR: None obsolete note was supplied to $self->obsolete_dbxref_association().\n");
2051 my $dbxref_id = shift
2052 || croak
("OBSOLETE ERROR: None dbxref_id was supplied to $self->obsolete_dbxref_association().\n");
2054 my $revert_tag = shift;
2057 ## If exists the tag revert change obsolete to 0
2060 my $modification_note = 'change to obsolete';
2061 if (defined $revert_tag && $revert_tag =~ m/REVERT/i) {
2063 $modification_note = 'revert obsolete';
2066 ## Create a new metadata with the obsolete tag
2068 my %asdbxref_metadata = $self->get_platform_dbxref_metadbdata($metadata);
2069 my $mod_metadata_id = $asdbxref_metadata{$dbxref_id}->store( { modification_note
=> $modification_note,
2070 obsolete
=> $obsolete,
2071 obsolete_note
=> $obsolete_note } )
2072 ->get_metadata_id();
2074 ## Modify the group row in the database
2076 my @geplatformdbxref_rows = $self->get_geplatformdbxref_rows();
2077 foreach my $geplatformdbxref_row (@geplatformdbxref_rows) {
2078 if ($geplatformdbxref_row->get_column('dbxref_id') == $dbxref_id) {
2080 $geplatformdbxref_row->set_column( metadata_id
=> $mod_metadata_id );
2082 $geplatformdbxref_row->update()
2083 ->discard_changes();
2088 =head2 store_pub_associations
2090 Usage: $platform->store_pub_associations($metadata);
2092 Desc: Store in the database the pub association for the platform
2097 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
2099 Side_Effects: Die if:
2100 1- None metadata object is supplied.
2101 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
2104 Example: $platform->store_pub_associations($metadata);
2108 sub store_pub_associations
{
2111 ## FIRST, check the metadata_id supplied as parameter
2112 my $metadata = shift
2113 || croak
("STORE ERROR: None metadbdata object was supplied to $self->store_dbxref_associations().\n");
2115 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
2116 croak
("STORE ERROR: Metadbdata supplied to $self->store_dbxref_associations() is not CXGN::Metadata::Metadbdata object.\n");
2119 ## It is not necessary check the current user used to store the data because should be the same than the used
2120 ## to create a metadata_id. In the medadbdata object, it is checked.
2122 ## SECOND, check if exists or not platform_dbxref_id.
2123 ## if exists platform_pub_id => update
2124 ## if do not exists platform_pub_id => insert
2126 my @geplatformpub_rows = $self->get_geplatformpub_rows();
2128 foreach my $geplatformpub_row (@geplatformpub_rows) {
2130 my $platform_pub_id = $geplatformpub_row->get_column('platform_pub_id');
2131 my $pub_id = $geplatformpub_row->get_column('pub_id');
2133 unless (defined $platform_pub_id) { ## NEW INSERT and DISCARD CHANGES
2136 my $metadata_id = $metadata->get_metadata_id();
2138 $geplatformpub_row->set_column( metadata_id
=> $metadata_id ); ## Set the metadata_id column
2140 $geplatformpub_row->insert()
2141 ->discard_changes(); ## It will set the row with the updated row
2144 else { ## UPDATE IF SOMETHING has change
2146 my @columns_changed = $geplatformpub_row->is_changed();
2148 if (scalar(@columns_changed) > 0) { ## ...something has change, it will take
2150 my @modification_note_list; ## the changes and the old metadata object for
2151 foreach my $col_changed (@columns_changed) { ## this dbiref and it will create a new row
2152 push @modification_note_list, "set value in $col_changed column";
2155 my $modification_note = join ', ', @modification_note_list;
2157 my %aspub_metadata = $self->get_platform_pub_metadbdata($metadata);
2158 my $mod_metadata = $aspub_metadata{$pub_id}->store({ modification_note
=> $modification_note });
2159 my $mod_metadata_id = $mod_metadata->get_metadata_id();
2161 $geplatformpub_row->set_column( metadata_id
=> $mod_metadata_id );
2163 $geplatformpub_row->update()
2164 ->discard_changes();
2170 =head2 obsolete_pub_association
2172 Usage: $platform->obsolete_pub_association($metadata, $note, $pub_id, 'REVERT');
2174 Desc: Change the status of a data to obsolete.
2175 If revert tag is used the obsolete status will be reverted to 0 (false)
2179 Args: $metadata, a metadata object (CXGN::Metadata::Metadbdata object).
2180 $note, a note to explain the cause of make this data obsolete
2184 Side_Effects: Die if:
2185 1- None metadata object is supplied.
2186 2- The metadata supplied is not a CXGN::Metadata::Metadbdata
2188 Example: $platform->obsolete_pub_association($metadata,
2189 'change to obsolete test',
2194 sub obsolete_pub_association
{
2197 ## FIRST, check the metadata_id supplied as parameter
2199 my $metadata = shift
2200 || croak
("OBSOLETE ERROR: None metadbdata object was supplied to $self->obsolete_pub_association().\n");
2202 unless (ref($metadata) eq 'CXGN::Metadata::Metadbdata') {
2203 croak
("OBSOLETE ERROR: Metadbdata obj. supplied to $self->obsolete_pub_association is not CXGN::Metadata::Metadbdata obj.\n");
2206 my $obsolete_note = shift
2207 || croak
("OBSOLETE ERROR: None obsolete note was supplied to $self->obsolete_pub_association().\n");
2210 || croak
("OBSOLETE ERROR: None pub_id was supplied to $self->obsolete_pub_association().\n");
2212 my $revert_tag = shift;
2215 ## If exists the tag revert change obsolete to 0
2218 my $modification_note = 'change to obsolete';
2219 if (defined $revert_tag && $revert_tag =~ m/REVERT/i) {
2221 $modification_note = 'revert obsolete';
2224 ## Create a new metadata with the obsolete tag
2226 my %aspub_metadata = $self->get_platform_pub_metadbdata($metadata);
2227 my $mod_metadata_id = $aspub_metadata{$pub_id}->store( { modification_note
=> $modification_note,
2228 obsolete
=> $obsolete,
2229 obsolete_note
=> $obsolete_note } )
2230 ->get_metadata_id();
2232 ## Modify the group row in the database
2234 my @geplatformpub_rows = $self->get_geplatformpub_rows();
2235 foreach my $geplatformpub_row (@geplatformpub_rows) {
2236 if ($geplatformpub_row->get_column('pub_id') == $pub_id) {
2238 $geplatformpub_row->set_column( metadata_id
=> $mod_metadata_id );
2240 $geplatformpub_row->update()
2241 ->discard_changes();
2248 #####################
2249 ### OTHER METHODS ###
2250 #####################
2252 =head2 get_technology_type
2254 Usage: my $technologytype = $platform->get_technology_type();
2256 Desc: Get a CXGN::GEM::TechnologyType object.
2258 Ret: A CXGN::GEM::TechnologyType object.
2262 Side_Effects: die if the platform object have not any
2265 Example: my $technologytype = $platform->get_technology_type();
2269 sub get_technology_type
{
2272 my $technology_type_id = $self->get_technology_type_id();
2274 unless (defined $technology_type_id) {
2275 croak
("OBJECT MANIPULATION ERROR: The $self object haven't any technology_type_id. Probably it hasn't store yet.\n");
2278 my $techtype = CXGN
::GEM
::TechnologyType
->new($self->get_schema(), $technology_type_id);
2284 =head2 get_template_list
2286 Usage: my @templates = $platform->get_template_list();
2288 Desc: Get a list of CXGN::GEM::Template objects.
2290 Ret: An array of CXGN::GEM::Templates objects.
2294 Side_Effects: die if the platform object have not any
2297 Example: my @templates = $platform->get_template_list();
2301 sub get_template_list
{
2306 my $platform_id = $self->get_platform_id();
2308 unless (defined $platform_id) {
2309 croak
("OBJECT MANIPULATION ERROR: The $self object haven't any platform_id. Probably it hasn't store yet.\n");
2312 my @getemplate_rows = $self->get_schema()
2313 ->resultset('GeTemplate')
2314 ->search( { platform_id
=> $platform_id } );
2316 foreach my $getemplate_row (@getemplate_rows) {
2318 my $template = CXGN
::GEM
::Template
->new($self->get_schema(), $getemplate_row->get_column('template_id') );
2320 push @templates, $template;
2326 =head2 count_templates
2328 Usage: my $template_count = $platform->count_templates();
2330 Desc: Count how many templates has associated this platform
2332 Ret: $templates_n, a scalar
2336 Side_Effects: return undef if the platform has not platform_id
2338 Example: my $templates_n = $platform->count_templates();
2342 sub count_templates
{
2345 my $templates_count;
2347 my $platform_id = $self->get_platform_id();
2349 if (defined $platform_id) {
2350 $templates_count = $self->get_schema()
2351 ->resultset('GeTemplate')
2352 ->search({ platform_id
=> $platform_id })
2356 return $templates_count;
2361 Usage: my $probe_count = $platform->count_probes();
2363 Desc: Count how many probes has associated this platform
2365 Ret: $probes_count, a scalar
2369 Side_Effects: return undef if the platform has not platform_id
2371 Example: my $probes_n = $platform->count_probes();
2380 my $platform_id = $self->get_platform_id();
2382 if (defined $platform_id) {
2383 $probes_count = $self->get_schema()
2384 ->resultset('GeProbe')
2385 ->search({ platform_id
=> $platform_id })
2389 return $probes_count;