# Fit model
pds2_model = pertpy.tl.PyDESeq2(adata, design='~ my_cont_covariate + other_covariates')
# Get contrast
cont_contrast = pd.Series(0, index=pds2_model.design.columns)
cont_contrast.loc['my_cont_covariate'] = 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import yaml | |
import pandas as pd | |
from typing import Dict, Any | |
def flatten_list_values(value: Any) -> str: | |
"""Convert list values to comma-separated strings.""" | |
if isinstance(value, list): | |
return ', '.join(str(item) for item in value) | |
return str(value) if value is not None else '' |
This is a checklist I use to harmonize scRNA-seq datasets before saving them as AnnData objects, loosely following cellxgene schema
- Check for NAs or cells labelled as None - rename all cells with such label as
'unknown'
- Store main cell type annotation to use as
adata.obs["cell_type"]
- Remove additional
adata.obs
columns containing alternative cell type annotation labels. If one or more alternative annotation labels need to be kept, rename tocell_type_*
where*
describes the difference with the main cell type annotation. - Store disease annotation to
adata.obs['disease']
, labelling healthy cells as'control'
(notControl
,healthy
,normal
)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(miloR) | |
## Load dummy data | |
data(sim_trajectory) | |
milo.meta <- sim_trajectory$meta | |
milo.obj <- Milo(sim_trajectory$SCE) | |
## Build KNN graph neighbourhoods | |
milo.obj <- buildGraph(milo.obj, k=20, d=30) | |
milo.obj <- makeNhoods(milo.obj, k=20, d=30, refined=TRUE, prop=0.2, refinement_scheme="graph") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### A collection of frequently googled snippets ### | |
## Seaborn boxplot with groups and colors | |
sns.boxplot(data=data_df, x='x', y='y', hue='color_cov') | |
## Adding axes lines to plot | |
fig,ax = plt.subplots() | |
ax.axhline(y=0, color='r', linewidth=1, linestyle='--'); ## horizontal | |
ax.axvline(y=0, color='r', linewidth=1, linestyle='--'); ## vertical | |
plt.plot(); |