From e00fe4140cd08c56637dfbc17dfb6b650a155e8f Mon Sep 17 00:00:00 2001 From: bobhanson Date: Thu, 5 Dec 2024 13:08:58 -0600 Subject: [PATCH] FAIRSpec-gui fixes for substructure search --- docs/examples/assets/FAIRSpec-config.js | 8 ++ docs/examples/assets/FAIRSpec-get.js | 49 +++++++--- docs/examples/assets/FAIRSpec-gui.js | 89 +++++++++---------- .../html/site/assets/FAIRSpec-config.js | 8 ++ .../html/site/assets/FAIRSpec-get.js | 45 ++++++++-- .../html/site/assets/FAIRSpec-gui.js | 77 ++++++++-------- 6 files changed, 174 insertions(+), 102 deletions(-) diff --git a/docs/examples/assets/FAIRSpec-config.js b/docs/examples/assets/FAIRSpec-config.js index b579a65..5d6083a 100644 --- a/docs/examples/assets/FAIRSpec-config.js +++ b/docs/examples/assets/FAIRSpec-config.js @@ -29,3 +29,11 @@ IFD = { contentHeader: null, cache: {} } + +IFD.MODE_NONE = "none"; +IFD.MODE_COMPOUNDS = "compounds"; +IFD.MODE_STRUCTURES = "structures"; +IFD.MODE_SPECTRA = "spectra"; +IFD.MODE_SAMPLES = "samples"; +IFD.MODE_SAMPLESPECTRA = "samplespectra"; + diff --git a/docs/examples/assets/FAIRSpec-get.js b/docs/examples/assets/FAIRSpec-get.js index bc996e5..3ae9d9d 100644 --- a/docs/examples/assets/FAIRSpec-get.js +++ b/docs/examples/assets/FAIRSpec-get.js @@ -46,8 +46,12 @@ ;(function() { +IFD.getCollection = function(aidID) { + return IFD.collections[aidID]; +} + IFD.getSmilesForStructureID = function(aidID, id) { - var struc = IFD.collections[aidID].structures[id]; + var struc = IFD.getCollection(aidID).structures[id]; if (!struc) return ""; var reps = struc.representations; var types = IFD.getRepTypes(reps); @@ -55,7 +59,7 @@ IFD.getSmilesForStructureID = function(aidID, id) { } IFD.getSpectrumIDsForSample = function(aidID,id) { - var samplespecs = IFD.collections[aidID]["sample-spectra associations"]; + var samplespecs = IFD.getCollection(aidID)["sample-spectra associations"]; var items = IFD.items[aidID].samplespectra; for (var i = 0; i < items.length; i++) { var assoc = samplespecs[items[i]]; @@ -67,11 +71,11 @@ IFD.getSpectrumIDsForSample = function(aidID,id) { } IFD.getCompoundIndexesForText = function(aidID, text) { - var compounds = IFD.collections[aidID].compounds; + var compounds = IFD.getCollection(aidID).compounds; var keys = IFD.getCompoundCollectionKeys(); var ids = []; - var citems = IFD.items[aidID].compounds; text = text.toLowerCase(); + var citems = IFD.items[aidID].compounds; for (var i = 0; i < citems.length; i++) { var assoc = compounds[citems[i]]; var found = false; @@ -90,8 +94,8 @@ var testText = function(s, text) { } IFD.getCompoundIndexesForStructures = function(aidID, strucIDs) { - var compounds = IFD.collections[aidID].compounds; - var structures = IFD.collections[aidID].structures; + var compounds = IFD.getCollection(aidID).compounds; + var structures = IFD.getCollection(aidID).structures; var keys = IFD.getCompoundCollectionKeys(); var ids = []; var citems = IFD.items[aidID].compounds; @@ -112,7 +116,7 @@ IFD.getCompoundIndexesForStructures = function(aidID, strucIDs) { } IFD.getStructureIDsForSpectra = function(aidID, specIDs) { - var compounds = IFD.collections[aidID].compounds; + var compounds = IFD.getCollection(aidID).compounds; var keys = IFD.getCompoundCollectionKeys(); var ids = []; var items = IFD.items[aidID].compounds; @@ -233,12 +237,14 @@ IFD.shortType = function(type) { IFD.getCollectionSetById = function(aid) { IFD.byID = !!aid.collectionSet.itemsByID; IFD.itemsKey = (IFD.byID ? "itemsByID" : "items"); - IFD.collectionKeys = (IFD.byID ? null : {}); + IFD.collectionKeys = {}; var collections = aid.collectionSet.itemsByID || aid.collectionSet.items; var dc = IFD.collections[aid.id] = {}; + if (IFD.findingAidID == '.') + IFD.collections['.'] = dc; for (var i in collections) { c = collections[i]; - dc[c.id] = c.items || c.itemsById; + dc[c.id] = c.items || c.itemsByID; if (!IFD.byID) { IFD.collectionKeys[c.id] = c.collections; // compounds only } @@ -246,6 +252,29 @@ IFD.getCollectionSetById = function(aid) { return dc; } +IFD.getCollectionSetItems = function(aid) { + var dc = IFD.getCollectionSetById(aid); + var dItems = IFD.items[aid.id] = {}; + if (IFD.findingAidID == '.') + IFD.items['.'] = dItems; + if (dc[IFD.MODE_SAMPLES]) { + dItems[IFD.MODE_SAMPLES] = IFD.getIDs(dc[IFD.MODE_SAMPLES]); + } + if (dc[IFD.MODE_COMPOUNDS]) { + dItems[IFD.MODE_COMPOUNDS] = IFD.getIDs(dc[IFD.MODE_COMPOUNDS]); + } + if (dc[IFD.MODE_STRUCTURES]) { + dItems[IFD.MODE_STRUCTURES] = IFD.getIDs(dc[IFD.MODE_STRUCTURES]); + } + if (dc[IFD.MODE_SPECTRA]) { + dItems[IFD.MODE_SPECTRA] = IFD.getIDs(dc[IFD.MODE_SPECTRA]); + } + if (dc["sample-spectra associations"]) { + dItems[IFD.MODE_SAMPLESPECTRA] = IFD.getIDs(dc["sample-spectra associations"]); + } + return dItems; +} + IFD.getCompoundCollectionKeys = function() { var ckeys = IFD.collectionKeys.compounds; if (ckeys && !ckeys[0]) { @@ -272,7 +301,7 @@ IFD.getSMILES = function(aidID, retIDs, retSMILES, allowReactions, withAidID) { var structureIDs = IFD.items[aidID]["structures"]; for (var i = 0; i < structureIDs.length; i++) { var id = structureIDs[i]; - var struc = IFD.collections[aidID].structures[id]; + var struc = IFD.getCollection(aidID).structures[id]; var reps = struc.representations; var types = IFD.getRepTypes(reps, "smiles"); if (types.smiles) { diff --git a/docs/examples/assets/FAIRSpec-gui.js b/docs/examples/assets/FAIRSpec-gui.js index 16685d5..87fa4f3 100644 --- a/docs/examples/assets/FAIRSpec-gui.js +++ b/docs/examples/assets/FAIRSpec-gui.js @@ -19,11 +19,7 @@ var MAIN_SEARCH_PROP = "main_search_prop"; var MAIN_SEARCH = "main_search"; var MAIN_SUMMARY = "main_summary"; - var MODE_NONE = "none"; - var MODE_COMPOUNDS = "compounds"; - var MODE_STRUCTURES = "structures"; - var MODE_SPECTRA = "spectra"; - var MODE_SAMPLES = "samples"; + var NMRDB_PREDICT_SMILES = "https://www.nmrdb.org/service.php?name=%TYPE%-prediction&smiles=%SMILES%"; // where type = 1h, 13c, cosy, hmbc, hsqc @@ -31,7 +27,7 @@ var divId = 0; var dirFor = function(aidID) { - return IFD.properties.baseDir + "/" + aidID; + return IFD.properties.baseDir + (IFD.findingAidID == '.' ? "" : "/" + aidID); } var fileFor = function(aidID, fname) { @@ -68,7 +64,7 @@ // external IFD.loadFindingAids = function() { - var aids = IFD.findingAids || []; + var aids = IFD.findingAids || ["."]; IFD.aidIDs = []; var s = (aids.length == 1 ? null : '