PageSourceSearch

https://glycoanalysis.info/static/src/search-module/tree-search.mjs

js glycoanalysis.info collected 2026-10-05 02:02:10 UTC 3,570 bytes, 90 lines download raw bytes

1import { Glycan } from '../Glycan.mjs'
2import { format } from '../format-instances.mjs';
3import { renderClickResult, renderResultTabs, renderResultExceed} from '../decoration-module/render.mjs';
4var treeObject;
5var inInstances = {};
6var exInstances = {};
7var allInstances = {};
8var selected;
9var flag;
10
11function treeSearch(s, mode) {
12    sessionStorage.setItem('mode', 'tree');
13    selected = s.map(s => { return s.data.id });
14    var data = {
15        nodes: selected,
16        mode: mode
17    };
18    sessionStorage.setItem('treeSearchCondition', JSON.stringify(data));
19    flag = false;
20    treeObject = JSON.parse(localStorage.getItem('treeObject'));
21    [exInstances, inInstances, allInstances] = format()
22    if(selected.length == 0){
23        sessionStorage.setItem('treeResult', JSON.stringify([...Object.keys(exInstances).map( glycan => exInstances[glycan]), ...Object.keys(inInstances).map( glycan =>inInstances[glycan])]) );
24        return [exInstances, inInstances, allInstances]
25    }
26
27    switch (mode) {
28        case 'fit':
29            var result = search_by_fit();
30            if(result['flag']){
31                switch (result['type']){
32                    case 'ex':
33                        renderClickResult( exInstances[ result['glycan'] ], allInstances);
34                        break;
35                    case 'in':
36                        renderClickResult( inInstances[ result['glycan'] ], allInstances);
37                        break;
38                }
39                sessionStorage.setItem('treeResult', JSON.stringify([...Object.keys(exInstances).map( glycan => exInstances[glycan]), ...Object.keys(inInstances).map( glycan =>inInstances[glycan])]) );
40                return [exInstances, inInstances, allInstances]
41            }else{
42                return [exInstances, inInstances, allInstances]
43            }
44        case 'fuzzy':
45            search_by_fuzzy();
46            sessionStorage.setItem('treeResult', JSON.stringify([...Object.keys(exInstances).map( glycan => exInstances[glycan]), ...Object.keys(inInstances).map( glycan =>inInstances[glycan])]) );
47            return [exInstances, inInstances, allInstances];
48        default:
49            alert('mode select ERROR: at tree node select search window.search_by_tree');
50            break;
51    }
52}
53
54function search_by_fit() {
55    var result = [null, null];
56    Object.keys(exInstances).forEach(glycan => {
57        if(JSON.stringify(exInstances[glycan].structureComposition()) == JSON.stringify(selected)){ 
58            exInstances[glycan].singleClicked();
59            flag = true;
60            result = ['ex', glycan];
61        }
62    })
63    Object.keys(inInstances).forEach(glycan => {
64        if(JSON.stringify(inInstances[glycan].structureComposition()) == JSON.stringify(selected)){
65            inInstances[glycan].singleClicked();
66            flag = true;
67            result = ['in', glycan];
68        }
69    })
70    return {'flag': flag, 'glycan': result[1], 'type': result[0]};
71}
72
73function search_by_fuzzy() {
74    Object.keys(exInstances).forEach(glycan => {
75        if(selected.every( select => exInstances[glycan].structureComposition().includes(select))){
76            exInstances[glycan].multiSelected();
77        }else{
78            exInstances[glycan].makeHidden();
79        }
80    });
81    Object.keys(inInstances).forEach(glycan => {
82        if(selected.every( select => inInstances[glycan].structureComposition().includes(select))){
83            inInstances[glycan].multiSelected();
84        }else{
85            inInstances[glycan].makeHidden();
86        }
87    })
88}
89
90export {treeSearch}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.