A package to generate IGV screenshots and load them into Matplotlib figures.
Project description
IGVer
Conveniently take IGV snapshots in multiple bam files over mutliple regions.
Prerequisites
- The standard way of running
igver.pyis through docker or singularity. - Supports genomes listed in the genomes.json from the IGV team.
Installation (Python API)
You don't need to install igver using pip if you just want the CLI, but you need to install through pip if you want to use the python API.
pip install igver
Features
- Load BAM files and visualize genomic regions using IGV
- Generate IGV batch scripts programmatically
- Run IGV inside a Singularity container for reproducibility
- Save IGV screenshots as high-resolution PNG files
- Load screenshots directly into Matplotlib figures for visualization
Usage
CLI
igver.py --helpgives:
usage: igver.py [-h] --bam BAM [BAM ...] -r REGIONS -o OUTDIR [-g GENOME]
[-t TAG] [-mph MAX_PANEL_HEIGHT] [-od OVERLAP_DISPLAY]
[--overwrite] [-d IGV_DIR] [--config CONFIG]
Create temporary batchfile and run IGV for a region list
optional arguments:
-h, --help show this help message and exit
--bam BAM [BAM ...] Input tumor bam file(s) to be shown vertically
-r REGIONS, --regions REGIONS
Either a 'chr:start-end' string, or input regions file
with region columns to be shown horizontally
-o OUTDIR, --outdir OUTDIR
Output png directory
-g GENOME, --genome GENOME
Genome version [default: 'GRCh37']
-t TAG, --tag TAG Tag to suffix your png file [default: 'tumor']
-mph MAX_PANEL_HEIGHT, --max_panel_height MAX_PANEL_HEIGHT
Max panel height [default: 200]
-od OVERLAP_DISPLAY, --overlap_display OVERLAP_DISPLAY
'expand', 'collapse' or 'squish'; [default: 'squish']
--overwrite Overwrite existing png files [default: False]
-d IGV_DIR, --igv_dir IGV_DIR
/path/to/IGV_x.xx.x
--config CONFIG Additional preferences [default: None]
Python API
from igver import load_screenshot
bam_files = ["sample1.bam", "sample2.bam"]
regions = ["chr1:100000-200000", "chr2:300000-400000"]
figures = load_screenshot(bam_files, regions)
for fig in figures:
fig.show()
Additional IGV preferences
- You can plug in additional IGV preferences as in https://github.com/igvteam/igv/wiki/Batch-commands -- an example would be
test/tag_haplotype.batch:
group TAG HP
colorBy TAG rl
sort READNAME
Caveat: setting IGV screenshot width
- AFAIK, the only way to modify the batch screenshot width is by modifying your
${IGV_DIR}/prefs.propertiesfile. There is a line that looks something likeIGV.Bounds=0,0,640,480, meaning that IGV set the bounds of the left, top, width, height (refer to https://github.com/igvteam/igv/issues/161). I've tried to override this but seems that it doesn't work that way. For the example below, I've fixed my prefs.properties file so that the screenshot width is 800 (i.e. setIGV.Bounds=0,0,800,480).
Run example
- An example command getting two bam files as inputr, displayed vertically in the order put in (i.e. top panel:
haplotag_tumor.bam, bottom panel:haplotag_normal.bam), is as follows. - Here,
test/tag_haplotype.batchincludes additional IGV preferences to group and color haplotagged reads, as written above.
singularity run -B /juno docker://shahcompbio/igv igver.py \
--bam test/test_tumor.bam test/test_normal.bam \
-r test/region.txt \
-o test/snapshots \
-mph 500 -od squish \
--config test/tag_haplotype.batch
- The regions file for the test case,
test/region.txt, includes 4 lines of different regions. The number of regions in the same line will lead to a snapshot with the regions horizontally aligned. You can annotate the region with an optional final field, which you can omit. - Here's the content of
test/region.txtand some explanation below.
8:32534767-32536767 region_of_interest
8:32534767-32536767 19:11137898-11139898 translocation
19:16780041-16782041 19:17553189-17555189 inversion
19:12874447-12876447 19:13500000-13501000 19:14461465-14463465 duplication
- The first region will take a 1001bp;1001bp snapshot on the region coined "region of interest", and create a png file
8-32534767-32536767.region_of_interest.tumor.pngin the OUTDIR. - The second region will take a 1001bp;1001bp snapshot on the two breakpoints of the translocation, and create a png file
8-32534767-32536767.19-11137898-11139898.translocation.tumor.pngin the OUTDIR. - The third region will take a 1001bp;1001bp snapshot on the two breakpoints of the inversion, and create a png file
19-16780041-16782041.19-17553189-17555189.inversion.tumor.pngin the OUTDIR. - The fourth region will take a 1001bp;1001bp;1001bp snapshot on the two breakpoints and a region inbetween, and create a png file
19-12874447-12876447.19-13500000-13501000.19-14461465-14463465.duplication.tumor.pngin the OUTDIR.
- You can see that the png files in OUTDIR includes
.tumoras a suffix. This is because the default TAG of the--tag / -toption is "tumor". You can set it to "None" to omit tagging the suffix.
Example results
- You can see the IGV snapshots already taken using the script above in
test/snapshots.
- Region of interest
- Translocation
- Inversion
- Duplication
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
igver-0.2.tar.gz
(34.8 MB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
igver-0.2-py3-none-any.whl
(7.5 kB
view details)
File details
Details for the file igver-0.2.tar.gz.
File metadata
- Download URL: igver-0.2.tar.gz
- Upload date:
- Size: 34.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21b1863f23d32b13c435ec37a4b197ec24d8ac95b7fa79089610b1344c3d5749
|
|
| MD5 |
8ad086a6a37fddbb70dee2483d5a7620
|
|
| BLAKE2b-256 |
f3500b75f3a840ff2c266b4a4a9d18095c5991d916112d489805ecc8f14ef935
|
File details
Details for the file igver-0.2-py3-none-any.whl.
File metadata
- Download URL: igver-0.2-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd769bf74ff319b35c383f7a36a4dcc536e260da9e2425f773a9e64be7c522bd
|
|
| MD5 |
c711bd3288909f2ddf9c2c10be538a76
|
|
| BLAKE2b-256 |
ad3cf3257db91089f90afb2d1b8ce502bada4e09a54c5ebae1a3f5b120026e96
|