Skip to content

Commit

Permalink
Merge branch 'develop' into y24-055
Browse files Browse the repository at this point in the history
  • Loading branch information
harrietc52 committed Sep 3, 2024
2 parents d4d5731 + 6b78652 commit caca1ff
Show file tree
Hide file tree
Showing 18 changed files with 392 additions and 44 deletions.
12 changes: 6 additions & 6 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ GEM
backports (3.25.0)
base64 (0.2.0)
bigdecimal (3.1.8)
bootsnap (1.18.3)
bootsnap (1.18.4)
msgpack (~> 1.2)
builder (3.3.0)
bullet (7.2.0)
Expand Down Expand Up @@ -154,7 +154,7 @@ GEM
choice (0.2.0)
chronic (0.10.2)
coderay (1.1.3)
concurrent-ruby (1.3.3)
concurrent-ruby (1.3.4)
configatron (4.5.1)
connection_pool (2.4.1)
crack (1.0.0)
Expand Down Expand Up @@ -275,7 +275,7 @@ GEM
mime-types-data (3.2024.0305)
mini_magick (4.12.0)
mini_mime (1.1.5)
minitest (5.24.1)
minitest (5.25.1)
minitest-profiler (0.0.2)
activesupport (>= 4.1.0)
minitest (>= 5.3.3)
Expand Down Expand Up @@ -389,7 +389,7 @@ GEM
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rexml (3.3.4)
rexml (3.3.6)
strscan
roo (2.10.1)
nokogiri (~> 1)
Expand All @@ -402,7 +402,7 @@ GEM
rspec-expectations (>= 2.99.0.beta1)
rspec-core (3.13.0)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.1)
rspec-expectations (3.13.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-github (2.4.0)
Expand All @@ -416,7 +416,7 @@ GEM
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-rails (6.1.3)
rspec-rails (6.1.4)
actionpack (>= 6.1)
activesupport (>= 6.1)
railties (>= 6.1)
Expand Down
85 changes: 52 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,44 +27,51 @@ a organisation of 900 people.

<!-- toc -->

- [Documentation](#documentation)
- [Requirements](#requirements)
- [Getting started (using Docker)](#getting-started-using-docker)
- [Getting started (using native installation)](#getting-started-using-native-installation)
- [Installing ruby](#installing-ruby)
- [rbenv](#rbenv)
- [Automatic Sequencescape setup](#automatic-sequencescape-setup)
- [Manual Sequencescape setup](#manual-sequencescape-setup)
- [Installing gems](#installing-gems)
- [Adjusting config](#adjusting-config)
- [Default setup](#default-setup)
- [Starting rails](#starting-rails)
- [Delayed job](#delayed-job)
- [Message broker](#message-broker)
- [Testing](#testing)
- [Linting and formatting](#linting-and-formatting)
- [Rake tasks](#rake-tasks)
- [Supporting applications](#supporting-applications)
- [Barcode printing](#barcode-printing)
- [Plate barcode service](#plate-barcode-service)
- [Data warehousing](#data-warehousing)
- [Miscellaneous](#miscellaneous)
- [Lefthook](#lefthook)
- [Ruby warnings and rake 11](#ruby-warnings-and-rake-11)
- [NPG - Illumina tracking software](#npg---illumina-tracking-software)
- [Troubleshooting](#troubleshooting)
- [MySQL errors when installing](#mysql-errors-when-installing)
- [Installing on Apple Silicon (M1)](#installing-on-apple-silicon-m1)
- [API V2 Authentication](#api-v2-authentication)
- [Publishing AMQP Messages](#publishing-amqp-messages)
- [Updating the table of contents](#updating-the-table-of-contents)
- [CI](#ci)
- [ Sequencescape](#-sequencescape)
- [Contents](#contents)
- [Documentation](#documentation)
- [Linting](#linting)
- [Requirements](#requirements)
- [Getting started (using Docker)](#getting-started-using-docker)
- [Getting started (using native installation)](#getting-started-using-native-installation)
- [Installing ruby](#installing-ruby)
- [rbenv](#rbenv)
- [Automatic Sequencescape setup](#automatic-sequencescape-setup)
- [Manual Sequencescape setup](#manual-sequencescape-setup)
- [Installing gems](#installing-gems)
- [Adjusting config](#adjusting-config)
- [Default setup](#default-setup)
- [Starting rails](#starting-rails)
- [Delayed job](#delayed-job)
- [Message broker](#message-broker)
- [Testing](#testing)
- [Linting and formatting](#linting-and-formatting)
- [Rake tasks](#rake-tasks)
- [Supporting applications](#supporting-applications)
- [Barcode printing](#barcode-printing)
- [Plate barcode service](#plate-barcode-service)
- [Data warehousing](#data-warehousing)
- [Miscellaneous](#miscellaneous)
- [Lefthook](#lefthook)
- [Ruby warnings and rake 11](#ruby-warnings-and-rake-11)
- [NPG - Illumina tracking software](#npg---illumina-tracking-software)
- [Troubleshooting](#troubleshooting)
- [MySQL errors when installing](#mysql-errors-when-installing)
- [Installing on Apple Silicon (M1)](#installing-on-apple-silicon-m1)
- [API V2 Authentication](#api-v2-authentication)
- [Publishing AMQP Messages](#publishing-amqp-messages)
- [Updating the table of contents](#updating-the-table-of-contents)
- [CI](#ci)
- [ERD](#erd)

<!-- tocstop -->

## Documentation

In addition to the [externally hosted YARD docs](https://www.rubydoc.info/github/sanger/sequencescape), you can also run a local server:
The Yard documentation is also hosted at [GitHub Pages](https://pages.github.com/) under [https://sanger.github.io/sequencescape/](https://sanger.github.io/sequencescape/).
The documentation is automatically updated via a CI workflow when a merge to master occurs, but you can also trigger it manually against any branch (the branch can be selected using the "Run Workflow" button in the [corresponding action](https://github.com/sanger/sequencescape/actions/workflows/generate_pages.yml)).

To preview this documentation, you can spin up a yard server locally using the following command:

```shell
yard server --reload sequencescape
Expand Down Expand Up @@ -461,3 +468,15 @@ npx markdown-toc -i README.md --bullets "-"
The GH actions builds use the Knapsack-pro gem to reduce build time by parallelizing the RSpec and Cucumber tests. There is no need to regenerate the knapsack_rspec_report.json file, Knapsack Pro will dynamically allocate tests to ensure tests finish as close together as possible.

Copyright (c) 2007, 2010-2021 Genome Research Ltd.

### ERD

You can create a database entity relationship diagram, by specifying the title and attributes optionally, and view the output:

```
bundle exec rake erd title='Sequencescape Entity Relationship Diagram' attributes='primary_keys,foreign_keys,inheritance' orientation=horizontal polymorphism=true notation=bachman indirect=false inheritance=true only='Sample,Study,AliquotIndex,Aliquot,Project,Order,Submission,Labware,Receptacle,Request,Request::Metadata,Batch,BatchRequest,LabEvent,RequestType,Pipeline,SampleManifest,Sample::Metadata,Study::Metadata,Item,BaitLibrary,RequestEvent,Project::Metadata,Barcode,Purpose,QCResult,QCAssay,User,Plate,Tube,Well' exclude='Target,Commentable,Failable,Eventful,Eventable,Resource,Attributable,Owner,Authorizable,Documentable'
open erd.pdf
```

The command uses the [rails-erd](https://github.com/voormedia/rails-erd) gem.
2 changes: 1 addition & 1 deletion app/views/receptacles/new_request.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<% instance_variable_or_id_param(:request_type) do |field_name, value| %>
<div class="form-group col-xs-12">
<%= label_tag(field_name, 'Request type', class: 'col-md-4') %>
<%= select_field_sorted_by_name(field_name, @request_types, value, can_edit) %>
<%= select_field_sorted_by_name(field_name, @request_types, value, can_edit, prompt: 'Select a request type', required: true) %>
</div>
<% end %>
<% if @asset.studies.uniq.count > 1 -%>
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/metadata/edit/_request.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<%- request.request_metadata.field_infos.each do |field_info| %>
<!-- todo unify with how submission use field info-->
<%- if field_info.selection %>
<%= metadata_fields.select(field_info.key, field_info.selection) %>
<%= metadata_fields.select(field_info.key, field_info.selection, { prompt: "Select a #{field_info.key.to_s.gsub( '_', ' ')}" }) %>
<%- elsif field_info.kind == FieldInfo::BOOLEAN %>
<%= metadata_fields.check_box(field_info.key) %>
<%- elsif field_info.kind == FieldInfo::NUMERIC %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# This submission template is associated with the Limber Bait Capture Library preparation pipeline.
# To create this run WIP=010_bait_capture_library_submission_templates rake record_loader:all
---
Limber-Htp - RVI - Bait Capture Library:
Limber-Htp - RVI Bait Capture Library - NovaSeq 6000 Paired end sequencing:
submission_class_name: "LinearSubmission"
related_records:
request_type_keys: ["limber_bait_capture_library_prep", "limber_multiplexing"]
request_type_keys:
["limber_bait_capture_library_prep", "limber_multiplexing", "illumina_htp_novaseq_6000_paired_end_sequencing"]
project_name: Respiratory Virus and Microbiome Initiative
product_line_name: Illumina-HTP
product_catalogue_name: Bait Capture Library
3 changes: 3 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@
Bullet.bullet_logger = true
Bullet.rails_logger = true
end

# load WIP features flag
config.deploy_wip_pipelines = true
end

Rack::MiniProfiler.config.position = 'right'
3 changes: 3 additions & 0 deletions config/environments/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,7 @@

# Raises error for missing translations.
# config.action_view.raise_on_missing_translations = true

# load WIP features flag
config.deploy_wip_pipelines = true
end
20 changes: 20 additions & 0 deletions lib/record_loader/application_record_loader.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true
require 'find'

# This file was automatically generated by `rails g record_loader`
module RecordLoader
Expand All @@ -9,5 +10,24 @@ class ApplicationRecordLoader < RecordLoader::Base
# Uses the standard RailsAdapter
# @see https://rubydoc.info/github/sanger/record_loader/RecordLoader/Adapter
adapter RecordLoader::Adapter::Rails.new

def wip_list
# return a list of WIP files name as features if deploy_wip_pipelines is set to true, or return empty list
deploy_wip_pipelines = Rails.application.config.try(:deploy_wip_pipelines) || false
return [] unless deploy_wip_pipelines

wip_files = []
# @path is initialised from the directory argument passed to the initialiser method of the super class.
# By default, it returns 'config/default_records' directory
# see https://github.com/sanger/record_loader/blob/master/lib/record_loader/base.rb
wip_files_path = @path
Find.find(wip_files_path) do |path|
if path.match?(/\wip\.yml$/)
file_name = File.basename(path, '.wip.yml')
wip_files << file_name
end
end
wip_files
end
end
end
83 changes: 83 additions & 0 deletions lib/tasks/add_missing_asset_audit_records.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

# Rails task to add missing asset audit records from a CSV file
namespace :asset_audit do
# This rake task is used to add missing asset audit records from a CSV file.
# If there are any errors in the CSV file, no records will be inserted.
# Usage: rails asset_audit:add_missing_records['/path/to/file.csv']
# The CSV file should have the following headers:
# barcode, message, created_by, created_at
# The message column should have one of the following values:
# 'Destroying location', 'Destroying labware'

desc 'Add missing asset audit records'
task :add_missing_records, [:file_path] => :environment do |_, args|
required_csv_headers = %w[barcode message created_by created_at]

# Check if the file path is provided and valid
file_path = args[:file_path] == 'nil' ? nil : args[:file_path]
raise 'Please provide a valid file path' if file_path.nil? || !File.exist?(file_path)

# Read the CSV file and validate the headers
begin
csv_data = CSV.read(file_path, headers: true)
rescue StandardError => e
raise "Failed to read CSV file: #{e.message}"
end

unless csv_data.headers.length == required_csv_headers.length
raise 'Failed to read CSV file: Invalid number of header columns.'
end

# Process the CSV data and create asset audit records data array to insert
asset_audit_data = []
csv_data.each do |row|
missing_columns = required_csv_headers.select { |header| row[header].nil? }

# Check if any of the required columns are missing
raise 'Failed to read CSV file: Missing columns.' unless missing_columns.empty?

# Find the asset by barcode
asset = Labware.find_by_barcode(row['barcode'].strip)
raise "Asset with barcode #{row['barcode']} not found." if asset.nil?

# Check if the message is valid
key =
case row['message']
when 'Destroying location'
'destroy_location'
when 'Destroying labware'
'destroy_labware'
end

raise "Invalid message for asset with barcode #{row['barcode']}." if key.nil?

# Create the asset audit record data
data = {
asset_id: asset.id,
created_by: row['created_by'],
created_at: row['created_at'],
message: "Process '#{row['message']}' performed on instrument Destroying instrument",
key: key
}
asset_audit_data << data
end

# Insert the asset audit records
ActiveRecord::Base.transaction do
asset_audit_data.each do |data|
AssetAudit.create!(
message: data[:message],
created_by: data[:created_by],
created_at: data[:created_at],
asset_id: data[:asset_id],
key: data[:key]
)
end
puts 'All records successfully inserted.'
rescue ActiveRecord::ActiveRecordError => e
puts "Failed to insert records: #{e.message}"
raise ActiveRecord::Rollback
end
end
end
2 changes: 2 additions & 0 deletions spec/data/asset_audits/bad_format.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
barcode,message,created_by,created_at
SQPD-9002;"Destroying location;User1,2021-01-01 12:00:00
2 changes: 2 additions & 0 deletions spec/data/asset_audits/invalid_message.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
barcode,message,created_by,created_at
SQPD-1,Destroying test,User1,2021-01-01 12:00:00
2 changes: 2 additions & 0 deletions spec/data/asset_audits/missing_column.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
barcode,message,created_by,created_at
SQPD-1,Destroying location,2021-01-01 12:00:00
2 changes: 2 additions & 0 deletions spec/data/asset_audits/missing_header.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
barcode,created_by,created_at
SQPD-1,Destroying location,2021-01-01 12:00:00
3 changes: 3 additions & 0 deletions spec/data/asset_audits/valid_data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
barcode,message,created_by,created_at
SQPD-1,Destroying location,User1,2021-01-01 12:00:00
SQPD-2,Destroying labware,User2,2021-01-02 12:00:00
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Test record loader records
---
Test Record:
test_attribute: "A Value"
28 changes: 28 additions & 0 deletions spec/features/assets/asset_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,34 @@
create(request_factory, study: study, project: project, asset: asset, request_type: original_request_type)
end

describe 'The request form does not set default values' do
let(:user) { create :admin }

before do
login_user user
visit labware_path(asset)
click_link 'Request additional sequencing'
end

describe 'when the form is loaded' do
it 'does not set request type' do
expect(page).to have_select('Request type', selected: 'Select a request type')
end
end

describe 'when the user selects a request type' do
before { select 'Request Type 1', from: 'Request type' }

it 'does not set flowcell type to default value' do
expect(page).to have_select('Flowcell type', selected: 'Select a requested flowcell type')
end

it 'does not set read length to default value' do
expect(page).to have_select('Read length', selected: 'Select a read length')
end
end
end

shared_examples 'it allows additional sequencing' do
it 'request additional sequencing' do
login_user user
Expand Down
Loading

0 comments on commit caca1ff

Please sign in to comment.