Skip to content
Snippets Groups Projects
Commit cc95264d authored by Glenn Proctor's avatar Glenn Proctor
Browse files

Added lots of sanity checking to track down formatting errors.

parent 034681c2
No related branches found
No related tags found
No related merge requests found
...@@ -53,6 +53,9 @@ if($release_num) { ...@@ -53,6 +53,9 @@ if($release_num) {
@dbnames = grep {/^[a-zA-Z]+\_[a-zA-Z]+\_(core|est|estgene|vega|otherfeatures|cdna)\_${release_num}\_\d+[A-Za-z]?$/} @dbnames; @dbnames = grep {/^[a-zA-Z]+\_[a-zA-Z]+\_(core|est|estgene|vega|otherfeatures|cdna)\_${release_num}\_\d+[A-Za-z]?$/} @dbnames;
} }
my @field_names = qw(external_db_id db_name release status dbprimary_acc_linkable display_label_linkable priority db_display_name type);
my @types = qw(ARRAY ALT_TRANS MISC LIT PRIMARY_DB_SYNONYM);
# #
# make sure the user wishes to continue # make sure the user wishes to continue
...@@ -77,8 +80,9 @@ if ($input ne 'yes') { ...@@ -77,8 +80,9 @@ if ($input ne 'yes') {
my $fh = IO::File->new(); my $fh = IO::File->new();
$fh->open($file) or die("Could not open input file $file"); $fh->open($file) or die("Could not open input file $file");
my @rows; my @rows;
my $row; my %bad_lines;
while ($row = <$fh>) {
while (my $row = <$fh>) {
chomp($row); chomp($row);
next if ($row =~ /^#/); # skip comments next if ($row =~ /^#/); # skip comments
next if ($row =~ /^$/); # and blank lines next if ($row =~ /^$/); # and blank lines
...@@ -104,16 +108,45 @@ while ($row = <$fh>) { ...@@ -104,16 +108,45 @@ while ($row = <$fh>) {
exit(1); exit(1);
} }
if ( $a[1] =~ /^$/ || $a[1] =~ /^\s+$/ || $a[1] =~ /^\d+$/ ) { # do some formatting checks
print STDERR "Cannot parse the following line:\n" my $blank;
. $row for (my $i=0; $i < scalar(@a); $i++) {
. "\nIt probably has spaces separating the fields " if ($a[$i] eq '') {
. "rather than tabs.\n"; $bad_lines{$row} = $field_names[$i] . " - field blank - check all tabs/spaces in line";
exit(1); }
}
if ($a[1] =~ /\s/) {
$bad_lines{$row} = "db_name field appears to contain spaces";
} }
if ($a[1] =~ /^$/) {
$bad_lines{$row} = "db_name field appears to be missing";
}
if ($a[1] =~ /^\s+$/) {
$bad_lines{$row} = "db_name field appears to be blank";
}
if ($a[1] =~ /^\d+$/) {
$bad_lines{$row} = "db_name field appears to be numeric - check formatting";
}
my $type_ok;
foreach my $type (@types) {
$type_ok = 1 if ($a[8] eq $type);
}
$bad_lines{$row} = "type field is " . $a[8] . ", not one of the recognised types" if (!$type_ok);
} }
$fh->close(); $fh->close();
if (%bad_lines) {
print STDERR "Cannot parse the following line(s) from $file; check that all fields are present and are separated by one tab (not spaces). \n";
print STDERR "Name of problem field, and the error is printed in brackets first\n\n";
foreach my $row (keys %bad_lines) {
print STDERR "[". $bad_lines{$row} . "]" . " $row\n";
}
exit(1);
}
# Load into master database # Load into master database
if(!$nonreleasemode){ if(!$nonreleasemode){
load_database($db, $master, @rows); load_database($db, $master, @rows);
...@@ -121,30 +154,28 @@ $fh->close(); ...@@ -121,30 +154,28 @@ $fh->close();
# Check each other database in turn # Check each other database in turn
# Load if no extra rows in db that aren't in master # Load if no extra rows in db that aren't in master
# Warn and skip if there are # Warn and skip if there are
foreach my $dbname (@dbnames) { foreach my $dbname (@dbnames) {
print STDERR "Looking at $dbname ... \n"; print STDERR "Looking at $dbname ... \n";
if ($force || $nonreleasemode) { if ($force || $nonreleasemode) {
print STDERR "Forcing overwrite of external_db table in " print STDERR "Forcing overwrite of external_db table in "
. "$dbname from $file\n"; . "$dbname from $file\n";
load_database( $db, $dbname, @rows ); load_database( $db, $dbname, @rows );
} elsif (compare_external_db($db, $master, $dbname)) { } elsif (compare_external_db($db, $master, $dbname)) {
print STDERR "$dbname has no additional rows. " print STDERR "$dbname has no additional rows. "
. "Overwriting external_db table from $file\n"; . "Overwriting external_db table from $file\n";
load_database( $db, $dbname, @rows ); load_database( $db, $dbname, @rows );
} else { } else {
print STDERR "$dbname has extra rows " print STDERR "$dbname has extra rows "
. "that are not in $file, skipping\n"; . "that are not in $file, skipping\n";
} }
} }
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment