Skip to content

Instantly share code, notes, and snippets.

View slowkow's full-sized avatar
🐄
moooooo

Kamil Slowikowski slowkow

🐄
moooooo
View GitHub Profile
@slowkow
slowkow / index.html
Last active November 3, 2024 17:38
Karabiner-Elements mouse4 to back and mouse5 to forward
<html>
<body>
<a href="karabiner://karabiner/assets/complex_modifications/import?url=https%3A%2F%2Fgist.githubusercontent.com%2Fslowkow%2F275e53573e2aeb60c8304add1e54faf5%2Fraw%2Fc63540925dba76f46293834c24700ebf1578ed10%2Fmouse-buttons-back-forward.json">click here to import into Karabiner-Elements</a>
</body>
</html>
@slowkow
slowkow / rotating-3d-mp4.R
Last active October 21, 2024 18:46
Make an animation to visualize millions of points in 3 dimensions.
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 / read_cellranger.R
Last active October 21, 2024 07:50
Read Cell Ranger HDF5 .h5 files in 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"
)
@slowkow
slowkow / counts_to_tpm.R
Last active October 8, 2024 02:00
Convert read counts to transcripts per million (TPM).
#' Convert counts to transcripts per million (TPM).
#'
#' Convert a numeric matrix of features (rows) and conditions (columns) with
#' raw feature counts to transcripts per million.
#'
#' Lior Pachter. Models for transcript quantification from RNA-Seq.
#' arXiv:1104.3889v2
#'
#' Wagner, et al. Measurement of mRNA abundance using RNA-seq data:
#' RPKM measure is inconsistent among samples. Theory Biosci. 24 July 2012.
@slowkow
slowkow / remove-emoji.py
Created July 19, 2018 14:10
Remove all traces of emoji from a text file.
#!/usr/bin/env python
"""
Remove emoji from a text file and print it to stdout.
Usage
-----
python remove-emoji.py input.txt > output.txt
"""
@slowkow
slowkow / install-units.md
Last active September 8, 2024 02:54
Install the 'units' R package on Partners

Summary

I had a difficult time installing the units R package on the Partners ERIS servers.

I hope this post helps you to figure out how to work around the errors.

Instructions

@slowkow
slowkow / rpkm_versus_tpm.R
Created December 8, 2015 16:14
Comparison of RPKM (reads per kilobase per million) and TPM (transcripts per million).
# RPKM versus TPM
#
# RPKM and TPM are both normalized for library size and gene length.
#
# RPKM is not comparable across different samples.
#
# For more details, see: http://blog.nextgenetics.net/?e=51
rpkm <- function(counts, lengths) {
rate <- counts / lengths
@slowkow
slowkow / plot-umap-experiment.R
Last active August 18, 2024 09:07
UMAP on 30k cells with different values for min_dist and spread
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 / Apache www-data setup
Last active August 4, 2024 21:21 — forked from milo/github-webhook-handler.php
Github webhook handler in PHP.
sudo mkdir -m 0700 /var/www/.ssh
sudo chown -R www-data:www-data /var/www/.ssh
sudo -u www-data ssh-keygen (empty passphrase)
# On Github, paste public key into "Deploy keys"
sudo -u www-data bash
cd /path/to/repo
git clone ...
@slowkow
slowkow / zotero-pdf-program.md
Last active August 1, 2024 09:21
Open pdfs in Zotero with a different program than your other pdfs

I want to open pdf files with program A unless it is stored in Zotero, in which case I want to open it program B.

  1. Change the OS settings, so the default program for opening pdf files is the shell script shown below.
  2. Set Zotero preferences to store files in "zotero-data".

Below, I use playonlinux to launch Foxit Reader for my Zotero pdf files because Foxit has nice highlighting and annotation features that I like to use on scientific articles. I use [evince][4] for all other pdf files (figures, books, documents, etc.)