Skip to content

Commit

Permalink
save metadata into csv for CV layout and add CDS layout (#1273)
Browse files Browse the repository at this point in the history
Co-authored-by: Lan Le <[email protected]>
  • Loading branch information
baolanlequang and Lan Le authored May 9, 2023
1 parent 23809bf commit 2b2bd33
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .service-dependencies
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#syntax=v1
CONVERTER=ComPlat/[email protected]
KETCHER=ptrxyz/chemotion-ketchersvc@main
SPECTRA=ComPlat/[email protected].2-patch.1
SPECTRA=ComPlat/[email protected].3
44 changes: 38 additions & 6 deletions app/models/concerns/attachment_jcamp_aasm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,31 @@ def generate_json_att(json_tmp, addon, to_edit = false)
generate_att(json_tmp, addon, to_edit, 'json')
end

def generate_csv_att(csv_tmp, addon, to_edit = false)
generate_att(csv_tmp, addon, to_edit, 'csv')
def generate_csv_att(csv_tmp, addon, to_edit = false, params={})
csv_reader = CSV.new(csv_tmp)
csv_data = csv_reader.read
sample_id_field = csv_data[2]
sample_id_field[1] = params[:sample_id]
analysis_id_field = csv_data[3]
analysis_id_field[1] = params[:analysis_id]
dataset_id_field = csv_data[4]
dataset_id_field[1] = params[:dataset_id]
dataset_name_field = csv_data[5]
dataset_name_field[1] = params[:dataset_name]

csv_data[2] = sample_id_field
csv_data[3] = analysis_id_field
csv_data[4] = dataset_id_field
csv_data[5] = dataset_name_field
Tempfile.create(['jcamp', '.csv']) do |new_csv_tmp|
CSV.open(new_csv_tmp, 'wb') do |csv|
csv_data.each do |row|
csv << row
end
end
new_csv_tmp.rewind
generate_att(new_csv_tmp, addon, to_edit, 'csv')
end
end

def generate_nmrium_att(nmrium_tmp, addon, to_edit = false)
Expand All @@ -176,8 +199,17 @@ def generate_nmrium_att(nmrium_tmp, addon, to_edit = false)
def build_params(params = {})
_, extname = extension_parts
params[:mass] = 0.0
params[:dataset_id] = attachable.id
params[:dataset_name] = attachable.name
if attachable&.root_element.is_a?(Sample)
params[:mass] = attachable&.root_element&.molecule&.exact_molecular_weight || 0.0
params[:sample_id] = attachable&.root_element.id

attachable.ancestors.each do |ancestor|
if ancestor.container_type == 'analysis'
params[:analysis_id] = ancestor.id
end
end
end
params[:ext] = extname.downcase
params[:fname] = filename.to_s
Expand Down Expand Up @@ -217,7 +249,7 @@ def create_process(is_regen)
check_invalid_molfile(invalid_molfile)

if spc_type == 'bagit'
read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen)
read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen, params)
elsif arr_jcamp.length > 1
read_processed_data(arr_jcamp, arr_img, spc_type, is_regen)
else
Expand Down Expand Up @@ -251,7 +283,7 @@ def edit_process(is_regen, orig_params)

unless arr_csv.nil? || arr_csv.length == 0
curr_tmp_csv = arr_csv[0]
csv_att = generate_csv_att(curr_tmp_csv, 'edit', false)
csv_att = generate_csv_att(curr_tmp_csv, 'edit', false, params)
tmp_files_to_be_deleted.push(*arr_csv)
delete_related_csv(csv_att)
end
Expand Down Expand Up @@ -331,7 +363,7 @@ def read_processed_data(arr_jcamp, arr_img, spc_type, is_regen)
jcamp_att
end

def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen)
def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen, params)
jcamp_att = nil
tmp_to_be_deleted = []
tmp_img_to_deleted = []
Expand All @@ -344,7 +376,7 @@ def read_bagit_data(arr_jcamp, arr_img, arr_csv, spc_type, is_regen)
tmp_img_to_deleted.push(img_att)

curr_tmp_csv = arr_csv[idx]
_ = generate_csv_att(curr_tmp_csv, "#{idx + 1}_bagit")
_ = generate_csv_att(curr_tmp_csv, "#{idx + 1}_bagit", false, params)
tmp_to_be_deleted.push(curr_tmp_csv)

