Skip to content

Commit

Permalink
Merge pull request #21 from bodegalab/more_verbosity
Browse files Browse the repository at this point in the history
Set multiple verbosity level
  • Loading branch information
bepoli authored Sep 19, 2024
2 parents 22ef8a8 + 12a8a7c commit 29e7bb9
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 30 deletions.
6 changes: 3 additions & 3 deletions irescue/count.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ def run_count(maps_file, features_index, tmpdir, dumpEC, verbose,
writerr(
f'[{taskn}] Run count for cell '
f'{cellidx} ({cellbarcode.decode()})',
send=verbose
level=2, send=verbose
)
cellcounts, dump = compute_cell_counts(
equivalence_classes=cellmaps,
Expand All @@ -258,7 +258,7 @@ def run_count(maps_file, features_index, tmpdir, dumpEC, verbose,
writerr(
f'[{taskn}] Write count for cell '
f'{cellidx} ({cellbarcode.decode()})',
send=verbose
level=1, send=verbose
)
# round counts to 3rd decimal point and write to matrix file
# only if count is at least 0.001
Expand All @@ -270,7 +270,7 @@ def run_count(maps_file, features_index, tmpdir, dumpEC, verbose,
writerr(
f'[{taskn}] Write ECdump for cell '
f'{cellidx} ({cellbarcode.decode()})',
send=verbose
level=1, send=verbose
)
# reverse features index to get names back
findex = dict(zip(features_index.values(),
Expand Down
12 changes: 6 additions & 6 deletions irescue/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ def parseArguments():
"presence in bam file.")
parser.add_argument('--keeptmp', action='store_true',
help="Keep temporary files under <output_dir>/tmp.")
parser.add_argument('-v', '--verbose', action='store_true',
help="Writes a lot of stuff to stderr, such as "
"chromosomes as they are mapped and cell barcodes "
"as they are processed.")
parser.add_argument('-v', '--verbose', action='count', default=0,
help="Writes additional logging to stderr. "
"Use once for normal verbosity (-v), "
"twice for debugging (-vv).")
parser.add_argument('-V', '--version', action='version',
version='%(prog)s {}'.format(__version__),
help="Print software's version and exit.")
Expand Down Expand Up @@ -156,7 +156,7 @@ def main():
writerr(
"Computing overlap between reads and TEs coordinates in the "
"following references: {}".format(', '.join(chrNames)),
send=args.verbose
level=1, send=args.verbose
)
isecFun = partial(
isec, args.bam, regions, whitelist, args.cb_tag, args.umi_tag,
Expand Down Expand Up @@ -214,7 +214,7 @@ def main():
writerr(f'Writing Equivalence Classes to {ecdump_file}')

if not args.keeptmp:
writerr(f'Cleaning up temporary files.', send=args.verbose)
writerr(f'Cleaning up temporary files.', level=1, send=args.verbose)
rmtree(dirs['tmp'])

writerr('Done.')
11 changes: 6 additions & 5 deletions irescue/map.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ def checkIndex(bamFile, verbose):
writerr('BAM indexing done.')
else:
if verbose:
writerr(f'Found index for BAM file {bamFile}', send=verbose)
writerr(f'Found index for BAM file {bamFile}',
level=1, send=verbose)


# Check repeatmasker regions bed file format. Download if not provided.
Expand Down Expand Up @@ -208,11 +209,11 @@ def isec(bamFile, bedFile, whitelist, CBtag, UMItag, bpOverlap, fracOverlap,
cmd += ' print qname[n-1]"\\t"qname[n]"\\t"qname[1]"\\t"$16 }\' '
cmd += f' | gzip > {isecFile}'

writerr(f'Extracting {chrom} reference', send=verbose)
writerr(f'Extracting {chrom} reference', level=2, send=verbose)
run_shell_cmd(cmd0)
writerr(f'Intersecting alignments with {chrom} reference', send=verbose)
writerr(f'Mapping alignments to {chrom}', level=1, send=verbose)
run_shell_cmd(cmd)
writerr(f'Finished mapping {chrom}', send=verbose)
writerr(f'Mapped {chrom}', level=1, send=verbose)

return isecFile

Expand Down Expand Up @@ -247,7 +248,7 @@ def chrcat(filesList, threads, outdir, tmpdir, bedtools, verbose):
cmd2 += ' print $1"\\t"gensub(/#.+/,"",1,$1)"\\tGene Expression" }\' '
cmd2 += f' | LC_ALL=C sort -u | gzip > {features_file} '

writerr('Concatenating mappings', send=verbose)
writerr('Concatenating mappings', level=1, send=verbose)
run_shell_cmd(cmd0)
if getlen(mappings_file) == 0:
writerr(
Expand Down
14 changes: 8 additions & 6 deletions irescue/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def check_requirement(cmd, required_version, parser, verbose):
else:
writerr(
f"Found {cmd} version {version}. Proceeding.",
send=verbose
level=1, send=verbose
)
except:
writerr(
Expand All @@ -68,7 +68,7 @@ def check_requirement(cmd, required_version, parser, verbose):
)

# Small function to write a message to stderr with timestamp
def writerr(msg, error=False, send=True):
def writerr(msg, error=False, level=0, send=0):
"""
Write a message to stderr with timestamp.
Expand All @@ -78,10 +78,12 @@ def writerr(msg, error=False, send=True):
Message to write to stderr.
error: bool
Set True if the message is an error (write with sys.exit).
send: bool
Decides if the message should be sent (useful for verbose messages).
verbosity: int
Verbosity level of the message.
send: int
If >=verbosity, the message will be sent.
"""
if send:
if send>=level or error:
timelog = datetime.now().strftime("%Y/%m/%d - %H:%M:%S")
message = f'[{timelog}] '
if not msg[-1]=='\n':
Expand Down Expand Up @@ -158,7 +160,7 @@ def check_tags(
writerr(
f"Testing bam file for {CBtag} and {UMItag} tags presence. "
"Will stop at the first occurrence.",
send=verbose
level=1, send=verbose
)
for read in f:
if nLines and c >= nLines:
Expand Down
20 changes: 10 additions & 10 deletions tests/test.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
- name: base
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 1a74fa12e65ac1703bbe61282854f151
Expand All @@ -11,7 +11,7 @@
- name: genome
tags:
- genome
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -g test --keeptmp -v
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -g test --keeptmp -vv
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 1a74fa12e65ac1703bbe61282854f151
Expand All @@ -23,7 +23,7 @@
- name: multi
tags:
- multi
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -p 2 --keeptmp -v
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -p 2 --keeptmp -vv
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 1a74fa12e65ac1703bbe61282854f151
Expand All @@ -35,7 +35,7 @@
- name: whitelist
tags:
- whitelist
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -w ./tests/data/whitelist.txt --keeptmp -v
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -w ./tests/data/whitelist.txt --keeptmp -vv
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 95dccc15cbee4feeeae2fbce4d7b41ad
Expand All @@ -48,7 +48,7 @@
tags:
- multi
- whitelist
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -w ./tests/data/whitelist.txt --keeptmp -v -p 2
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz -w ./tests/data/whitelist.txt --keeptmp -vv -p 2
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 95dccc15cbee4feeeae2fbce4d7b41ad
Expand All @@ -60,7 +60,7 @@
- name: ecdump
tags:
- ecdump
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v --dump-ec
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv --dump-ec
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 1a74fa12e65ac1703bbe61282854f151
Expand All @@ -75,7 +75,7 @@
tags:
- multi
- ecdump
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v -p 2 --dump-ec
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv -p 2 --dump-ec
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 1a74fa12e65ac1703bbe61282854f151
Expand All @@ -89,7 +89,7 @@
- name: bp
tags:
- bp
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v --min-bp-overlap 10
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv --min-bp-overlap 10
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 7433e88e94aec2f16a20459275188f1f
Expand All @@ -101,7 +101,7 @@
- name: fraction
tags:
- fraction
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v --min-fraction-overlap 0.5
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv --min-fraction-overlap 0.5
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 4de44d3e4a851392a48ccabfee5bb6fc
Expand All @@ -114,7 +114,7 @@
tags:
- bp
- fraction
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -v --min-bp-overlap 10 --min-fraction-overlap 0.5
command: irescue -b ./tests/data/Aligned.sortedByCoord.out.bam -r ./tests/data/rmsk.bed.gz --keeptmp -vv --min-bp-overlap 10 --min-fraction-overlap 0.5
files:
- path: "irescue_out/counts/barcodes.tsv.gz"
md5sum: 4de44d3e4a851392a48ccabfee5bb6fc
Expand Down

0 comments on commit 29e7bb9

Please sign in to comment.