Skip to content

Instantly share code, notes, and snippets.

@stevekm
Last active April 28, 2022 06:50
Show Gist options
  • Save stevekm/ac76c0c2fa4ee89db8ce2421cc6fbffc to your computer and use it in GitHub Desktop.
Save stevekm/ac76c0c2fa4ee89db8ce2421cc6fbffc to your computer and use it in GitHub Desktop.
Sample Batch Script for IGV Snapshots

You can use IGV to automatically & programmatically load genomic datasets and take snapshots of regions of interest. This is very handy and helps you avoid taking many screenshots manually.

Manual page here:

http://software.broadinstitute.org/software/igv/batch

These commands are also available:

http://software.broadinstitute.org/software/igv/PortCommands

Download here:

http://software.broadinstitute.org/software/igv/download

After installing IGV, a specially-formatted IGV batch script can be used to automate the program. Format your script like this: (save this as IGV_test.bat):

new
snapshotDirectory /path/to/snapshot_dir
load /path/to/sample1.bam
load /path/to/sample2.bam
genome hg19
maxPanelHeight 400
goto chr11:108138003-108138003
snapshot custom_chr11-108138003-108138003.png
goto chr9:21971111-21971111
snapshot custom_chr9-21971111-21971111.png
exit

You can run the script from the terminal like this:

bin/IGV_2.3.81/igv.sh -b code/IGV_test.bat

Upon running the script, a window to appear and you should see the tracks load and the regions appear on screen as snapshots are taken.

If you are running IGV from a headless server (accessing the server via ssh), then this will require X11 to be running on the server and installed on your local computer (use XQuartz for OS X). Remember to enable X11 in your terminal by adding -Y to your ssh command, like so:

ssh username@server.edu -Y

For scripting purposes, you can run the X11 virtualizer to avoid the requirement for an active X11 window when you call IGV. Use this command:

(Xvfb :10 &) && DISPLAY=:10 java -Xmx750m -jar bin/IGV_2.3.81/igv.jar -b code/IGV_test.bat && killall Xvfb

Note that you can run an IGV batch script from within IGV itself as well. This allows you to load your tracks and apply manual customization, then iterate through a series of regions and take snapshots. Just omit the portions of the script that start and new session & adjust visual parameters. If you've already loaded your tracks, all your script needs is this:

snapshotDirectory /path/to/snapshot_dir
goto chr11:108138003-108138003
snapshot custom_chr11-108138003-108138003.png
goto chr9:21971111-21971111
snapshot custom_chr9-21971111-21971111.png

Example output:

chr3_185850354-185872709

@jimguo
Copy link

jimguo commented Apr 22, 2019

Hi, how did you load multiple bed files? Thanks.

@ShwetaCh
Copy link

ShwetaCh commented Nov 3, 2020

Is there a way to size to snapshot in a landscape mode? It gives me a portrait mode image. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment