From 54224070e02a6e9aa4ef3794b5a5d4b417877a6f Mon Sep 17 00:00:00 2001 From: Naama Menda Date: Fri, 14 Apr 2017 15:34:06 -0400 Subject: [PATCH] remove variable overloading --- .../data_fixes/delete_illegal_phen_values.pl | 74 +++++++++++----------- 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/bin/loading_scripts/cassavabase/data_fixes/delete_illegal_phen_values.pl b/bin/loading_scripts/cassavabase/data_fixes/delete_illegal_phen_values.pl index da22609..5486cf8 100644 --- a/bin/loading_scripts/cassavabase/data_fixes/delete_illegal_phen_values.pl +++ b/bin/loading_scripts/cassavabase/data_fixes/delete_illegal_phen_values.pl @@ -43,31 +43,31 @@ my $coderef = sub { ###DELETE FROM phenotype WHERE value ilike '#%' ; # delete phenotype rows that contain error values from the excel spreadsheet uploads ## - $phen_rs = $schema->resultset('Phenotype::Phenotype')->search( + my $phen_rs2 = $schema->resultset('Phenotype::Phenotype')->search( { 'value' => { ilike => '#%' } } ); - $rows = $phen_rs->count; + $rows = $phen_rs2->count; print STDERR "DELETING $rows phenotype rows that contain excel error values...\n\n" ; - $phen_rs->delete() ; + $phen_rs2->delete() ; ###DELETE FROM phenotype WHERE value ilike 'CO:%' # delete phenotype rows that contain values that are the actual ontology term name, probably came from an error in the phenotyping file ## - $phen_rs = $schema->resultset('Phenotype::Phenotype')->search( + my $phen_rs3 = $schema->resultset('Phenotype::Phenotype')->search( { 'value' => { ilike => 'CO:%' } } ); - $rows = $phen_rs->count; + $rows = $phen_rs3->count; print STDERR "DELETING $rows phenotype rows that contain string values of the trait name...\n\n" ; - $phen_rs->delete() ; + $phen_rs3->delete() ; ###Update phenotype values of CO:0000085 (taste of boiled roots 1-3) from string to numeric scale. Taste of boiled root rating as 1 = sweet, 2 = bland, and 3 = bitter # UPDATE phenotype SET value = '1' WHERE value ilike 's' AND observable_id = (SELECT cvterm_id FROM cvterm JOIN dbxref USING (dbxref_id) JOIN db USING (db_id) WHERE db.name = 'CO' AND dbxref.accession = '0000085') # UPDATE phenotype SET value = '2' WHERE value ilike 'bl' AND observable_id = (SELECT cvterm_id FROM cvterm JOIN dbxref USING (dbxref_id) JOIN db USING (db_id) WHERE db.name = 'CO' AND dbxref.accession = '0000085') # UPDATE phenotype SET value = '3' WHERE value ilike 'b' AND observable_id = (SELECT cvterm_id FROM cvterm JOIN dbxref USING (dbxref_id) JOIN db USING (db_id) WHERE db.name = 'CO' AND dbxref.accession = '0000085') ## - $phen_rs = $schema->resultset('Phenotype::Phenotype')->search( + my $phen_rs4 = $schema->resultset('Phenotype::Phenotype')->search( { 'db.name' => 'CO', 'dbxref.accession' => '0000085', @@ -75,17 +75,17 @@ my $coderef = sub { { join => { observable => { 'dbxref' => 'db' } } }, ); - my $phen1 = $phen_rs->search( { value => { ilike => 's' } } ); + my $phen1 = $phen_rs4->search( { value => { ilike => 's' } } ); my $rows1 = $phen1->count; $phen1->update( { value => '1' } ); print STDERR "UPDATED $rows1 phenotype rows for cvterm CO:0000085 from value = 's' to value = '1' \n\n" ; - my $phen2 = $phen_rs->search( { value => { ilike => 'bl' } } ); + my $phen2 = $phen_rs4->search( { value => { ilike => 'bl' } } ); my $rows2 = $phen2->count; $phen2->update( { value => '2' } ); print STDERR "UPDATED $rows2 phenotype rows for cvterm CO:0000085 from value = 'bl' to value = '2' \n\n" ; - my $phen3 = $phen_rs->search( { value => { ilike => 'b' } } ); + my $phen3 = $phen_rs4->search( { value => { ilike => 'b' } } ); my $rows3 = $phen3->count; $phen3->update( { value => '3' } ); print STDERR "UPDATED $rows3 phenotype rows for cvterm CO:0000085 from value = 'b' to value = '3' \n\n" ; @@ -101,7 +101,7 @@ my $coderef = sub { # # UPDATE phenotype SET value = '3' WHERE value ilike 'y' AND observable_id = (SELECT cvterm_id FROM cvterm JOIN dbxref USING (dbxref_id) JOIN db USING (db_id) WHERE db.name = 'CO' AND dbxref.accession = '0000114') - $phen_rs = $schema->resultset('Phenotype::Phenotype')->search( + my $phen_rs5 = $schema->resultset('Phenotype::Phenotype')->search( { 'db.name' => 'CO', 'dbxref.accession' => '0000114', @@ -109,49 +109,49 @@ my $coderef = sub { { join => { observable => { 'dbxref' => 'db' } } }, ); - $phen1 = $phen_rs->search( { value => { ilike => 'w' } } ); - $rows1 = $phen1->count; - $phen1->update( { value => '1' } ); - print STDERR "UPDATED $rows1 phenotype rows for cvterm CO:0000114 from value = 'w' to value = '1' \n\n" ; - - $phen2 = $phen_rs->search( { value => { ilike => 'c' } } ); - $rows2 = $phen2->count; - $phen2->update( { value => '2' } ); - print STDERR "UPDATED $rows2 phenotype rows for cvterm CO:0000114 from value = 'c' to value = '2' \n\n" ; - - $phen3 = $phen_rs->search( { value => { ilike => 'y' } } ); - my $rows3 = $phen3->count; - $phen3->update( { value => '3' } ); - print STDERR "UPDATED $rows3 phenotype rows for cvterm CO:0000114 from value = 'y' to value = '3' \n\n" ; + my $phen5 = $phen_rs5->search( { value => { ilike => 'w' } } ); + my $rows5 = $phen5->count; + $phen5->update( { value => '1' } ); + print STDERR "UPDATED $rows5 phenotype rows for cvterm CO:0000114 from value = 'w' to value = '1' \n\n" ; + + my $phen6 = $phen_rs5->search( { value => { ilike => 'c' } } ); + my $rows6 = $phen6->count; + $phen6->update( { value => '2' } ); + print STDERR "UPDATED $rows6 phenotype rows for cvterm CO:0000114 from value = 'c' to value = '2' \n\n" ; + + my $phen7 = $phen_rs5->search( { value => { ilike => 'y' } } ); + my $rows7 = $phen7->count; + $phen7->update( { value => '3' } ); + print STDERR "UPDATED $rows7 phenotype rows for cvterm CO:0000114 from value = 'y' to value = '3' \n\n" ; ##Delete remaining non-numeric phenotype values - $phen_rs = $schema->resultset('Phenotype::Phenotype')->search( + my $phen_rs6 = $schema->resultset('Phenotype::Phenotype')->search( { + 'me.value' => { '!~' , '[0-9]' }, 'db.name' => 'CO', 'dbxref.accession' => { in => "('0000010', '0000011', '0000019', '0000085', '0000106', '0000114', '0000119')" } , - value => { '!~' , '[0-9]' } , - value => { '~' , '[a-z|A-Z]' } }, { join => { observable => { 'dbxref' => 'db' } } }, ); - $rows = $phen_rs->count; - $phen_rs->delete; - print STDERR "DELETED $rows phenotype rows with orphaned non-numeric values \n\n" ; + my $rows8 = $phen_rs6->count; + $phen_rs6->delete; + print STDERR "DELETED $rows8 phenotype rows with orphaned non-numeric values \n\n" ; }; try { $schema->txn_do($coderef); - if (!$opt_t) { print "Transaction succeeded! Committing \n\n"; } - else { - print "TEST MODE: Rolling back\n\n"; - $schema->txn_rollback(); + if (!$opt_t) { + print "Transaction succeeded! Committing \n\n"; + $schema->txn_commit(); + } else { + print "TEST MODE: Rolling back\n\n"; + $schema->txn_rollback(); } - $schema->txn_commit(); } catch { # Transaction failed - die "An error occured! Rolling back and reseting database sequences!" . $_ . "\n"; + die "An error occured! Rolling back and reseting database sequences!" . $_ . "\n"; }; -- 2.11.4.GIT