Skip to content

Commit

Permalink
pre translate docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jcopperm committed May 29, 2024
1 parent 0a05c89 commit 37bd141
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions celltraj/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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:
Expand Down
21 changes: 11 additions & 10 deletions celltraj/translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import scipy
import pyemma.coordinates as coor
from adjustText import adjust_text
import itertools

#class Translate():
"""
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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)
Expand All @@ -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
1 change: 1 addition & 0 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ dependencies:
- adjustText
- cmapfile
- nanomesh
- seaborn
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" },
]
Expand Down

0 comments on commit 37bd141

Please sign in to comment.