Example of a custom DS implementation

From Bioclipse
Jump to: navigation, search

Declaring the model in plugin.xml

<plugin>
   <extension
         point="net.bioclipse.decisionsupport">
         <endpoint
               id="myendpoint"
               name="My Endpoint"
               icon="icons/sign.png">
         </endpoint>
        <test
              id="mytest"
              endpoint="myendpoint"
              name="Test model"
              class="testmodel.TestModelImpl"
              icon="icons/magic-wand.png">
        </test>
  </extension>

</plugin>


Implementation of the custom model

public class TestModelImpl extends AbstractDSTest{

	@Override
	public List<String> getRequiredParameters() {
		return null;
	}
	
	@Override
	public void initialize(IProgressMonitor monitor) throws DSException {
		super.initialize(monitor);
		
		//Do something once when model is initiated, 
		//e.g. load model into memory from file
		
	}

	@Override
	protected List<? extends ITestResult> doRunTest(ICDKMolecule cdkmol,
			IProgressMonitor monitor) {
		
		List<SimpleResult> lst = new ArrayList<SimpleResult>();
		
		ICDKManager cdk = Activator.getDefault().getJavaCDKManager();

		String smiles;
		try {
			
			//A simple result (String)
			smiles = cdk.calculateSMILES(cdkmol);
			lst.add(new SimpleResult("Smiles: " + smiles, ITestResult.POSITIVE));

			//An example for a match that colors specific atoms in query molecule
			PosNegIncMatch match = new PosNegIncMatch("Highlighted Atoms", ITestResult.POSITIVE);
			Map<Integer, Number> m = new HashMap<Integer, Number>();
			m.put(2,ITestResult.POSITIVE);
			m.put(5,ITestResult.INCONCLUSIVE);
			m.put(7,ITestResult.NEGATIVE);
			match.setResultMap(m);
			lst.add(match);
			
			//An external molecule match, such as result from a similarity search
			ExternalMoleculeMatch em = new ExternalMoleculeMatch("External hit", 
					cdk.fromSMILES("O=S(c2nc1ccc(OC)cc1n2)Cc3ncc(c(OC)c3C)C"), 
					ITestResult.NEGATIVE);
			lst.add(em);
			
			return lst;
		} catch (BioclipseException e) {
			return returnError("Model failed: " + e.getLocalizedMessage(), e.getLocalizedMessage());
		}
	}

}