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

Empty factors - Spatial Transcripomics data #165

Open
rockdeme opened this issue Jul 13, 2024 · 0 comments
Open

Empty factors - Spatial Transcripomics data #165

rockdeme opened this issue Jul 13, 2024 · 0 comments

Comments

@rockdeme
Copy link

Hey!

I'm running MEFISTO on a 10X Visium sample based on the spatial transcriptomics tutorial. I have encountered an issue where some of the factors estimated by MEFISTO are all zeros, I'm not sure if this is an expect behaviour or something else I missed. I'm running MEFISTO with quite a lot (28) factors, maybe that's related to the problem.

Here is the code I'm running:

adata = sc.read_h5ad(adp)
sc.pp.filter_genes(adata, min_cells=len(adata) * 0.05)
sc.pp.normalize_total(adata, inplace=True)
sc.pp.log1p(adata)
sc.pp.highly_variable_genes(adata, flavor="seurat", n_top_genes=2000)

adata.obs = pd.concat([adata.obs, pd.DataFrame(adata.obsm["spatial"], columns=["imagerow", "imagecol"], index=adata.obs_names), ], axis=1)

ent = entry_point()
ent.set_data_options(use_float32=True)
ent.set_data_from_anndata(adata, features_subset="highly_variable")

ent.set_model_options(factors=28)
ent.set_train_options(save_interrupted=True)
ent.set_train_options(seed=2021)

n_inducing = 1000

ent.set_covariates([adata.obsm["spatial"]], covariates_names=["imagerow", "imagecol"])
ent.set_smooth_options(sparseGP=True, frac_inducing=n_inducing/adata.n_obs, start_opt=10, opt_freq=10)

ent.build()
ent.run()
factor_df = m.get_factors(df=True)

This is the output:

unnamed

Training logs:
        #########################################################
        ###           __  __  ____  ______                    ### 
        ###          |  \/  |/ __ \|  ____/\    _             ### 
        ###          | \  / | |  | | |__ /  \ _| |_           ### 
        ###          | |\/| | |  | |  __/ /\ \_   _|          ###
        ###          | |  | | |__| | | / ____ \|_|            ###
        ###          |_|  |_|\____/|_|/_/    \_\              ###
        ###                                                   ### 
        ######################################################### 
       
 
        
use_float32 set to True: replacing float64 arrays by float32 arrays to speed up computations...

Loaded view='rna' group='group1' with N=2261 samples and D=2000 features...


Model options:
- Automatic Relevance Determination prior on the factors: False
- Automatic Relevance Determination prior on the weights: True
- Spike-and-slab prior on the factors: False
- Spike-and-slab prior on the weights: True
Likelihoods:
- View 0 (rna): gaussian


Loaded 2 covariate(s) for each sample...


##
## sparseGP set to True: using sparse Gaussian Process to speed up the training procedure
##


######################################
## Training the model with seed 2021 ##
######################################


ELBO before training: -76965346.50 

