@@ -187,36 +187,36 @@ sub upload_rename_accessions_store : Path('/ajax/rename_accessions/upload_store'
187
187
my $schema = $c -> dbic_schema(" Bio::Chado::Schema" );
188
188
189
189
my ($header , $rename ) = $self -> _get_rename_accessions_from_file($c , $archived_filename );
190
-
190
+
191
191
my $info = $self -> validate_rename_accessions($c , $header , $rename );
192
192
193
193
print STDERR " FILE CONTENTS: " .Dumper($rename );
194
194
195
195
my @renamed_accessions ;
196
196
my @accessions_already_present ;
197
197
my @error_accessions ;
198
-
198
+
199
199
if (exists ($info -> {accessions_already_present }) && defined ($info -> {accessions_already_present })) {
200
200
@accessions_already_present = @{$info -> {accessions_already_present }};
201
201
}
202
202
my $error ;
203
203
204
204
foreach my $g (@$rename ) {
205
205
my ($old_accession_name , $new_accession_name ) = @$g ;
206
-
207
-
206
+
207
+
208
208
my $stock = CXGN::Stock-> new( { schema => $schema , uniquename => $old_accession_name });
209
-
209
+
210
210
$stock -> uniquename($new_accession_name );
211
-
211
+
212
212
if ($store_old_name_as_synonym eq " on" ) {
213
213
print STDERR " Storing old name ($old_accession_name ) as synonym for $new_accession_name .\n " ;
214
214
$stock -> add_synonym($old_accession_name );
215
215
}
216
216
else {
217
217
print STDERR " Synonym storing not requested. \n " ;
218
218
}
219
-
219
+
220
220
$stock -> store();
221
221
222
222
if (exists ($info -> {errors }) && defined ($info -> {error }) && $info -> {error } ne ' ' ){
@@ -228,7 +228,7 @@ sub upload_rename_accessions_store : Path('/ajax/rename_accessions/upload_store'
228
228
}
229
229
230
230
if (@error_accessions ){
231
- $c -> stash-> {rest } = { error => join (" , " ,@error_accessions ) };
231
+ $c -> stash-> {rest } = { error => join (" , " ,@error_accessions ) };
232
232
$c -> detach();
233
233
}
234
234
$c -> stash-> {rest } = { success => 1, renamed_accession_count => \@renamed_accessions , renamed_accessions => $rename };
@@ -243,9 +243,9 @@ sub _get_rename_accessions_from_file {
243
243
my $header = <$F >;
244
244
$header =~ s /\r // g ;
245
245
chomp ($header );
246
-
246
+
247
247
my @header = split /\t/, $header ;
248
-
248
+
249
249
foreach my $h (@header ) {
250
250
$h =~ s / ^\s +|\s +$// g
251
251
}
@@ -261,39 +261,48 @@ sub _get_rename_accessions_from_file {
261
261
$new_accession_name =~ s / ^\s +|\s +$// g ; # trim also
262
262
push @rename , [ $old_accession_name , $new_accession_name ];
263
263
}
264
-
265
- return \@header , \@rename ;
264
+
265
+ return ( \@header , \@rename ) ;
266
266
}
267
267
268
+
268
269
sub validate_rename_accessions {
269
270
my $self = shift ;
270
271
my $c = shift ;
271
272
my $header = shift ;
272
273
my $rename = shift ;
273
-
274
+
275
+ my $error = " " ;
276
+
277
+ if ($header -> [0] ne " old_name" ) {
278
+ $error = " Column 1 header must be old_name. " ;
279
+ }
280
+ if ($header -> [1] ne " new_name" ) {
281
+ $error .= " Column 2 header must be new_name. " ;
282
+ }
283
+
274
284
my @must_exist = map { $_ -> [0] } @$rename ;
275
-
285
+
276
286
my @must_not_exist = map { $_ -> [1] } @$rename ;
277
-
287
+
278
288
$self -> schema( $c -> dbic_schema(" Bio::Chado::Schema" ) );
279
289
print STDERR " INPUT MUST EXIST: " .Dumper(\@must_exist );
280
290
print STDERR " INPUT MUST NOT EXIST: " .Dumper(\@must_not_exist );
281
291
my $list_validate = CXGN::List::Validate-> new();
282
292
283
-
284
293
my $must_exist_data = $list_validate -> validate( $self -> schema, ' accessions' , \@must_exist );
285
-
294
+
286
295
print STDERR " MUST EXIST: " .Dumper($must_exist_data );
287
-
296
+
288
297
my $must_not_exist_data = $list_validate -> validate( $self -> schema, ' accessions' , \@must_not_exist );
289
-
298
+
290
299
my @missing = ();
291
300
if (ref ($must_not_exist_data -> {missing })) {
292
301
@missing = @{$must_not_exist_data -> {missing }};
293
302
}
294
-
303
+
295
304
print STDERR " MUST NOT EXIST MISSING: " .Dumper(\@missing );
296
-
305
+
297
306
my @must_not_exist_but_present = ();
298
307
foreach my $m (@must_not_exist ) {
299
308
print STDERR " checking $m ...\n " ;
@@ -302,10 +311,10 @@ sub validate_rename_accessions {
302
311
push @must_not_exist_but_present , $m ;
303
312
}
304
313
}
305
-
314
+
306
315
print STDERR " MUST NOT EXIST BUT PRESENT: " .Dumper(\@must_not_exist_but_present );
307
316
308
- return { must_exist_missing => $must_exist_data -> {missing }, must_not_exist_present => \@must_not_exist_but_present };
317
+ return { error => $error , must_exist_missing => $must_exist_data -> {missing }, must_not_exist_present => \@must_not_exist_but_present };
309
318
}
310
319
311
320
0 commit comments