Calling a python script (emboss_needle.py) with parameters in knime

Hi there,

I’m trying to get knime to execute a python script (or java, or perl) from the EMBL-EBI github repository. In my case emboss_needle.py and the latest knime version (SeqAn is therefore not available right now)

Let’s say this is my command: “python emboss_needle.py --email ilove@knime.com --stype protein --asequence KNIME --bsequence KNIMD” to compare two sequences. On the cmd line in my conda environment it works, for the life of me I just don’t find a solution that lets me port this to knime.

Any suggestions?

Best,
Christoph

Hi
the script needs to be remote?
In that case i could only think of downloading the script with KNIME and then excecute it via bash or sth like that.
Out of the box idea nothing more
br

2 Likes

Hi

The script can be local, but as I understood the bash node is gone. Furthermore, I couldn’t find the Execute Shell node, even though I have the full Knime installation.

Since the script is acutally a call to a REST API, I also try the POST node, but it’s more of a guessing game how to post the parameters to the server, since there is no documentation (they want you to use the python/java/perl scripts instead)

Thanks
Christoph

I could handle it with a POST node

Here is how I did for people want to interface EMBL-EBI tools:

POST node set URL to: “https://www.ebi.ac.uk/Tools/services/rest/TOOL_NAME/run
Request Headers add Header Key “Content-Type” and Header value “application/x-www-form-urlencoded”
For the request body use the parameters that the tool offers, e.g. for emboss_needle: “email=your_mail@example.com&stype=protein&asequence=KNIME&bsequence=KNIMD”

To get the status of the job make a GET request to https://www.ebi.ac.uk/Tools/services/rest/emboss_needle/status/$jobId$ (use string manipulation node and the retrieved body column from the POST request to get there)

To get the result make a GET request to: “https://www.ebi.ac.uk/Tools/services/rest/emboss_needle/result/$jobId$/aln” where “aln” in this example is the resulttype (https://www.ebi.ac.uk/Tools/services/rest/emboss_needle/resulttypes) that is available for that tool.

Your body column will contain the requested result type and you can continue your analysis. Use your correct email to comply with the terms of EMBL and don’t spam jobs. Please refer to the EMBL guidelines on how many concurrent jobs are okay.

Hope that helps others.
Christoph

1 Like

Hi @sagerch

Welcome to the KNIME community

Further to @Daniel_Weikert 's comment, you can build a script in KNIME and write it to a command file / shell script file, and use the Execute Shell Script node (from @AnotherFraudUser 's AF Utilities)

A simple mock up
image
image

This works for me in Windows in KNIME 4.7 and 5.2


In the demo, this is just writing static lines, but the script could be created using dynamically generated python commands with parameters

Here is the above example. You’ll need to modify the script and location for your OS
call shell commands.knwf (14.8 KB)

5 Likes

Thanks @takbb,

This is an excellent how to. For the moment I go with my solution with POST and GET nodes. Just a further question to the Exec Shell Script node. In the field Script to execute, can we also pass parameters?

e.g. “runsomestuff.cmd --variable1=1 --variable2=2”

Kind regards,
Christoph

Hi @sagerch , there should be no reason why not.

I made the following call to python to attempt to install pandas (which I already had installed)

C:\apps\Python\python.exe -m pip install pandas

… and yes, here is a screenshot of a call to a cmd file with a parameter:

Edit: I just realised in the above screenshot I put the full path even though the path is mentioned in the second text box. It worked fine.

This also worked equally well:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.