Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pRegion for all #172

Merged
merged 37 commits into from
Jul 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
404c264
use pRegion for HiC tracks to speed up
lldelisle Jan 9, 2020
28d5653
added a test with a bed with multiple chr
lldelisle Jan 9, 2020
7e38dfa
added pybedtools
lldelisle Jan 9, 2020
9d7a3a4
added pRegion everywhere there is an intervaltree
lldelisle Jan 9, 2020
1cea057
remove try/catch but use UCSC format
lldelisle Jan 10, 2020
34cb06a
remove the chr added to the region
lldelisle Jan 10, 2020
3c0a900
use one cool in the test of hic rasterize
lldelisle Jan 20, 2020
3b051fa
deal with cases where the matrix is empty on the region
lldelisle Jan 20, 2020
de5b0fd
change error to warning and trycatch the vmax as percentile
lldelisle Jan 21, 2020
329b153
linting
lldelisle Jan 21, 2020
20c929f
new test
lldelisle Jan 21, 2020
0a3a3da
Merge branch 'develop' of https://github.com/deeptools/pyGenomeTracks…
lldelisle Jun 3, 2020
bd88273
remove ununsed matplotlib
lldelisle Jun 3, 2020
815c8ea
put back HUGE_NUMBER
lldelisle Jun 3, 2020
afa1fe2
update comment
lldelisle Jun 3, 2020
1ec106d
forgot a , in merge
lldelisle Jun 3, 2020
ca58b09
update gtfTrack
lldelisle Jun 3, 2020
8aa4c21
fix issues when plotting matrix on the chr end
lldelisle Jun 3, 2020
836e54d
update output of hic_small_test
lldelisle Jun 3, 2020
16c76b1
add test for bed vs region
lldelisle Jun 3, 2020
9e9c062
remove y_axis when no data
lldelisle Jun 3, 2020
3c39a02
adapt pChrnameList to exceptions
lldelisle Jun 3, 2020
40bc04b
update and add new tests
lldelisle Jun 3, 2020
f68a2b7
remove debug prints
lldelisle Jun 3, 2020
4f559b7
require hicmatrix>=13
lldelisle Jun 3, 2020
4144cc7
update doc
lldelisle Jun 3, 2020
0823bef
linting
lldelisle Jun 3, 2020
2318fa8
remove redundant test
lldelisle Jun 3, 2020
a140022
mv self.img=None on top
lldelisle Jun 3, 2020
fbf9eb5
remove useless comments
lldelisle Jun 3, 2020
5357f7d
linting
lldelisle Jun 4, 2020
c9a32f7
change pRegion to plot_regions and intersect with all plot_regions ex…
lldelisle Jun 4, 2020
96fbd6b
update tests/doc to use imbricated bed
lldelisle Jun 4, 2020
254c911
linting
lldelisle Jun 4, 2020
e46f72f
make prettier the coding
lldelisle Jun 4, 2020
a68dbbe
Merge branch 'develop' of https://github.com/deeptools/pyGenomeTracks…
lldelisle Jun 4, 2020
63e103d
Merge branch 'develop' of https://github.com/deeptools/pyGenomeTracks…
lldelisle Jul 5, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions docs/content/all_default_properties_rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ parameter :doc:`tracks/x_axis` :doc:`tracks/epilogos`
========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= =========================
overlay_previous no no no no no no no no no no no no no
where bottom left
fontsize 15 12 12 12 12
fontsize 15 12 12 12
categories_file not set
orientation not set not set not set not set not set not set not set not set not set not set not set
links_type arcs
Expand Down Expand Up @@ -47,12 +47,10 @@ y_axis_values
second_file* not set not set
operation* file file
grid false false
use_middle false
rasterize false true true
pos_score_in_bin center
plot_horizontal_lines false
colormap viridis RdYlBu_r
region not set
depth 100000
show_masked_bins false
scale_factor 1
Expand Down
4 changes: 0 additions & 4 deletions docs/content/all_possible_properties.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,6 @@

- for *bigwig, bedgraph*: true, false

- **use_middle**:

- for *bedgraph*: true, false

- **rasterize**:

- for *bedgraph, bedgraph_matrix, hic_matrix*: true, false
Expand Down
10 changes: 8 additions & 2 deletions docs/content/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,18 @@ The output file of some 4C-seq pipeline are bedgraph where the coordinates are t

.. literalinclude:: ../../pygenometracks/tests/test_data/bedgraph_useMid.ini
:language: INI

We can generate two zooms using a bed instead of regions:

.. literalinclude:: ../../pygenometracks/tests/test_data/regions_imbricated_chr2.bed

