ExtendedMetadata_Support

7 views
Skip to first unread message

Yasmin Demerdash

unread,
Oct 23, 2024, 11:08:18 AM10/23/24
to SEEK Developers
Hello, 

We want to add new extended metadata to our Fairdom Seek instance. It's not new; we just want to incorporate the NGS metadata from GEO as extended metadata for the "assay." However, we are encountering errors, so I would really appreciate it if someone could provide feedback on this code.
Here, I am pasting the initial code and the error we encountered, followed by the modified code I created. I would appreciate your feedback on whether the new code is functional now. 

here is the first code used: 

# NGS Extended Metadata

ngs_emt = ExtendedMetadataType.where(title: 'NGS', supported_type: 'Assay').first_or_create!

# Define attributes
attributes = [
   {
    title: 'overall_design',
    label: 'Overall Design',
    required: true,
    description: 'Describe the overall experimental design.'
  },
  {
    title: 'growth_protocol',
    label: 'Growth Protocol',
    required: false,
    description: 'Describe the conditions used to grow or maintain organisms or cells prior to the extract preparations.'
  },
  {
    title: 'treatment_protocol',
    label: 'Treatment Protocol',
    required: false,
    description: 'If applicable, describes any treatments applied to the biological material prior to extract preparations.'
  },
  {
    title: 'extract_protocol',
    label: 'Extract Protocol',
    required: true,
    description: 'Describes the protocols used to extract and prepare the material to be sequenced.'
  },
  {
    title: 'library_construction_protocol',
    label: 'Library Construction Protocol',
    required: true,
    description: 'Describe the protocol used for library construction.'
  },
  {
    title: 'library_strategy',
    label: 'Library Strategy',
    required: true,
    description: 'Specify the library strategy (e.g., miRNA-Seq, RNA-Seq, ChIP-Seq, ncRNA-Seq).'
  },
  {
    title: 'data_processing_step',
    label: 'Data Processing Step',
    required: true,
    description: 'Provide details of how processed data files were generated.'
  }
]

# Create Extended Metadata Attributes
attributes.each do |attr|
  ngs_emt.extended_metadata_attributes.where(title: attr[:title]).first_or_create!(
    label: attr[:label],
    required: attr[:required],
    description: attr[:description],
    sample_attribute_type: SampleAttributeType.where(title: 'Text').first
  )
end

puts "NGS Extended Metadata created successfully!"

here is the error we got: 
The filename must be "ngs_extended_metadata.seeds.rb", then it throws the following error message:

bundle exec rails db:seed:ngs_extended_metadata
rails aborted!
ActiveRecord::RecordInvalid: Validation failed: Extended metadata attributes can't be blank
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/validations.rb:80:in `raise_validation_error'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/validations.rb:53:in `save!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:302:in `block in save!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:354:in `block in with_transaction_returning_status'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `block in transaction'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:319:in `block in within_new_transaction'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:26:in `block (2 levels) in synchronize'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `handle_interrupt'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:25:in `block in synchronize'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `handle_interrupt'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.8/lib/active_support/concurrency/load_interlock_aware_monitor.rb:21:in `synchronize'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/transaction.rb:317:in `within_new_transaction'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/connection_adapters/abstract/database_statements.rb:320:in `transaction'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:350:in `with_transaction_returning_status'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/transactions.rb:302:in `save!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/suppressor.rb:48:in `save!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/persistence.rb:55:in `create!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:799:in `_create!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:114:in `block in create!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:406:in `block in scoping'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:804:in `_scoping'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:406:in `scoping'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:114:in `create!'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/activerecord-6.1.7.8/lib/active_record/relation.rb:123:in `first_or_create!'
/data/rails/seek/db/seeds/ngs_extended_metadata.seeds.rb:4:in `evaluate'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/seedbank-0.5.0/lib/seedbank/runner.rb:51:in `instance_eval'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/seedbank-0.5.0/lib/seedbank/runner.rb:51:in `evaluate'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/seedbank-0.5.0/lib/seedbank/dsl.rb:32:in `block in define_seed_task'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `block in execute'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `each'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:281:in `execute'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `synchronize'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:199:in `invoke_with_call_chain'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/task.rb:188:in `invoke'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:182:in `invoke_task'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block (2 levels) in top_level'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `each'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:138:in `block in top_level'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:147:in `run_with_threads'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:132:in `top_level'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.8/lib/rails/commands/rake/rake_command.rb:24:in `block (2 levels) in perform'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/application.rb:208:in `standard_exception_handling'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.8/lib/rails/commands/rake/rake_command.rb:24:in `block in perform'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/rake-13.1.0/lib/rake/rake_module.rb:59:in `with_application'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.8/lib/rails/commands/rake/rake_command.rb:18:in `perform'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.8/lib/rails/command.rb:50:in `invoke'
/data/rails/seek/vendor/bundle/ruby/3.1.0/gems/railties-6.1.7.8/lib/rails/commands.rb:18:in `<top (required)>'
Tasks: TOP => db:seed:ngs_extended_metadata
(See full trace by running task with --trace)
 
