From 6e2afb3cf59dd928a765ccd5a28a00c95baca599 Mon Sep 17 00:00:00 2001
From: Andrew Yates <ayates@ebi.ac.uk>
Date: Thu, 29 Nov 2012 11:15:27 +0000
Subject: [PATCH] allow for column configuration

---
 misc-scripts/import/sort_feature_table.pl | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/misc-scripts/import/sort_feature_table.pl b/misc-scripts/import/sort_feature_table.pl
index 11ada536bc..a796b7bf0f 100644
--- a/misc-scripts/import/sort_feature_table.pl
+++ b/misc-scripts/import/sort_feature_table.pl
@@ -11,6 +11,7 @@ use POSIX qw/strftime/;
 
 my ($db_name,$db_host,$db_user,$db_pass,$db_port,$help);
 my @tables;
+my @columns;
 my ($optimise, $nobackup, $nolock);
 
 GetOptions ("db_name|dbname|database=s" => \$db_name,
@@ -22,12 +23,17 @@ GetOptions ("db_name|dbname|database=s" => \$db_name,
             'optimise!' => \$optimise,
             'nolock!' => \$nolock,
             'nobackup!' => \$nobackup,
+            'columns=s@' => \@columns,
             "h|help!"        => \$help,
 );
 
 if ($help) {&usage; exit 0;}
 unless ($db_name and $db_host) {print "Insufficient arguments\n"; &usage; exit 1;}
 
+if(!@columns) {
+  @columns = qw/seq_region_id seq_region_start seq_region_end/;
+}
+
 sub get_adaptor {
   my $dba = Bio::EnsEMBL::DBSQL::DBAdaptor->new(
     -species => 'tmp',
@@ -67,7 +73,8 @@ sub sort_table {
   }
   
   info("Re-ordering table");
-  $dba->dbc()->do("ALTER TABLE ${table} ORDER BY seq_region_id, seq_region_start, seq_region_end");
+  my $cols = join(',', @columns);
+  $dba->dbc()->do("ALTER TABLE ${table} ORDER BY $cols");
 
   if(!$nolock) {
     info("Unlocking table %s", $table);
@@ -166,6 +173,10 @@ Options:
     
     -nolock             Stop the code from applying for table locks
     
+    -columns            Specify the columns to sort on. Defaults to
+                        seq_region_id, seq_region_start and seq_region_end.
+                        Multiple parameters allowed
+    
     -help
 ";
 }
-- 
GitLab