CyniMetricTutorial

How to create a Cyni Metric

Introduction

In order to help app developers, we provide a Cyni Metric sample, which contains a "HelloWorld" implementation of a Cyni Metric. This sample will serve as a starting point or template for new app developers. Cyni sample code can be used by following these steps:

  1. Check out the cyni sample projects from our Github repository with this command:

git clone git://github.com/schwikowskilab/cyni-samples.git
  1. Go the cyni-metric-sample directory and compile it with mvn clean install

Next sections describe each file that needs to be created to produce a Cyni Metric App.

Pom File

Here are the main lines to modify in the pom.xml file. The fields bundle.symbolicName and bundle.namespace properties should be modified according to new app directory configuration. Tags groupId and artifactId also have to be modified. Finally, version tag should be set to developer requirements.

<properties>
        <bundle.symbolicName>cyni-metric-sample</bundle.symbolicName>
        <bundle.namespace>fr.systemsbiology.cyniSampleMetric.internal</bundle.namespace>
        <cytoscape.api.version>3.1.0</cytoscape.api.version>
        <cyni.api.version>1.0.0</cyni.api.version>
        <maven-bundle-plugin.version>2.3.4</maven-bundle-plugin.version>
        <osgi.api.version>4.2.0</osgi.api.version>
</properties>

<groupId>fr.systemsbiology.cyniSampleMetric</groupId>
<artifactId>cyniSampleMetric</artifactId>
<packaging>bundle</packaging>
<name>${bundle.symbolicName}</name>

<version>3.0.0-alpha1-SNAPSHOT</version>

CyActivator

In this file, any Cyni Metric implemented needs to be registered. These two lines do the work. First, we create the object for the new Cyni Metric and then we register it to make it available by the Cyni Metric Manager.

   1     //Define new Cyni Metric
   2     CyniSampleMetric sample = new CyniSampleMetric();
   3     //Register new Cyni Algorithm
   4     registerService(bc,sample,CyCyniMetric.class, new Properties());

CyniSampleMetric

The constructor of this class has two input parameters. The two names of the metric, the one used internally and the one to be displayed. Then, the tags that this metric support are added by the function addTag. These tags are strings and in the sample, the supported tags are filled by Cyni default tags but any string could be added too.

   1 public CyniSampleMetric() {
   2     super("sampleMetric.cyni","Cyni Sample Metric");
   3     addTag(CyniMetricTypes.INPUT_NUMBERS.toString());
   4     addTag(CyniMetricTypes.CORRELATION_METRIC.toString());
   5                 
   6 }

GetMetric method should contain the implementation of the metric. The dots should be replaced with the actual implementation, which should calculate a value that finally will be saved in the variable result. All data required to perform a measure is passed through CyniTable's.

   1 public Double getMetric(CyniTable table1, CyniTable table2, int indexBase, List<Integer> indexToCompare) { 
   2     double result = 0.0;
   3     int index2 = indexToCompare.get(0);
   4                 
   5     .........................................
   6                 
   7     return  result;
   8 }



last edited 2014-07-01 09:26:21 by OriolGuitart