From bfa51d99f8f8a52a4d96913605edf189f93d0b07 Mon Sep 17 00:00:00 2001
From: Graham McVicker <mcvicker@sanger.ac.uk>
Date: Fri, 20 Dec 2002 14:00:06 +0000
Subject: [PATCH] *** empty log message ***

---
 modules/Bio/EnsEMBL/Utils/CreateTable.pm      | 131 -------------
 .../EnsEMBL/Utils/ExportProgramTemplate.txt   | 125 -------------
 .../Bio/EnsEMBL/Utils/ExportProgramWriter.pm  |  57 ------
 modules/Bio/EnsEMBL/Utils/SchemaTool.pl       | 176 ------------------
 4 files changed, 489 deletions(-)
 delete mode 100644 modules/Bio/EnsEMBL/Utils/CreateTable.pm
 delete mode 100644 modules/Bio/EnsEMBL/Utils/ExportProgramTemplate.txt
 delete mode 100644 modules/Bio/EnsEMBL/Utils/ExportProgramWriter.pm
 delete mode 100755 modules/Bio/EnsEMBL/Utils/SchemaTool.pl

diff --git a/modules/Bio/EnsEMBL/Utils/CreateTable.pm b/modules/Bio/EnsEMBL/Utils/CreateTable.pm
deleted file mode 100644
index 53566139bf..0000000000
--- a/modules/Bio/EnsEMBL/Utils/CreateTable.pm
+++ /dev/null
@@ -1,131 +0,0 @@
-package CreateTable;
-
-sub new {
-  my $self = bless {}; 
-  return $self;
-}
-
-sub get_table_name {
-  my $this = shift;
-  return $this->{'table_name'};
-}
-
-sub set_table_name {
-  my $this = shift;
-  $this->{'table_name'} = shift;
-}
-
-
-sub get_create_statement {
-  my $this = shift;
-  return $this->{'create_statement'}; 
-}
-
-# returns array by reference
-sub get_fields{
-  my $this = shift;
-  return $this->{'fields'};
-}
-
-# pass array by reference
-sub set_fields{
-  my $this = shift;
-  #my $tmp_fieds = shift;
-  $this->{'fields'} = shift;
-}
-
-
-sub to_string {
-  my $this = shift;
-  return "CreateTable[" . $this->get_table_name() . ", " . $this->get_create_statement() . ", (" . scalar(@{$this->get_fields()}) . ")" . join(",", @{$this->get_fields()}) .  "]";
-}
-
-
-sub equals {
-  my $this=shift;
-  my $other= shift;
-
-  # check names same
-  if ( $this->get_table_name() ne $other->get_table_name() ) {return 0;}
-
-  # extract fields in order to compare them
-  my @this_fields = @{$this->get_fields()};
-  my @other_fields = @{$other->get_fields()};
-  #print "THIS " . $this->get_table_name() . "\t" . scalar(@this_fields) . " --> " . join(":", @this_fields) . "\n";
-  #print "OTHER " . $other->get_table_name() . "\t" . scalar(@other_fields) . " --> " . join(":",  @other_fields)."\n";
-
-  my $this_fields_len = scalar(@this_fields);
-  my $other_fields_len = scalar(@other_fields);
-  #check same number of fields
-  if (  $this_fields_len != $other_fields_len ) {return 0;}
-
-  #check same field names
-  for (my $i=0; $i<$this_fields_len; ++$i) {
-    if (@this_fields[$i] ne @other_fields[$i]) { return 0; }
-  }
-
-  return 1;
-}
-
-
-
-# Module function which returns 0 if no entry corresponding to
-# $table_name is found, otherwise returns a corresponding CreateTable
-# instance.
-
-sub create_from_string {
-  my $table_name;
-  my $string;
-
-  my @fields;
-  my $create_statement;
-  
-  my @complete_fields;
-  my $field_index;
-
-  #shift;
-  ($table_name, $string) = @_;
-
-  # extract the sql create table statement
-  $string =~ /(create\s+table\s+$table_name\s*\(([^;]*\))\s*\)\s*;)/sig;
-  $create_statement = $1;
-  my $tmp_fields = $2;
-  # remove all (...) sections because these can contain commas which would break our mechanism for sliptting fields at commas
-  $tmp_fields =~ s/\([^\)]*\)//g;
-  @complete_fields = split(",", $tmp_fields);
-  @fields = [];
-  $field_index = 0;
-  for (my $i=0; $i<scalar(@complete_fields); ++$i) {
-    @complete_fields[$i] =~ /^\s*(\w+)\s/;
-    my $row = $1;
-    unless ($row =~/PRIMARY/i  || $row=~/KEY/i || $row=~/UNIQUE/i || $row=~/^\s*$/) {@fields[$field_index++] = $row;}
-  }
-
-  if ( !$create_statement || $create_statement eq "" ) {return 0;}
-  else {
-    my $v = CreateTable::new();
-    $v->{'create_statement'} = $create_statement;
-    $v->{'table_name'} = $table_name;
-    $v->{'fields'} = \@fields;
-    return $v;
-  }
-}
-
-
-
-
-
-# returns array of all tables specified in schema string
-sub create_all_from_string {
-  (my $schema) = @_;
-
-  my @create_tables;
-  my $i = 0;
-  while($schema =~ m/(create\s*table\s*(\w+)\s*\(([^;]*\))\s*\)\s*;)/sig) {
-    my $create_table = CreateTable::create_from_string($2, $1);
-    @create_tables[$i++] = $create_table;
-  }
-  return @create_tables; # return by copying
-}
-
-1;
diff --git a/modules/Bio/EnsEMBL/Utils/ExportProgramTemplate.txt b/modules/Bio/EnsEMBL/Utils/ExportProgramTemplate.txt
deleted file mode 100644
index f703a65572..0000000000
--- a/modules/Bio/EnsEMBL/Utils/ExportProgramTemplate.txt
+++ /dev/null
@@ -1,125 +0,0 @@
-package PACKAGE_LABEL;
-
-# Fields are read from the database in the order specified in
-# @selection_list, they can then be modified, after loading, in the
-# function modify_loaded_values() before being written to a file.  
-
-# If the fields to be read are different to that list in #
-# @selection_list then edit the list. Similarly if the values need #
-# modifying before being saved change modify_loaded_values().
-
-use DBI;
-use strict;
-use Getopt::Long;
-
-# @row is a global array used to hold row of data read from data
-# base.It can be modified in modify_loaded_values() before writing to 
-# file as tab separated fields.
-
-my @row; 
-my $verbose;
-
-
-# *********************************************************************
-# INPUT PARAMETERS
-#
-my $old_tables="OLD_TABLE_NAME";
-my $where="";
-INPUT_ARRAY
-# *********************************************************************  
-
-# *********************************************************************  
-# MODIFY VALUES LOADED IN BEFORE WRITING TO FILE
-sub modify_loaded_values {
-  @row[0] = ensembl_id_to_int(@row[0]);
-}
-# *********************************************************************  
-
-
-# *********************************************************************
-# TARGET SQL DATABASE TABLE
-#OUTPUT_TABLE_CREATE_STATEMENT
-# *********************************************************************
-	
-
-
-main();
-
-
-sub main {
-  # Handle command line params
-  my $num_rows;
-  my $all;
-
-  GetOptions("num_rows:i" => \$num_rows,
-	     "all" => \$all,
-	     "verbose" => \$verbose);
-
-  my $limit = ($num_rows) ? "limit $num_rows" : "limit 10";
-  my $limit = ($all) ? "" : $limit;
-
-  my $file_contents = export($old_tables, CONNECTION_STRING, USER, PASSWORD, $limit); 
-
-  # Write the export program to a file.
-  open(OUTHANDLE, ">OUT_FILE_PATH");
-  print OUTHANDLE $file_contents;
-  close(OUTHANDLE);
-
-  if ($verbose) {print $file_contents;}
-  
-}
-
-
-sub ensembl_id_to_int {
-  my $old_id = shift;
-  $old_id =~ /[\D|0]*(\d*)/;
-  return $1;
-}
-
-sub chr_name_to_int {
-  (my $v) = @_;
-  $v =~ s/chr//; # remove chr from string
-  if ($v eq "x" || $v eq "X") {$v = 23} # map chr X to 23
-  elsif ($v eq "y" || $v eq "Y") {$v = 24; } # map chr Y to 24
-  return $v;
-}
-
-sub export {
-  ( my $table,
-    my $connection_string,
-    my $user,
-    my $password,
-    my $limit ) = @_;
-  
-  my $db_old = DBI->connect ($connection_string, $user, $password); 
-  if (!$db_old) {
-    print "Error connecting to old database; $DBI::errstr\n";
-    exit 1;
-  }
-  
-  # Construct the list of values to retrieve.
-  my $selection_list;
-  $selection_list = join(", ", @selection_list);
-
-  # Get the old format data
-  my $cmd = "select $selection_list from $table $where $limit";
-  if ($verbose) {print "SQL query : " . $cmd . "\n";}
-  $db_old->prepare($cmd);
-
-  my $sth_old = $db_old->prepare($cmd);
-  $sth_old->execute;
-  
-  my $export_program = "";
-  while ((@row) = $sth_old->fetchrow_array) {
-    modify_loaded_values();
-    $export_program .=  join("\t", @row) . "\n";
-  }
-
-  $sth_old->finish();
-  $db_old->disconnect();
-  
-  return $export_program;
-}
-
-
-1;
diff --git a/modules/Bio/EnsEMBL/Utils/ExportProgramWriter.pm b/modules/Bio/EnsEMBL/Utils/ExportProgramWriter.pm
deleted file mode 100644
index f4e52e2042..0000000000
--- a/modules/Bio/EnsEMBL/Utils/ExportProgramWriter.pm
+++ /dev/null
@@ -1,57 +0,0 @@
-package ExportProgramWriter;
-
-use CreateTable;
-
-sub create_export_program {
-  (my $package_label,
-   my $new_create_table,
-   my $old_create_table) = @_;
-
-  my $new_table_name = $new_create_table->get_table_name();
-  my $old_table_name = $old_create_table->get_table_name();
-
-  my $template;
-  open(TEMPLATE, "ExportProgramTemplate.txt") || die "can not open file: $!";;
-  while(<TEMPLATE>) {
-    $template .= $_;
-  }
-
-  my @old_fields = @{$old_create_table->get_fields()};
-  my $old_fields = join(", ", @old_fields);
-
-  my @new_fields = @{$new_create_table->get_fields()};
-  my $new_fields = join(", ", @new_fields);
-  my $new_table_create_statement = $new_create_table->get_create_statement();
-
-
-  my $old_max = scalar(@old_fields);
-  my $new_max = scalar(@new_fields);
-  my $max = ($old_max>$new_max) ? $old_max : $new_max;
-  
-  my $mapping = ($old_max!=$new_max) ? "# WARNING INCOMPATIBLE NUMBER OF FIELDS\n": "\n";
-  $mapping .= "my \@selection_list;\n";
-  for (my $i=0; $i<$max; ++$i) {
-    my $old_field = @old_fields[$i];
-    my $new_field = @new_fields[$i];
-    my $too_many = ($i>=$new_max) ? "**WARNNING TOO MANY OLD FIELDS**" : "";
-    my $hide = ($i>=$new_max) ? "#" : "";
-    $mapping .= "$hide\@selection_list[$i] \t= \"" . $old_field  . "\"; # $new_field $too_many\n";
-  }
-
-  # search and replace KEYWORDS in template
-  my $filename = $new_table_name . ".txt";
-  $template=~ s/OUT_FILE_PATH/$filename/s;
-  $template=~ s/OLD_TABLE_NAME/$old_table_name/s;
-  $template=~ s/NEW_TABLE_CREATE_STATEMENT/$new_table_create_statement/s;
-  $template=~ s/INPUT_ARRAY/$mapping/s;
-  $template=~ s/CONNECTION_STRING/"DBI:mysql:homo_sapiens_core_110:ensrv3:3306",/s;
-  $template=~ s/USER/"ensro"/s;
-  $template=~ s/PASSWORD/""/s;
-  my $table_statment =  $new_table_create_statement;
-  $table_statment =~ s/^|\n/\n#/gs;
-  $template=~ s/OUTPUT_TABLE_CREATE_STATEMENT/$table_statment/s;
-
-  return $template;
-}
-
-1;
diff --git a/modules/Bio/EnsEMBL/Utils/SchemaTool.pl b/modules/Bio/EnsEMBL/Utils/SchemaTool.pl
deleted file mode 100755
index 7ec8123f0b..0000000000
--- a/modules/Bio/EnsEMBL/Utils/SchemaTool.pl
+++ /dev/null
@@ -1,176 +0,0 @@
-#!/usr/bin/env perl
-
-# Command line front end to ExportProgramWriter.pm.
-#
-# Use --help for help.
-
-use ExportProgramWriter;
-use Carp;
-use Getopt::Long;
-
-# Command line param variables. e.g. --newtable value stored in $newtable
-my $verbose;
-my $help;
-my $outdir;
-my $newtable;
-my $oldtable;
-my $print;
-
-# Created during compare_two_schema()
-my @unchanged = [];
-my @changed = [];
-my @novel = [];
-
-
-main();
-
-sub main {
-  GetOptions(
-	     "verbose" => \$verbose,
-	     "help" => \$help,
-	     "outdir:s" => \$outdir,
-	     "newtable:s" => \$newtable,
-	     "oldtable:s" => \$oldtable,
-	     "print" => \$print
-	    );
-  
-  if (scalar($help || @ARGV)==0) {
-    print "usage: $0 <--print> <--verbose> <--newtable NEW_TABLE_NAME <--oldtable OLD_TABLE_NAME>> <--outdir OUTPUT_DIR> new_schema_filename old_schema_filename \n";
-    print "usage: $0 --help\n";
-    exit 1;
-    
-  }
-  
-  elsif ($newtable) {
-    if ( !$oldtable ) { $oldtable = $newtable; }
-    create_specific_export_program($newtable, @ARGV[0], $oldtable, @ARGV[1]);
-  }
-
-  elsif (scalar(@ARGV)==2) {
-    compare_two_schemas(@ARGV[1], @ARGV[0]);
-    if ( !$print ) {
-      create_many_export_programs("Creating export program for Changed table : ", @changed);
-      create_many_export_programs("Creating export program for Novel table : ", @novel);
-    }
-  }
-  
-
-}
-
-
-sub file_to_string {
-  (my $filename) = @_;
-  my $str = "";
-  open(INFILE, $filename)|| confess "cannot open \"$filename\": $!";
-  $str = join("", <INFILE>);
-  close(INFILE);
-  return $str;
-}
-
-
-sub save {
-  (my $package_name, 
-   my $new_create_table, 
-   my $old_create_table) =@_;
-
-  my $filename = $package_name;
-  $filename =~ s/::/\//g;
-  $filename .= ".pm";
-  $filename = $outdir . "/" . $filename;
-
-  open(OUTFILE, ">" . $filename) || die "failed to open file $filename : $!";
-  print OUTFILE ExportProgramWriter::create_export_program($package_name, 
-							   $new_create_table, 
-							   $old_create_table);
-  close(OUTFILE);
-}
-
-
-sub create_many_export_programs {
-  (my $description, my @new_old_pairs) = @_;
-
-  foreach $pair (@new_old_pairs) {
-    my $new_create_table = @{$pair}[0];
-    my $old_create_table = @{$pair}[1];
-    my $package_name = ucfirst($new_create_table->get_table_name());
-    if ($verbose) {print $description . $new_create_table->get_table_name() . "\n"};
-    save($package_name, $new_create_table, $old_create_table);
-  }
-}
-
-
-sub create_specific_export_program {
-  ( my $new_table_name,
-    my $new_schema_file,
-    my $old_table_name,
-    my $old_schema_file, ) = @_;
-
-  my $package_name = ucfirst($new_table_name);
-  
-  my $new_schema = file_to_string($new_schema_file);
-  my $old_schema =  file_to_string($old_schema_file);
-  
-  my $new_create_table = CreateTable::create_from_string($new_table_name, $new_schema);
-  my $old_create_table = CreateTable::create_from_string($old_table_name, $old_schema);
-  if ($old_create_table==0) {
-    $old_create_table = CreateTable::new();
-  }
-  save($package_name, $new_create_table, $old_create_table);
-}
-
-
-
-sub compare_two_schemas {
-  (my $new_schema_filename, my $old_schema_filename) = @_;
-  
-  # Read in new schema file and create CreateTable objects for each..
-  
-  my $new_schema = file_to_string($new_schema_filename);
-  my $old_schema = file_to_string($old_schema_filename);
-  my @create_tables = CreateTable::create_all_from_string($new_schema);
-  
-  # Identify different tables.
-  my $len = scalar(@create_tables);
-  
-  my $unchanged_index = 0;    
-  my $changed_index = 0;
-  my $novel_index = 0;
-
-  my $empty_create_table = CreateTable::new();
-  $empty_create_table->set_table_name("****UNKNOWN*****");
-  my @empty = [];
-  $empty_create_table->set_fields(\@empty);
-  
-  print "EMPTY TABLE : " . $empty_create_table->to_string() . "\n";
-
-  for(my $i=0; $i<$len; ++$i) {
-    # look for a correspondingly named table in the old file
-    my $new_create_table = @create_tables[$i];
-    my $new_table_name = $new_create_table->get_table_name();
-    my $equivalent_old_create_table = CreateTable::create_from_string( $new_table_name, $old_schema);
-    
-    if ( $verbose ) {print "$i/$len " . $new_create_table->get_table_name() . " ";}
-    
-    if ( !$equivalent_old_create_table ) {
-      #@novel[$novel_index++] = $new_create_table;
-      @novel[$novel_index++] = ([$new_create_table, $empty_create_table]);
-      if ( $verbose ) {print "UNKOWN\n";}
-    }
-    elsif ( $new_create_table->equals($equivalent_old_create_table) ) {
-      #@unchanged[$unchanged_index++] = $new_create_table;
-      @unchanged[$unchanged_index++] = ([$new_create_table, $equivalent_old_create_table]);
-      if ( $verbose ) {print "SAME\n" . join(",", @{$new_create_table->get_fields()}) . "\n" . join(",", @{$equivalent_old_create_table->get_fields()}) . "\n";}
-    } 
-    else {
-      #@changed[$changed_index++] = $new_create_table;
-      @changed[$changed_index++] = ([$new_create_table, $equivalent_old_create_table]);
-      if ( $verbose ) {print "CHANGED\n" . join(",", @{$new_create_table->get_fields()}) . "\n" . join(",", @{$equivalent_old_create_table->get_fields()}) . "\n";}
-    }
-  }
-  
-  print "Unchanged : " . scalar(@unchanged) ."\n";
-  print "Changed : " . scalar(@changed) ."\n";
-  print "Novel : " . scalar(@novel) ."\n";
-
-  
-}
-- 
GitLab