Skip to content

Commit

Permalink
update verbose mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maxibor committed May 7, 2020
1 parent 509f3f6 commit acf0e48
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pydamage/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
help='Number of processes')
@click.option('-m',
'--mini',
default=2000,
default=1000,
type=int,
show_default=True,
help='Minimum reads aligned to consider reference')
@click.option('-c',
'--cov',
default=0.5,
default=8,
type=float,
show_default=True,
help='Minimum coverage to consider reference')
Expand Down
10 changes: 7 additions & 3 deletions pydamage/damage.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,13 @@ def test_damage(ref, bam, mode, wlen, show_al, min_al, min_cov, process, verbose
test_res['coverage'] = cov
return(check_model_fit(test_res, wlen))
else:
if verbose:
print(f"Did not attempt to fit a model to {ref} because of too few reads aligned")
print(f"nb_reads_aligned: {nb_reads_aligned} - coverage: {cov} - reflen: {reflen}\n")
pass
except ValueError as e:
print(f"Could not fit a model for {ref} because of too few reads aligned")
print(f"Model fitting error: {e}")
print(f"nb_reads_aligned: {nb_reads_aligned} - coverage: {cov} - reflen: {reflen}\n")
if verbose:
print(f"Model fitting for {ref} failed because of too few reads aligned")
print(f"Model fitting error: {e}")
print(f"nb_reads_aligned: {nb_reads_aligned} - coverage: {cov} - reflen: {reflen}\n")
return(False)
7 changes: 6 additions & 1 deletion pydamage/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
import sys
from tqdm import tqdm
import warnings
from pydamage import __version__

def analyze(bam, wlen=30, show_al=False, mini=2000, cov=0.5, process=1, outdir="", plot = False, verbose=False, force=False):
Expand All @@ -31,6 +32,9 @@ def analyze(bam, wlen=30, show_al=False, mini=2000, cov=0.5, process=1, outdir="
print(f"Pydamage version {__version__}\n")
utils.makedir(outdir, force=force)

if not verbose:
warnings.filterwarnings("ignore")

mode = utils.check_extension(bam)
alf = pysam.AlignmentFile(bam, mode)

Expand Down Expand Up @@ -61,8 +65,9 @@ def analyze(bam, wlen=30, show_al=False, mini=2000, cov=0.5, process=1, outdir="
test_damage_partial = partial(damage.test_damage, bam=bam, wlen=wlen,
min_al=mini, min_cov=cov, show_al=show_al,
mode=mode, process=process, verbose=verbose)
print("Estimating and testing Damage")
with multiprocessing.Pool(proc) as p:
res = p.map(test_damage_partial, refs)
res = tqdm(p.imap(test_damage_partial, refs), total = len(refs))
filt_res = [i for i in res if i]
if plot and len(filt_res) > 0:
print("\nGenerating pydamage plots")
Expand Down
12 changes: 6 additions & 6 deletions pydamage/vuong.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ def vuong_closeness(ref, model_A, model_B, ct_data, ga_data, wlen, verbose):
omega = np.std(LA-LB)
Z = LR/(np.sqrt(len(ct_data))*omega)
pval = norm.cdf(Z)
if verbose:
print(f"\nReference: {ref}")
print(f"Vuong closeness test Z-score for {ref}: {round(Z, 4)}")
print(f"Vuong closeness test p-value for {ref}: {round(pval, 4)}")
print(f"Model A parameters for {ref}: {optim_A}")
print(f"Model B parameters for {ref}: {optim_B}")
# if verbose:
# print(f"\nReference: {ref}")
# print(f"Vuong closeness test Z-score for {ref}: {round(Z, 4)}")
# print(f"Vuong closeness test p-value for {ref}: {round(pval, 4)}")
# print(f"Model A parameters for {ref}: {optim_A}")
# print(f"Model B parameters for {ref}: {optim_B}")
res.update(ydata_counts)
res.update(ctot_out)
res.update(gtoa_out)
Expand Down

0 comments on commit acf0e48

Please sign in to comment.