Skip to content

Instantly share code, notes, and snippets.

View wflynny's full-sized avatar

Bill Flynn wflynny

View GitHub Profile
@wflynny
wflynny / cellranger_count_scenarios.sh
Created January 23, 2019 19:55
Cellranger count snippets (version 2)
# Some universal variables
NCELLS=6000
OUTPUT_NAME="nice-name"
FASTQ_DIR="/path/to/fastqs"
REFERENCE_GENOME="/path/to/reference_dir"
[[ -z "${PBS_NUM_PPN}" ]] && NCORES=20 || NCORES=${PBS_NUM_PPN}
# When reads look like:
# sample-name_S?_L00?_R1_001.fastq.gz
# sample-name_S?_L00?_R2_001.fastq.gz
@wflynny
wflynny / build_10x_reference.sh
Last active February 5, 2019 20:01
Building 10X reference genomes from Ensembl
# Visit the Ensembl ftp site.
# ftp://ftp.ensembl.org/pub/release-95/
#
# You want to find data under the following two URLs:
# 1. ftp://ftp.ensembl.org/pub/release-95/fasta/[YOUR_SPECIES_HERE]/dna/
# 2. ftp://ftp.ensembl.org/pub/release-95/gtf/[YOUR_SPECIES_HERE]/
#
# The first file of interest is under the fasta URL:
# [YOUR_SPECIES_HERE].[ASSEMBLY].dna.primary_assembly.fa.gz
# or, if that doesn't exist,
@wflynny
wflynny / jupyter-server
Created June 6, 2019 15:28
Running jupyter on a cluster
#!/usr/bin/env bash
#### PBS preamble
#PBS -N jupyter-server
#PBS -o /path/to/software/logs/jupyter-server.${PBS_JOBID%%.*}.out
#PBS -j oe
#PBS -m n
#PBS -l mem=128GB
@wflynny
wflynny / jupyter-launch.bash
Last active June 6, 2019 15:31
Bash alias/functions to launch jupyter-server
_grab_ip() {
jobid=$1
port=$2
hostname=$(qstat -f ${jobid} | grep -oP "exec_host = (\K[a-z0-9]+)")
echo "http://${hostname}:${port}"
}
_submit_job() {
queue=$1
port=$2
@wflynny
wflynny / hto_demux.py
Last active December 18, 2019 19:54
HTO demuxing in python
from sklearn.cluster import KMeans
import numpy as np
import pandas as pd
import scanpy as sc
def load_hto_matrix(mtx_dir):
raw_htos = sc.read_mtx(mtx_dir + "/matrix.mtx.gz").T
raw_htos.var = pd.read_csv(mtx_dir + "/features.tsv.gz", header=None, index_col=0)
raw_htos.obs = pd.read_csv(mtx_dir + "/barcodes.tsv.gz", header=None, index_col=0)
raw_htos = raw_htos[:, ~raw_htos.var_names.isin(["unmapped"])]
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 (".*?");')
@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
@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 / 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 / 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