-
Notifications
You must be signed in to change notification settings - Fork 55
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
fix: creating molecules with invalid molfile using faulty smiles #2255
base: main
Are you sure you want to change the base?
fix: creating molecules with invalid molfile using faulty smiles #2255
Conversation
@@ -42,15 +42,16 @@ class MoleculeAPI < Grape::API | |||
molfile = babel_info[:molfile] if babel_info | |||
begin | |||
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles) | |||
rd_mol = rw_mol.mol_to_mol_block unless rw_mol.nil? | |||
rd_mol = rw_mol.mol_to_mol_block unless rw_mol.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [291/200]
LCOV of commit
|
let(:faulty_smiles) { Chemotion::OpenBabelService.get_smiles_from_molfile(invalid_molfile) } | ||
|
||
before do | ||
allow(Chemotion::PubchemService).to receive(:molfile_from_smiles).with(faulty_smiles).and_return(corrupt_molfile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/LineLength: Line is too long. [121/120]
LCOV of commit
|
d057483
to
d2fb6be
Compare
LCOV of commit
|
d2fb6be
to
b17441a
Compare
@@ -42,15 +42,15 @@ class MoleculeAPI < Grape::API | |||
molfile = babel_info[:molfile] if babel_info | |||
begin | |||
rw_mol = RDKitChem::RWMol.mol_from_smiles(smiles) | |||
rd_mol = rw_mol.mol_to_mol_block unless rw_mol.nil? | |||
rd_mol = rw_mol.mol_to_mol_block unless rw_mol.nil? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ClassLength: Class has too many lines. [290/200]
b17441a
to
16992a1
Compare
LCOV of commit
|
LCOV of commit
|
fix: return nil when response status is 400 for get_molfile_by_smiles |
16992a1
to
4cd48c2
Compare
@@ -80,7 +80,10 @@ def self.get_molfile_by_smiles(smiles) | |||
@auth = { username: '', password: '' } | |||
options = { timeout: 10, headers: { 'Content-Type' => 'text/json' } } | |||
encoded_smiles = URI.encode(smiles, '[]/()+-.@#=\\') | |||
HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options).body | |||
response = HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Metrics/ModuleLength: Module has too many lines. [192/100]
@@ -80,7 +80,10 @@ def self.get_molfile_by_smiles(smiles) | |||
@auth = { username: '', password: '' } | |||
options = { timeout: 10, headers: { 'Content-Type' => 'text/json' } } | |||
encoded_smiles = URI.encode(smiles, '[]/()+-.@#=\\') | |||
HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options).body | |||
response = HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style/StringConcatenation: Prefer string interpolation to string concatenation.
@@ -80,7 +80,10 @@ def self.get_molfile_by_smiles(smiles) | |||
@auth = { username: '', password: '' } | |||
options = { timeout: 10, headers: { 'Content-Type' => 'text/json' } } | |||
encoded_smiles = URI.encode(smiles, '[]/()+-.@#=\\') | |||
HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options).body | |||
response = HTTParty.get(http_s + PUBCHEM_HOST + '/rest/pug/compound/smiles/' + encoded_smiles + '/record/SDF', options) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/LineLength: Line is too long. [123/120]
spec/api/molecule_api_spec.rb
Outdated
before do | ||
allow(Chemotion::OpenBabelService).to receive(:molfile_clear_hydrogens) | ||
.with(any_args) | ||
.and_return("Status: 400\n OpenBabel01092512342D\nMessage: Unable to standardize the given structure - perhaps some special charac\n 0 0 0 0 0 0 0 0 0 0999 V2000\nM END\n") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/LineLength: Line is too long. [193/120]
end | ||
|
||
JSON.parse(File.read('spec/fixtures/structures/bad_smiles.json')).each_value do |data| | ||
context 'when testing SMILES entry' do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RSpec/NestedGroups: Maximum example group nesting exceeded [4/3].
spec/spec_helper.rb
Outdated
error_body = "<<~BODY | ||
Status: 400 | ||
Code: PUGREST.BadRequest | ||
Message: Unable to standardize the given structure - perhaps some special characters need to be escaped or data packed in a MIME form? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Layout/LineLength: Line is too long. [140/120]
LCOV of commit
|
4cd48c2
to
5930336
Compare
5930336
to
bbaa130
Compare
LCOV of commit
|
LCOV of commit
|
ensure the status of request to pubchem for getting mol from smiles is OK.
Otherwise return nil