Skip to content

Instantly share code, notes, and snippets.

View afrendeiro's full-sized avatar

André F. Rendeiro afrendeiro

View GitHub Profile
@afrendeiro
afrendeiro / enrichr.py
Last active May 3, 2016 09:08
Function to use Enrichr's API
def enrichr(dataframe, gene_set_libraries=None, kind="genes"):
"""
Use Enrichr on a list of genes (currently only genes supported through the API).
"""
import json
import requests
import pandas
ENRICHR_ADD = 'http://amp.pharm.mssm.edu/Enrichr/addList'
#!/usr/bin/env python
import csv
import sys
# usage:
# samtools view -h file.bam | shift_reads.py genome | samtools view -S -b - | samtools sort - file.shifted
def getChrSizes(chrmFile):
"""
Reads tab-delimiter file with two rows describing the chromossomes and its lengths.
@afrendeiro
afrendeiro / enrichr.py
Created August 9, 2016 17:20
Use Enrichr's API to get enrichments of a gene set
#! /usr/bin/env python
import argparse
import pandas as pd
import json
import requests
default_gene_set_libraries = [
'GO_Biological_Process_2015',
@afrendeiro
afrendeiro / quantile_tracks.py
Created November 14, 2016 15:46
Scripts to produce Quantile bigWig files as seen in http://www.nature.com/articles/ncomms11938/figures/2
from pipelines.models import Project
import os
import pandas as pd
import pysam
# Start project
prj = Project("metadata/project_config.yaml")
prj.add_sample_sheet()
@afrendeiro
afrendeiro / merry_xmas.py
Created December 23, 2016 15:00
Merry Xmas by Jörg Mensche
# By Jörg Mensche
import matplotlib.pyplot as plt # basic plot functionalities
import seaborn as sns
# more advanced plotting
import scipy.stats as sc
# random number generator
# generate the x-mas tree:
all_branches = []
balls_x = []
@afrendeiro
afrendeiro / sra2bam.py
Last active February 9, 2017 19:41
SRA sample to unaligned bam using sra tools and sambamba, job submission through slurm
from argparse import ArgumentParser
import sys
from pypiper import NGSTk
import textwrap
global tk
tk = NGSTk()
def sra2bam(sra_acession, output_bam):
# Slurm header
@afrendeiro
afrendeiro / make_tracks.py
Last active March 2, 2017 13:54
Make a UCSC trackHub from a looper.Project
from looper.models import Project
import argparse
import os
import pandas as pd
import re
import string
import textwrap
def get_colors(level, pallete="gist_rainbow", nan_color=[0.5, 0.5, 0.5]):
@afrendeiro
afrendeiro / divideAndSlurm.py
Last active March 13, 2017 11:28
Class to perform map reduce-style operations split in jobs across high-performance computing cluster
class DivideAndSlurm(object):
"""
DivideAndSlurm is a class to handle a map-reduce style submission of jobs to a Slurm cluster.
Add a particula task to the object (though a specific function) and it will divide the input data
into pools, which will be submitted (use the submit() function) in parallel to the cluster.
Tasks can also further process its input in parallel, taking advantage of all processors.
"""
def __init__(self, tmpDir="/fhgfs/scratch/users/user/", logDir="/home/user/logs", queue="shortq", userMail=""):
super(DivideAndSlurm, self).__init__()
@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),
@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",