xchrom.tl.calc_ism
- xchrom.tl.calc_ism(cell_embedding_ad: AnnData, XChrom_model: tensorflow.keras.Model, seq_ref_1hot: ndarray, cellembed_raw: str = 'X_pca_harmony', layer_offset: int = -8) ndarray[source]
Calculate ISM (In Silico Mutagenesis) for a single sequence
- Parameters:
cell_embedding_ad (anndata.AnnData) – anndata object with Initial cell embeddings
cellembed_raw (str) – Key of the raw cell input embedding in the cell embedding adata,to generate model input.
seq_ref_1hot (np.ndarray) – One-hot encoded reference sequence, shape (seq_len, 4)
XChrom_model (tf.keras.Model) – Trained XChrom model for sequence encoding
layer_offset (int, optional (default is -8)) – Layer offset for extracting sequence embeddings from XChrom_model. Default is -8 (8th layer from the end). Adjust if model architecture changes.
- Returns:
ISM matrix showing nucleotide importance, shape (n_cells, seq_len, 4)
- Return type:
np.ndarray
Examples
>>> seq_ref_1hot = dna_1hot("ATCGATCG" * 168) # shape: (1344, 4) >>> XChrom_model = XChrom_model(n_cells=1, cell_vec=32) >>> XChrom_model.load_weights('model_weights.h5') >>> ism = calc_ism(seq_ref_1hot, XChrom_model,layer_offset=-8) >>> print(f"The ISM matrix is saved in ism")