Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# adjust for sequence indexes
black_seq_start = (black_interval.begin - mseq.start)// options.pool_width
black_seq_end = int( np.ceil( (black_interval.end - mseq.start)/ options.pool_width ) )
seq_hic_raw[:,black_seq_start:black_seq_end] = np.nan
seq_hic_raw[black_seq_start:black_seq_end,:] = np.nan
seq_hic_nan = np.isnan(seq_hic_raw)
# clip first diagonals and high values
clipval = np.nanmedian(np.diag(seq_hic_raw,options.diagonal_offset))
for i in range(-options.diagonal_offset+1,options.diagonal_offset):
set_diag(seq_hic_raw, clipval, i)
seq_hic_raw = np.clip(seq_hic_raw, 0, clipval)
seq_hic_raw[seq_hic_nan] = np.nan
# adaptively coarsegrain based on raw counts
seq_hic_smoothed = adaptive_coarsegrain(
seq_hic_raw,
genome_hic_cool.matrix(balance=False).fetch(mseq_str),
cutoff=2, max_levels=8)
seq_hic_nan = np.isnan(seq_hic_smoothed)
#todo: pass an option to add a certain pseudocount value, or the minimum nonzero value
if options.as_obsexp:
# compute obs/exp
if options.global_obsexp: # compute global obs/exp
exp_chr = genome_hic_expected.iloc[ genome_hic_expected['chrom'].values ==mseq.chr][0:seq_len_pool]
if len(exp_chr) ==0:
raise ValueError('no expected values found for chr:'+mseq.chr)
exp_map= np.zeros((seq_len_pool,seq_len_pool))
for i in range(seq_len_pool):
set_diag(exp_map,exp_chr['balanced.avg'].values[i],i)
set_diag(exp_map,exp_chr['balanced.avg'].values[i],-i)
for black_interval in black_chr_trees[mseq.chr][mseq.start:mseq.end]:
# adjust for sequence indexes
black_seq_start = (black_interval.begin - mseq.start)// options.pool_width
black_seq_end = int( np.ceil( (black_interval.end - mseq.start)/ options.pool_width ) )
seq_hic_raw[:,black_seq_start:black_seq_end] = np.nan
seq_hic_raw[black_seq_start:black_seq_end,:] = np.nan
seq_hic_nan = np.isnan(seq_hic_raw)
# clip first diagonals and high values
clipval = np.nanmedian(np.diag(seq_hic_raw,2))
for i in [-1,0,1]: set_diag(seq_hic_raw,clipval,i)
seq_hic_raw = np.clip(seq_hic_raw, 0, seq_hic_raw)
seq_hic_raw[seq_hic_nan] = np.nan
# adaptively coarsegrain based on raw counts
seq_hic_smoothed = adaptive_coarsegrain(
seq_hic_raw,
genome_hic_cool.matrix(balance=False).fetch(mseq_str),
cutoff= 2, max_levels=8)
#todo: pass an option to add a certain pseudocount value, or the minimum nonzero value
if options.as_obsexp == True:
# interpolate single missing bins
seq_hic_interpolated = interpolate_bad_singletons(seq_hic_smoothed, mask=(~seq_hic_nan),
fillDiagonal=True, returnMask=False, secondPass=True,verbose=False)
seq_hic_nan = np.isnan(seq_hic_interpolated)
# compute observed/expected
seq_hic_obsexp = observed_over_expected(seq_hic_interpolated, ~seq_hic_nan)[0]
# todo: allow passing a global expected rather than computing locally
# log