From 9d5f35ed1a6fa29535b93c83d1b43fffce7de33c Mon Sep 17 00:00:00 2001 From: WardDeb Date: Sat, 26 Sep 2026 21:27:47 +0200 Subject: [PATCH 1/2] existingFilecheck --- pydeeptools/deeptools/alignmentSieve2.py | 2 ++ pydeeptools/deeptools/bamCompare2.py | 3 +++ pydeeptools/deeptools/bamCoverage2.py | 2 ++ pydeeptools/deeptools/bamPEFragmentSize.py | 4 +++- pydeeptools/deeptools/bigwigAverage.py | 2 ++ pydeeptools/deeptools/bigwigCompare.py | 3 +++ pydeeptools/deeptools/computeMatrix2.py | 4 +++- pydeeptools/deeptools/computeMatrixOperations.py | 7 ++++++- pydeeptools/deeptools/estimateReadFiltering.py | 3 +++ pydeeptools/deeptools/estimateScaleFactor.py | 3 ++- pydeeptools/deeptools/multiBamSummary2.py | 3 +++ pydeeptools/deeptools/multiBigwigSummary.py | 3 +++ pydeeptools/deeptools/parserCommon.py | 14 +++++++++++++- pydeeptools/deeptools/plotCorrelation.py | 3 ++- pydeeptools/deeptools/plotCoverage.py | 5 ++++- pydeeptools/deeptools/plotEnrichment.py | 3 +++ pydeeptools/deeptools/plotFingerprint.py | 5 ++++- pydeeptools/deeptools/plotPCA.py | 3 ++- 18 files changed, 63 insertions(+), 9 deletions(-) diff --git a/pydeeptools/deeptools/alignmentSieve2.py b/pydeeptools/deeptools/alignmentSieve2.py index 39b315b93f..09dff1478c 100644 --- a/pydeeptools/deeptools/alignmentSieve2.py +++ b/pydeeptools/deeptools/alignmentSieve2.py @@ -5,6 +5,7 @@ from deeptools import parserCommon from deeptools.hp import r_alignmentsieve +from deeptools.parserCommon import existingFile def parseArguments(): @@ -18,6 +19,7 @@ def parseArguments(): required.add_argument('--bam', '-b', metavar='FILE1', help='An indexed BAM file.', + type=existingFile, required=True) required.add_argument('--outFile', '-o', diff --git a/pydeeptools/deeptools/bamCompare2.py b/pydeeptools/deeptools/bamCompare2.py index fceb36822e..4ebd7de04a 100644 --- a/pydeeptools/deeptools/bamCompare2.py +++ b/pydeeptools/deeptools/bamCompare2.py @@ -4,6 +4,7 @@ from deeptools import parserCommon from deeptools.hp import r_bamcompare +from deeptools.parserCommon import existingFile def parseArguments(): @@ -51,12 +52,14 @@ def getRequiredArgs(): metavar='BAM file', help='Sorted BAM file 1. Usually the BAM file ' 'for the treatment.', + type=existingFile, required=True) required.add_argument('--bamfile2', '-b2', metavar='BAM file', help='Sorted BAM file 2. Usually the BAM ' 'file for the control.', + type=existingFile, required=True) return parser diff --git a/pydeeptools/deeptools/bamCoverage2.py b/pydeeptools/deeptools/bamCoverage2.py index b27270258f..9f80f15c56 100644 --- a/pydeeptools/deeptools/bamCoverage2.py +++ b/pydeeptools/deeptools/bamCoverage2.py @@ -4,6 +4,7 @@ from deeptools import parserCommon from deeptools.hp import r_bamcoverage +from deeptools.parserCommon import existingFile def parseArguments(): @@ -45,6 +46,7 @@ def get_required_args(): required.add_argument('--bam', '-b', help='BAM file to process', metavar='BAM file', + type=existingFile, required=True) return parser diff --git a/pydeeptools/deeptools/bamPEFragmentSize.py b/pydeeptools/deeptools/bamPEFragmentSize.py index 7f2fec0297..eb50da5f79 100644 --- a/pydeeptools/deeptools/bamPEFragmentSize.py +++ b/pydeeptools/deeptools/bamPEFragmentSize.py @@ -8,7 +8,7 @@ from deeptools import matplotlib_defaults # noqa: F401 from deeptools.getFragmentAndReadSize import get_read_and_fragment_length -from deeptools.parserCommon import writableFile +from deeptools.parserCommon import existingFile, writableFile def parse_arguments(): @@ -30,6 +30,7 @@ def parse_arguments(): help="List of BAM files to process", nargs="+", metavar="bam files", + type=existingFile, ) parser.add_argument( @@ -114,6 +115,7 @@ def parse_arguments(): "-bl", help="A BED file containing regions that should be excluded from all analyses. Currently this works by rejecting genomic chunks that happen to overlap an entry. Consequently, for BAM files, if a read partially overlaps a blacklisted region or a fragment spans over it, then the read/fragment might still be considered.", metavar="BED file", + type=existingFile, required=False, ) parser.add_argument( diff --git a/pydeeptools/deeptools/bigwigAverage.py b/pydeeptools/deeptools/bigwigAverage.py index 237ee243a5..615d131bb2 100644 --- a/pydeeptools/deeptools/bigwigAverage.py +++ b/pydeeptools/deeptools/bigwigAverage.py @@ -4,6 +4,7 @@ import numpy as np from deeptools import parserCommon, writeBedGraph_bam_and_bw +from deeptools.parserCommon import existingFile debug = 0 @@ -30,6 +31,7 @@ def parse_arguments(args=None): metavar="Bigwig files", help="Bigwig files separated by space.", nargs="+", + type=existingFile, required=True, ) diff --git a/pydeeptools/deeptools/bigwigCompare.py b/pydeeptools/deeptools/bigwigCompare.py index a2b6900b30..883574336c 100644 --- a/pydeeptools/deeptools/bigwigCompare.py +++ b/pydeeptools/deeptools/bigwigCompare.py @@ -2,6 +2,7 @@ from deeptools import parserCommon, writeBedGraph_bam_and_bw from deeptools.getRatio import getRatio +from deeptools.parserCommon import existingFile debug = 0 @@ -26,12 +27,14 @@ def parse_arguments(args=None): metavar='Bigwig file', help='Bigwig file 1. Usually the file for the ' 'treatment.', + type=existingFile, required=True) parser.add_argument('--bigwig2', '-b2', metavar='Bigwig file', help='Bigwig file 2. Usually the file for the ' 'control.', + type=existingFile, required=True) parser.add_argument('--scaleFactors', diff --git a/pydeeptools/deeptools/computeMatrix2.py b/pydeeptools/deeptools/computeMatrix2.py index 0a609a20d6..070e414ac6 100644 --- a/pydeeptools/deeptools/computeMatrix2.py +++ b/pydeeptools/deeptools/computeMatrix2.py @@ -5,7 +5,7 @@ from deeptools import parserCommon from deeptools.hp import r_computematrix -from deeptools.parserCommon import numberOfProcessors, writableFile +from deeptools.parserCommon import existingFile, numberOfProcessors, writableFile def parse_arguments(args=None): @@ -86,6 +86,7 @@ def computeMatrixRequiredArgs(args=None): "the regions to plot. If multiple bed files are given, each one is considered a " "group that can be plotted separately.", nargs="+", + type=existingFile, required=True, ) required.add_argument( @@ -99,6 +100,7 @@ def computeMatrixRequiredArgs(args=None): "http://genome.ucsc.edu/goldenPath/help/bigWig.html ", metavar="File", nargs="+", + type=existingFile, required=True, ) return parser diff --git a/pydeeptools/deeptools/computeMatrixOperations.py b/pydeeptools/deeptools/computeMatrixOperations.py index a227bd654b..0f29e1676e 100755 --- a/pydeeptools/deeptools/computeMatrixOperations.py +++ b/pydeeptools/deeptools/computeMatrixOperations.py @@ -10,6 +10,7 @@ import numpy as np from deeptools import heatmapper +from deeptools.parserCommon import existingFile def parse_arguments(): @@ -153,6 +154,7 @@ def bindArgs(): required.add_argument('--matrixFile', '-m', help='Matrix files from the computeMatrix tool.', nargs='+', + type=existingFile, required=True) required.add_argument('--outFileName', '-o', @@ -168,6 +170,7 @@ def infoArgs(): required.add_argument('--matrixFile', '-m', help='Matrix file from the computeMatrix tool.', + type=existingFile, required=True) return parser @@ -259,6 +262,7 @@ def sortArgs(): required.add_argument('--matrixFile', '-m', help='Matrix file from the computeMatrix tool.', + type=existingFile, required=True) required.add_argument('--outFileName', '-o', @@ -276,7 +280,8 @@ def sortArgs(): 'column with group labels. Note that these should be ' 'sorted such that all group entries are together.', required=True, - nargs='+') + nargs='+', + type=existingFile) optional = parser.add_argument_group('Optional arguments') diff --git a/pydeeptools/deeptools/estimateReadFiltering.py b/pydeeptools/deeptools/estimateReadFiltering.py index 469e9c10b4..303d0aa81f 100644 --- a/pydeeptools/deeptools/estimateReadFiltering.py +++ b/pydeeptools/deeptools/estimateReadFiltering.py @@ -5,6 +5,7 @@ from deeptools import bamHandler, parserCommon, utilities from deeptools.mapReduce import mapReduce +from deeptools.parserCommon import existingFile from deeptools.utilities import smartLabels @@ -40,6 +41,7 @@ def parseArguments(): metavar='FILE1 FILE2', help='List of indexed bam files separated by spaces.', nargs='+', + type=existingFile, required=True) general = parser.add_argument_group('General arguments') @@ -147,6 +149,7 @@ def parseArguments(): help="A BED or GTF file containing regions that should be excluded from all analyses. Currently this works by rejecting genomic chunks that happen to overlap an entry. Consequently, for BAM files, if a read partially overlaps a blacklisted region or a fragment spans over it, then the read/fragment might still be considered. Please note that you should adjust the effective genome size, if relevant.", metavar="BED file", nargs="+", + type=existingFile, required=False) return parser diff --git a/pydeeptools/deeptools/estimateScaleFactor.py b/pydeeptools/deeptools/estimateScaleFactor.py index 5a0e28fe1f..c1ed769883 100644 --- a/pydeeptools/deeptools/estimateScaleFactor.py +++ b/pydeeptools/deeptools/estimateScaleFactor.py @@ -2,7 +2,7 @@ import sys from importlib.metadata import version -from deeptools.parserCommon import numberOfProcessors +from deeptools.parserCommon import existingFile, numberOfProcessors from deeptools.SES_scaleFactor import estimateScaleFactor debug = 0 @@ -22,6 +22,7 @@ def parseArguments(args=None): metavar='list of bam files', help='List of indexed BAM files, space delineated', nargs='+', + type=existingFile, required=True) parser.add_argument('--ignoreForNormalization', '-ignore', diff --git a/pydeeptools/deeptools/multiBamSummary2.py b/pydeeptools/deeptools/multiBamSummary2.py index fb9c08d91b..16e1066a4c 100644 --- a/pydeeptools/deeptools/multiBamSummary2.py +++ b/pydeeptools/deeptools/multiBamSummary2.py @@ -6,6 +6,7 @@ from deeptools import parserCommon from deeptools.hp import r_mbams +from deeptools.parserCommon import existingFile from deeptools.utilities import smartLabels @@ -108,6 +109,7 @@ def bamcorrelate_args(case="bins"): metavar="FILE1 FILE2", help="List of indexed bam files separated by spaces.", nargs="+", + type=existingFile, required=True, ) @@ -189,6 +191,7 @@ def bamcorrelate_args(case="bins"): "the regions specified in these files.", metavar="FILE1.bed FILE2.bed", nargs="+", + type=existingFile, required=True, ) diff --git a/pydeeptools/deeptools/multiBigwigSummary.py b/pydeeptools/deeptools/multiBigwigSummary.py index f61f00677c..97c243e2df 100644 --- a/pydeeptools/deeptools/multiBigwigSummary.py +++ b/pydeeptools/deeptools/multiBigwigSummary.py @@ -7,6 +7,7 @@ import deeptools.getScorePerBigWigBin as score_bw from deeptools import parserCommon +from deeptools.parserCommon import existingFile from deeptools.utilities import smartLabels @@ -128,6 +129,7 @@ def multiBigwigSummaryArgs(case="bins"): metavar="FILE1 FILE2", help="List of bigWig files, separated by spaces.", nargs="+", + type=existingFile, required=True, ) @@ -216,6 +218,7 @@ def multiBigwigSummaryArgs(case="bins"): help="Limits the analysis to the regions specified in this file.", metavar="file1.bed file2.bed", nargs="+", + type=existingFile, required=True, ) diff --git a/pydeeptools/deeptools/parserCommon.py b/pydeeptools/deeptools/parserCommon.py index 5bf6a11399..784d4a7651 100644 --- a/pydeeptools/deeptools/parserCommon.py +++ b/pydeeptools/deeptools/parserCommon.py @@ -333,6 +333,7 @@ def getParentArgParse(args=None, binSize=True, blackList=True): help="A BED or GTF file (optionally gzip-compressed) containing regions that should be excluded from all analyses. Filtering is performed at base-pair resolution, so only the portion of a read/fragment that overlaps a blacklisted region is excluded. Please note that you should adjust the effective genome size, if relevant.", metavar="BED file", nargs="+", + type=existingFile, required=False) optional.add_argument('--numberOfProcessors', '-p', @@ -414,6 +415,17 @@ def writableFile(string): return string +def existingFile(string): + """ + Simple function that checks if a path exists (skip URL, skip 'None' as placeholders for rust code) + """ + if string == "None" or string.startswith(("http://", "https://", "ftp://")): + return string + if not Path(string).is_file(): + raise argparse.ArgumentTypeError(f"{string} file does not exist") + return string + + """ Arguments used by heatmapper and profiler """ @@ -424,7 +436,7 @@ def heatmapperMatrixArgs(args=None): required = parser.add_argument_group('Required arguments') required.add_argument('--matrixFile', '-m', help='Matrix file from the computeMatrix tool.', - type=Path, + type=existingFile, ) required.add_argument('--outFileName', '-out', '-o', diff --git a/pydeeptools/deeptools/plotCorrelation.py b/pydeeptools/deeptools/plotCorrelation.py index d632809195..966d0e6d00 100644 --- a/pydeeptools/deeptools/plotCorrelation.py +++ b/pydeeptools/deeptools/plotCorrelation.py @@ -7,7 +7,7 @@ from deeptools import matplotlib_defaults # noqa: F401 from deeptools.correlation import Correlation -from deeptools.parserCommon import writableFile +from deeptools.parserCommon import existingFile, writableFile def parse_arguments(args=None): @@ -48,6 +48,7 @@ def plot_correlation_args(): required.add_argument('--corData', '-in', metavar='FILE', help='Compressed matrix of values generated by multiBigwigSummary or multiBamSummary', + type=existingFile, required=True) required.add_argument('--corMethod', '-c', diff --git a/pydeeptools/deeptools/plotCoverage.py b/pydeeptools/deeptools/plotCoverage.py index 7da465ed17..8ac1dba862 100644 --- a/pydeeptools/deeptools/plotCoverage.py +++ b/pydeeptools/deeptools/plotCoverage.py @@ -11,6 +11,7 @@ matplotlib_defaults, # noqa: F401 parserCommon, ) +from deeptools.parserCommon import existingFile from deeptools.utilities import smartLabels @@ -69,6 +70,7 @@ def required_args(): metavar='FILE1 FILE2', help='List of indexed BAM files separated by spaces.', nargs='+', + type=existingFile, required=True) optional = parser.add_argument_group('Optional arguments') @@ -122,7 +124,8 @@ def required_args(): '--outRawCounts or many tens of thousands of regions, as per-base ' 'coverage is used!', metavar='FILE1.bed FILE2.bed', - nargs='+') + nargs='+', + type=existingFile) optional.add_argument('--outRawCounts', help='Save raw counts (coverages) to file.', diff --git a/pydeeptools/deeptools/plotEnrichment.py b/pydeeptools/deeptools/plotEnrichment.py index 96961154b7..de7eb0ab56 100644 --- a/pydeeptools/deeptools/plotEnrichment.py +++ b/pydeeptools/deeptools/plotEnrichment.py @@ -14,6 +14,7 @@ from deeptools.countReadsPerBin import CountReadsPerBin as cr from deeptools.getFragmentAndReadSize import get_read_and_fragment_length from deeptools.mapReduce import blSubtract, getUserRegion, mapReduce +from deeptools.parserCommon import existingFile from deeptools.utilities import getCommonChrNames, getTLen, mungeChromosome, smartLabels @@ -57,6 +58,7 @@ def plot_enrichment_args(): metavar='file1.bam file2.bam', help='List of indexed bam files separated by spaces.', nargs='+', + type=existingFile, required=True) required.add_argument('--BED', @@ -67,6 +69,7 @@ def plot_enrichment_args(): 'and "peak" for BED files.', metavar='FILE1.bed FILE2.bed', nargs='+', + type=existingFile, required=True) optional = parser.add_argument_group('Optional arguments') diff --git a/pydeeptools/deeptools/plotFingerprint.py b/pydeeptools/deeptools/plotFingerprint.py index 3fe4e18c0a..2a914384a7 100644 --- a/pydeeptools/deeptools/plotFingerprint.py +++ b/pydeeptools/deeptools/plotFingerprint.py @@ -14,6 +14,7 @@ matplotlib_defaults, # noqa: F401 parserCommon, ) +from deeptools.parserCommon import existingFile from deeptools.utilities import smartLabels MAXLEN = 10000000 @@ -74,6 +75,7 @@ def get_required_args(): metavar='bam files', nargs='+', help='List of indexed BAM files', + type=existingFile, required=True) return parser @@ -155,7 +157,8 @@ def get_optional_args(): 'based on code from Sitanshu Gakkhar at BCGSC. The ' 'CHANCE implementation is based on code from Matthias ' 'Haimel.', - metavar='sample.bam') + metavar='sample.bam', + type=existingFile) return parser diff --git a/pydeeptools/deeptools/plotPCA.py b/pydeeptools/deeptools/plotPCA.py index 95dcd4cd93..72f5c094e2 100644 --- a/pydeeptools/deeptools/plotPCA.py +++ b/pydeeptools/deeptools/plotPCA.py @@ -4,7 +4,7 @@ from deeptools import matplotlib_defaults # noqa: F401 from deeptools.correlation import Correlation -from deeptools.parserCommon import expand_list, writableFile +from deeptools.parserCommon import existingFile, expand_list, writableFile def parse_arguments(args=None): @@ -37,6 +37,7 @@ def plotCorrelationArgs(): required.add_argument('--corData', '-in', metavar='FILE', help='Coverage file (generated by multiBamSummary or multiBigwigSummary)', + type=existingFile, required=True) optional = parser.add_argument_group('Optional arguments') From af23509229608e8b245e6a6676b0a2f265d748ac Mon Sep 17 00:00:00 2001 From: WardDeb Date: Sat, 26 Sep 2026 21:28:51 +0200 Subject: [PATCH 2/2] no bl is None --- pydeeptools/deeptools/alignmentSieve2.py | 1 + pydeeptools/deeptools/computeMatrix2.py | 3 ++- src/computematrix.rs | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pydeeptools/deeptools/alignmentSieve2.py b/pydeeptools/deeptools/alignmentSieve2.py index 09dff1478c..fd8966d150 100644 --- a/pydeeptools/deeptools/alignmentSieve2.py +++ b/pydeeptools/deeptools/alignmentSieve2.py @@ -124,6 +124,7 @@ def parseArguments(): metavar="BED file", nargs="+", default="None", + type=existingFile, required=False) filtering.add_argument('--ignoreDuplicates', diff --git a/pydeeptools/deeptools/computeMatrix2.py b/pydeeptools/deeptools/computeMatrix2.py index 070e414ac6..ac2d15435b 100644 --- a/pydeeptools/deeptools/computeMatrix2.py +++ b/pydeeptools/deeptools/computeMatrix2.py @@ -371,7 +371,8 @@ def computeMatrixOptArgs(case=["scale-regions", "reference-point"][0]): "-bl", help="A BED file (optionally gzip-compressed) containing regions that should be excluded from all analyses. Filtering is performed at base-pair resolution, so only the portion of a region that overlaps a blacklisted region is excluded.", metavar="BED file", - default='none', + default='None', + type=existingFile, required=False, ) diff --git a/src/computematrix.rs b/src/computematrix.rs index ed00eeeb46..65118a6bb2 100644 --- a/src/computematrix.rs +++ b/src/computematrix.rs @@ -132,7 +132,7 @@ pub fn r_computematrix( } // If there is a blacklist, read it and build an index. - let blacklist_index: Option> = if blacklist != "none" { + let blacklist_index: Option> = if blacklist != "None" { let isbed = is_bed_or_gtf(blacklist); match isbed.as_str() { "gtf" => panic!("Error: Please provide a bed file for the blacklist."),