27 July 2011

Controlling IGV through a Port: my notebook.

A protocol for interacting with the The Integrative Genomics Viewer (IGV) is described here: http://www.broadinstitute.org/igv/PortCommands. So, you can save some pictures of a genomic region without interacting with IGV.

Via a shell script


$ cat script.sh

mkdir -p /tmp/igv
sleep 2
echo "snapshotDirectory /tmp/igv"
sleep 2
echo "goto chr3:100"
sleep 2
echo "snapshot"
sleep 2
echo "goto chr3:200-300"
sleep 2
echo "snapshot"
sleep 2

invoke the script
$ sh script.sh |  telnet 127.0.0.1 60151
Trying 127.0.0.1...
Connected to srv-clc-02.irt.univ-nantes.prive (127.0.0.1).
Escape character is '^]'.
INFO [2011-07-27 17:58:16,680] [CommandExecutor.java:124] [Thread-6] OK
OK
INFO [2011-07-27 17:58:18,685] [CommandExecutor.java:124] [Thread-6] OK
OK
INFO [2011-07-27 17:58:18,687] [MacroSnapshotAction.java:85] [Thread-6] Snapshot: chr3_80_119.png
INFO [2011-07-27 17:58:20,787] [CommandExecutor.java:124] [Thread-6] OK
OK
INFO [2011-07-27 17:58:22,792] [CommandExecutor.java:124] [Thread-6] OK
OK
INFO [2011-07-27 17:58:22,794] [MacroSnapshotAction.java:85] [Thread-6] Snapshot: chr3_200_300.png
Connection closed by foreign host.


Via java


The code
import java.io.*;
import java.net.*;
class Test
{
public static void main(String[] args) throws Exception
{
Socket socket = new Socket("127.0.0.1", 60151);
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));


out.println("snapshotDirectory /tmp/igv");
System.out.println(in.readLine());
out.println("goto chr3:100");
System.out.println(in.readLine());

out.println("snapshot");
System.out.println(in.readLine());

in.close();
out.close();
socket.close();
}
}

Compile and execute:
$ javac Test
$ java Test
INFO [2011-07-27 18:01:15,706] [CommandExecutor.java:124] [Thread-6] OK
OK

INFO [2011-07-27 18:01:17,711] [CommandExecutor.java:124] [Thread-6] OK
OK

INFO [2011-07-27 18:01:17,729] [MacroSnapshotAction.java:85] [Thread-6] Snapshot: chr3_80_119.png
INFO [2011-07-27 18:01:20,533] [CommandExecutor.java:124] [Thread-6] OK
OK

3 comments:

Anonymous said...

Some Linux os do not come with telnet anymore but replacing the telnet command with nc (netcat) will work

IgorFobia said...

Excellent idea, thank you for sharing. But why all those sleep commands?

Pierre Lindenbaum said...

As far as I remember ; if there is no "sleep", IGV has no time to change before the next command.