Skip to content

Commit

Permalink
Merge pull request #1282 from deeptools/plotheatmap_ymax_mpl
Browse files Browse the repository at this point in the history
drop deepblue support, heatmapper constrained layout,
  • Loading branch information
WardDeb authored Jan 9, 2024
2 parents 484f30d + 1e3fa9f commit d027314
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 545 deletions.
12 changes: 12 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
3.5.5
* drop support for python 3.7
* doc fixes (argparse properly displayed, minor changes in installation instructions)
* deepblue support stops
* initiate deprecation of tight_layout in plotheatmap, in favor of constrained_layout. Minor changes in paddings, etc can occur (but for the better).

3.5.4
* error handling and cases for bwAverage with >2 samples
* Tick.label deprecation for mpl 3.8
* minimal mpl version is 3.5
* cicd update for pypi push

3.5.3
* requirement cap for matplotlib lifted (changes in plotting can occur)
* nose has been deprecated in favor of pytests
Expand Down
42 changes: 3 additions & 39 deletions deeptools/bigwigAverage.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse # to parse command line arguments
import argparse
import sys
import multiprocessing
import os
import numpy as np
from deeptools import parserCommon
from deeptools import writeBedGraph_bam_and_bw
import deeptools.deepBlue as db

debug = 0


def parse_arguments(args=None):
parentParser = parserCommon.getParentArgParse()
outputParser = parserCommon.output()
dbParser = parserCommon.deepBlueOptionalArgs()
parser = argparse.ArgumentParser(
parents=[parentParser, outputParser, dbParser],
parents=[parentParser, outputParser],
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='This tool average multiple bigWig files based on the number '
'of mapped reads. To average the bigWig files, the genome is '
Expand Down Expand Up @@ -59,7 +55,7 @@ def parse_arguments(args=None):

def getType(fname):
"""
Tries to determine if a file is a wiggle file from deepBlue or a bigWig file.
Tries to determine if a file is a wiggle file a bigWig file.
Returns 'wiggle' if the file name ends with .wig, otherwise 'bigwig'
"""
if fname.endswith(".wig") or fname.endswith(".wiggle"):
Expand Down Expand Up @@ -119,29 +115,6 @@ def main(args=None):
FUNC = average
function_args = {'scaleFactors': scaleFactors}

# Preload deepBlue files, which need to then be deleted
deepBlueFiles = []
for idx, fname in enumerate(args.bigwigs):
if db.isDeepBlue(fname):
deepBlueFiles.append([fname, idx])
if len(deepBlueFiles) > 0:
sys.stderr.write("Preloading the following deepBlue files: {}\n".format(",".join([x[0] for x in deepBlueFiles])))
foo = db.deepBlue(deepBlueFiles[0][0], url=args.deepBlueURL, userKey=args.userKey)
regs = db.makeChromTiles(foo)
for x in deepBlueFiles:
x.extend([args, regs])
if len(deepBlueFiles) > 1 and args.numberOfProcessors > 1:
pool = multiprocessing.Pool(args.numberOfProcessors)
res = pool.map_async(db.preloadWrapper, deepBlueFiles).get(9999999)
else:
res = list(map(db.preloadWrapper, deepBlueFiles))

# substitute the file names with the temp files
for (ftuple, r) in zip(deepBlueFiles, res):
args.bigwigs[ftuple[1]] = r
deepBlueFiles = [[x[0], x[1]] for x in deepBlueFiles]
del regs

writeBedGraph_bam_and_bw.writeBedGraph(
[(b, getType(b)) for b in args.bigwigs],
args.outFileName, 0, FUNC,
Expand All @@ -154,12 +127,3 @@ def main(args=None):
smoothLength=False,
missingDataAsZero=not args.skipNonCoveredRegions,
extendPairedEnds=False)

# Clean up temporary bigWig files, if applicable
if not args.deepBlueKeepTemp:
for k, v in deepBlueFiles:
os.remove(args.bigwigs[v])
else:
for k, v in deepBlueFiles:
foo = args.bigwigs[v]
print("{} is stored in {}".format(k, foo))
51 changes: 3 additions & 48 deletions deeptools/bigwigCompare.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse # to parse command line arguments
import sys
import multiprocessing
import os
import argparse
from deeptools import parserCommon
from deeptools.getRatio import getRatio
from deeptools import writeBedGraph_bam_and_bw
import deeptools.deepBlue as db

debug = 0


def parse_arguments(args=None):
parentParser = parserCommon.getParentArgParse()
outputParser = parserCommon.output()
dbParser = parserCommon.deepBlueOptionalArgs()
parser = argparse.ArgumentParser(
parents=[parentParser, outputParser, dbParser],
parents=[parentParser, outputParser],
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='This tool compares two bigWig files based on the number '
'of mapped reads. To compare the bigWig files, the genome is '
Expand Down Expand Up @@ -104,7 +99,7 @@ def parse_arguments(args=None):

def getType(fname):
"""
Tries to determine if a file is a wiggle file from deepBlue or a bigWig file.
Tries to determine if a file is a wiggle file or a bigWig file.
Returns 'wiggle' if the file name ends with .wig, otherwise 'bigwig'
"""
if fname.endswith(".wig") or fname.endswith(".wiggle"):
Expand Down Expand Up @@ -136,32 +131,6 @@ def main(args=None):
'scaleFactors': scaleFactors,
'pseudocount': args.pseudocount}

# Preload deepBlue files, which need to then be deleted
deepBlueFiles = []
for idx, fname in enumerate([args.bigwig1, args.bigwig2]):
if db.isDeepBlue(fname):
deepBlueFiles.append([fname, idx])
if len(deepBlueFiles) > 0:
sys.stderr.write("Preloading the following deepBlue files: {}\n".format(",".join([x[0] for x in deepBlueFiles])))
foo = db.deepBlue(deepBlueFiles[0][0], url=args.deepBlueURL, userKey=args.userKey)
regs = db.makeChromTiles(foo)
for x in deepBlueFiles:
x.extend([args, regs])
if len(deepBlueFiles) > 1 and args.numberOfProcessors > 1:
pool = multiprocessing.Pool(args.numberOfProcessors)
res = pool.map_async(db.preloadWrapper, deepBlueFiles).get(9999999)
else:
res = list(map(db.preloadWrapper, deepBlueFiles))

# substitute the file names with the temp files
for (ftuple, r) in zip(deepBlueFiles, res):
if ftuple[1] == 0:
args.bigwig1 = r
else:
args.bigwig2 = r
deepBlueFiles = [[x[0], x[1]] for x in deepBlueFiles]
del regs

writeBedGraph_bam_and_bw.writeBedGraph(
[(args.bigwig1, getType(args.bigwig1)),
(args.bigwig2, getType(args.bigwig2))],
Expand All @@ -176,17 +145,3 @@ def main(args=None):
missingDataAsZero=not args.skipNonCoveredRegions,
extendPairedEnds=False,
fixedStep=args.fixedStep)

# Clean up temporary bigWig files, if applicable
if not args.deepBlueKeepTemp:
for k, v in deepBlueFiles:
if v == 0:
os.remove(args.bigwig1)
else:
os.remove(args.bigwig2)
else:
for k, v in deepBlueFiles:
foo = args.bigwig1
if v == 1:
foo = args.bigwig2
print("{} is stored in {}".format(k, foo))
51 changes: 8 additions & 43 deletions deeptools/computeMatrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,10 @@

import argparse
import sys
import os
import multiprocessing

from deeptools.parserCommon import writableFile, numberOfProcessors
from deeptools import parserCommon
from deeptools import heatmapper
import deeptools.computeMatrixOperations as cmo
import deeptools.deepBlue as db
from importlib.metadata import version


Expand Down Expand Up @@ -44,17 +40,16 @@ def parse_arguments(args=None):
dest='command',
metavar='')