Iteration 1: time=7.73, ELBO=-2587610.86, deltaELBO=74377735.641 (96.63795334%), Factors=28
Iteration 2: time=7.19, ELBO=-2437343.13, deltaELBO=150267.728 (0.19524076%), Factors=28
Iteration 3: time=7.20, ELBO=-2381010.32, deltaELBO=56332.812 (0.07319244%), Factors=28
Iteration 4: time=7.20, ELBO=-2370936.18, deltaELBO=10074.139 (0.01308919%), Factors=28
Iteration 5: time=7.18, ELBO=-2366720.97, deltaELBO=4215.207 (0.00547676%), Factors=28
Iteration 6: time=7.68, ELBO=-2363330.84, deltaELBO=3390.130 (0.00440475%), Factors=28
Iteration 7: time=7.27, ELBO=-2360469.15, deltaELBO=2861.693 (0.00371816%), Factors=28
Iteration 8: time=7.27, ELBO=-2358012.11, deltaELBO=2457.035 (0.00319239%), Factors=28
Iteration 9: time=7.26, ELBO=-2355950.70, deltaELBO=2061.412 (0.00267836%), Factors=28
Optimising sigma node...
Iteration 10: time=277.38, ELBO=-2245553.37, deltaELBO=110397.331 (0.14343771%), Factors=28
Iteration 11: time=23.35, ELBO=-2324369.11, deltaELBO=-78815.744 (0.10240420%), Factors=28
Warning, lower bound is decreasing...�
Iteration 12: time=21.29, ELBO=-2315719.92, deltaELBO=8649.194 (0.01123778%), Factors=28
Iteration 13: time=22.62, ELBO=-2310927.10, deltaELBO=4792.816 (0.00622724%), Factors=28
Iteration 14: time=21.73, ELBO=-2307503.60, deltaELBO=3423.498 (0.00444810%), Factors=28
Iteration 15: time=22.93, ELBO=-2304850.19, deltaELBO=2653.415 (0.00344754%), Factors=28
Iteration 16: time=21.04, ELBO=-2302676.33, deltaELBO=2173.857 (0.00282446%), Factors=28
Iteration 17: time=23.12, ELBO=-2300786.11, deltaELBO=1890.225 (0.00245594%), Factors=28
Iteration 18: time=20.95, ELBO=-2299002.34, deltaELBO=1783.764 (0.00231762%), Factors=28
Iteration 19: time=22.73, ELBO=-2297239.95, deltaELBO=1762.397 (0.00228986%), Factors=28
Optimising sigma node...
Iteration 20: time=252.55, ELBO=-2295414.17, deltaELBO=1825.775 (0.00237220%), Factors=28
Iteration 21: time=23.38, ELBO=-2295356.47, deltaELBO=57.698 (0.00007497%), Factors=28
Iteration 22: time=21.31, ELBO=-2293432.14, deltaELBO=1924.338 (0.00250027%), Factors=28
Iteration 23: time=23.37, ELBO=-2291737.80, deltaELBO=1694.332 (0.00220142%), Factors=28
Iteration 24: time=21.26, ELBO=-2290347.46, deltaELBO=1390.345 (0.00180646%), Factors=28
Iteration 25: time=23.39, ELBO=-2289241.89, deltaELBO=1105.566 (0.00143645%), Factors=28
Iteration 26: time=21.33, ELBO=-2288333.65, deltaELBO=908.242 (0.00118007%), Factors=28
Iteration 27: time=23.49, ELBO=-2287549.41, deltaELBO=784.242 (0.00101896%), Factors=28
Iteration 28: time=21.88, ELBO=-2286852.86, deltaELBO=696.553 (0.00090502%), Factors=28
Iteration 29: time=25.29, ELBO=-2286229.91, deltaELBO=622.948 (0.00080939%), Factors=28
Optimising sigma node...
Iteration 30: time=359.29, ELBO=-2285490.63, deltaELBO=739.273 (0.00096053%), Factors=28
Iteration 31: time=27.38, ELBO=-2293869.65, deltaELBO=-8379.011 (0.01088673%), Factors=28
Warning, lower bound is decreasing...�
Iteration 32: time=24.32, ELBO=-2292963.65, deltaELBO=905.998 (0.00117715%), Factors=28
Iteration 33: time=28.33, ELBO=-2292207.38, deltaELBO=756.265 (0.00098260%), Factors=28
Iteration 34: time=25.16, ELBO=-2291545.92, deltaELBO=661.464 (0.00085943%), Factors=28
Iteration 35: time=26.70, ELBO=-2290951.27, deltaELBO=594.646 (0.00077262%), Factors=28
Iteration 36: time=24.08, ELBO=-2290412.84, deltaELBO=538.431 (0.00069958%), Factors=28
Iteration 37: time=31.96, ELBO=-2289917.60, deltaELBO=495.242 (0.00064346%), Factors=28
Iteration 38: time=25.61, ELBO=-2289461.21, deltaELBO=456.386 (0.00059298%), Factors=28
Iteration 39: time=24.18, ELBO=-2289038.30, deltaELBO=422.916 (0.00054949%), Factors=28
Optimising sigma node...
Iteration 40: time=255.44, ELBO=-2288558.93, deltaELBO=479.362 (0.00062283%), Factors=28
Iteration 41: time=23.36, ELBO=-2289573.09, deltaELBO=-1014.154 (0.00131768%), Factors=28
Warning, lower bound is decreasing...�
Iteration 42: time=21.33, ELBO=-2289146.12, deltaELBO=426.972 (0.00055476%), Factors=28
Iteration 43: time=23.29, ELBO=-2288793.99, deltaELBO=352.124 (0.00045751%), Factors=28
Iteration 44: time=21.20, ELBO=-2288474.15, deltaELBO=319.842 (0.00041557%), Factors=28

Converged!



#######################
## Training finished ##
#######################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant