use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.
the class GalaxyNodeConfigurationReader method readOutPort.
private Port readOutPort(Node portnode) throws Exception {
Port port = new Port();
port.setDescription("");
String extension = DOMHelper.valueOf(portnode, "@format");
port.addMimeType(extension);
String portname = DOMHelper.valueOf(portnode, "@name");
port.setName(portname);
return port;
}
use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.
the class NodeFactoryXMLTemplate method getInPorts.
/**
* Returns the xml representation of the input ports.
*
* @param nodeConfiguration
* The {@link INodeConfiguration} containing the port
* information.
* @return A {@link String} representing the input port part of the xml
* config file.
*/
private static String getInPorts(final INodeConfiguration nodeConfiguration) {
// ports
String ip = "\t\t<inPort index=\"__IDX__\" name=\"__PORTNAME__ [__MIMETYPE__]\">__PORTDESCR__ [__MIMETYPE____OPT__]</inPort>";
String inPorts = "";
int idx = 0;
for (Port port : nodeConfiguration.getInputPorts()) {
Parameter<?> parameter = nodeConfiguration.getParameter(port.getName());
String ipp = ip;
ipp = ip.replace("__PORTNAME__", parameter.getKey());
ipp = ipp.replace("__PORTDESCR__", StringEscapeUtils.escapeHtml(port.getDescription()));
ipp = ipp.replace("__IDX__", String.format("%d", idx++));
ipp = ipp.replace("__MIMETYPE__", join(port.getMimeTypes(), ","));
ipp = ipp.replace("__OPT__", (port.isOptional() ? ",opt." : ""));
inPorts += ipp + "\n";
}
return inPorts;
}
use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.
the class DynamicGenericNodeFactory method createNodeModel.
/**
* {@inheritDoc}
*/
@Override
public DynamicGenericNodeModel createNodeModel() {
INodeConfiguration tmpConfig;
try {
tmpConfig = getNodeConfiguration();
String[][] inputs = new String[tmpConfig.getInputPorts().size()][];
String[][] outputs = new String[tmpConfig.getOutputPorts().size()][];
int i = 0;
for (Port p : tmpConfig.getInputPorts()) {
inputs[i++] = p.getMimeTypes().toArray(new String[0]);
}
i = 0;
for (Port p : tmpConfig.getOutputPorts()) {
outputs[i++] = p.getMimeTypes().toArray(new String[0]);
}
return new DynamicGenericNodeModel(tmpConfig, getPluginConfig(), inputs, outputs);
} catch (Exception e) {
logger.error("Dynamic node model instantiation failed", e);
}
return null;
}
use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.
the class DynamicGenericNodeModel method transferOutgoingPorts2Config.
/**
* Creates a list of lists of output files (as {@link URI}s) pointing to the
* files that will be generated by the executed tool.
*
* @param jobdir
* The working directory of the executable.
* @param inData
* The input data as {@link PortObject} array
* @return A list of lists of output files
* @throws Exception
* If the input has an invalid configuration.
*/
private List<PortObject> transferOutgoingPorts2Config(final File jobdir, PortObject[] inData, ExecutionContext exec) throws Exception {
final int nOut = m_nodeConfig.getOutputPorts().size();
List<PortObject> outPorts = new ArrayList<PortObject>(nOut);
for (int i = 0; i < nOut; i++) {
Port port = m_nodeConfig.getOutputPorts().get(i);
String name = port.getName();
String ext = "";
boolean isPrefix = port.isPrefix();
if (!isPrefix) {
ext = getOutputType(i);
}
Parameter<?> p = m_nodeConfig.getParameter(name);
// basenames and number of output files guessed from input
List<String> basenames = getOutputBaseNames();
if (p instanceof FileListParameter && port.isMultiFile()) {
// we currently do not support lists of prefixes
if (isPrefix) {
throw new InvalidSettingsException("GKN currently does not support lists of prefixes as output.");
}
FileListParameter flp = (FileListParameter) p;
List<String> fileNames = new ArrayList<String>();
if (basenames.size() == 0) {
throw new Exception("Cannot determine number of output files if no input file is given.");
}
// if MimeType is "Inactive" just create Empty FileStore(Prefix)URIPortObjects
PortObject fsupo;
if (!ext.equals("Inactive")) {
fsupo = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
for (int f = 0; f < basenames.size(); ++f) {
// create basename: <base_name>_<port_nr>_<outfile_nr>
String file_basename = String.format("%s_%d", basenames.get(f), f);
File file = ((FileStoreURIPortObject) fsupo).registerFile(file_basename + "." + ext);
fileNames.add(file.getAbsolutePath());
}
} else {
fsupo = InactiveBranchPortObject.INSTANCE;
}
// add filled portobject
outPorts.add(fsupo);
// overwrite existing settings with new values generated by the
// stash
flp.setValue(fileNames);
} else if (p instanceof FileParameter && !port.isMultiFile()) {
// if MimeType is "Inactive" just create Empty FileStore(Prefix)URIPortObjects
PortObject po;
if (!ext.equals("Inactive")) {
// if we have no basename to use (e.g., Node without input-file)
// we use the nodename
String basename;
if (basenames.isEmpty()) {
basename = m_nodeConfig.getName();
} else {
basename = basenames.get(0);
}
// create basename: <base_name>_<outfile_nr>
String fileName = basename;
if (!isPrefix) {
fileName += '.' + ext;
}
if (isPrefix) {
po = new FileStorePrefixURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i), fileName);
((FileParameter) p).setValue(((FileStorePrefixURIPortObject) po).getPrefix());
LOGGER.debug("> setting param " + name + "->" + ((FileStorePrefixURIPortObject) po).getPrefix());
} else {
po = new FileStoreURIPortObject(exec.createFileStore(m_nodeConfig.getName() + "_" + i));
// we do not append the file extension if we have a prefix
File file = ((FileStoreURIPortObject) po).registerFile(fileName);
((FileParameter) p).setValue(file.getAbsolutePath());
LOGGER.debug("> setting param " + name + "->" + file);
}
} else {
po = InactiveBranchPortObject.INSTANCE;
}
// remember output file
outPorts.add(po);
} else {
throw new Exception("Invalid connection between ports and parameters.");
}
}
return outPorts;
}
use of com.genericworkflownodes.knime.port.Port in project GenericKnimeNodes by genericworkflownodes.
the class DynamicGenericNodeModel method transferIncomingPorts2Config.
/**
* Transfers the incoming ports into the config, that it can be written out
* into a config file or can be transferred to the command line.
*
* @param inData
* The incoming port objects.
* @throws Exception
*/
private void transferIncomingPorts2Config(PortObject[] inData) throws Exception {
// Transfer settings from the input ports into the configuration object
for (int i = 0; i < inData.length; i++) {
// find the internal port for this PortObject
Port port = m_nodeConfig.getInputPorts().get(i);
IURIPortObject po = (IURIPortObject) inData[i];
String name = port.getName();
// find the associated parameter in the configuration
Parameter<?> p = m_nodeConfig.getParameter(name);
boolean isMultiFile = port.isMultiFile();
boolean isPrefix = port.isPrefix();
// skip optional and unconnected inport ports
if (inData[i] == null) {
((FileParameter) p).setValue(null);
continue;
}
// connected: check contents
List<URIContent> uris = po.getURIContents();
// check validity of subtypes with actual inputs
if (uris.size() > 1 && (!isMultiFile && !isPrefix)) {
throw new Exception("IURIPortObject with multiple URIs supplied at single URI port #" + i);
}
// port
if (!(p instanceof IFileParameter)) {
throw new Exception("Invalid reference from port to non-file parameter. URI port #" + i);
}
if (isPrefix) {
// we pass only the prefix to the tool
IPrefixURIPortObject puri = (IPrefixURIPortObject) inData[i];
((FileParameter) p).setValue(puri.getPrefix());
} else if (isMultiFile) {
// we need to collect all filenames and then set them as a batch
// in the config
List<String> filenames = new ArrayList<String>();
for (URIContent uric : uris) {
URI uri = uric.getURI();
filenames.add(new File(uri).getAbsolutePath());
}
((FileListParameter) p).setValue(filenames);
} else {
// just one filename
URI uri = uris.get(0).getURI();
String filename = new File(uri).getAbsolutePath();
((FileParameter) p).setValue(filename);
}
}
}
Aggregations