Skip to content

Commit

Permalink
Exposed the JNI-InChI functionality for checking InChIs (not Standard…
Browse files Browse the repository at this point in the history
… InChI it seems; try inchi.checkStrict("InChI=1S/CH4/h1H4"))
  • Loading branch information
egonw committed Nov 1, 2012
1 parent b558482 commit 1f5cd00
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
Expand Up @@ -17,6 +17,7 @@
import net.bioclipse.core.Recorded;
import net.bioclipse.core.TestClasses;
import net.bioclipse.core.TestMethods;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.IMolecule;
import net.bioclipse.inchi.InChI;
import net.bioclipse.jobs.BioclipseJob;
Expand Down Expand Up @@ -57,6 +58,27 @@ public BioclipseJob<InChI> generate(IMolecule molecule, String options,
@TestMethods("testOptions")
public List<String> options();

@Recorded
@PublishedMethod(
methodSummary = "Checks the validity of an InChIKey.",
params="String inchikey"
)
public boolean checkKey(String inchikey) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary = "Checks the validity of an InChI (loose).",
params="String inchi"
)
public boolean check(String inchi) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary = "Checks the validity of an InChI (strict).",
params="String inchi"
)
public boolean checkStrict(String inchi) throws BioclipseException;

@Recorded
@PublishedMethod(
methodSummary = "Loads the InChI library.")
Expand Down
Expand Up @@ -17,12 +17,17 @@

import net.bioclipse.core.PublishedMethod;
import net.bioclipse.core.Recorded;
import net.bioclipse.core.business.BioclipseException;
import net.bioclipse.core.domain.IMolecule;
import net.bioclipse.inchi.InChI;
import net.bioclipse.jobs.IReturner;
import net.bioclipse.managers.business.IBioclipseManager;
import net.sf.jniinchi.INCHI_KEY_STATUS;
import net.sf.jniinchi.INCHI_OPTION;
import net.sf.jniinchi.INCHI_RET;
import net.sf.jniinchi.INCHI_STATUS;
import net.sf.jniinchi.JniInchiException;
import net.sf.jniinchi.JniInchiWrapper;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
Expand Down Expand Up @@ -165,6 +170,45 @@ public boolean isLoaded() {
return isLoaded;
}

public boolean checkKey(String inchikey) throws BioclipseException {
INCHI_KEY_STATUS status;
try {
status = JniInchiWrapper.checkInchiKey(inchikey);
} catch (JniInchiException exception) {
throw new BioclipseException("Error while validating the inchi: " + exception.getMessage(), exception);
}
if (status == INCHI_KEY_STATUS.VALID_STANDARD || status == INCHI_KEY_STATUS.VALID_NON_STANDARD)
return true;
// everything else is false
return false;
}

public boolean check(String inchi) throws BioclipseException {
INCHI_STATUS status;
try {
status = JniInchiWrapper.checkInchi(inchi, false);
} catch (JniInchiException exception) {
throw new BioclipseException("Error while validating the inchi: " + exception.getMessage(), exception);
}
if (status == INCHI_STATUS.VALID_STANDARD || status == INCHI_STATUS.VALID_NON_STANDARD)
return true;
// everything else is false
return false;
}

public boolean checkStrict(String inchi) throws BioclipseException {
INCHI_STATUS status;
try {
status = JniInchiWrapper.checkInchi(inchi, true);
} catch (JniInchiException exception) {
throw new BioclipseException("Error while validating the inchi: " + exception.getMessage(), exception);
}
if (status == INCHI_STATUS.VALID_STANDARD || status == INCHI_STATUS.VALID_NON_STANDARD)
return true;
// everything else is false
return false;
}

public boolean isAvailable() {
if (!isLoaded && loadingFailed) return false;
if (!loadingFailed && isLoaded) return true;
Expand Down

0 comments on commit 1f5cd00

Please sign in to comment.