diff --git a/docs/content/all_default_properties_rst.txt b/docs/content/all_default_properties_rst.txt index 7b8d962a..81e0a467 100644 --- a/docs/content/all_default_properties_rst.txt +++ b/docs/content/all_default_properties_rst.txt @@ -1,62 +1,62 @@ -========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= -parameter :doc:`tracks/x_axis` :doc:`tracks/epilogos` :doc:`tracks/links` :doc:`tracks/domains` :doc:`tracks/bed` :doc:`tracks/gtf` :doc:`tracks/narrow_peak` :doc:`tracks/bigwig` :doc:`tracks/bedgraph` :doc:`tracks/bedgraph_mat :doc:`tracks/hlines` :doc:`tracks/hic_matrix` :doc:`tracks/scalebar` -========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= -overlay_previous no no no no no no no no no no no no no -where bottom left -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 -line_width not set 0.5 0.5 0.5 1 0.5 0.5 -line_style solid solid -color blue #1f78b4 #1f78b4 #1f78b4 #FF000080 #33a02c #a6cee3 black black -alpha 0.8 1 1 1 1 -max_value not set not set not set not set not set not set not set not set not set -min_value not set not set not set not set not set not set not set not set -ylim not set -compact_arcs_level 0 -use_middle false false -border_color black black black -prefered_name transcript_name transcript_name transcript_name -merge_transcripts false false false -labels true true -style flybase flybase -display stacked stacked -max_labels 60 60 -global_max_row false false -gene_rows not set not set -arrow_interval 2 2 -arrowhead_included false false -color_utr grey grey -height_utr 1 1 -arrow_length not set not set -all_labels_inside false false -labels_in_margin false false -show_data_range true true true true true -show_labels true -use_summit true -width_adjust 1.5 -type peak fill fill matrix -negative_color not set not set -nans_to_zeros false false -summary_method mean not set -number_of_bins 700 700 -transform no no no -log_pseudocount 0 0 -y_axis_values transformed transformed -second_file* not set not set -operation* file file -grid false false -rasterize false true true -pos_score_in_bin center -plot_horizontal_lines false -colormap viridis RdYlBu_r -depth 100000 -show_masked_bins false -scale_factor 1 -x_center not set -size not set -========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= ========================= +============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= +parameter :doc:`tracks/x_axis` :doc:`tracks/epilogos` :doc:`tracks/links` :doc:`tracks/domains` :doc:`tracks/bed` :doc:`tracks/gtf` :doc:`tracks/narrow_peak` :doc:`tracks/bigwig` :doc:`tracks/bedgraph` :doc:`tracks/bedgraph_matrix` :doc:`tracks/hlines` :doc:`tracks/hic_matrix` :doc:`tracks/scalebar` +============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= +overlay_previous no no no no no no no no no no no no no +where bottom left +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 +line_width not set 0.5 0.5 0.5 1 0.5 0.5 +line_style solid solid +color blue #1f78b4 #1f78b4 #1f78b4 #FF000080 #33a02c #a6cee3 black black +alpha 0.8 1 1 1 1 +max_value not set not set not set not set not set not set not set not set not set +min_value not set not set not set not set not set not set not set not set +ylim not set +compact_arcs_level 0 +use_middle false false +border_color black black black +prefered_name transcript_name transcript_name transcript_name +merge_transcripts false false false +labels true true +style flybase flybase +display stacked stacked +max_labels 60 60 +global_max_row false false +gene_rows not set not set +arrow_interval 2 2 +arrowhead_included false false +color_utr grey grey +height_utr 1 1 +arrow_length not set not set +all_labels_inside false false +labels_in_margin false false +show_data_range true true true true true +show_labels true +use_summit true +width_adjust 1.5 +type peak fill fill matrix +negative_color not set not set +nans_to_zeros false false +summary_method mean not set +number_of_bins 700 700 +transform no no no +log_pseudocount 0 0 +y_axis_values transformed transformed +second_file* not set not set +operation* file file +grid false false +rasterize false true true +pos_score_in_bin center +plot_horizontal_lines false +colormap viridis RdYlBu_r +depth 100000 +show_masked_bins false +scale_factor 1 +x_center not set +size not set +============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= ============================= \* While pyGenomeTracks can convert coverage tracks on the fly, this might be a time-consuming step, especially on large files and if you want to replot many times. In this situation, we recommend using the deepTools suite to convert your files in advance. For example `bamCoverage `_ or `bamCompare `_ \ No newline at end of file diff --git a/docs/content/faq.rst b/docs/content/faq.rst index 36949fa7..c7cdbf3e 100644 --- a/docs/content/faq.rst +++ b/docs/content/faq.rst @@ -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 `_ 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 `_. @@ -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 `_ 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. diff --git a/pygenometracks/getAllDefaultsAndPossible.py b/pygenometracks/getAllDefaultsAndPossible.py index 43ace338..e560c61e 100644 --- a/pygenometracks/getAllDefaultsAndPossible.py +++ b/pygenometracks/getAllDefaultsAndPossible.py @@ -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): diff --git a/pygenometracks/tracks/BedGraphTrack.py b/pygenometracks/tracks/BedGraphTrack.py index e426cebd..44363426 100644 --- a/pygenometracks/tracks/BedGraphTrack.py +++ b/pygenometracks/tracks/BedGraphTrack.py @@ -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): @@ -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']) diff --git a/pygenometracks/utilities.py b/pygenometracks/utilities.py index e9df2c8e..f6c2c43b 100644 --- a/pygenometracks/utilities.py +++ b/pygenometracks/utilities.py @@ -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): @@ -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: @@ -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 @@ -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 diff --git a/requirements.txt b/requirements.txt index 92c2f103..1b0257c5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,4 @@ pysam >=0.14 gffutils >=0.9 pybedtools >=0.8.1 tqdm >=4.20 -libopenblas < 0.3.10 +