Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/deeptools/pyGenomeTracks
Browse files Browse the repository at this point in the history
…into updateDocBEDTools
  • Loading branch information
lldelisle committed Oct 7, 2020
2 parents e48c764 + 8a2630b commit ae923af
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 83 deletions.
118 changes: 59 additions & 59 deletions docs/content/all_default_properties_rst.txt

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions docs/content/faq.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ FAQ
.. contents::
:local:

Why the scale of my Hi-C plot suddenly changed
----------------------------------------------
Why the scale of my Hi-C plot suddenly changed?
-----------------------------------------------
pyGenomeTracks is using `HiCMatrix <https://github.com/deeptools/HiCMatrix>`_ to read the matrix from ``h5`` and ``cool`` format.
From version 12 to version 13, a normalization step when reading ``cool`` file was removed. This normalization was mostly used
when you were providing ``cool`` file from `cooler balance <https://cooler.readthedocs.io/en/latest/cli.html#cooler-balance>`_.
Expand All @@ -22,3 +22,9 @@ If you used pyGenomeTracks version 3.5 and the last line you get is:
INFO:pygenometracks.tracksClass:initialize x. [xxxxx]
It is highly probable that BEDTools is not installed or not loaded in your environment.

My Hi-C plot looks like no correction was applied when using cool matrix
------------------------------------------------------------------------
pyGenomeTracks is using `HiCMatrix <https://github.com/deeptools/HiCMatrix>`_ to read the matrix from ``cool`` format.
Unfortunately, a bug was introduced in version 14 ignoring the correction factors.
This bug was fixed in version 15 so update HiCMatrix to last version should fix it.
2 changes: 1 addition & 1 deletion pygenometracks/getAllDefaultsAndPossible.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def main():

# For the default they are summarized in a matrix
mat = np.empty((len(all_default_parameters) + 2, len(all_tracks_with_default) + 1),
dtype='U25')
dtype='U100')
mat[0, 0] = 'parameter'
mat[1, 0] = '--'
for j, track_type in enumerate(all_tracks_with_default, start=1):
Expand Down
26 changes: 10 additions & 16 deletions pygenometracks/tracks/BedGraphTrack.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,13 @@ def __init__(self, properties_dict):
" requires to set the parameter"
" second_file.")
else:
if self.properties['second_file'].endswith(".bgz"):
# First try to open it as a Tabix file
try:
# from the tabix file is not possible to know the
# global min and max
try:
self.tbx2 = pysam.TabixFile(self.properties['second_file'])
except IOError:
self.interval_tree2, __, __ = file_to_intervaltree(self.properties['second_file'])
# load the file as an interval tree
else:
self.tbx2 = pysam.TabixFile(self.properties['second_file'])
except IOError:
# load the file as an interval tree
self.interval_tree2, __, __ = file_to_intervaltree(self.properties['second_file'])

def set_properties_defaults(self):
Expand Down Expand Up @@ -183,17 +181,13 @@ def set_properties_defaults(self):

def load_file(self):
self.tbx = None
# try to load a tabix file is available
if self.properties['file'].endswith(".bgz"):
# try to load a tabix file if available
try:
# from the tabix file is not possible to know the
# global min and max
try:
self.tbx = pysam.TabixFile(self.properties['file'])
except IOError:
self.interval_tree, __, __ = file_to_intervaltree(self.properties['file'],
self.properties['region'])
# load the file as an interval tree
else:
self.tbx = pysam.TabixFile(self.properties['file'])
except IOError:
# load the file as an interval tree
self.interval_tree, __, __ = file_to_intervaltree(self.properties['file'],
self.properties['region'])

Expand Down
26 changes: 22 additions & 4 deletions pygenometracks/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
import pybedtools
import tempfile
import warnings
import logging


FORMAT = "[%(levelname)s:%(filename)s:%(lineno)s - %(funcName)20s()] %(message)s"
logging.basicConfig(format=FORMAT)
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)


class InputError(Exception):
Expand Down Expand Up @@ -86,6 +93,13 @@ def temp_file_from_intersect(file_name, plot_regions=None, around_region=0):
file_to_open = original_file.intersect(regions, wa=True, u=True).fn
except pybedtools.helpers.BEDToolsError:
file_to_open = file_name
except NotImplementedError as e:
log.error("BEDTools is not installed but required.")
raise e
except Exception as e:
log.warning(f"BEDTools intersect raised: {e}"
"\nWill not subset the file.")
file_to_open = file_name
sys.stderr.close()
sys.stderr = sys.__stderr__
with open(temporary_file.name, 'r') as f:
Expand All @@ -94,9 +108,9 @@ def temp_file_from_intersect(file_name, plot_regions=None, around_region=0):
error_lines = [line for line in temp_std_error if 'error' in line.lower()]
if len(error_lines) > 0:
error_lines_printable = '\n'.join(error_lines)
sys.stderr.write("Bedtools intersect raised an error:\n"
f"{error_lines_printable}\n"
"Will not use bedtools.\n")
log.warning("BEDTools intersect raised an error:\n"
f"{error_lines_printable}\n"
"Will not use BEDTools.\n")
file_to_open = file_name
return file_to_open

Expand Down Expand Up @@ -171,7 +185,11 @@ def file_to_intervaltree(file_name, plot_regions=None):
valid_intervals += 1

if valid_intervals == 0:
sys.stderr.write(f"No valid intervals were found in file {file_name}")
if file_to_open == file_name:
suffix = " after intersection with the plotted region"
else:
suffix = ""
log.warning(f"No valid intervals were found in file {file_name}{suffix}")
file_h.close()

return interval_tree, min_value, max_value
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pysam >=0.14
gffutils >=0.9
pybedtools >=0.8.1
tqdm >=4.20
libopenblas < 0.3.10

0 comments on commit ae923af

Please sign in to comment.