Skip to content

DRA submission #480

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ gem "rails", "~> 8.0.0"

gem "aws-sdk-s3"
gem "base62-rb"
gem "bcrypt_pbkdf"
gem "bootsnap", require: false
gem "ed25519"
gem "fetch-api"
gem "jb"
gem "json"
gem "metabobank_tools", github: "ddbj/metabobank_tools"
gem "net-ssh"
gem "noodles_gff", path: "../noodles_gff-rb"
gem "openid_connect"
gem "pagy"
Expand Down
7 changes: 7 additions & 0 deletions api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ GEM
aws-eventstream (~> 1, >= 1.0.2)
base62-rb (0.3.1)
base64 (0.2.0)
bcrypt_pbkdf (1.1.1)
bcrypt_pbkdf (1.1.1-arm64-darwin)
benchmark (0.4.0)
bigdecimal (3.1.8)
bindata (2.5.0)
Expand All @@ -143,6 +145,7 @@ GEM
reline (>= 0.3.8)
diff-lcs (1.5.1)
drb (2.2.1)
ed25519 (1.3.0)
email_validator (2.2.4)
activemodel
erubi (1.13.0)
Expand Down Expand Up @@ -221,6 +224,7 @@ GEM
timeout
net-smtp (0.5.0)
net-protocol
net-ssh (7.3.0)
nio4r (2.7.4)
nokogiri (1.16.8-aarch64-linux)
racc (~> 1.4)
Expand Down Expand Up @@ -431,15 +435,18 @@ PLATFORMS
DEPENDENCIES
aws-sdk-s3
base62-rb
bcrypt_pbkdf
bootsnap
brakeman
climate_control
debug
ed25519
factory_bot_rails
fetch-api
jb
json
metabobank_tools!
net-ssh
noodles_gff!
openid_connect
pagy
Expand Down
13 changes: 7 additions & 6 deletions api/app/models/database/bioproject/submitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,16 @@ def submit(submission)
)

tx.after_commit do
DRMDB::ExtEntity.create!(
entity = DRMDB::ExtEntity.create!(
acc_type: :study,
ref_name: submission_id,
status: :valid
) do |entity|
entity.ext_permits.build(
submitter_id:
)
end
)

DRMDB::ExtPermit.create!(
ext_id: entity.ext_id,
submitter_id:
)
end
end
end
Expand Down
16 changes: 7 additions & 9 deletions api/app/models/database/biosample/submitter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def submit(submission)
BioSample::OperationHistory.create!(
type: :fatal,
summary: "[repository:CreateNewSubmission] Number of submission surpass the upper limit",
date: Time.current,
submitter_id:
)
end
Expand All @@ -27,7 +26,6 @@ def submit(submission)
BioSample::OperationHistory.create!(
type: :error,
summary: "[repository:CreateNewSubmission] rollback transaction",
date: Time.current,
submitter_id:
)
end
Expand Down Expand Up @@ -126,22 +124,22 @@ def submit(submission)
)

tx.after_commit do
DRMDB::ExtEntity.create!(
entity = DRMDB::ExtEntity.create!(
acc_type: :sample,
ref_name: sample.smp_id,
status: :valid
) do |entity|
entity.ext_permits.build(
submitter_id:
)
end
)

DRMDB::ExtPermit.create!(
ext_id: entity.ext_id,
submitter_id:
)
end
end

BioSample::OperationHistory.create!(
type: :info,
summary: "[repository:CreateNewSubmission] Create new submission",
date: Time.current,
submitter_id:,
submission_id:
)
Expand Down
94 changes: 93 additions & 1 deletion api/app/models/database/dra/submitter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,97 @@
class Database::DRA::Submitter
def submit(submission)
# do nothing
submitter_id = submission.validation.user.uid
user_id = SubmitterDB::Login.where(submitter_id:).pick(:usr_id)

DRMDB::Record.transaction isolation: Rails.env.test? ? nil : :serializable do
serial = (DRMDB::Submission.where(submitter_id:).maximum(:serial) || 0) + 1

dra_submission = DRMDB::Submission.create!(
usr_id: user_id,
submitter_id:,
serial:,
create_date: Date.current
)

