2 package ApplyPopulationTypes
;
5 extends
'CXGN::Metadata::Dbpatch';
7 use Bio
::Chado
::Schema
;
12 my $name = __PACKAGE__
;
13 print "dbpatch name is ':" . $name . "\n\n";
14 my $description = 'Adding explicit population types to stocks of type population';
15 my @previous_requested_patches = ('LoadPhenomeInStock'); #ADD HERE
17 $self->description($description);
18 $self->prereq(\
@previous_requested_patches);
24 print STDOUT
"Executing the patch:\n " . $self->name . ".\n\nDescription:\n ". $self->description . ".\n\nExecuted by:\n " . $self->username . " .";
26 print STDOUT
"\nChecking if this db_patch was executed before or if previous db_patches have been executed.\n";
28 print STDOUT
"\nExecuting the SQL commands.\n";
30 my $schema = Bio
::Chado
::Schema
->connect( sub { $self->dbh->clone } );
33 my $cvterm_rs = $schema->resultset('Cv::Cvterm');
34 my $f2_cvterm = $cvterm_rs->create_with( {
35 name
=> 'f2 population',
38 my $bc_cvterm = $cvterm_rs->create_with( {
39 name
=> 'backcross population',
42 my $mutant_cvterm = $cvterm_rs->create_with( {
43 name
=> 'mutant population',
46 my $population_stocks = $schema->resultset('Cv::Cvterm')->search( { 'me.name' => 'population' } )->
47 search_related
('stocks');
48 while (my $population = $population_stocks->next) {
49 my $population_name = $population->name;
50 print "Looking at population $population_name..\n";
51 if ( grep { /F2/i } ($population_name) ) {
52 print "updating type to " . $f2_cvterm->name . "\n";
53 $population->update( { type_id
=>$f2_cvterm->cvterm_id } );
55 if ( grep { /Backcross/i } ($population_name) ) {
56 print "updating type to " . $bc_cvterm->name . "\n";
57 $population->update( { type_id
=>$bc_cvterm->cvterm_id } );
59 if ( grep { /mutant/i } ($population_name) ) {
60 print "updating type to " . $mutant_cvterm->name . "\n";
61 $population->update( { type_id
=>$mutant_cvterm->cvterm_id } );
65 print "Trial mode! Rolling back transaction\n\n";
66 $schema->txn_rollback;
72 $schema->txn_do($coderef);
73 print "Data committed! \n";
75 die "Load failed! " . $_ . "\n" ;
78 print "You're done!\n";