-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from privrja/devel
Version 1.0.2
- Loading branch information
Showing
21 changed files
with
769 additions
and
400 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
import IFinder from "./IFinder"; | ||
import SingleStructure from "./SingleStructure"; | ||
import Sleep from "../helper/Sleep"; | ||
import {ServerEnum} from "../enum/ServerEnum"; | ||
import ComputeHelper from "../helper/ComputeHelper"; | ||
|
||
const ENDPOINT_URI = "https://guarded-atoll-36331.herokuapp.com/https://coconut.naturalproducts.net/api/search/"; | ||
|
||
interface Molecule { | ||
coconut_id: string; | ||
name: string; | ||
unique_smiles: string; | ||
molecular_formula: string; | ||
} | ||
|
||
class CoconutFinder implements IFinder { | ||
|
||
async simpleFind(parameter: string, query: string = 'simple?query=') { | ||
if (parameter === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
if (query.includes('simple?query')) { | ||
query += parameter; | ||
} | ||
return fetch(ENDPOINT_URI + query).then(async response => { | ||
if (response.status === 200) { | ||
let json = await response.json().catch(() => []); | ||
if (json.naturalProducts.length > 0) { | ||
return json.naturalProducts.map((molecule: Molecule) => { | ||
let mass = 0; | ||
try { | ||
mass = ComputeHelper.computeMass(ComputeHelper.removeUnnecessaryCharactersFromFormula(molecule.molecular_formula ?? '')); | ||
} catch (e) { | ||
} | ||
return new SingleStructure( | ||
molecule.coconut_id, | ||
ServerEnum.COCONUT, | ||
molecule.name, | ||
molecule.unique_smiles, | ||
molecule.molecular_formula, | ||
mass | ||
) | ||
}); | ||
} | ||
} | ||
return []; | ||
}).catch(() => []); | ||
} | ||
|
||
findByFormula(formula: string): Promise<SingleStructure[]> { | ||
return this.simpleFind(formula); | ||
} | ||
|
||
async findByIdentifier(id: string): Promise<SingleStructure[]> { | ||
if (id === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return fetch(ENDPOINT_URI + 'simple?query=' + id).then(async response => { | ||
if (response.status === 200) { | ||
let json = await response.json().catch(() => []); | ||
if (json.naturalProducts.length > 0) { | ||
let mass = 0; | ||
try { | ||
mass = ComputeHelper.computeMass(ComputeHelper.removeUnnecessaryCharactersFromFormula(json.naturalProducts[0].molecular_formula ?? '')); | ||
} catch (e) { | ||
} | ||
return [new SingleStructure( | ||
json.naturalProducts[0].coconut_id, | ||
ServerEnum.COCONUT, | ||
json.naturalProducts[0].name, | ||
json.naturalProducts[0].unique_smiles, | ||
json.naturalProducts[0].molecular_formula, | ||
mass | ||
)]; | ||
} else { | ||
return []; | ||
} | ||
} else { | ||
return []; | ||
} | ||
}).catch(() => []); | ||
} | ||
|
||
findByIdentifiers(ids: string[]): Promise<SingleStructure[]> { | ||
return Sleep.noSleepPromise(); | ||
} | ||
|
||
findByMass(mass: number): Promise<SingleStructure[]> { | ||
return Sleep.noSleepPromise(); | ||
} | ||
|
||
findByName(name: string): Promise<SingleStructure[]> { | ||
return this.simpleFind(name); | ||
} | ||
|
||
findBySmiles(smiles: string): Promise<SingleStructure[]> { | ||
return this.simpleFind(smiles, 'exact-structure?type=inchi&max-hits=100&smiles=' + smiles); | ||
} | ||
|
||
|
||
} | ||
|
||
export default CoconutFinder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import IFinder from "./IFinder"; | ||
import SingleStructure from "./SingleStructure"; | ||
import Sleep from "../helper/Sleep"; | ||
import {ServerEnum} from "../enum/ServerEnum"; | ||
import ComputeHelper from "../helper/ComputeHelper"; | ||
|
||
const ENDPOINT_URI = "https://guarded-atoll-36331.herokuapp.com/https://www.npatlas.org/api/v1/"; | ||
|
||
interface Molecule { | ||
npaid: string; | ||
original_name: string; | ||
smiles: string; | ||
mol_formula: string; | ||
} | ||
|
||
const BASIC_SEARCH = 'compounds/basicSearch?'; | ||
const PARAMS = '&threshold=0&origin_type=all&rank=all&skip=0&limit=100'; | ||
|
||
class NPAtlasFinder implements IFinder { | ||
|
||
basicSearch(endpoint: string, method: string, oneResult: boolean = false): Promise<SingleStructure[]> { | ||
return fetch(endpoint, {method: method}).then(async response => { | ||
if (response.status === 200) { | ||
let json = await response.json().catch(() => []); | ||
if (oneResult) { | ||
let mass = 0; | ||
try { | ||
mass = ComputeHelper.computeMass(ComputeHelper.removeUnnecessaryCharactersFromFormula(json.mol_formula ?? '')); | ||
} catch (e) { | ||
} | ||
return [new SingleStructure(json.npaid, ServerEnum.NP_ATLAS, json.original_name, json.smiles, json.mol_formula, mass)]; | ||
} else { | ||
if (json.length > 0) { | ||
return json.map((molecule: Molecule) => { | ||
let mass = 0; | ||
try { | ||
mass = ComputeHelper.computeMass(ComputeHelper.removeUnnecessaryCharactersFromFormula(molecule.mol_formula ?? '')); | ||
} catch (e) { | ||
} | ||
return new SingleStructure(molecule.npaid, ServerEnum.NP_ATLAS, molecule.original_name, molecule.smiles, molecule.mol_formula, mass); | ||
}); | ||
} | ||
} | ||
} | ||
return []; | ||
}).catch(() => []); | ||
} | ||
|
||
findByFormula(formula: string): Promise<SingleStructure[]> { | ||
if (formula === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return this.basicSearch(ENDPOINT_URI + BASIC_SEARCH + 'formula=' + formula + PARAMS, 'POST'); | ||
} | ||
|
||
async findByIdentifier(id: string): Promise<SingleStructure[]> { | ||
if (id === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return this.basicSearch(ENDPOINT_URI + 'compound/' + id, 'GET', true); | ||
} | ||
|
||
findByIdentifiers(ids: string[]): Promise<SingleStructure[]> { | ||
return Sleep.noSleepPromise(); | ||
} | ||
|
||
findByMass(mass: number): Promise<SingleStructure[]> { | ||
if (mass === 0) { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return this.basicSearch(ENDPOINT_URI + 'compounds/massSearch?mass=' + mass + '&type=exact_mass&range=100&skip=0&limit=100', 'POST'); | ||
} | ||
|
||
findByName(name: string): Promise<SingleStructure[]> { | ||
if (name === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return this.basicSearch(ENDPOINT_URI + BASIC_SEARCH + 'name=' + name + PARAMS, 'POST'); | ||
} | ||
|
||
findBySmiles(smiles: string): Promise<SingleStructure[]> { | ||
if (smiles === '') { | ||
return Sleep.noSleepPromise(); | ||
} | ||
return this.basicSearch(ENDPOINT_URI + BASIC_SEARCH + 'smiles=' + smiles + '&method=sub' + PARAMS, 'POST'); | ||
} | ||
|
||
} | ||
|
||
export default NPAtlasFinder; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.