Skip to content

Commit 861687c

Browse files
authored
Merge pull request #594 from deeptools/develop
Develop
2 parents 1fad772 + 1814cd6 commit 861687c

10 files changed

+45
-51
lines changed

hicexplorer/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
# This file is originally generated from Git information by running 'setup.py
33
# version'. Distribution tarballs contain a pre-generated copy of this file.
44

5-
__version__ = '3.5'
5+
__version__ = '3.5.1'

hicexplorer/hicAdjustMatrix.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def adjustMatrix(pArgs):
137137
elif pArgs.action == 'remove':
138138
hic_matrix.maskBins(matrix_indices_regions)
139139
hic_matrix.orig_bin_ids = []
140+
hic_matrix.orig_cut_intervals = []
140141
hic_matrix.nan_bins = []
141142

142143
elif pArgs.maskBadRegions:

hicexplorer/hicBuildMatrix.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,21 +119,19 @@ def parse_arguments(args=None):
119119
metavar='FOLDER',
120120
required=True)
121121
parserRequired.add_argument('--restrictionCutFile', '-rs',
122-
help=('BED file(s) with all restriction cut places '
123-
'(output of "findRestSite" command). '
124-
'Should contain only mappable '
125-
'restriction sites. If given, the bins are '
126-
'set to match the restriction fragments (i.e. '
127-
'the region between one restriction site and '
128-
'the next). Alternatively, a fixed binSize can be defined instead. '
129-
'However, either binSize or restrictionCutFile must be defined. '
130-
'To use more than one restriction enzyme, generate for each one a restrictionCutFile and list them space seperated.'),
122+
help='BED file(s) with all restriction cut sites '
123+
'(output of "hicFindRestSite" command). '
124+
'Should only contain the restriction sites of the same genome which has been used '
125+
'to generate the input sam files. Using regions of a different genome version can '
126+
'generate false results! To use more than one restriction enzyme, generate '
127+
'a restrictionCutFile for each enzyne and list them space seperated.',
131128
type=argparse.FileType('r'),
132129
metavar='BED file',
133130
nargs='+',
134131
required=True)
135132
parserRequired.add_argument('--restrictionSequence', '-seq',
136-
help='Sequence of the restriction site, if multiple are used, please list them space seperated. If a dangling sequence '
133+
help='Sequence of the restriction site, if multiple are used, '
134+
'please list them space seperated. If a dangling sequence '
137135
'is listed at the same time, please preserve the same order.',
138136
type=str,
139137
nargs='+',
@@ -172,9 +170,8 @@ def parse_arguments(args=None):
172170
parserOpt.add_argument('--binSize', '-bs',
173171
help='Size in bp for the bins. The bin size depends '
174172
'on the depth of sequencing. Use a larger bin size for '
175-
'libraries sequenced with lower depth. Alternatively, the location of '
176-
'the restriction sites can be given (see --restrictionCutFile). However, either binSize or restrictionCutFile must be defined.'
177-
'Optional for mcool file format: Define multiple resolutions which are all a multiple of the first value. '
173+
'libraries sequenced with lower depth. If not given, matrices of restriction site resolution will be built. '
174+
'Optionally for mcool file format: Define multiple resolutions which are all a multiple of the first value. '
178175
' Example: --binSize 10000 20000 50000 will create a mcool file formate containing the three defined resolutions.',
179176
type=int,
180177
nargs='+')

hicexplorer/hicCorrelate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def main(args=None):
325325
hic_mat_list.append(_mat)
326326

327327
# remove nan bins
328-
rows_keep = cols_keep = np.delete(list(range(all_mat.shape[1])), all_nan)
328+
rows_keep = cols_keep = np.delete(list(range(all_mat.shape[1])), all_nan.astype('int'))
329329
all_mat = all_mat[rows_keep, :][:, cols_keep]
330330

331331
# make large matrix to correlate by

hicexplorer/hicMergeDomains.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import logging
88
log = logging.getLogger(__name__)
9+
from hicexplorer._version import __version__
910

1011

1112
def parse_arguments(args=None):
@@ -72,6 +73,9 @@ def parse_arguments(args=None):
7273
help='File format of the relationship tree. Supported formats are listed on: https://www.graphviz.org/doc/info/output.html',
7374
default='pdf',
7475
required=False)
76+
parserOpt.add_argument("--help", "-h", action="help", help="show this help message and exit")
77+
78+
parserOpt.add_argument('--version', action='version', version='%(prog)s {}'.format(__version__))
7579

