Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seek ena upload #1650

Merged
merged 35 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f2c472b
Add Seed file with metadata for ena
Oct 5, 2023
a297f6e
Add "ENA collection date" to template attribute validation schema
Oct 5, 2023
f4070a0
Add custom metadata functionality to Isa Assays
Oct 6, 2023
db3713f
Add custom metadata functionality to Isa Studies
Oct 6, 2023
a629118
Only make custom metadatafields appear on the first assay
Oct 6, 2023
93ace07
Fix failing tests
Oct 6, 2023
c94e172
Make metadata show in edit form as well
Oct 6, 2023
a4bf9fd
Transfer custom metadata to the assay comments section of the ISA JSON
Oct 9, 2023
edf9ad5
Split assays into streams of assays
Oct 9, 2023
0fc1ab3
Change assay position logic
Oct 9, 2023
4edf9e3
Showing custom metadata if assay position is 0
Oct 9, 2023
641eb81
Correction `show_custom_metadata` logic
Oct 9, 2023
55fbc50
fix failing tests
Oct 9, 2023
3a2300b
Prevent position to increment when editing
Oct 9, 2023
079c12c
Add Assay stream name as custom metadata
Oct 9, 2023
28a0180
Filter stream name out of the comments and set as filename
Oct 9, 2023
a0aaf24
fix merge errors
Oct 10, 2023
619ac5b
Change Custom Metadata to Extended Metadata
Oct 10, 2023
ab0cebe
Fix failing tests
Oct 10, 2023
b033f08
Add Study title
Oct 10, 2023
bbbb26d
Updated ISA exporter:
Oct 10, 2023
03965b8
Fix failing test
Oct 11, 2023
a58e231
Implement ENA custom metadata for ISA Study
Oct 12, 2023
ef9b67c
Export Study extended metadata
Oct 12, 2023
14f8581
Fixed the stream name in the isa_exporter
Oct 19, 2023
e16e802
Fix isa_exporter. output is othermaterial if corresponding isatag is …
Oct 19, 2023
5da37c3
fix error after rebase
Nov 8, 2023
95ab48e
Remove seed file
kdp-cloud Nov 9, 2023
c577db5
Add ENA specific sample attribute type to the sample attributes seed …
kdp-cloud Nov 9, 2023
28603a0
Fix failing tests.
kdp-cloud Nov 14, 2023
e4a436b
Add test for adding custom metadata to an isa study
kdp-cloud Nov 14, 2023
18bf872
Add test for creating an isa assay with custom metadata
kdp-cloud Nov 14, 2023
69a94f3
Merge branch 'main' of github.com:seek4science/seek into seek_ena_upload
kdp-cloud Nov 14, 2023
f5a162d
Add seed task to seek upgrade_version
kdp-cloud Nov 15, 2023
33405c5
Change data type title to something more generic.
kdp-cloud Nov 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -596,9 +596,13 @@ def relationify_collection(collection)
end
end

def determine_extended_metadata_keys
def determine_extended_metadata_keys(asset = nil)
keys = []
type_id = params.dig(controller_name.singularize.to_sym, :extended_metadata_attributes, :extended_metadata_type_id)
if asset
type_id = params.dig(controller_name.singularize.to_sym, asset, :extended_metadata_attributes, :extended_metadata_type_id)
else
type_id = params.dig(controller_name.singularize.to_sym, :extended_metadata_attributes, :extended_metadata_type_id)
end
if type_id.present?
metadata_type = ExtendedMetadataType.find(type_id)
keys = [:extended_metadata_type_id, :id, data: recursive_determine_extended_metadata_keys(metadata_type)]
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/extended_metadata_types_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class ExtendedMetadataTypesController < ApplicationController
# generated for form, to display fields for selected metadata type
def form_fields
id = params[:id]
parent_resource = params[:parentResource] unless params[:parentResource]&.empty?
respond_to do |format|
if id.blank?
format.html { render html: '' }
Expand All @@ -15,7 +16,7 @@ def form_fields
resource.extended_metadata = ExtendedMetadata.new(extended_metadata_type: cm)
format.html do
render partial: 'extended_metadata/extended_metadata_fields',
locals: { extended_metadata_type: cm, resource: resource }
locals: { extended_metadata_type: cm, resource:, parent_resource: }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/isa_assays_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def assay_params
{ samples_attributes: %i[asset_id direction] },
{ data_files_attributes: %i[asset_id direction relationship_type_id] },
{ publication_ids: [] },
{ extended_metadata_attributes: determine_extended_metadata_keys },
{ extended_metadata_attributes: determine_extended_metadata_keys(:assay) },
{ discussion_links_attributes: %i[id url label _destroy] }]
end

Expand Down
2 changes: 1 addition & 1 deletion app/controllers/isa_studies_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def study_params
[:title, :description, :experimentalists, :investigation_id, { sop_ids: [] },
*creator_related_params, :position, { scales: [] }, { publication_ids: [] },
{ discussion_links_attributes: %i[id url label _destroy] },
{ extended_metadata_attributes: determine_extended_metadata_keys }]
{ extended_metadata_attributes: determine_extended_metadata_keys(:study) }]
end

