Skip to content

Instantly share code, notes, and snippets.

View wflynny's full-sized avatar

Bill Flynn wflynny

View GitHub Profile
@wflynny
wflynny / scanpy_cluster_proportions.py
Last active October 13, 2023 17:42
Stacked barplot of scRNA-seq cluster proportions per sample
import scanpy.api as sc
import matplotlib.pyplot as plt
import seaborn as sns
def get_cluster_proportions(adata,
cluster_key="cluster_final",
sample_key="replicate",
drop_values=None):
"""
Input
@wflynny
wflynny / gist:d6c95deadf0c4d1cce4f01a729314dbb
Created January 24, 2019 21:20
Illumina sequencer identifiers in fastq read headers
# Find myself referring to this thread a lot:
# https://www.biostars.org/p/198143/
# However updating codes with what I see at JAX
@Mxxxx - MiSeq
@Dxxxx - HiSeq 2500
@Kxxxx - HiSeq 4000
@NSxxx - NextSeq 500/550
@Axxxxx - NovaSeq
@wflynny
wflynny / loupe_generation.md
Last active October 3, 2021 17:13
Generate a 10x Genomics Loupe file with custom annotations and projections:
@wflynny
wflynny / gse_to_adata.py
Created May 12, 2021 14:51
Convert a GSE microarray to AnnData
import scanpy as sc
import pandas as pd
import GEOparse
def gse_to_adata(gse):
X = gse.pivot_samples("VALUE")
key = list(gse.gpls.keys())[0]
annotated = X.index.to_frame(index=False).merge(
gse.gpls[key].table[["ID", "Gene Symbol"]],
left_on="ID_REF", right_on="ID"
@wflynny
wflynny / gpfs_expiration_checker.sh
Created January 24, 2019 20:05
Check file lifetime stats on a GPFS
# I usually put this in my ~/.bash_aliases
# A portion of our GPFS storage removes files after 21 days of creation.
# `stat` does not show creation time, so we have to resort to parsing the
# output of `mmlsattr`
ftime() {
# Usage:
# ftime path/to/file
#
# Outputs:
@wflynny
wflynny / gist:ba14df9fe553fd3f1fa63b5c5606e8d3
Created February 2, 2021 21:59
cellphonedb chord plot
###################
# chord diagram
import matplotlib.pyplot as plt
from matplotlib.path import Path as mplPath
import matplotlib.patches as patches
import numpy as np
import pandas as pd
LW = 0.3
@wflynny
wflynny / fancy_legend.py
Created December 17, 2020 20:43
Add annotation cluster numbers to UMAP plots
from matplotlib.text import Annotation
from matplotlib.legend_handler import HandlerBase
from matplotlib import patheffects
from matplotlib.colors import CSS4_COLORS, hex2color
class AnnotationHandler(HandlerBase):
def create_artists(self, legend, artist, xdescent, ydescent,
width, height, fontsize, trans):
a = Annotation(
artist.get_text(), [width/2, height/2],
@wflynny
wflynny / stitch_harmony_export.py
Last active September 17, 2020 20:17
Stitch together tiles of a slide exported from PE Harmony
import re
from pathlib import Path
from xml.etree import ElementTree as ET
import numpy as np
from skimage import exposure
from skimage.io import imread, imsave, imshow
from skimage.filters import threshold_otsu, gaussian
@wflynny
wflynny / susage
Last active July 29, 2020 02:00
Small utility to run top or nvidia-smi on a compute node from the login node
#!/usr/bin/env bash
TEMP=$(getopt -o hsg --long help,snapshot,gpu -n 'susuage' -- "$@")
if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"
SNAPSHOT=false
import re
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--infile", required=True)
parser.add_argument("-o", "--outfile", required=True)
args = parser.parse_args()
gene_matcher = re.compile('\tgene\t.*gene_id (".*?");.*Name (".*?");')
parent_matcher = re.compile('gene_id (".*?");.*Parent (".*?");')