dra_submission.status_histories.create! status: :data_validated

submission_group = dra_submission.create_submission_group!(
submit_version: 1,
valid: true,
serial_version: 1
)

submission_id = "#{submitter_id}-#{serial.to_s.rjust(4, '0')}"
center_name = SubmitterDB::Organization.where(submitter_id:).pick(:center_name)
objs = submission.validation.objs.where(_id: %w(Submission Experiment Run Analysis))

acc_entities_assoc = objs.map { |obj|
DRMDB::AccessionEntity.create!(
alias: "#{submission_id}_#{obj._id}_0001",
center_name:,
acc_type: obj._id.downcase
)
}.index_by(&:acc_type)

objs.each do |obj|
parent_acc_entity = case obj._id
when "Submission"
nil
when "Study", "Sample"
acc_entities_assoc["DRA"]
when "Sample"
acc_entities_assoc["sample"]
when "Experiment"
acc_entities_assoc["sample"] || acc_entities_assoc["study"]
when "Run"
acc_entities_assoc["DRX"]
when "Analysis"
acc_entities_assoc["study"]
else
raise "must not happen"
end

submission_group.accession_relations.create!(
accession_entity: acc_entity,
parent_accession_entity: parent_acc_entity
) do |relation|
relation.build_meta_entity(
accession_entity: acc_entity,
meta_version: 1,
type: obj._id.downcase,
content: obj.file.download
)
end

ext_entity = DRMDB::ExtEntity.create!(
acc_type: :submission,
ref_name: "160053",
status: :valid
)

submission_group.ext_relations.create!(
acc_id: acc_entity.acc_id,
ext_id: ext_entity.ext_id
) do |relation|
relation.build_ext_permit(
ext_id: ext_entity.ext_id,
submitter_id:
)
end
end

host, user, key_data = ENV.values_at("DRA_SSH_HOST", "DRA_SSH_USER", "DRA_SSH_KEY_DATA")

Net::SSH.start host, user, key_data: [ key_data ] do |ssh|
ssh.exec! "sudo /usr/local/sbin/chroot-createdir.sh #{submitter_id} #{submission_id}"
end

DRMDB::OperationHistory.create!(
type: :info,
summary: "Direct submission via repository",
usr_id: user_id,
submitter_id:
)
end
end
end
12 changes: 12 additions & 0 deletions api/app/models/drmdb/accession_entity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class DRMDB::AccessionEntity < DRMDB::Record
self.table_name = "accession_entity"

belongs_to :accession_relation, optional: true, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id", primary_key: "acc_id"

enum :acc_type, {
submission: "DRA",
experiment: "DRX",
run: "DRR",
analysis: "DRZ"
}
end
10 changes: 10 additions & 0 deletions api/app/models/drmdb/accession_relation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class DRMDB::AccessionRelation < DRMDB::Record
self.table_name = "accession_relation"

belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id", primary_key: "grp_id"
belongs_to :accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id"
belongs_to :parent_accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "p_acc_id", primary_key: "acc_id", optinal: true

has_many :accession_entities, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id"
has_one :meta_entity, class_name: "DRMDB::MetaEntity", foreign_key: "acc_id", primary_key: "acc_id"
end
3 changes: 3 additions & 0 deletions api/app/models/drmdb/batch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class DRMDB::Batch < DRMDB::Record
self.table_name = 'batch'
end
2 changes: 1 addition & 1 deletion api/app/models/drmdb/ext_entity.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class DRMDB::ExtEntity < DRMDB::Record
self.table_name = "ext_entity"

has_many :ext_permits, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id"
belongs_to :ext_relation, optional: true, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id", primary_key: "ext_id"

