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

Compare XML and database for tax id #748

Closed
wants to merge 2 commits into from
Closed
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
17 changes: 13 additions & 4 deletions api/app/models/database/bioproject/submitter.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Database::BioProject::Submitter
class VisibilityMismatch < StandardError; end
class TaxIdMismatch < StandardError; end
class SubmissionIDOverflow < StandardError; end

PROJECT_DATA_TYPES = {
Expand Down Expand Up @@ -237,12 +238,20 @@ def submission_data_attrs(submission, doc)
},

doc.at("/PackageSet/Package/Project/Project/ProjectType/ProjectTypeSubmission/Target/Organism").then {
tax_id = _1&.[](:taxID) || begin
if organism_name = doc.at("/PackageSet/Package/Project/Project/ProjectType/ProjectTypeSubmission/Target/Organism/OrganismName")&.text
DRASearch::TaxName.where(search_name: organism_name, name_class: "scientific name").pick(:tax_id)
xml_tax_id = _1&.[](:taxID)

tax_id = if organism_name = doc.at("/PackageSet/Package/Project/Project/ProjectType/ProjectTypeSubmission/Target/Organism/OrganismName")&.text
drasearch_tax_id = DRASearch::TaxName.where(search_name: organism_name, name_class: "scientific name").pick(:tax_id)

if xml_tax_id
raise TaxIdMismatch if xml_tax_id != drasearch_tax_id.to_s

xml_tax_id
else
nil
drasearch_tax_id
end
else
nil
end

[ "target", "taxonomy_id", tax_id == "0" ? nil : tax_id, -1 ]
Expand Down
2 changes: 1 addition & 1 deletion api/spec/fixtures/files/bioproject/valid/full.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<ProjectType>
<ProjectTypeSubmission>
<Target sample_scope="project_type.sample_scope" material="project_type.material" capture="project_type.capture">
<Organism taxID="target.taxonomy_id || 0">
<Organism taxID="42">
<OrganismName>target.organism_name</OrganismName>
<Label>target.isolate_name_or_label?</Label>
<Strain>target.strain_breed_cultivar</Strain>
Expand Down
4 changes: 3 additions & 1 deletion api/spec/models/database/bioproject/submitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ def create_submission(visibility:, file:)
end

example "full" do
create :drasearch_tax_names, search_name: "target.organism_name", name_class: "scientific name", tax_id: 42

submission = create_submission(visibility: :private, file: "bioproject/valid/full.xml")

Database::BioProject::Submitter.new.submit submission
Expand Down Expand Up @@ -298,7 +300,7 @@ def create_submission(visibility:, file:)
{
form_name: "target",
data_name: "taxonomy_id",
data_value: "target.taxonomy_id || 0",
data_value: "42",
t_order: -1
},
{
Expand Down
Loading