.. code:: bash

$ pyGenomeTracks --tracks bedgraph_useMid.ini --region chr2:73,800,000-75,744,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o master_bedgraph_useMid.pdf
$ pyGenomeTracks --tracks bedgraph_useMid.ini --BED regions_imbricated_chr2.bed --trackLabelFraction 0.2 --width 38 --dpi 130 -o master_bedgraph_useMid.png

.. image:: ../../pygenometracks/tests/test_data/master_bedgraph_useMid_chr2-73800000-75744000.png

The output is available `here <https://github.com/deeptools/pyGenomeTracks/raw/master/pygenometracks/tests/test_data/master_bedgraph_useMid.pdf>`_.
.. image:: ../../pygenometracks/tests/test_data/master_bedgraph_useMid_chr2-74000000-74800000.png


Examples with peaks
Expand Down
2 changes: 0 additions & 2 deletions docs/content/tracks/auto/bedgraph_deduced_from_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Optional:

- **grid**: `false` (default) or true.

- **use_middle**: `false` (default) or true.

- **rasterize**: `false` (default) or true.


Expand Down
2 changes: 0 additions & 2 deletions docs/content/tracks/auto/domains_deduced_from_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ Optional:

- **overlay_previous**: `no` (default) or yes or share-y.

- **fontsize**: `12` (default) or any float above 0

- **orientation**: by default this option is not set but you can also put: inverted.

- **line_width**: `0.5` (default) or any float above 0
Expand Down
2 changes: 0 additions & 2 deletions docs/content/tracks/auto/hic_matrix_deduced_from_code.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ Optional:

- **colormap**: `RdYlBu_r` (default)

- **region**: by default this option is not set

- **depth**: `100000` (default) or any integer above 1

- **show_masked_bins**: `false` (default) or true.
Expand Down
3 changes: 2 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ dependencies:
- intervaltree >=2.1.0
- pybigwig >=0.3.16
- future >=0.17.0
- hicmatrix >=12
- hicmatrix >=13
- pysam >=0.14
- pytest
- gffutils >=0.9
- pybedtools >=0.8.1
- tqdm >=4.20
- pip:
- "git+https://github.com/deeptools/pyGenomeTracks.git"
7 changes: 4 additions & 3 deletions pygenometracks/getAllDefaultsAndPossible.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def main():
all_default_parameters[p][track_type] = value
has_default = False
for p, value in track_class.DEFAULTS_PROPERTIES.items():
all_default_parameters[p] = all_default_parameters.get(p, {})
all_default_parameters[p][track_type] = value
has_default = True
if p != 'region':
all_default_parameters[p] = all_default_parameters.get(p, {})
all_default_parameters[p][track_type] = value
has_default = True
if has_default:
all_tracks_with_default += [track_type]

Expand Down
56 changes: 34 additions & 22 deletions pygenometracks/plotTracks.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,14 +143,14 @@

import sys
import argparse
import matplotlib
matplotlib.use('Agg')
import warnings

from pygenometracks.tracksClass import PlotTracks
from pygenometracks._version import __version__
from .utilities import InputError

DEFAULT_FIGURE_WIDTH = 40 # in centimeters
HUGE_NUMBER = 1e15 # Which should be above any chromosome size


