diff --git a/celltraj/features.py b/celltraj/features.py index 6808bdf..953ce03 100644 --- a/celltraj/features.py +++ b/celltraj/features.py @@ -436,7 +436,7 @@ def featNucBoundary(regionmask, intensity): xf = np.ones(15)*np.nan return xf -def get_cc_cs_border(mskcell,fmskcell,bordersize=10): +def get_cc_cs_border(mskcell,fmskcell,bordersize=0): """ Identifies core-cell (cc) and cell-surrounding (cs) borders within a given cell mask by applying morphological operations and boundary detection. @@ -513,7 +513,7 @@ def get_cc_cs_border(mskcell,fmskcell,bordersize=10): csborder=csborder.astype(int) return ccborder,csborder -def boundaryCB_FFT(msk,fmsk,ncomp=15,center=None,nth=256,bordersize=1): +def boundaryCB_FFT(msk,fmsk,ncomp=15,center=None,nth=256,bordersize=0): """ Computes the Fourier Transform of boundary data for a mask distinguishing between core-cell and cell-surrounding regions, encoding the shape information in frequency space. @@ -649,7 +649,7 @@ def featBoundaryCB(regionmask, intensity): - Visualization commands within the function (commented out) can be enabled for debugging or understanding the process by visual inspection. """ - regionmask=skimage.morphology.binary_erosion(regionmask) + #regionmask=skimage.morphology.binary_erosion(regionmask) #plt.clf();plt.imshow(np.max(intensity,axis=0));plt.contour(np.max(regionmask,axis=0),colors='red');plt.pause(2) intensity=intensity>0 if regionmask.ndim==3: diff --git a/celltraj/translate.py b/celltraj/translate.py index bc41966..e818913 100644 --- a/celltraj/translate.py +++ b/celltraj/translate.py @@ -6,6 +6,7 @@ import scipy import pyemma.coordinates as coor from adjustText import adjust_text +import itertools #class Translate(): """ @@ -51,7 +52,7 @@ def get_predictedFC(state_probs,statesFC): x_FC_predicted[itr,:]=(np.tile(statep,(nG,1))*statesFC.T).sum(-1) return x_FC_predicted -def get_state_decomposition(self,x_fc,state_probs,npermutations=500,inds_tm_training=None,save_file=None,visual=False,verbose=True,nchunk=100,gene_names=None,lb=None,ub=None): +def get_state_decomposition(x_fc,state_probs,npermutations=500,inds_tm_training=None,save_file=None,visual=False,verbose=True,nchunk=100,gene_names=None,lb=None,ub=None): n=state_probs.shape[1] ntr=state_probs.shape[0] nG=x_fc.shape[1] @@ -103,18 +104,21 @@ def get_state_decomposition(self,x_fc,state_probs,npermutations=500,inds_tm_trai np.save(save_file,x_fc_states) return x_fc_states -def get_null_correlations(self,x_fc,x_fc_states,x_fc_predicted,nrandom=500,nchunk=20,save_file=None): +def get_null_correlations(x_fc,x_fc_states,x_fc_predicted,nrandom=500,seed=None,tmfSet=None): n=x_fc_states.shape[0] ntr=x_fc.shape[0] - nrandom=500 - xr=6 + if tmfSet is None: + tmfSet=np.arange(ntr).astype(str) + if seed is None: + seed=0 + rng = np.random.default_rng(seed=seed) corrSet_pred=np.zeros(ntr) corrSet_predrand=np.zeros((nrandom,ntr)) corrSet_rand=np.zeros((nrandom,ntr)) for ir in range(nrandom): state_probs_r=np.zeros((ntr,n)) for itr in range(ntr): - rp=np.random.rand(n) + rp=rng.random(n) rp=rp/np.sum(rp) state_probs_r[itr,:]=rp.copy() x_fc_null=get_predictedFC(state_probs_r,x_fc_states) @@ -127,8 +131,5 @@ def get_null_correlations(self,x_fc,x_fc_states,x_fc_predicted,nrandom=500,nchun corrSet_pred[itr]=rhoSet[0,2] corrSet_rand[ir,itr]=rhoSet[1,2] corrSet_predrand[ir,itr]=rhoSet[0,1] - print(tmfSet[itr]+f' correlation: prediction {rhoSet[0,2]:.2f}, null {rhoSet[1,2]:.2f} prednull {rhoSet[0,1]:.2f}, ir: {ir} of {nrandom}') - if ir%nchunk==0 or ir==nrandom-1: - if save_file is not None: - np.save(save_file,corrSet_rand) - return corrSet_pred, corrSet_rand, corrSet_predrand + #print(tmfSet[itr]+f' correlation: prediction {rhoSet[0,2]:.2f}, null {rhoSet[1,2]:.2f} prednull {rhoSet[0,1]:.2f}, ir: {ir} of {nrandom}') + return corrSet_pred, corrSet_rand, corrSet_predrand diff --git a/environment.yml b/environment.yml index be7a3b8..6560b74 100644 --- a/environment.yml +++ b/environment.yml @@ -33,3 +33,4 @@ dependencies: - adjustText - cmapfile - nanomesh + - seaborn diff --git a/pyproject.toml b/pyproject.toml index 7889b65..3fbcc91 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "celltraj" -version = "0.1.51" +version = "0.1.52" authors = [ { name="Jeremy Copperman", email="copperma@ohsu.edu" }, ]