def sample_type_params(params, field)
Expand Down
9 changes: 7 additions & 2 deletions app/helpers/extended_metadata_helper.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
module ExtendedMetadataHelper
include SamplesHelper

def extended_metadata_form_field_for_attribute(attribute, resource)
def extended_metadata_form_field_for_attribute(attribute, resource, parent_resource=nil)
element_class = "extended_metadata_attribute_#{attribute.sample_attribute_type.base_type.downcase}"
element_name = "#{resource.class.name.underscore}[extended_metadata_attributes][data][#{attribute.title}]"

if parent_resource
element_name = "#{parent_resource}[#{resource.class.name.underscore}][extended_metadata_attributes][data][#{attribute.title}]"
else
element_name = "#{resource.class.name.underscore}[extended_metadata_attributes][data][#{attribute.title}]"
end

if attribute.linked_extended_metadata? || attribute.linked_extended_metadata_multi?
content_tag(:span, class: 'linked_extended_metdata') do
Expand Down
7 changes: 7 additions & 0 deletions app/models/assay.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ def has_linked_child_assay?
sample_type&.linked_sample_attributes&.any?
end

# Fetches the assay which is linked through linked_sample_attributes (Single Page specific method)
def linked_assay
sample_type.linked_sample_attributes
.select { |lsa| lsa.isa_tag.nil? && lsa.title.include?('Input') }
.first&.sample_type&.assays&.first
end

def default_contributor
User.current_user.try :person
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<%
panel_label ||= 'Extended metadata'
panel_style = resource.extended_metadata.try(:extended_metadata_type) ? '' : 'display:none'
%>
parent_resource ||= parent_resource
%>

<%= folding_panel(panel_label, false, style:panel_style,id:'extended_metadata_attribute_panel') do %>
<div id="extended_attributes">
<% if resource.extended_metadata.try(:extended_metadata_type) %>
<%= render partial: 'extended_metadata/extended_metadata_fields', locals: { extended_metadata_type: resource.extended_metadata.extended_metadata_type, resource: resource } %>
<%= render partial: 'extended_metadata/extended_metadata_fields', locals: { extended_metadata_type: resource.extended_metadata.extended_metadata_type, resource:, parent_resource: } %>
<% end %>
</div>
<% end %>
Expand All @@ -15,6 +16,8 @@

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

const parentResourceData = "<%= local_assigns.has_key?(:parent_resource) ? parent_resource : nil %>"