jcamp_att = curr_jcamp_att if idx == 0
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@babel/preset-env": "^7.11.0",
"@babel/preset-react": "7.10.4",
"@citation-js/plugin-isbn": "0.3.0",
"@complat/chem-spectra-client": "0.11.4",
"@complat/react-spectra-editor": "0.11.4",
"@complat/chem-spectra-client": "0.11.5",
"@complat/react-spectra-editor": "0.11.5",
"@novnc/novnc": "^1.2.0",
"@rails/ujs": "^6.1.3-1",
"@rails/webpacker": "https://github.com/rails/webpacker.git",
Expand Down
41 changes: 39 additions & 2 deletions spec/models/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -723,9 +723,44 @@

describe '#generate_csv_att' do
it 'calls #generate_att with ext = csv and all other parameters verbatim' do
expect(attachment).to receive(:generate_att).with('somethingThatGetsPassed', 'foo', false, 'csv')
csv_temp = Tempfile.new(['jcamp', '.csv'])
csv_data = Array.new(10) {
Array.new(5) {|i| i.to_s }
}
CSV.open(csv_temp, 'wb') do |csv|
csv_data.each do |row|
csv << row
end
end

params = {
sample_id: 10,
dataset_id: 1,
dataset_name: 'root',
analysis_id: 2,
}

expected_csv_data = Array.new(10) { |line|
Array.new(5) { |i|
if line == 2 && i == 1
params[:sample_id].to_s
elsif line == 3 && i == 1
params[:analysis_id].to_s
elsif line == 4 && i == 1
params[:dataset_id].to_s
elsif line == 5 && i == 1
params[:dataset_name].to_s
else
i.to_s
end
}
}

attachment.generate_csv_att('somethingThatGetsPassed', 'foo')
att = attachment.generate_csv_att(csv_temp, 'foo', false, params)
generated_csv = att.read_file
csv_reader = CSV.new(generated_csv)
generated_csv_data = csv_reader.read
expect(generated_csv_data).to eq expected_csv_data
end
end

Expand Down Expand Up @@ -777,6 +812,8 @@
mass: 0.0,
ext: 'txt',
fname: 'upload.txt',
dataset_id: attachment.attachable.id,
dataset_name: attachment.attachable.name,
}

expect(attachment.build_params({ foo: :bar })).to eq(expected_result)
Expand Down
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1355,12 +1355,12 @@
resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9"
integrity sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ==

"@complat/[email protected].4":
version "0.11.4"
resolved "https://registry.yarnpkg.com/@complat/chem-spectra-client/-/chem-spectra-client-0.11.4.tgz#651d3255bfb8a7a693bee9b15fd74b0a31b1e273"
integrity sha512-97V6Q1ztaJkUshl162kInedzusDXNDPZ3TRw40DJIMmFuCzma/bAXPEQhoIQVZzJ9ufEPzke+dl6o8RvVG7D2Q==
"@complat/[email protected].5":
version "0.11.5"
resolved "https://registry.yarnpkg.com/@complat/chem-spectra-client/-/chem-spectra-client-0.11.5.tgz#fdfa6510a34673207f91a2efe19a94735bdef178"
integrity sha512-Rrky504uYdRfxN/mdY0SQbhTCkR46bsiQhskYdzrh2jg+fIbot+aC6DyiRFM9bIwoCG4BLRwlLwFYhrwkfgdJw==
dependencies:
"@complat/react-spectra-editor" "0.11.4"
"@complat/react-spectra-editor" "0.11.5"
"@material-ui/core" "^3.9.4"
"@material-ui/icons" "^3.0.2"
axios "^0.21.1"
Expand All @@ -1377,10 +1377,10 @@
redux-form "^8.3.7"
redux-saga "^1.1.3"

"@complat/[email protected].4":
version "0.11.4"
resolved "https://registry.yarnpkg.com/@complat/react-spectra-editor/-/react-spectra-editor-0.11.4.tgz#5abfc4268fd2bc9a2bd954f91a0b3708843bac63"
integrity sha512-CFcDog6IriKF63FhyuG4A8kUvfncbHrQx5BphUfdUe0Ke3SOUuSZgzO5HmvB7LOMBnyTFiIu8cZAvRLNWkd2sg==
"@complat/[email protected].5":
version "0.11.5"
resolved "https://registry.yarnpkg.com/@complat/react-spectra-editor/-/react-spectra-editor-0.11.5.tgz#b2322eeda7233fddc4d1de0f34d14849f56dc80b"
integrity sha512-BNxh8XOB3wxPRNzRZx7zRXj5EFrsc0XMDjM0foTNYHPAcL8GjxCU1LSsXwfO3yBd75lhlZLYc8Qc0fUm5zXdww==
dependencies:
"@complat/react-svg-file-zoom-pan" "1.0.15"
"@material-ui/core" "^4.10.0"
Expand Down

0 comments on commit 2b2bd33

Please sign in to comment.