Introduction

This guide describes how to create a simple Java Algorithm which can read and write into a tabular data format. You also will learn how to mutate the parameters. Please refer to Supported Data Formats for other available data formats.

We will read in the nameWithFavorNumber.csv file which contains tabular data. During this tutorial you will retrieve data from the columns of the input file (name and favor number) and print that data in the CIShell console. In the Generate a Tabular Output for the Algorithm section you will create a sample output table.

Creating an Algorithm with Tabular Data as Input

Due to a versioning issue this plugin will not work with previous versions of Sci2. To fix this, before exporting the plugin from Eclipse, change the minimum version to match of org.cishell.utilities to 1.0.1 in the Dependencies tab of MANIFEST.MF file.

Create a CIShell Java Algorithm Project, go to File -> New -> Project... and continue the step same as showed in Hello World Tutorial until the setting the input and output data step. Use prefuse.data.Table in the Data the algorithm will take in field as shown below.

When you are finished, click Next > to go to the Algorithm Parameters page.

Click the Add button to add a algorithm parameter and insert the following values into the input fields. You will need to add a nameparameter as a String and a favor parameter as a String as in the above image.

Finally, press the Finish button to generate a new Java Algorithm project. Open your algorithm.properties file you will see a the in_data is set to prefuse.data.Table.

Mutating and Preserving Parameters

For this example we want to mutate one parameter while preserving the other. Ideally, we want to mutate the name field to become a drop down box containing the available column titles from the user-provided tabular data (such as a CSV file). The favor_number field should remain as it is. To achieve this, we will edit the factory class to implement the ParameterMutator interface. The factory is defined in your HelloWorldFromFileAlgorithmFactory.java file, which should look like this:

Now we need to edit the HelloWorldFromFileAlgorithm.java file to manipulate the tabular data. This time you will add the content into the execute() method. The first input data is always stored in data[0]. If there are more than one input data, you will access them through data[0], data[1], ... in the order defined in the algorithm.properties file. This example shows how could the algorithm access rows and columns through prefuse.data.Table.

Export the algorithm into CIShell (or Sci2). Restart the tool an you can try to run the algorithm with the nameWithFavorNumber.csv file as input. To load the file into the tool, you can drag and drop the CSV file into the Data Manager panel. Alternatively, you can use the File -> Open menu option. Then run the algorithm by selecting AwesomeAlgorithms -> Tabular Data Practice from the menu bar. A pop-up window will ask for the columns to be included.

Generate a Tabular Output for the Algorithm

We will continue working on the same code. You can simply edit algorithm.properties as follows to tell CIShell that your algorithm should generate a tabular output file.

The generateOutputTable() method shows how to create a table and add rows and columns. The generateOutData() shows how to create output data for return, so that Cishell's Data Manager understands how to display the output.

Export this algorithm into CIShell and run with the name.csv file. Now, a new tabular data set is created in the Data Manager panel. You can save by right-clicking on the target file.

Resolving Missing Dependencies

If you followed along with this example, you may notice a few errors pertaining to importing packages and missing type definitions. We can resolve these errors in the MANIFEST.MF file of this algorithm.

In your Algorithm directory, navigate to the META-INF directory. Open the MANIFEST.MF file. A series of tabs should now be visible under your file editor. Click Dependencies to see a list of all packages imported for this project. Compare these packages to what you are missing in your algorithm.

To add a package, click the Add... button. Type the entire name of the desired package, or part of the name surrounded by asterisks *

Example:If you were looking for org.cishell.reference.service.metatype, you could search *service.metatype* and get all results which contain that sequence of characters.