$j('#extended_metadata_attributes_extended_metadata_type_id').change(function() {
if (this.value) {
$j('#extended_metadata_attribute_panel').show();
Expand All @@ -24,7 +27,7 @@
$j.ajax({
url: "<%= form_fields_extended_metadata_types_path %>",
type: "get",
data: {'id':this.value},
data: {'id':this.value, 'parentResource': parentResourceData},
dataType: 'html',
beforeSend: function() {
$j('#extended_attributes').html('<div class="spinner"></div>');
Expand All @@ -48,4 +51,4 @@
});
});

</script>
</script>
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% extended_metadata_type.extended_metadata_attributes.each do |attribute| %>
<div class="form-group">
<%= extended_metadata_form_field_for_attribute(attribute,resource) %>
<%= extended_metadata_form_field_for_attribute(attribute,resource, parent_resource) %>
<% unless attribute.description.nil? %>
<%= extended_metadata_attribute_description(attribute.description) %>
<% end %>
</div>
<% end %>
<% end %>
43 changes: 32 additions & 11 deletions app/views/isa_assays/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,31 @@
<%
input_sample_type_id = params[:isa_assay][:input_sample_type_id] if params.dig(:isa_assay, :input_sample_type_id)
source_assay = Assay.find(params[:source_assay_id]) if params[:source_assay_id]
input_sample_type_id ||=

if !@isa_assay.assay.new_record?
assay_position = source_assay.position
elsif params[:source_assay_id]
assay_position = source_assay.position + 1
else
assay_position = 0
end

# assay_position = params[:source_assay_id] ? source_assay.position + 1 : 0
input_sample_type_id ||=
if params[:is_source]
study.sample_types.second.id
else
source_assay.sample_type.id if params[:source_assay_id]
end

show_extended_metadata =
if params[:is_source]
true
elsif source_assay&.position&.zero? && !@isa_assay.assay.new_record?
true # Custom metadata should be shown in edit as well if assay position is 0.
else
false
end
%>

<%= error_messages_for :isa_assay %>
Expand All @@ -25,16 +44,18 @@ input_sample_type_id ||=
<%= assay_fields.text_area :description, :rows => 5, :class=>"form-control rich-text-edit" -%>
</div>

<%= render partial: 'extended_metadata/extended_metadata_type_selection', locals:{f:assay_fields, resource:@isa_assay.assay} %>
<%= render partial: 'extended_metadata/extended_metadata_attribute_input', locals:{f:assay_fields,resource:@isa_assay.assay} %>
<% if show_extended_metadata %>
<%= render partial: 'extended_metadata/extended_metadata_type_selection', locals:{f:assay_fields, resource:@isa_assay.assay} %>
<%= render partial: 'extended_metadata/extended_metadata_attribute_input', locals:{f:assay_fields,resource:@isa_assay.assay, parent_resource: "isa_assay"} %>
<% end %>

<div class="form-group hidden" >
<label class="required"><%= t('study') -%></label>
<%= assay_study_selection('isa_assay[assay][study_id]',@isa_assay.assay.study) %>
</div>

<div class="hidden">
<%= assay_fields.number_field :position, value: source_assay&.position || study.assays.length -%>
<%= assay_fields.number_field :position, value: assay_position || study.assays.length -%>
</div>

<%= assay_fields.hidden_field :assay_class_id -%>
Expand All @@ -48,7 +69,7 @@ input_sample_type_id ||=

<%= render :partial=> "assets/discussion_links_form", :locals=>{:resource => @isa_assay.assay} -%>

<% end -%>
<% end -%>

<%= f.hidden_field :input_sample_type_id, value: input_sample_type_id -%>

Expand All @@ -57,7 +78,7 @@ input_sample_type_id ||=
<%= render partial: 'isa_studies/sample_types_form', locals: {f: f, sample_type: @isa_assay.sample_type, id_suffix: "_sample_type", isa_element: "assay", action: action} %>
<% end %>
<% end %>

<%= form_submit_buttons(@isa_assay.assay) %>


Expand All @@ -75,15 +96,15 @@ input_sample_type_id ||=
showTemplateModal()
}

$j(document).ready(function () {
$j(document).ready(function () {
const urlSearchParams = new URLSearchParams(window.location.search);
const params = Object.fromEntries(urlSearchParams.entries());
const study_id = params["study_id"]
$j("option:enabled", "#isa_assay_input_sample_type_id").prop('selected', true);
// Prevent setting the hidden field on redirect (query string parameters are missing)
if(study_id)
$j("#isa_assay_assay_study_id").val(study_id).change();
if(study_id)
$j("#isa_assay_assay_study_id").val(study_id).change();

Templates.init($j('#template-attributes'));
});
Templates.init($j('#template-attributes'));
});
</script>
5 changes: 2 additions & 3 deletions app/views/isa_studies/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<%= study_fields.text_area :description, :rows=>5, :class=>"form-control rich-text-edit" %>
</div>

<%= render partial: 'extended_metadata/extended_metadata_type_selection', locals:{f:f, resource:@isa_study.study} %>
<%= render partial: 'extended_metadata/extended_metadata_type_selection', locals:{f:study_fields, resource:@isa_study.study} %>
<%= render partial: 'extended_metadata/extended_metadata_attribute_input', locals:{f:study_fields,resource:@isa_study.study, parent_resource: "isa_study"} %>

<% unless @isa_study.study.experimentalists.blank? %>
<div class="form-group">
Expand All @@ -31,8 +32,6 @@
<%= study_fields.number_field :position, :rows => 5, :class=>"form-control" -%>
</div>

<%= render partial: 'extended_metadata/extended_metadata_attribute_input', locals:{f:f,resource:@isa_study.study} %>

<%= render partial: 'assets/manage_specific_attributes', locals: { f: study_fields } if show_form_manage_specific_attributes? %>

<%= study_fields.fancy_multiselect :publications, { other_projects_checkbox: true, name: "isa_study[study][publication_ids]" } %>
Expand Down
6 changes: 6 additions & 0 deletions db/seeds/007_sample_attribute_types.seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
resolution:'http://identifiers.org/inchi/\\0')


# Custom Date dataType tailored to what ENA expects => combination of regex and controlled vocabulary
ena_iso_date_type = SampleAttributeType.find_or_initialize_by(title: 'ENA collection date')
kdp-cloud marked this conversation as resolved.
Show resolved Hide resolved
ena_iso_date_type.update(base_type: Seek::Samples::BaseType::STRING,
regexp: '^(?:[12]\d{3}(?:-(?:0[1-9]|1[0-2])(?:-(?:0[1-9]|[12]\d|3[01]))?)?(?:T\d{2}:\d{2}(?::\d{2})?Z?(?:[+-]\d{1,2})?)?(?:\/\d{4}-(?:\d{2}-(?:\d{2}(?:T\d{2}:\d{2}(?::\d{2})?Z?(?:[+-]\d{1,2})?)?)?)?)?)?$|^not collected$|^not provided$|^restricted access$|^missing: control sample$|^missing: sample group$|^missing: synthetic construct$|^missing: lab stock$|^missing: third party data$|^missing: data agreement established pre-2023$|^missing: endangered species$|^missing: human-identifiable$',
kdp-cloud marked this conversation as resolved.
Show resolved Hide resolved
placeholder: '2015 or 2015-01 or 2015-01-01')

bool_type = SampleAttributeType.find_or_initialize_by(title:'Boolean')
bool_type.update(base_type: Seek::Samples::BaseType::BOOLEAN)

Expand Down
Loading
Loading