enum :acc_type, {
study: "PSUB",
Expand Down
2 changes: 2 additions & 0 deletions api/app/models/drmdb/ext_permit.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
class DRMDB::ExtPermit < DRMDB::Record
self.table_name = "ext_permit"

belongs_to :ext_relation, optional: true, class_name: "DRMDB::ExtRelation", foreign_key: "ext_id", primary_key: "ext_id"
end
8 changes: 8 additions & 0 deletions api/app/models/drmdb/ext_relation.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class DRMDB::ExtRelation < DRMDB::Record
self.table_name = "ext_relation"

belongs_to :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "grp_id", primary_key: "grp_id"

has_many :ext_entities, class_name: "DRMDB::ExtEntity", foreign_key: "ext_id", primary_key: "ext_id"
has_one :ext_permit, class_name: "DRMDB::ExtPermit", foreign_key: "ext_id", primary_key: "ext_id"
end
7 changes: 7 additions & 0 deletions api/app/models/drmdb/meta_entity.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class DRMDB::MetaEntity < DRMDB::Record
self.table_name = "meta_entity"
self.inheritance_column = nil

belongs_to :accession_relation, class_name: "DRMDB::AccessionRelation", foreign_key: "acc_id", primary_key: "acc_id"
belongs_to :accession_entity, class_name: "DRMDB::AccessionEntity", foreign_key: "acc_id", primary_key: "acc_id"
end
7 changes: 6 additions & 1 deletion api/app/models/drmdb/operation_history.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
class DRMDB::OperationHistory < DRMDB::Record
self.table_name = "operation_history"
self.table_name = "operation_history"
self.inheritance_column = nil

enum :type, {
info: 3
}
end
17 changes: 17 additions & 0 deletions api/app/models/drmdb/status_history.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
class DRMDB::StatusHistory < DRMDB::Record
self.table_name = "status_history"

belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id"

enum :status, {
new: 100,
meta_validated: 300,
data_validating: 380,
data_error: 390,
data_validated: 400,
acc_issued: 500,
private_complete: 700,
release_notifed: 750,
public_complete: 800,
cancel: 1000,
suppress: 1100,
killed: 1200
}, prefix: true
end
3 changes: 3 additions & 0 deletions api/app/models/drmdb/submission.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
class DRMDB::Submission < DRMDB::Record
self.table_name = "submission"

has_one :submission_group, class_name: "DRMDB::SubmissionGroup", foreign_key: "sub_id"
has_many :status_histories, class_name: "DRMDB::StatusHistory", foreign_key: "sub_id"
end
5 changes: 5 additions & 0 deletions api/app/models/drmdb/submission_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class DRMDB::SubmissionComponent < DRMDB::Record
self.table_name = 'submission_component'

belongs_to :submission_group, class_name: 'DRMDB::SubmissionGroup', foreign_key: 'grp_id', primary_key: 'grp_id'
end
21 changes: 21 additions & 0 deletions api/app/models/drmdb/submission_group.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
class DRMDB::SubmissionGroup < DRMDB::Record
self.table_name = "submission_group"

belongs_to :submission, class_name: "DRMDB::Submission", foreign_key: "sub_id"

has_many :submission_components, class_name: "DRMDB::SubmissionComponent", foreign_key: "grp_id", primary_key: "grp_id"
has_many :accession_relations, class_name: "DRMDB::AccessionRelation", foreign_key: "grp_id", primary_key: "grp_id"
has_many :ext_relations, class_name: "DRMDB::ExtRelation", foreign_key: "grp_id", primary_key: "grp_id"

has_many :accession_entities, through: :accession_relations
has_many :meta_entities, through: :accession_relations
has_many :ext_entities, through: :ext_relations
has_many :ext_permits, through: :ext_relations

class << self
def instance_method_already_implemented?(method_name)
return true if method_name == "valid?"
super
end
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BioProjectInit < ActiveRecord::Migration[7.2]
class BioProjectInit < ActiveRecord::Migration[8.0]
def change
execute 'CREATE SCHEMA mass'

Expand Down
2 changes: 1 addition & 1 deletion api/db/biosample_migrate/20240829001416_biosample_init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class BioSampleInit < ActiveRecord::Migration[7.2]
class BioSampleInit < ActiveRecord::Migration[8.0]
def change
execute 'CREATE SCHEMA mass'

Expand Down
2 changes: 1 addition & 1 deletion api/db/drasearch_migrate/20241023004659_dra_search_init.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
class DRASearchInit < ActiveRecord::Migration[7.2]
class DRASearchInit < ActiveRecord::Migration[8.0]
def change
execute 'CREATE SCHEMA sra'

Expand Down
Loading
Loading