Controlling IGV through a Port

IGV can optionally listen for http requests over a port. This option is turned off by default but can be enabled from the Advanced tab of the Preferences window

Note:  IGV will write a response back to the port socket upon completion of each command.  It is good practice to read this response before sending the next command.   Failure to do so can overflow the socket buffer and cause IGV to freeze.   See the example below for the recommended pattern.


Command Description
new Create a new session.  Unloads all tracks except the default genome annotations.
load file Loads data or session files.  Specify a comma-delimited list of full paths or URLs.

Note: for Google Genomics readgroup sets the id is the "file",  specify format=ga4gh (version 2.3.80 and greater only).  For example

load CMvnhpKTFhCjz9_25e_lCw format=ga4gh

To explicitly specify a path to an index file use the optional "index=" parameter.  

load foo.bam index=bar.bai

collapse trackName Collapses a given trackName. trackName is optional, however, and if it is not supplied all tracks are collapsed.
echo Writes "echo" back to the response.  (Primarily for testing)
exit Exit (close) the IGV application.
expand trackName Expands a given trackName. trackName is optional, however, and if it is not supplied all tracks are expanded.
genome genomeIdOrPath Selects a genome by id, or loads a genome (or indexed fasta) from the supplied path.
goto locus or listOfLoci Scrolls to a single locus or a space-delimited list of loci. If a list is provided, these loci will be displayed in a split screen view.  Use any syntax that is valid in the IGV search box.
goto all Scrolls to a whole genome view.
group option Alignment tracks only.  Group alignments by one of the following options: 


region chr start end Defines a region of interest bounded by the two loci (e.g., region chr1 100 200).
maxPanelHeight height Sets the number of vertical pixels (height) of each panel to include in image. Images created from a port command or batch script are not limited to the data visible on the screen. Stated another way, images can include the entire panel not just the portion visible in the scrollable screen area. The default value for this setting is 1000, increase it to see more data, decrease it to create smaller images.
setLogScale(true | false)  
setSleepInterval ms Sets a delay (sleep) time in milliseconds.  The sleep interval is invoked between successive commands.
snapshotDirectory path Sets the directory in which to write images.
snapshot filename Saves a snapshot of the IGV window to an image file.  If filename is omitted, writes a PNG file with a filename generated based on the locus.  If filename is specified, the filename extension determines the image file format, which must be either .png or .svg.

sort option locus

Sorts alignment or segmented copy number tracks.  Recognized values for the option parameter for segmented copy number are (1) for segmented copy number  AMPLIFICATION and DELETION, and (2) for alignment tracks POSITION, STRAND, BASE, QUALITY, SAMPLE, READGROUP, INSERSTSIZE, FIRSTOFPAIRSTRAND, MATECHR, READORDER, and READNAME.  Option values are case insensitive.  If supplied,  the locus option can define a single position, or a range.  If absent sorting will be perfomed based on the region in view, or the center position of the region in view, depending on the option.
squish trackName Squish a given trackName. trackName is optional, and if it is not supplied all annotation tracks are squished.
viewaspairs trackName Set the display mode for an alignment track to "View as pairs".  trackName is optional.
preference key value Temporarily set the preference named key to the specified value. This preference only lasts until IGV is shut down.


Example java code:

        Socket socket = new Socket("", 60151);
        PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));

        out.println("load na12788.bam,n12788.tdf");
        String response = in.readLine();

        out.println("genome hg18");
        response = in.readLine();

        out.println("goto chr1:65,827,301");
        //out.println("goto chr1:65,839,697");
        response = in.readLine();

        out.println("snapshotDirectory /screenshots");
        response = in.readLine();

        response = in.readLine();