and now here is the new code I modified:
puts 'Seeded NGS Extended Metadata'

# Define a method to create Extended Metadata Attributes
def create_extended_metadata_attribute(title:, required:, label:, description:, sample_attribute_type:)
  ExtendedMetadataAttribute.where(title: title).first_or_create!(
    title: title,
    required: required,
    label: label,
    description: description,
    sample_attribute_type: sample_attribute_type
  )
end

# NGS Extended Metadata
ngs_emt = ExtendedMetadataType.where(title: 'NGS', supported_type: 'Assay').first_or_create!(
  title: 'NGS',
  supported_type: 'Assay',
  extended_metadata_attributes: [
    create_extended_metadata_attribute(
      title: 'overall_design',
      required: true,
      label: 'Overall Design',
      description: 'Describe the overall experimental design.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'growth_protocol',
      required: false,
      label: 'Growth Protocol',
      description: 'Describe the conditions used to grow or maintain organisms or cells prior to the extract preparations.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'treatment_protocol',
      required: false,
      label: 'Treatment Protocol',
      description: 'If applicable, describes any treatments applied to the biological material prior to extract preparations.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'extract_protocol',
      required: true,
      label: 'Extract Protocol',
      description: 'Describes the protocols used to extract and prepare the material to be sequenced.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'library_construction_protocol',
      required: true,
      label: 'Library Construction Protocol',
      description: 'Describe the protocol used for library construction.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'library_strategy',
      required: true,
      label: 'Library Strategy',
      description: 'Specify the library strategy (e.g., miRNA-Seq, RNA-Seq, ChIP-Seq, ncRNA-Seq).',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    ),
    create_extended_metadata_attribute(
      title: 'data_processing_step',
      required: true,
      label: 'Data Processing Step',
      description: 'Provide details of how processed data files were generated.',
      sample_attribute_type: SampleAttributeType.where(title: 'Text').first
    )
  ]
)

puts "NGS Extended Metadata created successfully!"


Xiaoming Hu

unread,
Oct 25, 2024, 10:40:24 AM10/25/24
to Yasmin Demerdash, SEEK Developers
Morning Yasmin,

I have run your code successfully and created the NGS type (see attached screenshot). 

Attached is the file I used. Please name it ngs_extended_metadata.seeds.rb and place it under db/seeds/ngs_extended_metadata.seeds.rb.  Once the file is in the  db/seeds/ folder, you can run the seed file using the following command from the SEEK instance root path:

bundle exec rake db:seed:ngs_extended_metadata

Additionally, I wanted to mention that we’ve implemented a new feature allowing instance admins to upload a JSON file to create an extended metadata type. This feature will be included in the upcoming SEEK 1.16 release, which is coming soon.
If you’re interested, you can get an early look at it. Here’s the 
documentation for this new feature.

I hope it helps

Have a nice day
Xiaoming 





ngs_extended_metadata.seeds.rb
PastedGraphic-1.tiff

Yasmin Demerdash

unread,
Oct 25, 2024, 10:40:29 AM10/25/24
to Xiaoming Hu, SEEK Developers
Morning Xiaoming, 

Thanks a lot for your fast response and support. 
We will give it a try. 
I will check the documentation and I'm looking forward to the new release. 

best, 
Yasmin 

--
You received this message because you are subscribed to the Google Groups "SEEK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to seek-develope...@googlegroups.com.
To view this discussion on the web, visit https://groups.google.com/d/msgid/seek-developers/a3972155-1ce8-4f83-89b9-edf3f64166cen%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages