open files from command line without spawning new Jalview instance?

Hi,

When Jalview is already running, is it possible to open files in Jalview from the command line?

I have a bunch of multiple alignments I’d like to look at in Jalview, and rather than opening them through the GUI, I’d like to be able to do it from the command line.

Using the command-line invocation given in the FAQ, I can open alignment files like so:
$ java -Djava.ext.dirs=/Applications/Jalview/lib -cp /Applications/Jalview/jalview.jar jalview.bin.Jalview -open test.aln

but doing this fires up a new Jalview instance each time.

Thanks,
Dave

Hi Dave.

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

···

On 19/09/2011 10:54, Dave Messina wrote:

Awesome! Thanks so much for taking the time to work that out for me, Jim. I appreciate it. Looking forward to trying it out.

Dave

···

On Mon, Sep 19, 2011 at 17:23, Jim Procter <jprocter@compbio.dundee.ac.uk> wrote:

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 | 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 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


Jalview-discuss mailing list
Jalview-discuss@jalview.org
http://www.compbio.dundee.ac.uk/mailman/listinfo/jalview-discuss

In case anyone finds the above solution of value, improvements/extensions upon it are available and discussed here: controlling running Jalview instance