Skip to content

Instantly share code, notes, and snippets.

@yjzhang
yjzhang / cocluster_heatmap.py
Created June 13, 2019 22:56
spectral coclustering heatmap
import numpy as np
from sklearn.cluster.bicluster import SpectralCoclustering
spec = SpectralCoclustering(18)
cluster_counts_subset = np.vstack([cluster_counts[:31, :], cluster_counts[32:,:]])
spec.fit(cluster_counts + 0.0001)
row_labels = spec.row_labels_
column_labels = spec.column_labels_
row_order = np.argsort(row_labels)
# makes an svg bingo board
import svgwrite
def text_to_font_size(text):
if isinstance(text, str):
total_text = text
else:
total_text = ''.join(text)
if len(total_text) < 10:
return 18
@yjzhang
yjzhang / merge_dges.py
Last active May 28, 2019 18:12
merges multiple DGEs/gene matrices generated by the split seq pipeline.
#!/usr/bin/env python
# merge DGE matrices from multiple runs of split-seq
# joins on genes...
import os
import sys
import numpy as np
import pandas as pd
@yjzhang
yjzhang / run_split_seq.sh
Last active May 25, 2019 04:19
script for running split-seq
#!/bin/bash
# run using 'nohup sh run_split_seq.sh &'
nohup split-seq all --fq1 Matthew_77_S1_R1_001.fastq.gz --fq2 Matthew_77_S1_R2_001.fastq.gz --output_dir output --chemistry v2 --genome_dir /data/reference_genomes/mm10/ --nthreads 16
@yjzhang
yjzhang / download_aws.sh
Created May 25, 2019 04:08
download data from aws
#!/bin/bash
for i in $(seq 1 18); do
aws s3 cp --recursive s3://sdfas/S${i}_L1_outputDGE_filtered S${i}_L1_outputDGE_filtered
aws s3 cp --recursive s3://sdfas/S${i}_L2_outputDGE_filtered S${i}_L2_outputDGE_filtered
done
@yjzhang
yjzhang / kill_gunicorn.sh
Created February 16, 2019 01:29
kills all gunicorn processes with a certain port number. useful for when there are multiple gunicorns running on different ports.
#!/bin/bash
# kills all gunicorn processes with 8889
pids=`ps ax | grep gunicorn | grep "8889" | awk '{split($0,a," "); print a[1]}'`
# TODO
for pid in $pids; do
killall -9 $pid
echo "killed gunicorn process $pid"
done
#!/bin/bash
for var in "$@"; do
filename=${var%.*}
#echo $filename
#echo $@
echo writing to $filename.html
pandoc $var --self-contained --toc -c /home/yjzhang/Dropbox/Notes/buttondown.css -s --mathml -o $filename.html
done
@yjzhang
yjzhang / flatten.py
Created November 18, 2018 07:14
flattening a list in python
def flatten(l):
output = []
for x in l:
try:
output += flatten(x)
except:
output.append(x)
return output
class TrieNode(object):
def __init__(self, char = '', children = {}, parent = None, wordEnd = False, value = True):
self.char = char
self.children = children
self.parent = parent
self.wordEnd = wordEnd
self.value = value
# simple implementation of quantile normalization?
import numpy as np
def quantile_norm(data):
"""
Source: https://en.wikipedia.org/wiki/Quantile_normalization
Note: this doesn't deal with ties very well.
Args: