From fc06d7e1f4a9780bc9c9e31b5e28810ee21f0908 Mon Sep 17 00:00:00 2001 From: elserj Date: Thu, 16 Sep 2010 22:01:52 +0000 Subject: [PATCH] Added --new option for creating a new version of the database svn path=/; revision=35 --- .../inparanoid_output_parse.pl | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/interactome_scripts/inparanoid_output_parse.pl b/interactome_scripts/inparanoid_output_parse.pl index 8c035b5..111c57e 100755 --- a/interactome_scripts/inparanoid_output_parse.pl +++ b/interactome_scripts/inparanoid_output_parse.pl @@ -21,6 +21,11 @@ use warnings; use DBI; use Term::Screen::ReadLine; +use Getopt::Long; +my $new = ''; +GetOptions ('new' => \$new); + + require "$ENV{HOME}/scripts/jaiswallab/interactome_scripts/find_species.pl"; # open the file to be parsed, assume this is all sqltable* files in directory @@ -29,6 +34,8 @@ my @files = glob("sqltable*"); # define the database handle to be used +my $database; + my $screen = Term::Screen::ReadLine->new(); # clear the screen $screen->clrscr; @@ -42,11 +49,33 @@ my $screen = Term::Screen::ReadLine->new(); $screen->at(2,0); undef $screen; - -my $dbh = DBI->connect('DBI:mysql:inparanoid_data;host=floret.cgrb.oregonstate.edu', $username, $password, - { RaiseError=> 1, AutoCommit=>1 } - ) or die "Failed to connect to database: $DBI::errstr"; - + if($new) { + $database = ""; + my $dbh_temp = DBI->connect("DBI:mysql:$database;host=floret.cgrb.oregonstate.edu", $username, $password, + { RaiseError=> 1, AutoCommit=>1 } + ) or die "Failed to connect to database: $DBI::errstr"; + $dbh_temp->do("drop database inparanoid_data"); + $dbh_temp->do("create database inparanoid_data"); + $dbh_temp->disconnect; + } + my $dbh = DBI->connect("DBI:mysql:inparanoid_data;host=floret.cgrb.oregonstate.edu", $username, $password, + { RaiseError=> 1, AutoCommit=>1 } + ) or die "Failed to connect to database: $DBI::errstr"; + + +my $clust_table = "clusters"; +my $safe_clust_table = $dbh->quote_identifier($clust_table); + +if($new) { + $dbh->do("create table $safe_clust_table ( + `id` INT( 11 ) NOT NULL AUTO_INCREMENT, + `clust_id` VARCHAR( 255 ) NOT NULL , + INDEX ( `id` ) + ) TYPE = MYISAM"); +} + +my $tot_file_count = scalar @files; +my $file_counter = 1; # start the database entries foreach my $input_file (@files) { @@ -60,11 +89,12 @@ foreach my $input_file (@files) { $species_1 = find_species($species_1); $species_2 = find_species($species_2); my $species_table = $species_1."_".$species_2; - my $clust_table = "clusters"; + my %id_hash; - print "Working on $species_table\n"; + print "Working on $species_table: file $file_counter/$tot_file_count\n"; + $file_counter++; @@ -82,7 +112,7 @@ foreach my $input_file (@files) { my $sth = $dbh->prepare("insert into $safe_species_table (id, bit_score, species, score, gene) values (?,?,?,?,?)"); - my $safe_clust_table = $dbh->quote_identifier($clust_table); + my $sth_id_dump = $dbh->prepare("select * from clusters"); my $sth_id_add = $dbh->prepare("insert into $safe_clust_table (id, clust_id) values (?,?)"); my $sth_get_id = $dbh->prepare("select last_insert_id(id) from clusters order by id desc limit 1"); -- 2.34.1