7680
return parser
7781

hicexplorer/hicPlotMatrix.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -390,15 +390,14 @@ def plotHeatmap(ma, chrBinBoundaries, fig, position, args, cmap, xlabel=None,
390390
pValueMin=args.vMinBigwig, pValueMax=args.vMaxBigwig, pResolution=pResolution)
391391

392392

393-
def translate_region(region_string):
393+
def translate_region(region_string, ma):
394394
"""
395395
Takes an string and returns a list
396396
of chrom, start, end.
397397
If the region string only contains
398398
the chrom, then start and end
399-
are set to a 0 and 1e15
399+
are set to matrix start and end on this chromosome
400400
"""
401-
402401
# region_string = toBytes(region_string)
403402
region_string = region_string.replace(",", "")
404403
region_string = region_string.replace(";", "")
@@ -407,14 +406,24 @@ def translate_region(region_string):
407406

408407
fields = region_string.split(":")
409408
chrom = fields[0]
409+
410+
chrom = check_chrom_str_bytes(ma.interval_trees, chrom)
411+
if chrom not in list(ma.interval_trees):
412+
chrom = change_chrom_names(chrom)
413+
chrom = check_chrom_str_bytes(ma.interval_trees, chrom)
414+
if chrom not in list(ma.interval_trees):
415+
exit(
416+
"Chromosome name {} in --region not in matrix".format(change_chrom_names(chrom)))
417+
418+
first_bin, last_bin = ma.getChrBinRange(chrom)
410419
try:
411420
region_start = int(fields[1])
412421
except IndexError:
413-
region_start = 0
422+
region_start = ma.getBinPos(first_bin)[1]
414423
try:
415424
region_end = int(fields[2])
416425
except IndexError:
417-
region_end = 1e15 # vert large number
426+
region_end = ma.getBinPos(last_bin - 1)[2]
418427

419428
return chrom, region_start, region_end
420429

@@ -559,43 +568,27 @@ def plotPerChr(hic_matrix, cmap, args, pBigwig, pResolution):
559568
args, hic_matrix)
560569
plotHeatmap(matrix, chr_bin_boundary, fig, None,
561570
args, cmap, xlabel=chrname, ylabel=chrname,
562-
start_pos=start_pos1, start_pos2=start_pos2, pNorm=norm, pAxis=axis, pBigwig=bigwig_info, pChromsomeStartEndDict=chromosome_start_end(hic_matrix), pResolution=pResolution)
571+
start_pos=start_pos1, start_pos2=start_pos2, pNorm=norm, pAxis=axis, pBigwig=bigwig_info,
572+
pChromsomeStartEndDict=chromosome_start_end(hic_matrix), pResolution=pResolution)
563573
return fig
564574

565575

566576
def getRegion(args, ma):
567577
chrom = region_start = region_end = idx1 = start_pos1 = chrom2 = region_start2 = region_end2 = idx2 = start_pos2 = None
568-
chrom, region_start, region_end = translate_region(args.region)
569-
570-
chrom = check_chrom_str_bytes(ma.interval_trees, chrom)
571-
# if type(next(iter(ma.interval_trees))) in [np.bytes_, bytes]:
572-
# chrom = toBytes(chrom)
573-
574-
if chrom not in list(ma.interval_trees):
575-
576-
chrom = change_chrom_names(chrom)
577-
578-
chrom = check_chrom_str_bytes(ma.interval_trees, chrom)
579-
580-
# if type(next(iter(ma.interval_trees))) in [np.bytes_, bytes]:
581-
# chrom = toBytes(chrom)
582-
583-
if chrom not in list(ma.interval_trees):
584-
exit(
585-
"Chromosome name {} in --region not in matrix".format(change_chrom_names(chrom)))
578+
chrom, region_start, region_end = translate_region(args.region, ma)
586579

