Class: Study
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- Study
- Extended by:
- Attributable::Association::Target, EventfulRecord, Metadata
- Includes:
- AASM, Api::StudyIo::Extensions, Commentable, DataRelease, EventfulRecord, Role::Authorized, SampleManifest::Associations, SharedBehaviour::Named, StudyReport::StudyDetails, Uuid::Uuidable
- Defined in:
- app/models/study.rb
Overview
This is really quite convoluted, and couples together administrative organization alongside accessioning and data-access rules. It results in samples being tied to an EGAS/ERP far too early in their lifecycle, and as a result we often need to perform 'sample moves'. Although we do need to know if samples are open(ENA) or managed(EGA) at the point of accessioning.
A Study is a collection of various samples and the work done on them. They are perhaps slightly overloaded, and provide:
- A means of grouping together samples for administrative purposes
- A means of generating EGAS/ERP study accession numbers at the ENA/EGA
- @see Accessionable::Study
- These accession numbers are used at data release to group samples together for publication
- For managed/EGA studies, also ties the data to an Accessionable::Dac and Accessionable::Policy
- A means of generating the aforementioned Accessionable::Dac and Accessionable::Policy @note These should DEFINITELY be separate entities
- A means of tying data to internal data-release timings
- A means to apply internal data access policies to released sequencing data
- A means to tie interested parties to the samples and the work done on them
- A way of specifying common ways of filtering/processing generated data. eg. filter human sequence
- The service with which a Sample will be accessioned (eg. EGA/ENA)
When a Sample enters Sequencescape it will usually be associated with a single Study, usually determined by the Study associated with the SampleManifest. This study will be recorded on the Aliquot in the stock Receptacle, and additionally a StudySample will record this association.
When work is requested an Order will be created, specifying a list of receptacles and the Study for which this work is being performed. This will set initial study id on request and in turn will be recorded on any downstream aliquots. Critically, it is the study specified on the Aliquot in the Lane which will influence processes like data release and data access.
Defined Under Namespace
Classes: Metadata
Constant Summary collapse
- STOCK_PLATE_PURPOSES =
Constants
['Stock Plate', 'Stock RNA Plate'].freeze
- YES =
'Yes'- NO =
'No'- YES_OR_NO =
[YES, NO].freeze
- OTHER_TYPE =
'Other'- STUDY_SRA_HOLDS =
%w[Hold Public].freeze
- DATA_RELEASE_STRATEGY_OPEN =
'open'- DATA_RELEASE_STRATEGY_MANAGED =
'managed'- DATA_RELEASE_STRATEGY_NOT_APPLICABLE =
'not applicable'- DATA_RELEASE_STRATEGIES =
[ DATA_RELEASE_STRATEGY_OPEN, DATA_RELEASE_STRATEGY_MANAGED, DATA_RELEASE_STRATEGY_NOT_APPLICABLE ].freeze
- DATA_RELEASE_TIMING_STANDARD =
'standard'- DATA_RELEASE_TIMING_NEVER =
'never'- DATA_RELEASE_TIMING_DELAYED =
'delayed'- DATA_RELEASE_TIMING_IMMEDIATE =
'immediate'- DATA_RELEASE_TIMING_PUBLICATION =
'delay until publication'- ALL_DATA_RELEASE_TIMINGS =
The list of all possible data release timings
[ DATA_RELEASE_TIMING_STANDARD, DATA_RELEASE_TIMING_NEVER, DATA_RELEASE_TIMING_DELAYED, DATA_RELEASE_TIMING_IMMEDIATE, DATA_RELEASE_TIMING_PUBLICATION ].freeze
- DATA_RELEASE_TIMINGS_FOR_OPEN_RELEASE =
Release timings for open studies
[ DATA_RELEASE_TIMING_STANDARD, DATA_RELEASE_TIMING_IMMEDIATE, DATA_RELEASE_TIMING_DELAYED, DATA_RELEASE_TIMING_PUBLICATION ].freeze
- DATA_RELEASE_TIMINGS_FOR_MANAGED_RELEASE =
Release timings for managed studies
[ DATA_RELEASE_TIMING_STANDARD, DATA_RELEASE_TIMING_IMMEDIATE, DATA_RELEASE_TIMING_DELAYED ].freeze
- OLD_DATA_RELEASE_PREVENTION_REASONS =
['data validity', 'legal', 'replication of data subset'].freeze
- DATA_RELEASE_PREVENTION_REASON_OTHER =
'Other (please specify)'- DATA_RELEASE_PREVENTION_REASONS =
[ 'Pilot or validation studies - DAC approval not required', 'Collaborators will share data in a research repository - DAC approval not required', 'Prevent harm (e.g sensitive studies or biosecurity) - DAC approval required', 'Protecting IP - DAC approval required', DATA_RELEASE_PREVENTION_REASON_OTHER ].freeze
- OLD_DATA_RELEASE_DELAY_FOR_OTHER =
'other'- DATA_RELEASE_DELAY_FOR_OTHER =
'Other (please specify below)'- OLD_DATA_RELEASE_DELAY_REASONS =
['other', 'phd study'].freeze
- DATA_RELEASE_DELAY_REASONS_STANDARD =
[ 'PhD study', 'Capacity building', 'Intellectual property protection', 'Additional time to make data FAIR', DATA_RELEASE_DELAY_FOR_OTHER ].freeze
- DATA_RELEASE_DELAY_REASONS_ASSAY =
['assay of no other use'].freeze
- DATA_RELEASE_DELAY_PERIODS =
['3 months', '6 months', '9 months', '12 months', '18 months'].freeze
- EBI_LIBRARY_STRATEGY_OPTIONS =
- EBI_LIBRARY_SOURCE_OPTIONS =
- EBI_LIBRARY_SELECTION_OPTIONS =
- REMAPPED_ATTRIBUTES =
{ contaminated_human_dna: YES_OR_NO, remove_x_and_autosomes: YES_OR_NO, study_sra_hold: STUDY_SRA_HOLDS, contains_human_dna: YES_OR_NO, commercially_available: YES_OR_NO }.transform_values { |v| v.index_by { |b| b.downcase } }
Constants included from Metadata
Constants included from StudyReport::StudyDetails
StudyReport::StudyDetails::BATCH_SIZE
Instance Attribute Summary collapse
-
#approval ⇒ Object
Returns the value of attribute approval.
-
#run_count ⇒ Object
Returns the value of attribute run_count.
-
#skip_externally_managed_restriction ⇒ Object
Flag set by Integration Hub requests to lift the externally managed study edit lock.
-
#total_price ⇒ Object
Returns the value of attribute total_price.
Instance Method Summary collapse
- #abbreviation ⇒ Object
- #accession_number? ⇒ Boolean
- #approved? ⇒ Boolean
-
#asset_progress(assets = nil) {|initial_requests.asset_statistics(wheres)| ... } ⇒ Object
Yields information on the state of all assets in a convenient fashion for displaying in a table.
- #completed ⇒ Object
- #dac_accession_number ⇒ Object
- #dac_refname ⇒ Object
-
#data_release_delay_options(assay_option: false) ⇒ Array<String>
Helper method for edit dropdowns to support backwards compatibility with old options.
-
#data_release_prevention_options ⇒ Array<String>
Helper method for edit dropdowns to support backwards compatibility with old options.
- #dehumanise_abbreviated_name ⇒ Object
- #ebi_accession_number ⇒ Object
- #ethical_approval_required? ⇒ Boolean
-
#externally_managed_restrictions_enabled? ⇒ Boolean
Instance methods.
- #locale ⇒ Object
- #mailing_list_of_managers ⇒ Object
- #mark_active ⇒ Object
- #mark_deactive ⇒ Object
-
#owner ⇒ Object
Returns the study owner (user) if exists or nil TODO - Should be "owners" and return all owners or empty array - done TODO - Look into this is the person that created it really the owner? If so, then an owner should be created when a study is created.
- #policy_accession_number ⇒ Object
- #rebroadcast ⇒ Object
-
#request_progress {|@stats_cache ||= initial_requests.progress_statistics| ... } ⇒ Object
Yields information on the state of all request types in a convenient fashion for displaying in a table.
-
#sample_progress(samples = nil) ⇒ Object
Yields information on the state of all samples in a convenient fashion for displaying in a table.
-
#samples_accessionable? ⇒ Boolean
Returns true if the samples in this study are eligible for accessioning.
-
#study ⇒ Object
Used by EventfulMailer.
- #study_status ⇒ Object
- #subject_type ⇒ Object
- #text_comments ⇒ Object
-
#ui_locked? ⇒ Boolean
Returns true if the study is externally_managed and the feature flag is enabled.
- #unprocessed_submissions? ⇒ Boolean
- #validate_ethically_approved ⇒ Object
- #validate_study_for_accessioning! ⇒ Object
- #warnings ⇒ Object
Methods included from EventfulRecord
has_many_events, has_many_lab_events, has_one_event_with_family
Methods included from Metadata
Methods included from Attributable::Association::Target
default, extended, for_select_association
Methods included from SampleManifest::Associations
Methods included from SharedBehaviour::Named
Methods included from Commentable
Methods included from DataRelease
#accession_required?, #do_not_enforce_accessioning, #for_array_express?, #valid_data_release_properties?
Methods included from Uuid::Uuidable
included, #unsaved_uuid!, #uuid
Methods included from Api::StudyIo::Extensions
Methods included from StudyReport::StudyDetails
#each_stock_well_id_in_study_in_batches, #progress_report_header, #progress_report_on_all_assets
Methods inherited from ApplicationRecord
alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!
Methods included from Squishify
Methods included from Warren::Callback::ExceptExternallyManaged
#broadcast_except_externally_managed, included
Instance Attribute Details
#approval ⇒ Object
Returns the value of attribute approval.
142 143 144 |
# File 'app/models/study.rb', line 142 def approval @approval end |
#run_count ⇒ Object
Returns the value of attribute run_count.
142 143 144 |
# File 'app/models/study.rb', line 142 def run_count @run_count end |
#skip_externally_managed_restriction ⇒ Object
Flag set by Integration Hub requests to lift the externally managed study edit lock.
147 148 149 |
# File 'app/models/study.rb', line 147 def skip_externally_managed_restriction @skip_externally_managed_restriction end |
#total_price ⇒ Object
Returns the value of attribute total_price.
142 143 144 |
# File 'app/models/study.rb', line 142 def total_price @total_price end |
Instance Method Details
#abbreviation ⇒ Object
615 616 617 618 |
# File 'app/models/study.rb', line 615 def abbreviation abbreviation = .study_name_abbreviation abbreviation.presence || "#{id}STDY" end |
#accession_number? ⇒ Boolean
589 590 591 |
# File 'app/models/study.rb', line 589 def accession_number? ebi_accession_number.present? end |
#approved? ⇒ Boolean
624 625 626 627 |
# File 'app/models/study.rb', line 624 def approved? # TODO: remove true end |
#asset_progress(assets = nil) {|initial_requests.asset_statistics(wheres)| ... } ⇒ Object
Yields information on the state of all assets in a convenient fashion for displaying in a table.
527 528 529 530 531 |
# File 'app/models/study.rb', line 527 def asset_progress(assets = nil) wheres = {} wheres = { asset_id: assets.map(&:id) } if assets.present? yield(initial_requests.asset_statistics(wheres)) end |
#completed ⇒ Object
512 513 514 515 516 517 518 |
# File 'app/models/study.rb', line 512 def completed counts = requests.standard.group('state').count total = counts.values.sum failed = counts['failed'] || 0 cancelled = counts['cancelled'] || 0 (total - failed - cancelled) > 0 ? (counts.fetch('passed', 0) * 100) / (total - failed - cancelled) : 0 end |
#dac_accession_number ⇒ Object
581 582 583 |
# File 'app/models/study.rb', line 581 def dac_accession_number .ega_dac_accession_number end |
#dac_refname ⇒ Object
550 551 552 |
# File 'app/models/study.rb', line 550 def dac_refname "DAC for study - #{name} - ##{id}" end |
#data_release_delay_options(assay_option: false) ⇒ Array<String>
Helper method for edit dropdowns to support backwards compatibility with old options.
671 672 673 674 675 676 677 678 679 680 |
# File 'app/models/study.rb', line 671 def (assay_option: false) # If the current value is an old one, then we need to include it in the list of options = [] if OLD_DATA_RELEASE_DELAY_REASONS.include? .data_release_delay_reason << .data_release_delay_reason end .concat(DATA_RELEASE_DELAY_REASONS_ASSAY) if assay_option DATA_RELEASE_DELAY_REASONS_STANDARD + end |
#data_release_prevention_options ⇒ Array<String>
Helper method for edit dropdowns to support backwards compatibility with old options.
658 659 660 661 662 663 664 665 |
# File 'app/models/study.rb', line 658 def = [] if OLD_DATA_RELEASE_PREVENTION_REASONS.include? .data_release_prevention_reason << .data_release_prevention_reason end DATA_RELEASE_PREVENTION_REASONS + end |
#dehumanise_abbreviated_name ⇒ Object
620 621 622 |
# File 'app/models/study.rb', line 620 def dehumanise_abbreviated_name abbreviation.downcase.gsub(/ +/, '_') end |
#ebi_accession_number ⇒ Object
577 578 579 |
# File 'app/models/study.rb', line 577 def ebi_accession_number .study_ebi_accession_number end |
#ethical_approval_required? ⇒ Boolean
629 630 631 632 |
# File 'app/models/study.rb', line 629 def ethical_approval_required? .contains_human_dna == Study::YES && .contaminated_human_dna == Study::NO && .commercially_available == Study::NO end |
#externally_managed_restrictions_enabled? ⇒ Boolean
Instance methods
470 471 472 |
# File 'app/models/study.rb', line 470 def externally_managed_restrictions_enabled? Flipper.enabled?(:y26_172_enable_externally_managed_study_restrictions) end |
#locale ⇒ Object
573 574 575 |
# File 'app/models/study.rb', line 573 def locale funding_source end |
#mailing_list_of_managers ⇒ Object
642 643 644 645 |
# File 'app/models/study.rb', line 642 def mailing_list_of_managers configured_managers = managers.pluck(:email).compact.uniq configured_managers.empty? ? configatron.fetch(:ssr_emails, User.all_administrators_emails) : configured_managers end |
#mark_active ⇒ Object
504 505 506 |
# File 'app/models/study.rb', line 504 def mark_active logger.warn "Study activation failed! #{errors.map(&:to_s)}" unless active? end |
#mark_deactive ⇒ Object
500 501 502 |
# File 'app/models/study.rb', line 500 def mark_deactive logger.warn "Study deactivation failed! #{errors.map(&:to_s)}" unless inactive? end |
#owner ⇒ Object
Returns the study owner (user) if exists or nil TODO - Should be "owners" and return all owners or empty array - done TODO - Look into this is the person that created it really the owner? If so, then an owner should be created when a study is created.
569 570 571 |
# File 'app/models/study.rb', line 569 def owner owners.first end |
#policy_accession_number ⇒ Object
585 586 587 |
# File 'app/models/study.rb', line 585 def policy_accession_number .ega_policy_accession_number end |
#rebroadcast ⇒ Object
651 652 653 |
# File 'app/models/study.rb', line 651 def rebroadcast broadcast_except_externally_managed end |
#request_progress {|@stats_cache ||= initial_requests.progress_statistics| ... } ⇒ Object
Yields information on the state of all request types in a convenient fashion for displaying in a table. Used initial requests, which won't capture cross study sequencing requests.
522 523 524 |
# File 'app/models/study.rb', line 522 def request_progress yield(@stats_cache ||= initial_requests.progress_statistics) if block_given? end |
#sample_progress(samples = nil) ⇒ Object
Yields information on the state of all samples in a convenient fashion for displaying in a table.
534 535 536 537 538 539 540 541 542 543 544 |
# File 'app/models/study.rb', line 534 def sample_progress(samples = nil) if samples.blank? requests.sample_statistics_new else # Rubocop suggests this changes as it allows MySQL to perform a single query, which is usually better # however in this case we've actually already loaded the samples. If we do try passing in the # samples themselves, then things top working as intended. (Performance tanks in some places, and # we generate invalid SQL in others) yield(requests.where(aliquots: { sample_id: samples.pluck(:id) }).sample_statistics_new) end end |
#samples_accessionable? ⇒ Boolean
Returns true if the samples in this study are eligible for accessioning
A study's samples are eligible for accessioning if:
- the study is active
- the study's data release strategy open or managed
- the study is not set to never release
- the study requires accessioning
- the study has an accession number
603 604 605 606 607 608 609 610 611 612 613 |
# File 'app/models/study.rb', line 603 def samples_accessionable? # If updating this method, please also update app/views/studies/information/_study_accession_status.html.erb [ active?, !ui_locked?, !.strategy_not_applicable?, !.never_release?, accession_required?, accession_number? ].all? end |
#study ⇒ Object
Used by EventfulMailer
560 561 562 |
# File 'app/models/study.rb', line 560 def study self end |
#study_status ⇒ Object
546 547 548 |
# File 'app/models/study.rb', line 546 def study_status inactive? ? 'closed' : 'open' end |
#subject_type ⇒ Object
647 648 649 |
# File 'app/models/study.rb', line 647 def subject_type 'study' end |
#text_comments ⇒ Object
508 509 510 |
# File 'app/models/study.rb', line 508 def text_comments comments.each_with_object([]) { |c, array| array << c.description if c.description.present? }.join(', ') end |
#ui_locked? ⇒ Boolean
Returns true if the study is externally_managed and the feature flag is enabled
475 476 477 |
# File 'app/models/study.rb', line 475 def ui_locked? externally_managed_restrictions_enabled? && externally_managed? end |
#unprocessed_submissions? ⇒ Boolean
554 555 556 557 |
# File 'app/models/study.rb', line 554 def unprocessed_submissions? # TODO[mb14] optimize if needed study.orders.any? { |o| o.submission.nil? || o.submission.unprocessed? } end |
#validate_ethically_approved ⇒ Object
479 480 481 482 483 484 485 486 487 488 489 490 |
# File 'app/models/study.rb', line 479 def validate_ethically_approved return true if valid_ethically_approved? = if ethical_approval_required? 'should be either true or false for this study.' else 'should be not applicable (null) not false.' end errors.add(:ethically_approved, ) false end |
#validate_study_for_accessioning! ⇒ Object
634 635 636 637 638 639 640 |
# File 'app/models/study.rb', line 634 def validate_study_for_accessioning! if ui_locked? errors.add(:base, I18n.t('studies.externally_managed.accession_not_allowed')) raise ActiveRecord::RecordInvalid, self end valid?(:accession) or raise ActiveRecord::RecordInvalid, self end |
#warnings ⇒ Object
492 493 494 495 496 497 498 |
# File 'app/models/study.rb', line 492 def warnings # These studies are now invalid, but the warning should remain until existing studies are fixed. if .managed? && .data_access_group.blank? # rubocop:todo-next Layout/LineLength 'No user group specified for a managed study. Please specify a valid Unix user group to ensure study data is visible to the correct people.' end end |