[Jalview-discuss] open files from command line without spawning new Jalview instance?

Jim Procter jprocter at compbio.dundee.ac.uk
Mon Sep 19 16:23:25 BST 2011


Hi Dave.

On 19/09/2011 10:54, Dave Messina wrote:
> When Jalview is already running, is it possible to open files in 
> Jalview from the command line?
unfortunately, there isn't a really easy way of doing this, but after 
pondering the problem for a while, I came up with the following solution 
which I hope will work in your case.

Firstly, enable groovy scripting in jalview by downloading the groovy 
binary distribution from groovy.codehouse.org. You then need to copy the 
'groovy-all-1.X.jar' file from the 'embedded' directory into your 
jalview's lib directory.

If this worked, then when you restart Jalview, you should see a new menu 
entry under the Tools menu: 'Groovy Console ...'. Select that option to 
open a groovy script execution window.

Now cut'n'paste the line(s) below into the script input area (top half 
of the groovy console) :

new groovy.ui.GroovySocketServer(
          new GroovyShell(), false, "(new 
jalview.io.FileLoader()).LoadFileWaitTillLoaded(line,jalview.io.FormatAdapter.FILE);", 
true, 1962);

Pressing 'Ctrl-R' will execute the script, and you should see something 
like 'groovy is listening on port 1962' appear in the output half of the 
console window. You now have a server set up that will try to use any 
text sent on port 1962 as a filename to open with the running Jalview.

To test it out, try :
echo <alignment filename> | nc localhost 1962

If there are any problems, then you'll see errors written on Jalview's 
java console (opened using the Tools->Java Console' menu entry. If you 
use this regularly, I suggest you save the groovy script to a file, and 
pass it to Jalview on startup with the -groovy <scriptfile> argument.

Have fun!
Jim.

ps. you can put in any bit of groovy scripting in the third argument to 
the GroovySocketServer constructor. For instance, you might want to tag 
on any additional commands, such as loading default features, etc. For 
full details, start with the javadoc for the groovy socket server here:
http://groovy.codehaus.org/api/groovy/ui/GroovySocketServer.html



More information about the Jalview-discuss mailing list