Skip to content

Instantly share code, notes, and snippets.

View afrendeiro's full-sized avatar

André F. Rendeiro afrendeiro

View GitHub Profile
@afrendeiro
afrendeiro / add_tracking_to_scanpy.py
Last active February 10, 2019 11:00
Add a "tracker" attribute to AnnData objects to keep track of transformations to it's data
import scanpy.api as sc
import numpy as np
def add_tracker(field_name="tracker"):
from inspect import getcallargs
from functools import wraps
def tracker(f):
@wraps(f)
def wrapper(*args, **kwds):
@afrendeiro
afrendeiro / simple_score_within_signature.py
Created January 25, 2019 15:01
Simple method to score each sample withing the boundaries of a signature containing two blocks (e.g. gene expression signature with up- and down-regulated genes)
import pandas as pd
from sklearn.preprocessing import StandardScaler
# get list of genes of interest (e.g. from diff exp, or a known signature)
diff = pd.Index(['geneX', 'geneY'])
# X is our numeric matrix, shape (n_features, n_samples)
X = pd.DataFrame(index=['geneA', 'geneZ'], columns=['stimul_1', 'stimul_2'] + ['unstimul_1', 'unstimul_2'])
# Standardize and center
@afrendeiro
afrendeiro / fasta.fa
Last active January 10, 2019 16:31
pybedtools error related to pybedtools#147
>chr1
ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC
ATGCATGCATGCATGCATGCATGCATGCATGCATGCATGC
def plot_differential_enrichment(
enrichment_table,
enrichment_type,
data_type="ATAC-seq",
direction_dependent=True,
output_dir="results/differential_analysis_{data_type}/enrichments",
comp_variable="comparison_name",
output_prefix="differential_analysis",
rasterized=True,
@afrendeiro
afrendeiro / process_figures_for_paper.sh
Last active August 11, 2020 23:43
Convert SVG figures to high quality raster and aggregated pdfs - labeled and unlabeled figures will be produced
#!/usr/bin/env bash
# Dependencies:
# 1. inkscape
# 2. pdfunite
# 3. (optinal) minify (https://github.com/tdewolff/minify/tree/master/cmd/minify)
# `sudo apt install minify`
# Assumptions:
# 1. figures are made in SVG format
@afrendeiro
afrendeiro / figure_convert_NPG2CellPress.sh
Last active December 12, 2018 13:30
Convert SVG figures from Nature Publishing Group to CellPress style, generate high quality raster and aggregated pdfs
CURRENT_DATE=20181212
NUMBER_MAIN_FIGURES=5
NUMBER_SUPP_FIGURES=11
ROOT_DIR=/home/path/to/paper/figures
cd $ROOT_DIR
mkdir -p cropped_unlabeled_pngs
# Cell Press format convertion
@afrendeiro
afrendeiro / figure_convert_CellPress2NPG.sh
Last active December 12, 2018 13:33
Convert SVG figures from CellPress style to Nature Publishing Group style, generate high quality raster and aggregated pdfs
# Change this
CURRENT_DATE=20181212
NUMBER_MAIN_FIGURES=5
NUMBER_SUPP_FIGURES=11
ROOT_DIR=/home/path/to/paper/figures
# Don't change this
cd $ROOT_DIR
mkdir -p cropped_unlabeled_pngs
@afrendeiro
afrendeiro / process_csv.py
Last active March 26, 2018 14:37
Parse raw data out of CSV files exported from a Thrombin Generation Assay (TGA)
import os
import pandas as pd
from argparse import ArgumentParser
# Parse command-line arguments
parser = ArgumentParser(
prog="CSV parser",
description="Gets some column out of CSVs."
)
@afrendeiro
afrendeiro / ensembl_reg_build.py
Created December 28, 2017 13:48
Get Ensembl regulatory build annotations into bed format
import os
import pandas as pd
# Human
# hg38
ensembl_release = 91
date = "20161111"
organisms = {
"homo_sapiens": "GRCh38",
@afrendeiro
afrendeiro / rasterized_svg.py
Last active May 28, 2017 13:57
Mixing vector and rasterized elements in svg produced with matplotlib
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_style("white")
fig, axis = plt.subplots(1)
# all genes
axis.scatter(
np.arange(0, 8, 8./10000) + np.random.normal(0, 0.1, size=10000),