587580
args.region = [chrom, region_start, region_end]
588581
is_cooler = check_cooler(args.matrix)
589582
if is_cooler:
590583
idx1, start_pos1 = zip(*[(idx, x[1]) for idx, x in enumerate(ma.cut_intervals) if x[0] == chrom and # noqa: W504
591-
((x[1] >= region_start and x[2] < region_end) or # noqa: W504
584+
((x[1] >= region_start and x[2] <= region_end) or # noqa: W504
592585
(x[1] < region_end and x[2] < region_end and x[2] > region_start) or # noqa: W504
593586
(x[1] > region_start and x[1] < region_end))])
594587
else:
595588
idx1, start_pos1 = zip(*[(idx, x[1]) for idx, x in enumerate(ma.cut_intervals) if x[0] == chrom and # noqa: W504
596-
x[1] >= region_start and x[2] < region_end])
589+
x[1] >= region_start and x[2] <= region_end])
597590
if hasattr(args, 'region2') and args.region2:
598-
chrom2, region_start2, region_end2 = translate_region(args.region2)
591+
chrom2, region_start2, region_end2 = translate_region(args.region2, ma)
599592
chrom2 = check_chrom_str_bytes(ma.interval_trees, chrom2)
600593

601594
# if type(next(iter(ma.interval_trees))) in [np.bytes_, bytes]:
@@ -780,7 +773,6 @@ def main(args=None):
780773
matrix = np.asarray(ma.getMatrix().astype(float))
781774

782775
resolution = ma.getBinSize()
783-
784776
matrix_length = len(matrix[0])
785777
log.debug("Number of data points matrix: {}".format(matrix_length))
786778

hicexplorer/test/general/test_hicAggregateContacts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626

2727
ROOT = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "test_data/")
28-
tolerance = 13 # default matplotlib pixed difference tolerance
28+
tolerance = 50 # default matplotlib pixed difference tolerance
2929

3030

3131
@pytest.mark.xfail(raises=ImageComparisonFailure, reason='Matplotlib plots for reasons a different image size.')

hicexplorer/test/general/test_hicCorrelate.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def test_correlate():
2222
"--outFileNameHeatmap {} --outFileNameScatter {}".format(ROOT + "hicCorrectMatrix/small_test_matrix_ICEcorrected_chrUextra_chr3LHet.h5",
2323
ROOT + "hicCorrectMatrix/small_test_matrix_ICEcorrected_chrUextra_chr3LHet.h5",
2424
outfile_heatmap.name, outfile_scatter.name).split()
25-
# hicCorrelate.main(args)
26-
compute(hicCorrelate.main, args, 5)
25+
hicCorrelate.main(args)
26+
# compute(hicCorrelate.main, args, 5)
2727
res = compare_images(ROOT + "hicCorrelate" + '/heatmap.png', outfile_heatmap.name, tol=40)
2828
assert res is None, res
2929

@@ -44,8 +44,8 @@ def test_correlate_chromosomes():
4444
"--chromosomes chrUextra chr3LHet".format(ROOT + "hicCorrectMatrix/small_test_matrix_ICEcorrected_chrUextra_chr3LHet.h5",
4545
ROOT + "hicCorrectMatrix/small_test_matrix_ICEcorrected_chrUextra_chr3LHet.h5",
4646
outfile_heatmap.name, outfile_scatter.name).split()
47-
# hicCorrelate.main(args)
48-
compute(hicCorrelate.main, args, 5)
47+
hicCorrelate.main(args)
48+
# compute(hicCorrelate.main, args, 5)
4949

5050
res = compare_images(ROOT + "hicCorrelate" + '/heatmap_chrom.png', outfile_heatmap.name, tol=40)
5151
assert res is None, res

hicexplorer/test/general/test_hicPlotMatrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def test_hicPlotMatrix_cool_perChr_log1p():
440440

441441
outfile = NamedTemporaryFile(suffix='.png', prefix='hicexplorer_test', delete=False)
442442

443-
args = "--matrix {0}/small_test_matrix_50kb_res.h5 --perChr --disable_tight_layout " \
443+
args = "--matrix {0}/small_test_matrix_50kb_res.cool --perChr --disable_tight_layout " \
444444
"--outFileName {1} --log1 --vMax 10 ".format(ROOT, outfile.name).split()
445445
# hicexplorer.hicPlotMatrix.main(args)
446446
compute(hicexplorer.hicPlotMatrix.main, args, 5)

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ pandas >= 0.25.*
1111
pybigwig >= 0.3.*
1212
jinja2 >= 2.10
1313
unidecode >= 1.1.*
14-
hicmatrix >= 13
14+
hicmatrix >= 14
1515
hic2cool >= 0.8.3
1616
psutil >= 5.6.*
1717
pygenometracks >= 3.2
1818
fit_nbinom >= 1.1
19-
cooler >= 0.8.5
19+
cooler >= 0.8.9
2020
krbalancing >= 0.0.5
2121
pybedtools >= 0.8.*
2222
future >= 0.17

0 commit comments

Comments
 (0)