def test_condscvi(save_path): dataset = synthetic_iid(n_labels=5) model = CondSCVI(dataset) model.train(1, train_size=1) model.get_latent_representation() model.get_vamp_prior(dataset) model = CondSCVI(dataset, weight_obs=True) model.train(1, train_size=1) model.get_latent_representation() model.get_vamp_prior(dataset)
def from_rna_model( cls, st_adata: AnnData, sc_model: CondSCVI, vamp_prior_p: int = 50, layer: Optional[str] = None, **module_kwargs, ): """ Alternate constructor for exploiting a pre-trained model on a RNA-seq dataset. Parameters ---------- st_adata registed anndata object sc_model trained CondSCVI model vamp_prior_p number of mixture parameter for VampPrior calculations **model_kwargs Keyword args for :class:`~scvi.model.DestVI` """ decoder_state_dict = sc_model.module.decoder.state_dict() px_decoder_state_dict = sc_model.module.px_decoder.state_dict() px_r = sc_model.module.px_r.detach().cpu().numpy() mapping = sc_model.adata_manager.get_state_registry( REGISTRY_KEYS.LABELS_KEY ).categorical_mapping if vamp_prior_p is None: mean_vprior = None var_vprior = None else: mean_vprior, var_vprior = sc_model.get_vamp_prior( sc_model.adata, p=vamp_prior_p ) cls.setup_anndata(st_adata, layer=layer) return cls( st_adata, mapping, decoder_state_dict, px_decoder_state_dict, px_r, sc_model.module.n_hidden, sc_model.module.n_latent, sc_model.module.n_layers, mean_vprior=mean_vprior, var_vprior=var_vprior, **module_kwargs, )