Skip to content

Instantly share code, notes, and snippets.

View emdann's full-sized avatar

Emma Dann emdann

View GitHub Profile
@emdann
emdann / pertpyDE_cheatsheet.md
Created January 9, 2025 19:18
DE analysis in pertpy - cheatsheet

Continuous covariate

# 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
@emdann
emdann / yaml2googlesheets.py
Created December 13, 2024 22:32
Convert YAML 2 google sheets
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 ''
@emdann
emdann / seurat2anndata_the_dumb_way.md
Created July 17, 2024 20:52
Making AnnData objects from datasets saved as Seurat without going crazy with installations and conversions

Make an AnnData from a Seurat object

Extract key components in R

library(Seurat)
library(Matrix)

rds_file <- '/path/to/seurat.rds'
dataset_suffix <- sub("\\.rds$", "", rds_file)
data <- readRDS(rds_file)

Checklist for saving and sharing scRNA-seq datasets

This is a checklist I use to harmonize scRNA-seq datasets before saving them as AnnData objects, loosely following cellxgene schema

Cleaning cell-level metadata

  • 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 to cell_type_* where * describes the difference with the main cell type annotation.
  • Store disease annotation to adata.obs['disease'], labelling healthy cells as 'control' (not Control, healthy, normal)
@emdann
emdann / miloR_graph_refinement.R
Created September 28, 2022 07:24
Milo implementation using graph based features for neighbourhood sampling and SpatialFDR
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")
### 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();