Skip to content

Commit

Permalink
Merge pull request #172 from lldelisle/pRegionForAll
Browse files Browse the repository at this point in the history
pRegion for all
  • Loading branch information
bgruening authored Jul 5, 2020
2 parents 1f9f4fd + 63e103d commit b6cb3c6
Show file tree
Hide file tree
Showing 44 changed files with 531 additions and 228 deletions.
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

0 comments on commit b6cb3c6

Please sign in to comment.