Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: edge-case where dividing by zero results in inf values #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion workflow_peakcaller/scripts/multipoisson_peak_calling.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def poisson_filter(edit_c_df):

prefix = 'subregion_'
region_sites['{}fraction'.format(prefix)] = (region_sites['{}conversions'.format(prefix)]-region_sites['edited_bases'])/(region_sites['{}coverage'.format(prefix)] - region_sites['target_bases'])
region_sites.replace([np.inf, -np.inf], np.nan, inplace=True)
region_sites = region_sites.fillna(0)

depth_windows = [0, 10, 20, 30, 40, 50, 1000000]
Expand Down Expand Up @@ -129,4 +130,4 @@ def output_blank():

else:
write('\nNo values, outputting empty file\n')
output_blank()
output_blank()
9 changes: 3 additions & 6 deletions workflow_peakcaller/scripts/score_peaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@
import os
import pandas as pd
import sys
import pandas as pd
import numpy as np
from scipy.stats import nbinom

parser = argparse.ArgumentParser(description='Add statistical score to peaks')
parser.add_argument('peaks_with_edit_fraction', type=str)
parser.add_argument('peaks_with_scores', type=str)
parser.add_argument('all_windows_with_fdr')



args = parser.parse_args()
peaks_with_edit_fraction = args.peaks_with_edit_fraction
peaks_with_scores = args.peaks_with_scores
all_windows_with_fdr = args.all_windows_with_fdr

all_windows = pd.read_csv(all_windows_with_fdr, sep='\t')
all_windows.replace([np.inf, -np.inf], np.nan, inplace=True)
all_windows = all_windows.fillna(0)
background_rate = all_windows.subregion_fraction.mean()


print("Input file specified: {}".format(peaks_with_edit_fraction))
print("Input file specified: {}".format(peaks_with_scores))

print("Background rate for negative binomial peak scoring calculated as: {}".format(background_rate))



def get_confidence(conversions, coverage, frac=background_rate):
# # Determine nbinom CDF
# (nbinom.cdf(nbr_failures,nbr_successes,prob_success))
Expand Down