Description: Some changes that 2to3 probably missed Author: Pranav Ballaney Last-Update: Tue, 11 May 2020 21:53:00 +0530 --- a/fitGCP.py +++ b/fitGCP.py @@ -128,7 +128,7 @@ class NBinom(Distribution): return stats.nbinom.pmf(x,self._p1,self._p2) def estimate_par(self, data, weights=None): - if weights == None: + if weights is None: weights = data*0. + 1. norm = np.sum(weights) mean = np.sum(data*weights)/(norm + 10**(-25)) @@ -338,7 +338,7 @@ class DataSet: def read_from_pickle(self,filename): """ read a genome coverage profile from a pickle file. """ - data = pickle.load(open(filename,'r')) + data = pickle.load(open(filename,'rb')) self.cov = np.array(data[0],dtype=np.int) self.count = np.array(data[1],dtype=np.int) @@ -363,7 +363,7 @@ class DataSet: if not read.is_unmapped: r_start = start_pos[read.tid] + read.pos # start position r_end = start_pos[read.tid] + read.pos + read.qlen # end - cov[r_start:r_end] += 1 + cov[int(r_start):int(r_end)] += 1 num_reads += 1 read_length += r_end-r_start self.fname = filename @@ -376,7 +376,7 @@ class DataSet: def write_to_pickle(self, filename): """ store dataset in a pickle file. """ return pickle.dump([self.cov, self.count, self.rlen, self.rds, - self.glen, self.fname], open(filename,'w')) + self.glen, self.fname], open(filename,'wb')) @@ -446,11 +446,11 @@ def iterative_fitting(data_set, mixture_ # maximum CDF difference xs = np.arange(np.max(data_set.cov)+1) - ref_pdf = np.zeros((np.max(data_set.cov)+1,)) + ref_pdf = np.zeros((int(np.max(data_set.cov))+1,)) for dist in mixture_model: ref_pdf += dist.pmf(xs)*dist.alpha - obs_pdf = np.zeros((np.max(data_set.cov)+1,)) + obs_pdf = np.zeros((int(np.max(data_set.cov))+1,)) obs_pdf[data_set.cov.astype(np.int)] = data_set.count/float(np.sum(data_set.count)) max_cdf_diff = np.max(np.abs(np.cumsum(ref_pdf)-np.cumsum(obs_pdf)))