Skip to content

Commit

Permalink
Merge pull request #4341 from solgenomics/topic/rename_accession_ui
Browse files Browse the repository at this point in the history
add a bulk accession rename feature
  • Loading branch information
lukasmueller authored Dec 13, 2022
2 parents 4aec36d + 7e8daab commit efba125
Show file tree
Hide file tree
Showing 11 changed files with 796 additions and 37 deletions.
15 changes: 15 additions & 0 deletions docs/03_managing_breeding_data/03_03.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,21 @@ Grafted accessions can be used like any other accession, for example, they can b

Note that you shouldn't create new grafts based on other grafts. The scion accession and the rootstock accession have to be different, otherwise they will not be created.

3.3.5 Bulk renaming of accessions
---

Accessions can be renamed in bulk using the rename accessions feature. To rename accessions, prepare a tab delimited file with two columns: the first column should have the header "old name" and contain the accession names that need to be changed. The second column should have the header "new name" and contain the names that the accessions in column 1 should be renamed to.

The accession renaming feature is available from the Manage->Accessions page. Click on the "Rename Accessions" button. The first step is the upload of the file with a verification step. The verification step checks whether all the accession names in column 1 exist in the database, and whether all the accession names given in column 2 do NOT exist in the database. Only if both conditions are met, will the "rename" button become active, otherwise an error message is displayed listing the offending accession names.

Optionally, the old name can be automatically added as a synonym to the renamed accession, using the checkbox on the submit form. This option is clicked by default. Unclick the checkbox to NOT save any old names as synonyms.

Note that accession renaming should not be undertaken lightly. This feature is intended for special use cases, such as where accessions are created in a nursery with a name that is different from the accession name in the downstream breeding program.

It can also be used to rename accessions in bulk that have spelling mistakes and other issues. Please note however, that the tool does not make any attempt to change the names of associated elements, such a plots, that may have been constructed using accession names.

Because of the many implications of accession renaming, the feature is limited to accounts with the curator role.




Expand Down
120 changes: 120 additions & 0 deletions js/source/legacy/CXGN/BreedersToolbox/UploadRenameAccessions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*jslint browser: true, devel: true */

/**
=head1 UploadRenameAccessions.js
Dialogs for uploading accessions to be renamed
=head1 AUTHORS
Lukas Mueller <lam87@cornell.edu>, based on code by
Jeremy D. Edwards <jde22@cornell.edu>
=cut
*/


var $j = jQuery.noConflict();

jQuery(document).ready(function ($) {

$('#upload_rename_accessions_link').click(function () {
open_upload_rename_accessions_dialog();
});

$("#upload_rename_accessions_dialog_submit").click( function () {
$('#upload_rename_accessions_dialog').modal("hide");
upload_rename_accessions_file();
});

// $("#rename_accessions_upload_spreadsheet_format_info_link").click( function () {
// $('#upload_rename_accessions_dialog').modal("hide");
// $("#rename_accessions_upload_spreadsheet_format_info_dialog" ).modal("show");
// });

var archived_filename;
$('#upload_rename_accessions_form').iframePostForm({
json: false,
post: function () {
var uploadedRenameAccessionsFile = $("#rename_accessions_uploaded_file").val();
$('#working_modal').modal("show");
if (uploadedRenameAccessionsFile === '') {
$('#working_modal').modal("hide");
alert("No file selected");
}
},
complete: function (r) {
var clean_r = r.replace('<pre>', '');
clean_r = clean_r.replace('</pre>', '');
console.log(clean_r);
var response = JSON.parse(clean_r);
$('#working_modal').modal("hide");

var html;

if (response.error) {
html = '<h3>The Following Issues Were Identified</h3><p class="bg-warning">'+response.error+'</p>';
$('#upload_rename_accessions_store').prop("disabled", true);
}
else {

archived_filename = response.archived_filename_with_path;

$('#upload_rename_accessions_store').prop("disabled", false);
html = '<h3>There Were No Issues Identified</h3>Please click the "Rename" button to renamee the accessions in the database.';
}
$("#upload_rename_accessions_validate_display tbody").html(html);
$("#upload_rename_accessions_validate_display").modal('show');
}
});

function upload_rename_accessions_file() {
var uploadFile = $("#rename_accessions_uploaded_file").val();
$('#upload_rename_accessions_form').attr("action", "/ajax/rename_accessions/upload_verify");
if (uploadFile === '') {
alert("Please select a file");
return;
}
$("#upload_rename_accessions_form").submit();
}

function open_upload_rename_accessions_dialog() {
$('#upload_rename_accessions_dialog').modal("show");
}

jQuery('#upload_rename_accessions_store').click(function(){


jQuery.ajax( {
url: '/ajax/rename_accessions/upload_store',
data: {
'archived_filename':archived_filename,
'store_old_name_as_synonym' : jQuery('#store_old_name_as_synonym').val()
},
beforeSend: function(){
jQuery('#working_modal').modal('show');
},
success: function(response) {
jQuery('#working_modal').modal('hide');
if (response.error) {
alert('An Error Occured: No accessions were renamed! Try Fixing Your File For The Issues Identified In the Validation. '+response.error);
}
else {
//alert("RESPONSE: "+JSON.stringify(response));
jQuery('#rename_accessions_upload_success_dialog_message').modal('show');
var renamed_accessions_html = response.renamed_accessions.join("<br />");
jQuery('#list_of_uploaded_rename_accessions').html(renamed_accessions_html);
//jQuery('#list_of_already_uploaded_rename_accessions').val(response.grafts_already_present);
}
},
error: function(response) {
jQuery('#working_modal').modal('hide');
alert('An error occurred storing the accession data. None were renamed.'+response.responseText);
}
});
});

});
16 changes: 16 additions & 0 deletions lib/CXGN/Stock.pm
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ has 'subjects' => (
is => 'rw',
);


sub BUILD {
my $self = shift;

Expand All @@ -489,6 +490,18 @@ sub BUILD {
$self->stock($stock);
$self->stock_id($stock->stock_id);
}
elsif ($self->uniquename) {
$stock = $self->schema()->resultset("Stock::Stock")->find( { uniquename => $self->uniquename() });
if (!$stock) {
print STDERR "Can't find stock ".$self->uniquename.". Generating empty object.\n";
}
else {
$self->stock($stock);
$self->stock_id($stock->stock_id);
}
}


if (defined $stock && !$self->is_saving) {
$self->organism_id($stock->organism_id);
# my $organism = $self->schema()->resultset("Organism::Organism")->find( { organism_id => $stock->organism_id() });
Expand Down Expand Up @@ -521,6 +534,8 @@ sub BUILD {

$self->subjects(\@subjects);
}


return $self;
}

Expand All @@ -537,6 +552,7 @@ sub _retrieve_stock_owner {
$self->owners(\@owners);
}


=head2 store()
Usage: $self->store
Expand Down
Loading

0 comments on commit efba125

Please sign in to comment.