Skip to content

Instantly share code, notes, and snippets.

Avatar
🐄
moo

Kamil Slowikowski slowkow

🐄
moo
View GitHub Profile
@slowkow
slowkow / rotating-3d-mp4.R
Last active May 5, 2022
Make an animation to visualize millions of points in 3 dimensions.
View rotating-3d-mp4.R
library(data.table)
library(glue)
library(rgl)
# https://github.com/google/palette.js/blob/master/palette.js
mpn65 <- c(
'#ff0029', '#377eb8', '#66a61e', '#984ea3', '#00d2d5', '#ff7f00', '#af8d00',
'#7f80cd', '#b3e900', '#c42e60', '#a65628', '#f781bf', '#8dd3c7', '#bebada',
'#fb8072', '#80b1d3', '#fdb462', '#fccde5', '#bc80bd', '#ffed6f', '#c4eaff',
'#cf8c00', '#1b9e77', '#d95f02', '#e7298a', '#e6ab02', '#a6761d', '#0097ff',
@slowkow
slowkow / copy-to-google.sh
Created Mar 23, 2022
Copy files from Broad to Google
View copy-to-google.sh
#!/usr/bin/bash
#$ -N MY_JOB_NAME
#$ -o /path/on/broad/server/
#$ -e /path/on/broad/server/
#$ -cwd
#$ -j y
#$ -l h_rt=12:00:00
#$ -pe smp 8 -R y -binding linear:8
#$ -l h_vmem=2G
#
@slowkow
slowkow / plot-umap-experiment.R
Last active May 22, 2022
UMAP on 30k cells with different values for min_dist and spread
View plot-umap-experiment.R
library(uwot)
library(scattermore)
library(foreach)
library(doParallel)
library(data.table)
library(ggplot2)
library(scales)
library(glue)
# This code snippet assumes we have these objects:
@slowkow
slowkow / pay-water-bill.py
Created May 3, 2021
Pay your water bill in Baltimore City
View pay-water-bill.py
#!/usr/bin/env python3
# pay-water-bill.py
# 2021-05-02
"""
Pay your water bill in Baltimore City
=====================================
Steps:
@slowkow
slowkow / montage.py
Created Dec 23, 2020
Make a montage from a list of PDF files
View montage.py
#!/usr/bin/env python
"""
montage.py
2020-12-23
Kamil Slowikowski
Usage
-----
Write montage.png from a list of PDF files, each panel 500px wide:
@slowkow
slowkow / rsa-example.R
Created Oct 21, 2020
A toy example of RSA encryption and decryption
View rsa-example.R
#!/usr/bin/env Rscript
# rsa-example.R
#
# Inspired by Alex Van de Sande
# https://twitter.com/avsa/status/1318672796415819776
last_digit <- function(x) {
x_char <- as.character(x)
as.numeric(substr(x_char, nchar(x_char), nchar(x_char)))
}
@slowkow
slowkow / income.svg
Last active Oct 15, 2020
Trends in Income From 1975 to 2018 by Carter C. Price, Kathryn A. Edwards
View income.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@slowkow
slowkow / writeMMgz.R
Created Mar 16, 2020
Write a gzip compressed Matrix Market file in R.
View writeMMgz.R
#' @param x A sparse matrix from the Matrix package.
#' @param file A filename that ends in ".gz".
writeMMgz <- function(x, file) {
mtype <- "real"
if (is(x, "ngCMatrix")) {
mtype <- "integer"
}
writeLines(
c(
sprintf("%%%%MatrixMarket matrix coordinate %s general", mtype),
@slowkow
slowkow / needleman-wunsch.py
Last active Jun 13, 2022
A simple version of the Needleman-Wunsch algorithm in Python.
View needleman-wunsch.py
#!/usr/bin/env python
"""
The Needleman-Wunsch Algorithm
==============================
This is a dynamic programming algorithm for finding the optimal alignment of
two strings.
Example
-------
@slowkow
slowkow / read_cellranger.R
Last active May 13, 2022
Read Cell Ranger HDF5 .h5 files in R
View read_cellranger.R
# install.packages(c("Matrix", "rhdf5", "tidyverse"))
library(Matrix)
library(rhdf5)
library(tidyverse)
library(glue)
my_h5_files <- Sys.glob(
"path/to/cellranger-per-channel/output/*/filtered_feature_bc_matrix.h5"
)