Knime java snippet if

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

License

knime/knime-javasnippet

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

This repository contains the source code of KNIME Analytics Platform. The code is organized as follows:

Instructions for how to develop extensions for KNIME Analytics Platform can be found in the knime-sdk-setup repository on BitBucket or GitHub.

Источник

Using custom data types with the Java Snippet node

One of the cool new features of KNIME Analytics Platform 3.3 is the ability to use the Java Snippet node with objects and functions that are defined in KNIME extensions. This allows an interesting and powerful new way to work with extensions that are compatible with the new functionality (more on the small amount of work required for that in a separate post, but for those who want to get a head start, here’s a link to the commit that added the functionality to the RDKit nodes). This post will demonstrate how to use the RDKit Java wrappers from within a KNIME Java Snippet node. Though this blog post uses cheminformatics functionality from the RDKit as a demonstration, the new feature can also be used to work with things like images, XML and JSON documents, and SVGs.

We’ll be working with the Java Snippet node, here’s some more information about that. Needless to say, you need to have KNIME 3.3 (or later) with the RDKit community nodes installed. As of this writing you need the nightly build of the RDKit nodes; the update site (http://update.knime.org/community-contributions/trunk) is linked from the KNIME Community site.

Читайте также:  Php mysqli database name

Example 1: Working with RDKit Molecules.

Let’s start by reading in a set of SMILES from a file, converting those to RDKit molecules, and then adding a Java Snippet node. Here’s the fragment of the workflow:

To get started, I open the empty configuration dialog of the Java Snippet node (not shown) and double click the RDKit molecule column in the column list to add a new Input:

This also causes some magic to happen in the backend and the relevant dependencies to be automatically imported.

Variable completion even works, which is very cool since there’s not currently any useable documentation for the RDKit Java wrappers:

(click on the image to see it in full size)

Let’s bring in the rest of the RDKit (we could do this in a more targeted way, but this approach is simpler):

Now we can start to do the interesting stuff! Here’s a complete, but simple demonstration of using RDKit functionality to count the number of specified and unspecified chiral centers:

(click on the image to see it in full size)

That’s not a super-complicated example, but it already shows that you can call RDKit functions and use the methods available on the RDKit objects. The output from running the node is a new table that has three new columns added (the ones in the “Output” pane):

Example 2: Working with RDKit Fingerprints

Here’s another example snippet that generates a molecular fingerprint (using the RDKit’s Pattern Fingerprint function) and calculates some stats about it. The stats are returned as numbers, the fingerprint as a string of 0s and 1s:

(click on the image to see it in full size)

That string of 0s and 1s can be converted into a KNIME bit vector using KNIME’s Create Bit Vector node:

Example 3: Converting KNIME bit vectors into RDKit bit vectors

For the sake of symmetry and completeness, here’s a final Java snippet that shows how to convert KNIME bit vectors, which come into the Java Snippet node as strings, into RDKit ExplicitBitVects:

(click on the image to see it in full size)

Notice that this still has the ROMol column in the inputs; this is necessary for technical reasons: without it the rest of the RDKit cannot be imported. I got that line in the inputs by double clicking the “smiles (RDKit mol)” column as in the first example snippet and then just deleting the c_smilesRDKitMol text that was inserted into the editor window. It sounds more complicated than it is!

Wrapping up

To quickly review: in this blog post I showed how KNIME’s Java Snippet node can now be used to work with custom data types like RDKit molecules and bit vectors. A future post will provide a bit more technical detail on how KNIME extension developers can add support for this to their own data types.

Читайте также:  M4a1 hyper beast css

The workflow I created for this blog post is available on the KNIME public examples server knime://EXAMPLES/99_Community/03_RDKit/07_Java_Snippet_Example knime://EXAMPLES/99_Community/03_RDKit/07_Java_Snippet_Example * . You can access it directly in your version of the KNIME Analytics Platform by logging into the EXAMPLES server (in your “KNIME Explorer” pane) and browsing to the folder 99_Community/03_RDKit

Additional Resources

  • KNIME Node Guide example for the Java Snippet Node: https://www.knime.org/nodeguide/scripting/java/example-of-java-snippet
  • The workflow used in this blog post: knime://EXAMPLES/99_Community/03_RDKit/07_Java_Snippet_Exampleknime://EXAMPLES/99_Community/03_RDKit/07_Java_Snippet_Example *
  • The github page for the RDKit KNIME nodes: https://github.com/rdkit/knime-rdkit
  • The RDKit home page: http://www.rdkit.org

* The link will open the workflow directly in KNIME Analytics Platform (requirements: Windows; KNIME Analytics Platform must be installed with the Installer version 3.2.0 or higher)

Источник

Java Snippet

This node allows you to execute arbitrary java code to create a new columns or to replace an existing ones. Enter the java code in the text area.

An output columns is defined by creating a java field bound to this column. The value assigned to this field will be written to the output.

Note, that this node allows to add or modify flow variables in the same manner.

It is also possible to use external java libraries (that is, libraries that are not part of java boot classpath). In order to include such external jar or zip files, add their location in the «Additional Libraries» tab using the control buttons.

You can define reusable templates with the «Create templates. » button. Templates are stored in the users workspace by default and can be accessed via the «Templates» tab.

Dialog Options

Column List The list contains the columns that are available in the input table. Double click any of the column names to insert the respective field in the expression editor. It will replace your current selection or simply insert at the current caret position. Flow Variable List The list contains the flow variables that are currently available at the node input. Double clicking any of the entries will insert the respective identifier at the current cursor position (replacing the selection, if any). Snippet text area Enter your java code here. You can access input columns or flow variables by defining them in the Input table. A second way is to use the methods getCell(name, type) or getFlowVariable(name, type) where name is the name of the input column or the flow variable, respectively. You can use the following values for the type parameter.
tString : String (f)
tInt : Integer (f)
tDouble : Double (f)
tLong : Long
tBoolean : Boolean
tDate : java.util.Date
tCalendar : java.util.Calendar
tXML : org.w3c.document
(f) These Types can be used for flow variables.
Java Snippet Methods:
getCell(name, type)* : Get value of a cell by column name
isType(name, type)* : Test for type by column name
isMissing(name)* : Check if missing by column name
getColumnCount(index, type) : Number of columns in the input table
getColumnName(index) : Retrieve column name at index

getFlowVariable(name, type) : Get value of a flow variable by name
* Methods exist in a variant that takes the column index instead of its name.

Читайте также:  Center align button

You can hit ctrl+space to get an auto completion box with all available classes, methods and fields. When you select a class and hit enter a import statement will be generated if missing.

Note, that the snippet allows to define custom global variables and custom imports.

Exceptions in the snippet are caught by the framework and will result in missing values for all output columns for the row being processed unless there are flow variables defined by the snippet (in which case the execution will always fail). You can force the node to fail execution by throwing an exception of class Abort.

Input Define system input fields for the snippet text area. Every field will be populated with the data of the defined input during execution. Output To define output columns and flow variables by adding columns to this table. Every row in the Output table defines a java field bound to a column. Values assigned to this field in the snippet will show up at the output.

Ports

This node is contained in KNIME Java Snippet Nodes (draft) provided by KNIME GmbH, Konstanz, Germany.

Источник

Knime java snippet if

Copy link Copy short link

This node allows you to execute arbitrary java code to create a new column or to replace an existing one. Enter the java code in the text area. To address certain input values of the table use $name_of_col$ (a double click on the elements in the column list will insert a the place holder at the current cursor position). For instance, the sum of the first two columns is $col_1$ + $col_2$ (replace col_1 and col_2 by the name of the columns). Please also specify the return type with one of the radio buttons. You can also use more complex statements such as if-else switches. For instance, to bin a numeric column you could enter code as follows and check the String return type:

String bin; if ($col_1$ < 0.5) < bin = "Very small"; >else if ($col_1$ < 2.0) < bin = "Small"; >else if ($col_1$ < 10.0) < bin = "Medium"; >else if ($col_1$ < 20) < bin = "Large"; >else < bin = "Very Large"; >return bin;

You can also use static methods of java utility classes, e.g. to get a column with random values, simply enter Math.random() and check the double return type.

It is also possible to use external java libraries (that is, libraries that are not part of java boot classpath). In order to include such external jar or zip files, add their location in the «Additional Libraries» tab using the control buttons.

Exceptions in the snippet are caught by the framework and will result in a missing value for the current row. If the snippet throws an exception of class Abort (an inner class that is available to each snippet without further import statements), the entire execution will halt, using the exception message as error that is presented to the user.

Источник

Оцените статью