Skip to content

Commit

Permalink
Small improvements for a better galaxy support
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimwolff committed Dec 25, 2017
1 parent 05a32f1 commit 5af8806
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
2 changes: 1 addition & 1 deletion hicexplorer/HiCMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(self, matrixFile=None, file_format=None, skiprows=None, chrnameList
file_format = 'h5'
elif matrixFile.endswith('.gz'):
file_format = 'dekker'
elif matrixFile.endswith('.cool'):
elif matrixFile.endswith('.cool') or cooler.io.is_cooler(matrixFile):
file_format = 'cool'
# by default assume that the matrix file_format is hd5
else:
Expand Down
14 changes: 10 additions & 4 deletions hicexplorer/hicPlotMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from past.builtins import zip
from future.utils import itervalues

import cooler
import argparse
import matplotlib
matplotlib.use('Agg')
Expand Down Expand Up @@ -380,7 +381,10 @@ def getRegion(args, ma):
exit("Chromosome name {} in --region not in matrix".format(change_chrom_names(chrom)))

args.region = [chrom, region_start, region_end]
if args.matrix.endswith(".cool"):
is_cooler = False
if args.matrix.endswith('.cool') or cooler.io.is_cooler(args.matrix):
is_cooler = True
if is_cooler:
idx1, start_pos1 = zip(*[(idx, x[1]) for idx, x in enumerate(ma.cut_intervals) if x[0] == chrom and
((x[1] >= region_start and x[2] < region_end) or
(x[1] < region_end and x[2] < region_end and x[2] > region_start) or
Expand All @@ -398,7 +402,7 @@ def getRegion(args, ma):
chrom2 = toBytes(chrom)
if chrom2 not in list(ma.interval_trees):
exit("Chromosome name {} in --region2 not in matrix".format(change_chrom_names(chrom2)))
if args.matrix.endswith(".cool"):
if is_cooler:
idx2, start_pos2 = zip(*[(idx, x[1]) for idx, x in enumerate(ma.cut_intervals) if x[0] == chrom2 and
((x[1] >= region_start2 and x[2] < region_end2) or
(x[1] < region_end2 and x[2] < region_end2 and x[2] > region_start2) or
Expand Down Expand Up @@ -431,8 +435,10 @@ def main(args=None):
if args.region and args.region2 and args.pca:
log.error("Inter-chromosomal pca is not supported.")
exit(1)

if args.matrix.endswith('.cool') and not args.region2:
is_cooler = False
if args.matrix.endswith('.cool') or cooler.io.is_cooler(args.matrix):
is_cooler = True
if is_cooler and not args.region2:
log.debug("Retrieve data from cooler format and use its benefits.")
regionsToRetrieve = None
if args.region:
Expand Down
Binary file added hicexplorer/test/test_data/Li_et_al_2015
Binary file not shown.
Binary file not shown.
30 changes: 30 additions & 0 deletions hicexplorer/test/test_hicPlotMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,21 @@ def test_hicPlotMatrix_cool_log_region1_region2():
os.remove(outfile.name)


@pytest.mark.skipif(LOW_MEMORY > memory,
reason="Travis has too less memory to run it.")
def test_hicPlotMatrix_cool_log_region1_region2_without_cool_suffix():

outfile = NamedTemporaryFile(suffix='.png', prefix='hicexplorer_test_cool', delete=False)

args = "--matrix {0}/Li_et_al_2015 --region chrX:3000000-3500000 --region2 chrX:3100000-3600000 " \
"--outFileName {1} --log ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/Li_chrX30-35-chrX31-36_cool_log.png', outfile.name, tol=40)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)


@pytest.mark.skipif(LOW_MEMORY > memory,
reason="Travis has too less memory to run it.")
def test_hicPlotMatrix_cool_log1p_region1_region2():
Expand Down Expand Up @@ -293,6 +308,21 @@ def test_hicPlotMatrix_perChr():
os.remove(outfile.name)


@pytest.mark.skipif(LOW_MEMORY > memory,
reason="Travis has too less memory to run it.")
def test_hicPlotMatrix_perChr_without_h5_suffix():

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

args = "--matrix {0}/small_test_matrix_50kb_res --perChr " \
"--outFileName {1} ".format(ROOT, outfile.name).split()
hicexplorer.hicPlotMatrix.main(args)
res = compare_images(ROOT + "hicPlotMatrix" + '/small_test_matrix_50kb_res_perChr.png', outfile.name, tol=40)
assert res is None, res
if REMOVE_OUTPUT:
os.remove(outfile.name)


@pytest.mark.skipif(LOW_MEMORY > memory,
reason="Travis has too less memory to run it.")
def test_hicPlotMatrix_cool_perChr_log():
Expand Down

0 comments on commit 5af8806

Please sign in to comment.