IGV User Guide | Generating Genomic Visualizations on Linux

发布于

更新于


After extracting the package, IGV can be launched directly using the igv.sh script included in the installation directory.

Bash
# Download the IGV package
wget https://data.broadinstitute.org/igv/projects/downloads/2.18/IGV_2.18.0.zip
# Extract the downloaded archive
unzip IGV_2.18.0.zip
# Run IGV (requires the appropriate Java version to be installed)
cd IGV_2.18.0
igv.sh

IGV requires a specific version of Java to run properly. In addition, generating genomic visualization figures with IGV involves invoking a graphical interface, which depends on an X Window server. On Linux systems, this can be achieved by using Xvfb (X Virtual Frame Buffer) to provide a virtual X server for IGV.

Finally, since the figures exported directly from IGV do not fully meet my requirements, I also installed ImageMagick to perform image cropping and further adjustments.


Bash
# Pull a base Ubuntu image
[root@comput1 ~/example]$ singularity pull library://library/default/ubuntu
INFO:    Downloading library image
28.44 MiB / 28.44 MiB [================================] 100.00% 2.66 MiB/s 10s
WARNING: unable to verify container: ubuntu_latest.sif
WARNING: Skipping container verification

[root@comput1 ~/example]$ ls
ubuntu_latest.sif
Bash
# Convert the sif file into a writable sandbox
[root@comput1 ~/example]$ singularity build --sandbox IGV_env/ ubuntu_latest.sif
INFO:    Starting build...
INFO:    Creating sandbox directory...
INFO:    Build complete: IGV_env/

[root@comput1 ~/example]$ ls
IGV_env  ubuntu_latest.sif
Bash
# Enter the sandbox in writable mode
[root@comput1 ~/example]$ singularity shell --writable IGV_env/ 
Singularity> 
# Update apt
Singularity> apt-get update
# Install Java 17 (required by the IGV version used in this guide)
Singularity> apt install -y openjdk-17-jdk
# Install Xvfb
Singularity> apt-get install -y xvfb
# Install ImageMagick
Singularity> apt-get install -y imagemagick
# Exit the sandbox
Singularity> exit
查看完整代码
Bash
# Rebuild the sandbox into a read-only sif file
[root@comput1 ~/example]$ singularity build IGV_env.sif IGV_env/
INFO:    Starting build...
INFO:    Creating SIF file...
INFO:    Build complete: IGV_env.sif
[root@comput1 ~/example]$ ls
IGV_env  IGV_env.sif  ubuntu_latest.sif

If you encounter issues while installing software inside Singularity, or if you choose not to use Singularity at all, refer to the following subsections for installing IGV and its dependencies directly on your Linux system.


Bash
apt-get update
# Check available Java versions provided by apt
apt search openjdk | grep -E 'openjdk-.*-jdk/'
# This tutorial uses Java 17
apt install -y openjdk-17-jdk
# Verify Java version
java --version
Bash
# Download the Java package
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
# Create an installation directory
mkdir /etc/java-17-openjdk/
# Extract Java to the installation directory
tar -xvf jdk-17_linux-x64_bin.tar.gz -C /etc/java-17-openjdk/

# Add Java to environment variables (temporary)
export JAVA_HOME=/etc/java-17-openjdk/jdk-17.0.12/
export PATH=$PATH:$JAVA_HOME/bin

Bash
# Install Xvfb
apt-get install -y Xvfb
# Start Xvfb (Ctrl+C to stop the service)
Xvfb
Bash
# Run IGV with a virtual display
xvfb-run -a --server-args="-screen 0 1280x800x24 -nolisten tcp" igv.sh --batch Batch_scripts_example.txt

Bash
# Install imagemagick
apt-get install -y imagemagick
# Crop an image
# -crop format: WIDTHxHEIGHT+X_OFFSET+Y_OFFSET (origin at top-left corner)
convert example.raw.png -crop 968x485+167+0 example.png

Bash
genome hg19
load ./testSample.deduped.bam name=testSample
goto chrX:153,409,243-153,425,345
sort position
collapse
maxPanelHeight 300
preference NAME_PANEL_WIDTH 0
snapshotDirectory ./mySnapshotDirectory
snapshot testSample.OPN1LW.raw.png
exit

Next, open IGV on Windows and navigate to Genomes -> Create .genome file…. Fill in the genome information and file paths (the Gene field can be left empty; CytoBand and alias files are optional, but the sequence file is required).

Finally, Select the save location for the .genome file.

Once uploaded to Linux, IGV will use the .genome file to locate the reference genome files in THE SAME directory:

Text
hg19/
├─ cytoBand.txt
├─ hg19_alias.tab
├─ hg19.fasta
├─ hg19.fasta.fai
├─ hg19.genome
└─ ncbiRefSeq.txt.gz
Bash
genome ./genome/hg19/hg19.genome
load ./genome/hg19/ncbiRefSeq.txt.gz name=Gene
load ./testSample.deduped.bam name=testSample
goto chrX:153,409,243-153,425,345
sort position
collapse
maxPanelHeight 300
preference NAME_PANEL_WIDTH 0
snapshotDirectory ./mySnapshotDirectory
snapshot testSample.OPN1LW.raw.png
exit
Bash
# If Java was installed manually, uncomment the following lines to set temporary environment variables
# export JAVA_HOME=/etc/java-17-openjdk/jdk-17.0.12/
# export PATH=$PATH:$JAVA_HOME/bin

# Run IGV using Xvfb to generate the visualization plot.
# IGV executes commands from the batch file to produce the genomic visualization.
xvfb-run -a --server-args="-screen 0 2560x720x24 -nolisten tcp" /root/shenh/singularity/IGV/IGV_2.18.0/igv.sh --batch ./Batch_script.txt
# Crop the IGV-generated genomic plot
convert ./mySnapshotDirectory/testSample.OPN1LW.raw.png -crop 968x485+167+0 ./mySnapshotDirectory/testSample.OPN1LW.png
Bash
# 对于使用了Singularity的用户,命令如下
singularity exec IGV_env.sif sh run.sh
# 对于未使用Singularity的用户,命令如下
sh run.sh

Leave a Reply

Your email address will not be published. Required fields are marked *