dbParser = parserCommon.deepBlueOptionalArgs()

# scale-regions mode options
subparsers.add_parser(
'scale-regions',
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
parents=[computeMatrixRequiredArgs(),
computeMatrixOutputArgs(),
computeMatrixOptArgs(case='scale-regions'),
parserCommon.gtf_options(),
dbParser],
parents=[
computeMatrixRequiredArgs(),
computeMatrixOutputArgs(),
computeMatrixOptArgs(case='scale-regions'),
parserCommon.gtf_options()
],
help="In the scale-regions mode, all regions in the BED file are "
"stretched or shrunken to the length (in bases) indicated by the user.",
usage='An example usage is:\n computeMatrix scale-regions -S '
Expand All @@ -67,8 +62,8 @@ def parse_arguments(args=None):
parents=[computeMatrixRequiredArgs(),
computeMatrixOutputArgs(),
computeMatrixOptArgs(case='reference-point'),
parserCommon.gtf_options(),
dbParser],
parserCommon.gtf_options()
],
help="Reference-point refers to a position within a BED region "
"(e.g., the starting point). In this mode, only those genomic"
"positions before (upstream) and/or after (downstream) of the "
Expand Down Expand Up @@ -399,28 +394,6 @@ def main(args=None):

hm = heatmapper.heatmapper()

# Preload deepBlue files, which need to then be deleted
deepBlueFiles = []
for idx, fname in enumerate(args.scoreFileName):
if db.isDeepBlue(fname):
deepBlueFiles.append([fname, idx])
if len(deepBlueFiles) > 0:
sys.stderr.write("Preloading the following deepBlue files: {}\n".format(",".join([x[0] for x in deepBlueFiles])))
regs = db.makeRegions(args.regionsFileName, args)
for x in deepBlueFiles:
x.extend([args, regs])
if len(deepBlueFiles) > 1 and args.numberOfProcessors > 1:
pool = multiprocessing.Pool(args.numberOfProcessors)
res = pool.map_async(db.preloadWrapper, deepBlueFiles).get(9999999)
else:
res = list(map(db.preloadWrapper, deepBlueFiles))

# substitute the file names with the temp files
for (ftuple, r) in zip(deepBlueFiles, res):
args.scoreFileName[ftuple[1]] = r
deepBlueFiles = [[x[0], x[1]] for x in deepBlueFiles]
del regs

scores_file_list = args.scoreFileName
hm.computeMatrix(scores_file_list, args.regionsFileName, parameters, blackListFileName=args.blackListFileName, verbose=args.verbose, allArgs=args)
if args.sortRegions not in ['no', 'keep']:
Expand All @@ -446,11 +419,3 @@ def main(args=None):

if args.outFileSortedRegions:
hm.save_BED(args.outFileSortedRegions)

# Clean up temporary bigWig files, if applicable
if not args.deepBlueKeepTemp:
for k, v in deepBlueFiles:
os.remove(args.scoreFileName[v])
else:
for k, v in deepBlueFiles:
print("{} is stored in {}".format(k, args.scoreFileName[v]))
Loading

0 comments on commit d027314

Please sign in to comment.