def parse_arguments(args=None):
Expand Down Expand Up @@ -244,7 +244,11 @@ def get_region(region_string):
"""
if region_string:
# separate the chromosome name and the location using the ':' character
chrom, position = region_string.strip().split(":")
try:
chrom, position = region_string.strip().split(":")
except ValueError:
# It can be a full chromosome:
return region_string.strip(), 0, HUGE_NUMBER

# clean up the position
for char in ",.;|!{}()":
Expand All @@ -258,7 +262,7 @@ def get_region(region_string):
try:
region_end = int(position_list[1])
except IndexError:
region_end = 1e15 # a huge number
region_end = HUGE_NUMBER
if region_start < 0:
region_start = 0
if region_end <= region_start:
Expand All @@ -273,42 +277,50 @@ def get_region(region_string):
def main(args=None):

args = parse_arguments().parse_args(args)
trp = PlotTracks(args.tracks.name, args.width, fig_height=args.height,
fontsize=args.fontSize, dpi=args.dpi,
track_label_width=args.trackLabelFraction)

# Identify the regions to plot:
if args.BED:
count = 0
regions = []
for line in args.BED.readlines():
count += 1
try:
chrom, start, end = line.strip().split('\t')[0:3]
except ValueError:
continue
try:
start, end = map(int, [start, end])
except ValueError as detail:
sys.stderr.write("Invalid value found at line\t{}\t. {}\n".format(line, detail))
name = args.outFileName.split(".")
file_suffix = name[-1]
file_prefix = ".".join(name[:-1])
warnings.warn("Invalid value found at line\t{}\t. {}\n".format(line, detail))
continue
regions.append((chrom, start, end))
else:
regions = [get_region(args.region)]

if len(regions) == 0:
raise InputError("There is no valid regions to plot.")

# Create all the tracks
trp = PlotTracks(args.tracks.name, args.width, fig_height=args.height,
fontsize=args.fontSize, dpi=args.dpi,
track_label_width=args.trackLabelFraction,
plot_regions=regions)

# Plot them
if args.BED:
name = args.outFileName.split(".")
file_suffix = name[-1]
file_prefix = ".".join(name[:-1])
for chrom, start, end in regions:
file_name = "{}_{}-{}-{}.{}".format(file_prefix, chrom, start, end, file_suffix)
if end - start < 200000:
sys.stderr.write("A region shorter than 200kb has been "
"detected! This can be too small to return "
"a proper TAD plot!\n")
# start -= 100000
# start = max(0, start)
# end += 100000
warnings.warn("A region shorter than 200kb has been "
"detected! This can be too small to return "
"a proper TAD plot!\n")
sys.stderr.write("saving {}\n".format(file_name))
# print("{} {} {}".format(chrom, start, end))
trp.plot(file_name, chrom, start, end, title=args.title,
h_align_titles=args.trackLabelHAlign,
decreasing_x_axis=args.decreasingXAxis)
else:
region = get_region(args.region)
trp.plot(args.outFileName, *region, title=args.title,
trp.plot(args.outFileName, *regions[0], title=args.title,
h_align_titles=args.trackLabelHAlign,
decreasing_x_axis=args.decreasingXAxis)
trp.close_files()
10 changes: 6 additions & 4 deletions pygenometracks/tests/generateAllOutput.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/bed_colormap_genes.ini --regio
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph.ini --region X:2850000-3150000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph.png

# test bedGraphTrack:
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --region chr2:73,800,000-75,744,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_useMid.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --region chr2:74,000,000-74,800,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_useMid_zoom.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --BED ./pygenometracks/tests/test_data/regions_imbricated_chr2.bed --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_useMid.png
bin/pgt --tracks ./pygenometracks/tests/test_data/bedgraph_useMid.ini --region chr2:73,800,000-75,744,000 --trackLabelFraction 0.2 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_bedgraph_useMid.pdf
bin/pgt --tracks ./pygenometracks/tests/test_data/operation_bdg.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_operation_bdg.png

Expand All @@ -35,11 +34,14 @@ bin/pgt --tracks ./pygenometracks/tests/test_data/epilogos.ini --region X:310000

# test_hiCMatrixTracks:
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic.ini --region X:2500000-3500000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_plot_hic.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_rasterize_height.ini --region X:2500000-2600000 --trackLabelFraction 0.23 --width 38 --dpi 10 -o ./pygenometracks/tests/test_data/master_plot_hic_rasterize_height.pdf
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_rasterize_height.ini --BED ./pygenometracks/tests/test_data/regions_XY.bed --trackLabelFraction 0.23 --width 38 --dpi 10 -o ./pygenometracks/tests/test_data/master_plot_hic_rasterize_height.pdf
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_log-log.ini --region X:2500000-3500000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_plot_hic_log-log.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic.ini --region X:2500000-3500000 --trackLabelFraction 0.23 --width 38 --dpi 130 --decreasingXAxis -o ./pygenometracks/tests/test_data/master_plot_hic_dec.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test_2.ini --region chr1:0-100000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_2.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --BED ./pygenometracks/tests/test_data/regions_chr1XY.bed --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_small_test.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region 1:0-200000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_small_test.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region chrM:0-20000 --trackLabelFraction 0.23 --width 38 -o ./pygenometracks/tests/test_data/master_plot_hic_small_test_chrM.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test.ini --region chr1:0-5000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_small_region.png
bin/pgt --tracks ./pygenometracks/tests/test_data/browser_tracks_hic_small_test_2.ini --region chr1:0-100000 --trackLabelFraction 0.23 --width 38 --dpi 130 -o ./pygenometracks/tests/test_data/master_hic_small_test_2.png

# test_logScale:
bin/pgt --tracks ./pygenometracks/tests/test_data/log1p.ini --region X:2700000-3100000 --trackLabelFraction 0.2 --dpi 130 -o ./pygenometracks/tests/test_data/master_log1p.png
Expand Down
Loading