Skip to content

Commit

Permalink
fix: molecules filtering and other bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CS76 committed Nov 16, 2023
1 parent cf6763e commit bb3d701
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 43 deletions.
8 changes: 4 additions & 4 deletions app/Http/Controllers/API/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,15 @@ public function search(Request $request)
$offset;
} elseif ($queryType == 'inchi') {
$statement =
"select id, COUNT(*) OVER () from molecules where standard_inchi LIKE '%".
"select id, COUNT(*) OVER () from molecules WHERE identifier NOTNULL AND standard_inchi LIKE '%".
$query.
"%' limit ".
$limit.
' offset '.
$offset;
} elseif ($queryType == 'inchikey') {
$statement =
"select id, COUNT(*) OVER () from molecules where standard_inchi_key LIKE '%".
"select id, COUNT(*) OVER () from molecules WHERE identifier NOTNULL AND standard_inchi_key LIKE '%".
$query.
"%' limit ".
$limit.
Expand Down Expand Up @@ -257,7 +257,7 @@ public function search(Request $request)
if ($query) {
$query = str_replace("'", "''", $query);
$statement =
"select id, COUNT(*) OVER () from molecules WHERE (\"name\"::TEXT ILIKE '%".
"select id, COUNT(*) OVER () from molecules WHERE identifier NOTNULL AND (\"name\"::TEXT ILIKE '%".
$query.
"%') OR (\"synonyms\"::TEXT ILIKE '%".
$query.
Expand Down Expand Up @@ -294,7 +294,7 @@ public function search(Request $request)

if ($ids != '') {
$statement =
'SELECT * FROM molecules WHERE ID IN ('.
'SELECT * FROM molecules WHERE identifier NOTNULL AND ID IN ('.
implode(
',',
collect($hits)
Expand Down
77 changes: 40 additions & 37 deletions resources/js/Pages/Study/About.vue
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,11 @@
<div
class="rounded-md border my-3 flex justify-center items-center"
>
<span
v-html="
getSVGString(
molecule
)
<Depictor2D
:molecule="
molecule.canonical_smiles
"
></span>
></Depictor2D>
</div>
</div>
<button
Expand Down Expand Up @@ -492,7 +490,7 @@
<button
type="button"
class="inline-flex items-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-white bg-teal-600 hover:bg-teal-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-teal-500"
@click="saveMolecule"
@click="saveMolecule(null)"
>
ADD
</button>
Expand Down Expand Up @@ -607,6 +605,7 @@ import slider from "vue3-slider";
import OCL from "openchemlib/full";
import ToolTip from "@/Shared/ToolTip.vue";
import JetInputError from "@/Jetstream/InputError.vue";
import Depictor2D from "@/Shared/Depictor2D.vue";
export default {
components: {
StudyContent,
Expand All @@ -617,6 +616,7 @@ export default {
PencilIcon,
InformationCircleIcon,
JetInputError,
Depictor2D,
},
props: [
"study",
Expand Down Expand Up @@ -702,7 +702,7 @@ export default {
});
},
editMolecule(mol) {
this.editor.setMolFile("\n " + mol.MOL.replaceAll('"', ""));
this.editor.setSmiles(mol.canonical_smiles);
this.percentage = parseInt(mol.pivot.percentage_composition);
axios
.delete(
Expand All @@ -715,36 +715,39 @@ export default {
this.study.sample.molecules = res.data;
});
},
saveMolecule() {
let mol = this.editor.getMolFile();
saveMolecule(mol, study) {
if (!study) {
study = this.study;
}
if (!mol) {
let mol = this.editor.getMolFile();
this.standardizeMolecules(mol).then((res) => {
this.associateMoleculeToStudy(res.data, study);
});
} else {
this.associateMoleculeToStudy(mol, study);
}
},
standardizeMolecules(mol) {
return axios.post(
"https://api.naturalproducts.net/latest/chem/standardize",
mol
);
},
associateMoleculeToStudy(mol, study) {
axios
.post(
"https://www.cheminfo.org/webservices/inchi",
"molfile=" + mol
)
.then((response) => {
let InChI = response.data.output.InChI;
let InChIKey = response.data.output.InChIKey;
let MF = this.editor
.getMolecule()
.getMolecularFormula().formula;
axios
.post(
"/dashboard/studies/" + this.study.id + "/molecule",
{
InChI: InChI,
InChIKey: InChIKey,
percentage: this.percentage,
formula: MF,
mol: mol,
}
)
.then((res) => {
this.study.sample.molecules = res.data;
this.smiles = "";
this.percentage = 0;
this.editor.setSmiles("");
});
.post("/dashboard/studies/" + study.id + "/molecule", {
InChI: mol.inchi,
InChIKey: mol.inchikey,
percentage: 0,
mol: mol.standardized_mol,
canonical_smiles: mol.canonical_smiles,
})
.then((res) => {
study.sample.molecules = res.data;
this.smiles = "";
this.percentage = 0;
// this.editor.setSmiles("");
});
},
},
Expand Down
4 changes: 2 additions & 2 deletions resources/js/Pages/Upload.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2883,12 +2883,12 @@ export default {
},
standardizeMolecules(mol) {
return axios.post(
"https://dev.api.naturalproducts.net/latest/chem/standardize",
"https://api.naturalproducts.net/latest/chem/standardize",
mol
);
},
editMolecule(mol) {
this.editor.setMolFile(mol.MOL);
this.editor.setSmiles(mol.canonical_smiles);
this.percentage = parseInt(mol.pivot.percentage_composition);
axios
.delete(
Expand Down

0 comments on commit bb3d701

Please sign in to comment.